xref: /optee_os/core/include/crypto/crypto.h (revision 52ee414bd86e52e105b7ea0da2ee544f90d3b18b)
11bb92983SJerome Forissier /* SPDX-License-Identifier: BSD-2-Clause */
2e1770e71SJens Wiklander /*
3e1770e71SJens Wiklander  * Copyright (c) 2014-2017, Linaro Limited
4e1770e71SJens Wiklander  */
5e1770e71SJens Wiklander 
6e1770e71SJens Wiklander /*
7e1770e71SJens Wiklander  * This is the Cryptographic Provider API (CP API).
8e1770e71SJens Wiklander  *
9e1770e71SJens Wiklander  * This defines how most crypto syscalls that implement the Cryptographic
10e1770e71SJens Wiklander  * Operations API can invoke the actual providers of cryptographic algorithms
11e1770e71SJens Wiklander  * (such as LibTomCrypt).
12e1770e71SJens Wiklander  *
13e1770e71SJens Wiklander  * To add a new provider, you need to provide an implementation of this
14e1770e71SJens Wiklander  * interface.
15e1770e71SJens Wiklander  *
16e1770e71SJens Wiklander  * The following parameters are commonly used.
17e1770e71SJens Wiklander  *
18e1770e71SJens Wiklander  * @ctx: context allocated by the syscall, for later use by the algorithm
19e1770e71SJens Wiklander  * @algo: algorithm identifier (TEE_ALG_*)
20e1770e71SJens Wiklander  */
21e1770e71SJens Wiklander 
22e1770e71SJens Wiklander #ifndef __CRYPTO_CRYPTO_H
23e1770e71SJens Wiklander #define __CRYPTO_CRYPTO_H
24e1770e71SJens Wiklander 
25e1770e71SJens Wiklander #include <tee_api_types.h>
26e1770e71SJens Wiklander 
27e1770e71SJens Wiklander TEE_Result crypto_init(void);
28e1770e71SJens Wiklander 
29e1770e71SJens Wiklander /* Message digest functions */
30ecf2e014SJens Wiklander TEE_Result crypto_hash_alloc_ctx(void **ctx, uint32_t algo);
316b3a371cSJens Wiklander TEE_Result crypto_hash_init(void *ctx);
326b3a371cSJens Wiklander TEE_Result crypto_hash_update(void *ctx, const uint8_t *data, size_t len);
336b3a371cSJens Wiklander TEE_Result crypto_hash_final(void *ctx, uint8_t *digest, size_t len);
346b3a371cSJens Wiklander void crypto_hash_free_ctx(void *ctx);
356b3a371cSJens Wiklander void crypto_hash_copy_state(void *dst_ctx, void *src_ctx);
36e1770e71SJens Wiklander 
37e1770e71SJens Wiklander /* Symmetric ciphers */
3872a9b1a0SJens Wiklander TEE_Result crypto_cipher_alloc_ctx(void **ctx, uint32_t algo);
39cbda7091SJens Wiklander TEE_Result crypto_cipher_init(void *ctx, TEE_OperationMode mode,
40e1770e71SJens Wiklander 			      const uint8_t *key1, size_t key1_len,
41e1770e71SJens Wiklander 			      const uint8_t *key2, size_t key2_len,
42e1770e71SJens Wiklander 			      const uint8_t *iv, size_t iv_len);
43cbda7091SJens Wiklander TEE_Result crypto_cipher_update(void *ctx, TEE_OperationMode mode,
44cbda7091SJens Wiklander 				bool last_block, const uint8_t *data,
45cbda7091SJens Wiklander 				size_t len, uint8_t *dst);
46cbda7091SJens Wiklander void crypto_cipher_final(void *ctx);
47e1770e71SJens Wiklander TEE_Result crypto_cipher_get_block_size(uint32_t algo, size_t *size);
48cbda7091SJens Wiklander void crypto_cipher_free_ctx(void *ctx);
49cbda7091SJens Wiklander void crypto_cipher_copy_state(void *dst_ctx, void *src_ctx);
50e1770e71SJens Wiklander 
51e1770e71SJens Wiklander /* Message Authentication Code functions */
5282ef73bcSJens Wiklander TEE_Result crypto_mac_alloc_ctx(void **ctx, uint32_t algo);
53c69bc615SJens Wiklander TEE_Result crypto_mac_init(void *ctx, const uint8_t *key, size_t len);
54c69bc615SJens Wiklander TEE_Result crypto_mac_update(void *ctx, const uint8_t *data, size_t len);
55c69bc615SJens Wiklander TEE_Result crypto_mac_final(void *ctx, uint8_t *digest, size_t digest_len);
56c69bc615SJens Wiklander void crypto_mac_free_ctx(void *ctx);
57c69bc615SJens Wiklander void crypto_mac_copy_state(void *dst_ctx, void *src_ctx);
58e1770e71SJens Wiklander 
59e1770e71SJens Wiklander /* Authenticated encryption */
60d7ac7d0fSJens Wiklander TEE_Result crypto_authenc_alloc_ctx(void **ctx, uint32_t algo);
61*52ee414bSJens Wiklander TEE_Result crypto_authenc_init(void *ctx, TEE_OperationMode mode,
62e1770e71SJens Wiklander 			       const uint8_t *key, size_t key_len,
63e1770e71SJens Wiklander 			       const uint8_t *nonce, size_t nonce_len,
64e1770e71SJens Wiklander 			       size_t tag_len, size_t aad_len,
65e1770e71SJens Wiklander 			       size_t payload_len);
66*52ee414bSJens Wiklander TEE_Result crypto_authenc_update_aad(void *ctx, TEE_OperationMode mode,
67e1770e71SJens Wiklander 				     const uint8_t *data, size_t len);
68*52ee414bSJens Wiklander TEE_Result crypto_authenc_update_payload(void *ctx, TEE_OperationMode mode,
69e1770e71SJens Wiklander 					 const uint8_t *src_data,
70e1770e71SJens Wiklander 					 size_t src_len, uint8_t *dst_data,
71e1770e71SJens Wiklander 					 size_t *dst_len);
72*52ee414bSJens Wiklander TEE_Result crypto_authenc_enc_final(void *ctx, const uint8_t *src_data,
73*52ee414bSJens Wiklander 				    size_t src_len, uint8_t *dst_data,
74*52ee414bSJens Wiklander 				    size_t *dst_len, uint8_t *dst_tag,
75*52ee414bSJens Wiklander 				    size_t *dst_tag_len);
76*52ee414bSJens Wiklander TEE_Result crypto_authenc_dec_final(void *ctx, const uint8_t *src_data,
77*52ee414bSJens Wiklander 				    size_t src_len, uint8_t *dst_data,
78*52ee414bSJens Wiklander 				    size_t *dst_len, const uint8_t *tag,
79*52ee414bSJens Wiklander 				    size_t tag_len);
80*52ee414bSJens Wiklander void crypto_authenc_final(void *ctx);
81*52ee414bSJens Wiklander void crypto_authenc_free_ctx(void *ctx);
82*52ee414bSJens Wiklander void crypto_authenc_copy_state(void *dst_ctx, void *src_ctx);
83e1770e71SJens Wiklander 
84e1770e71SJens Wiklander /* Implementation-defined big numbers */
85e1770e71SJens Wiklander 
86e1770e71SJens Wiklander /*
87e1770e71SJens Wiklander  * Allocate a bignum capable of holding an unsigned integer value of
88e1770e71SJens Wiklander  * up to bitsize bits
89e1770e71SJens Wiklander  */
90e1770e71SJens Wiklander struct bignum *crypto_bignum_allocate(size_t size_bits);
91e1770e71SJens Wiklander TEE_Result crypto_bignum_bin2bn(const uint8_t *from, size_t fromsize,
92e1770e71SJens Wiklander 				struct bignum *to);
93e1770e71SJens Wiklander size_t crypto_bignum_num_bytes(struct bignum *a);
94e1770e71SJens Wiklander size_t crypto_bignum_num_bits(struct bignum *a);
95e1770e71SJens Wiklander void crypto_bignum_bn2bin(const struct bignum *from, uint8_t *to);
96e1770e71SJens Wiklander void crypto_bignum_copy(struct bignum *to, const struct bignum *from);
97e1770e71SJens Wiklander void crypto_bignum_free(struct bignum *a);
98e1770e71SJens Wiklander void crypto_bignum_clear(struct bignum *a);
99e1770e71SJens Wiklander 
100e1770e71SJens Wiklander /* return -1 if a<b, 0 if a==b, +1 if a>b */
101e1770e71SJens Wiklander int32_t crypto_bignum_compare(struct bignum *a, struct bignum *b);
102e1770e71SJens Wiklander 
103e1770e71SJens Wiklander /* Asymmetric algorithms */
104e1770e71SJens Wiklander 
105e1770e71SJens Wiklander struct rsa_keypair {
106e1770e71SJens Wiklander 	struct bignum *e;	/* Public exponent */
107e1770e71SJens Wiklander 	struct bignum *d;	/* Private exponent */
108e1770e71SJens Wiklander 	struct bignum *n;	/* Modulus */
109e1770e71SJens Wiklander 
110e1770e71SJens Wiklander 	/* Optional CRT parameters (all NULL if unused) */
111e1770e71SJens Wiklander 	struct bignum *p;	/* N = pq */
112e1770e71SJens Wiklander 	struct bignum *q;
113e1770e71SJens Wiklander 	struct bignum *qp;	/* 1/q mod p */
114e1770e71SJens Wiklander 	struct bignum *dp;	/* d mod (p-1) */
115e1770e71SJens Wiklander 	struct bignum *dq;	/* d mod (q-1) */
116e1770e71SJens Wiklander };
117e1770e71SJens Wiklander 
118e1770e71SJens Wiklander struct rsa_public_key {
119e1770e71SJens Wiklander 	struct bignum *e;	/* Public exponent */
120e1770e71SJens Wiklander 	struct bignum *n;	/* Modulus */
121e1770e71SJens Wiklander };
122e1770e71SJens Wiklander 
123e1770e71SJens Wiklander struct dsa_keypair {
124e1770e71SJens Wiklander 	struct bignum *g;	/* Generator of subgroup (public) */
125e1770e71SJens Wiklander 	struct bignum *p;	/* Prime number (public) */
126e1770e71SJens Wiklander 	struct bignum *q;	/* Order of subgroup (public) */
127e1770e71SJens Wiklander 	struct bignum *y;	/* Public key */
128e1770e71SJens Wiklander 	struct bignum *x;	/* Private key */
129e1770e71SJens Wiklander };
130e1770e71SJens Wiklander 
131e1770e71SJens Wiklander struct dsa_public_key {
132e1770e71SJens Wiklander 	struct bignum *g;	/* Generator of subgroup (public) */
133e1770e71SJens Wiklander 	struct bignum *p;	/* Prime number (public) */
134e1770e71SJens Wiklander 	struct bignum *q;	/* Order of subgroup (public) */
135e1770e71SJens Wiklander 	struct bignum *y;	/* Public key */
136e1770e71SJens Wiklander };
137e1770e71SJens Wiklander 
138e1770e71SJens Wiklander struct dh_keypair {
139e1770e71SJens Wiklander 	struct bignum *g;	/* Generator of Z_p (shared) */
140e1770e71SJens Wiklander 	struct bignum *p;	/* Prime modulus (shared) */
141e1770e71SJens Wiklander 	struct bignum *x;	/* Private key */
142e1770e71SJens Wiklander 	struct bignum *y;	/* Public key y = g^x */
143e1770e71SJens Wiklander 
144e1770e71SJens Wiklander 	/*
145e1770e71SJens Wiklander 	 * Optional parameters used by key generation.
146e1770e71SJens Wiklander 	 * When not used, q == NULL and xbits == 0
147e1770e71SJens Wiklander 	 */
148e1770e71SJens Wiklander 	struct bignum *q;	/* x must be in the range [2, q-2] */
149e1770e71SJens Wiklander 	uint32_t xbits;		/* Number of bits in the private key */
150e1770e71SJens Wiklander };
151e1770e71SJens Wiklander 
152e1770e71SJens Wiklander struct ecc_public_key {
153e1770e71SJens Wiklander 	struct bignum *x;	/* Public value x */
154e1770e71SJens Wiklander 	struct bignum *y;	/* Public value y */
155e1770e71SJens Wiklander 	uint32_t curve;	        /* Curve type */
156e1770e71SJens Wiklander };
157e1770e71SJens Wiklander 
158e1770e71SJens Wiklander struct ecc_keypair {
159e1770e71SJens Wiklander 	struct bignum *d;	/* Private value */
160e1770e71SJens Wiklander 	struct bignum *x;	/* Public value x */
161e1770e71SJens Wiklander 	struct bignum *y;	/* Public value y */
162e1770e71SJens Wiklander 	uint32_t curve;	        /* Curve type */
163e1770e71SJens Wiklander };
164e1770e71SJens Wiklander 
165e1770e71SJens Wiklander /*
166e1770e71SJens Wiklander  * Key allocation functions
167e1770e71SJens Wiklander  * Allocate the bignum's inside a key structure.
168e1770e71SJens Wiklander  * TEE core will later use crypto_bignum_free().
169e1770e71SJens Wiklander  */
170e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_rsa_keypair(struct rsa_keypair *s,
171e1770e71SJens Wiklander 				size_t key_size_bits);
172e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_rsa_public_key(struct rsa_public_key *s,
173e1770e71SJens Wiklander 				   size_t key_size_bits);
174e1770e71SJens Wiklander void crypto_acipher_free_rsa_public_key(struct rsa_public_key *s);
175e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_dsa_keypair(struct dsa_keypair *s,
176e1770e71SJens Wiklander 				size_t key_size_bits);
177e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_dsa_public_key(struct dsa_public_key *s,
178e1770e71SJens Wiklander 				   size_t key_size_bits);
179e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_dh_keypair(struct dh_keypair *s,
180e1770e71SJens Wiklander 			       size_t key_size_bits);
181e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_ecc_public_key(struct ecc_public_key *s,
182e1770e71SJens Wiklander 				   size_t key_size_bits);
183e1770e71SJens Wiklander TEE_Result crypto_acipher_alloc_ecc_keypair(struct ecc_keypair *s,
184e1770e71SJens Wiklander 				size_t key_size_bits);
185e1770e71SJens Wiklander void crypto_acipher_free_ecc_public_key(struct ecc_public_key *s);
186e1770e71SJens Wiklander 
187e1770e71SJens Wiklander /*
188e1770e71SJens Wiklander  * Key generation functions
189e1770e71SJens Wiklander  */
190e1770e71SJens Wiklander TEE_Result crypto_acipher_gen_rsa_key(struct rsa_keypair *key, size_t key_size);
191e1770e71SJens Wiklander TEE_Result crypto_acipher_gen_dsa_key(struct dsa_keypair *key, size_t key_size);
192e1770e71SJens Wiklander TEE_Result crypto_acipher_gen_dh_key(struct dh_keypair *key, struct bignum *q,
193e1770e71SJens Wiklander 				     size_t xbits);
194e1770e71SJens Wiklander TEE_Result crypto_acipher_gen_ecc_key(struct ecc_keypair *key);
195e1770e71SJens Wiklander 
196e1770e71SJens Wiklander TEE_Result crypto_acipher_dh_shared_secret(struct dh_keypair *private_key,
197e1770e71SJens Wiklander 					   struct bignum *public_key,
198e1770e71SJens Wiklander 					   struct bignum *secret);
199e1770e71SJens Wiklander 
200e1770e71SJens Wiklander TEE_Result crypto_acipher_rsanopad_decrypt(struct rsa_keypair *key,
201e1770e71SJens Wiklander 					   const uint8_t *src, size_t src_len,
202e1770e71SJens Wiklander 					   uint8_t *dst, size_t *dst_len);
203e1770e71SJens Wiklander TEE_Result crypto_acipher_rsanopad_encrypt(struct rsa_public_key *key,
204e1770e71SJens Wiklander 					   const uint8_t *src, size_t src_len,
205e1770e71SJens Wiklander 					   uint8_t *dst, size_t *dst_len);
206e1770e71SJens Wiklander TEE_Result crypto_acipher_rsaes_decrypt(uint32_t algo, struct rsa_keypair *key,
207e1770e71SJens Wiklander 					const uint8_t *label, size_t label_len,
208e1770e71SJens Wiklander 					const uint8_t *src, size_t src_len,
209e1770e71SJens Wiklander 					uint8_t *dst, size_t *dst_len);
210e1770e71SJens Wiklander TEE_Result crypto_acipher_rsaes_encrypt(uint32_t algo,
211e1770e71SJens Wiklander 					struct rsa_public_key *key,
212e1770e71SJens Wiklander 					const uint8_t *label, size_t label_len,
213e1770e71SJens Wiklander 					const uint8_t *src, size_t src_len,
214e1770e71SJens Wiklander 					uint8_t *dst, size_t *dst_len);
215e1770e71SJens Wiklander /* RSA SSA sign/verify: if salt_len == -1, use default value */
216e1770e71SJens Wiklander TEE_Result crypto_acipher_rsassa_sign(uint32_t algo, struct rsa_keypair *key,
217e1770e71SJens Wiklander 				      int salt_len, const uint8_t *msg,
218e1770e71SJens Wiklander 				      size_t msg_len, uint8_t *sig,
219e1770e71SJens Wiklander 				      size_t *sig_len);
220e1770e71SJens Wiklander TEE_Result crypto_acipher_rsassa_verify(uint32_t algo,
221e1770e71SJens Wiklander 					struct rsa_public_key *key,
222e1770e71SJens Wiklander 					int salt_len, const uint8_t *msg,
223e1770e71SJens Wiklander 					size_t msg_len, const uint8_t *sig,
224e1770e71SJens Wiklander 					size_t sig_len);
225e1770e71SJens Wiklander TEE_Result crypto_acipher_dsa_sign(uint32_t algo, struct dsa_keypair *key,
226e1770e71SJens Wiklander 				   const uint8_t *msg, size_t msg_len,
227e1770e71SJens Wiklander 				   uint8_t *sig, size_t *sig_len);
228e1770e71SJens Wiklander TEE_Result crypto_acipher_dsa_verify(uint32_t algo, struct dsa_public_key *key,
229e1770e71SJens Wiklander 				     const uint8_t *msg, size_t msg_len,
230e1770e71SJens Wiklander 				     const uint8_t *sig, size_t sig_len);
231e1770e71SJens Wiklander TEE_Result crypto_acipher_ecc_sign(uint32_t algo, struct ecc_keypair *key,
232e1770e71SJens Wiklander 				   const uint8_t *msg, size_t msg_len,
233e1770e71SJens Wiklander 				   uint8_t *sig, size_t *sig_len);
234e1770e71SJens Wiklander TEE_Result crypto_acipher_ecc_verify(uint32_t algo, struct ecc_public_key *key,
235e1770e71SJens Wiklander 				     const uint8_t *msg, size_t msg_len,
236e1770e71SJens Wiklander 				     const uint8_t *sig, size_t sig_len);
237e1770e71SJens Wiklander TEE_Result crypto_acipher_ecc_shared_secret(struct ecc_keypair *private_key,
238e1770e71SJens Wiklander 					    struct ecc_public_key *public_key,
239e1770e71SJens Wiklander 					    void *secret,
240e1770e71SJens Wiklander 					    unsigned long *secret_len);
241e1770e71SJens Wiklander 
242e1770e71SJens Wiklander /*
243e1770e71SJens Wiklander  * Verifies a SHA-256 hash, doesn't require crypto_init() to be called in
244e1770e71SJens Wiklander  * advance and has as few dependencies as possible.
245e1770e71SJens Wiklander  *
246e1770e71SJens Wiklander  * This function is primarily used by pager and early initialization code
247e1770e71SJens Wiklander  * where the complete crypto library isn't available.
248e1770e71SJens Wiklander  */
249e1770e71SJens Wiklander TEE_Result hash_sha256_check(const uint8_t *hash, const uint8_t *data,
250e1770e71SJens Wiklander 		size_t data_size);
251e1770e71SJens Wiklander 
252b8bb0afaSSumit Garg /*
253b8bb0afaSSumit Garg  * Computes a SHA-512/256 hash, vetted conditioner as per NIST.SP.800-90B.
254b8bb0afaSSumit Garg  * It doesn't require crypto_init() to be called in advance and has as few
255b8bb0afaSSumit Garg  * dependencies as possible.
256b8bb0afaSSumit Garg  *
257b8bb0afaSSumit Garg  * This function could be used inside interrupt context where the crypto
258b8bb0afaSSumit Garg  * library can't be used due to mutex handling.
259b8bb0afaSSumit Garg  */
260b8bb0afaSSumit Garg TEE_Result hash_sha512_256_compute(uint8_t *digest, const uint8_t *data,
261b8bb0afaSSumit Garg 		size_t data_size);
262b8bb0afaSSumit Garg 
2636e954a6eSJens Wiklander #define CRYPTO_RNG_SRC_IS_QUICK(sid) (!!((sid) & 1))
264e1770e71SJens Wiklander 
2656e954a6eSJens Wiklander /*
2666e954a6eSJens Wiklander  * enum crypto_rng_src - RNG entropy source
2676e954a6eSJens Wiklander  *
2686e954a6eSJens Wiklander  * Identifiers for different RNG entropy sources. The lowest bit indicates
2696e954a6eSJens Wiklander  * if the source is to be merely queued (bit is 1) or if it's delivered
2706e954a6eSJens Wiklander  * directly to the pool. The difference is that in the latter case RPC to
2716e954a6eSJens Wiklander  * normal world can be performed and in the former it must not.
2726e954a6eSJens Wiklander  */
2736e954a6eSJens Wiklander enum crypto_rng_src {
2746e954a6eSJens Wiklander 	CRYPTO_RNG_SRC_JITTER_SESSION	= (0 << 1 | 0),
2756e954a6eSJens Wiklander 	CRYPTO_RNG_SRC_JITTER_RPC	= (1 << 1 | 1),
2766e954a6eSJens Wiklander 	CRYPTO_RNG_SRC_NONSECURE	= (1 << 1 | 0),
2776e954a6eSJens Wiklander };
278e1770e71SJens Wiklander 
2796e954a6eSJens Wiklander /*
2806e954a6eSJens Wiklander  * crypto_rng_init() - initialize the RNG
2816e954a6eSJens Wiklander  * @data:	buffer with initial seed
2826e954a6eSJens Wiklander  * @dlen:	length of @data
2836e954a6eSJens Wiklander  */
2846e954a6eSJens Wiklander TEE_Result crypto_rng_init(const void *data, size_t dlen);
2856e954a6eSJens Wiklander 
2866e954a6eSJens Wiklander /*
2876e954a6eSJens Wiklander  * crypto_rng_add_event() - supply entropy to RNG from a source
2886e954a6eSJens Wiklander  * @sid:	Source identifier, should be unique for a specific source
2896e954a6eSJens Wiklander  * @pnum:	Pool number, acquired using crypto_rng_get_next_pool_num()
2906e954a6eSJens Wiklander  * @data:	Data associated with the event
2916e954a6eSJens Wiklander  * @dlen:	Length of @data
2926e954a6eSJens Wiklander  *
2936e954a6eSJens Wiklander  * @sid controls whether the event is merly queued in a ring buffer or if
2946e954a6eSJens Wiklander  * it's added to one of the pools directly. If CRYPTO_RNG_SRC_IS_QUICK() is
2956e954a6eSJens Wiklander  * true (lowest bit set) events are queue otherwise added to corresponding
2966e954a6eSJens Wiklander  * pool. If CRYPTO_RNG_SRC_IS_QUICK() is false, eventual queued events are
2976e954a6eSJens Wiklander  * added to their queues too.
2986e954a6eSJens Wiklander  */
2996e954a6eSJens Wiklander void crypto_rng_add_event(enum crypto_rng_src sid, unsigned int *pnum,
3006e954a6eSJens Wiklander 			  const void *data, size_t dlen);
3016e954a6eSJens Wiklander 
3026e954a6eSJens Wiklander /*
3036e954a6eSJens Wiklander  * crypto_rng_read() - read cryptograhically secure RNG
3046e954a6eSJens Wiklander  * @buf:	Buffer to hold the data
3056e954a6eSJens Wiklander  * @len:	Length of buffer.
3066e954a6eSJens Wiklander  *
3076e954a6eSJens Wiklander  * Eventual queued events are also added to their pools during this
3086e954a6eSJens Wiklander  * function call.
3096e954a6eSJens Wiklander  */
3106e954a6eSJens Wiklander TEE_Result crypto_rng_read(void *buf, size_t len);
311e1770e71SJens Wiklander 
312e7dbc357SSummer Qin /*
313e7dbc357SSummer Qin  * crypto_aes_expand_enc_key() - Expand an AES key
314e7dbc357SSummer Qin  * @key:	AES key buffer
315e7dbc357SSummer Qin  * @key_len:	Size of the the @key buffer in bytes
316e7dbc357SSummer Qin  * @enc_key:	Expanded AES encryption key buffer
317e7dbc357SSummer Qin  * @enc_keylen: Size of the @enc_key buffer in bytes
318e7dbc357SSummer Qin  * @rounds:	Number of rounds to be used during encryption
319e7dbc357SSummer Qin  */
3200d360202SJens Wiklander TEE_Result crypto_aes_expand_enc_key(const void *key, size_t key_len,
321e7dbc357SSummer Qin 				     void *enc_key, size_t enc_keylen,
322e7dbc357SSummer Qin 				     unsigned int *rounds);
323e7dbc357SSummer Qin 
324e7dbc357SSummer Qin /*
325e7dbc357SSummer Qin  * crypto_aes_enc_block() - Encrypt an AES block
326e7dbc357SSummer Qin  * @enc_key:	Expanded AES encryption key
327e7dbc357SSummer Qin  * @enc_keylen:	Size of @enc_key in bytes
328e7dbc357SSummer Qin  * @rounds:	Number of rounds
329e7dbc357SSummer Qin  * @src:	Source buffer of one AES block (16 bytes)
330e7dbc357SSummer Qin  * @dst:	Destination buffer of one AES block (16 bytes)
331e7dbc357SSummer Qin  */
332e7dbc357SSummer Qin void crypto_aes_enc_block(const void *enc_key, size_t enc_keylen,
333e7dbc357SSummer Qin 			  unsigned int rounds, const void *src, void *dst);
3340d360202SJens Wiklander 
335e1770e71SJens Wiklander #endif /* __CRYPTO_CRYPTO_H */
336