xref: /optee_os/core/drivers/crypto/caam/ae/local.h (revision 5395f0367b77ee32ac7ffbf7012af46c24fd3c56)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2024 NXP
4  */
5 #ifndef __LOCAL_H__
6 #define __LOCAL_H__
7 
8 #include <caam_utils_dmaobj.h>
9 #include <drvcrypt.h>
10 #include <drvcrypt_authenc.h>
11 
12 /* Maximum AAD size */
13 #define AAD_LENGTH_OVERFLOW 0xFF00
14 
15 /*
16  * Cipher Algorithm definition
17  * @type:		Algo type for operation
18  * @size_block:		Computing block size
19  * @size_ctx:		CAAM Context Register size
20  * @ctx_offset:		CAAM Context Register offset
21  * @def_key:		Define accepted key size
22  * @initialize:		Initialize function
23  * @final:		Final function
24  */
25 struct cipheralg {
26 	uint32_t type;
27 	uint8_t size_block;
28 	uint8_t size_ctx;
29 	uint8_t ctx_offset;
30 	struct caamdefkey def_key;
31 
32 	TEE_Result (*initialize)(struct drvcrypt_authenc_init *dinit);
33 	TEE_Result (*final)(struct drvcrypt_authenc_final *dfinal);
34 };
35 
36 /*
37  * CAAM Authenticated Encryption Context
38  *
39  * @descriptor:		Job descriptor
40  * @tag_length:		Hash tag length
41  * @aad_length:		Additional data length
42  * @payload_length:	Data length
43  * @encrypt:		Encrypt direction
44  * @key:		Cipher key
45  * @initial_ctx:	Initial CCM context
46  * @ctx:		Saved context for multi-part update
47  * @nonce:		Initial GCM Nonce value
48  * @buf_add:		Additional Data buffer if needed
49  * @blockbuf:		Temporary Block buffer
50  * @do_block:		Block Encryption operation function
51  * @alg:		Reference to the algo constants
52  */
53 struct caam_ae_ctx {
54 	uint32_t *descriptor;
55 
56 	size_t tag_length;
57 	size_t aad_length;
58 	size_t payload_length;
59 
60 	bool encrypt;
61 
62 	struct caambuf key;
63 	struct caambuf initial_ctx;
64 	struct caambuf ctx;
65 	struct caambuf nonce;
66 
67 	struct caamblock buf_aad;
68 	struct caamblock blockbuf;
69 
70 	bool (*do_block)(struct caam_ae_ctx *caam_ctx, bool encrypt,
71 			 struct caamdmaobj *src, struct caamdmaobj *dst,
72 			 bool final);
73 
74 	const struct cipheralg *alg;
75 };
76 
77 /*
78  * Update of the Authenticated Encryption Operation.
79  *
80  * @ctx      AE Cipher context
81  * @src      Source data to encrypt/decrypt
82  * @dst      [out] Destination data encrypted/decrypted
83  * @last     Last update flag
84  */
85 TEE_Result caam_ae_do_update(struct caam_ae_ctx *ctx, struct drvcrypt_buf *src,
86 			     struct drvcrypt_buf *dst, bool last);
87 
88 /*
89  * Initialization of the AES GCM operation
90  *
91  * @dinit  Data initialization object
92  */
93 TEE_Result caam_ae_initialize_gcm(struct drvcrypt_authenc_init *dinit);
94 
95 /*
96  * Finalize the AES GCM operation
97  *
98  * @dfinal  Last data object
99  */
100 TEE_Result caam_ae_final_gcm(struct drvcrypt_authenc_final *dfinal);
101 
102 /*
103  * Initialization of the AES CCM operation
104  *
105  * @dinit  Data initialization object
106  */
107 TEE_Result caam_ae_initialize_ccm(struct drvcrypt_authenc_init *dinit);
108 
109 /*
110  * Finalize the AES CCM operation
111  *
112  * @dfinal  Last data object
113  */
114 TEE_Result caam_ae_final_ccm(struct drvcrypt_authenc_final *dfinal);
115 
116 #endif /* __LOCAL_H__ */
117