1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright 2018-2019 NXP 4 * 5 * CAAM Cipher Local header. 6 */ 7 #ifndef __LOCAL_H__ 8 #define __LOCAL_H__ 9 10 #include <drvcrypt.h> 11 #include <drvcrypt_cipher.h> 12 13 /* 14 * Definition of flags tagging which key(s) is required 15 */ 16 #define NEED_KEY1 BIT(0) 17 #define NEED_KEY2 BIT(1) 18 #define NEED_IV BIT(2) 19 #define NEED_TWEAK BIT(3) 20 21 /* 22 * Cipher Algorithm definition 23 */ 24 struct cipheralg { 25 uint32_t type; /* Algo type for operation */ 26 uint8_t size_block; /* Computing block size */ 27 uint8_t size_ctx; /* CAAM Context Register size */ 28 uint8_t ctx_offset; /* CAAM Context Register offset */ 29 uint8_t require_key; /* Tag defining key(s) required */ 30 struct caamdefkey def_key; /* Key size accepted */ 31 32 TEE_Result (*update)(struct drvcrypt_cipher_update *dupdate); 33 }; 34 35 /* 36 * Full Cipher data SW context 37 */ 38 struct cipherdata { 39 uint32_t *descriptor; /* Job descriptor */ 40 bool encrypt; /* Encrypt direction */ 41 struct caambuf key1; /* First Key */ 42 struct caambuf key2; /* Second Key */ 43 struct caambuf tweak; /* XTS Tweak */ 44 struct caambuf ctx; /* CAAM Context Register */ 45 struct caamblock blockbuf; /* Temporary Block buffer */ 46 const struct cipheralg *alg; /* Reference to the algo constants */ 47 }; 48 49 /* 50 * Update of the cipher operation of complete block except 51 * if last block. Last block can be partial block. 52 * 53 * @ctx Cipher context 54 * @savectx Save or not the context 55 * @keyid Id of the key to be used during operation 56 * @encrypt Encrypt or decrypt direction 57 * @src Source data to encrypt/decrypt 58 * @dst [out] Destination data encrypted/decrypted 59 * @blockbuf Saved block during previous streaming update 60 */ 61 enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx, 62 uint8_t keyid, bool encrypt, 63 struct caambuf *src, struct caambuf *dst, 64 bool blockbuf); 65 66 /* 67 * Update of the cipher operation in xts mode. 68 * 69 * @dupdate Data update object 70 */ 71 TEE_Result caam_cipher_update_xts(struct drvcrypt_cipher_update *dupdate); 72 73 #endif /* __LOCAL_H__ */ 74