1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3 * Copyright (c) 2019, Linaro Limited
4 * Copyright (c) 2021, SumUp Services GmbH
5 */
6
7 #ifndef __CRYPTO_CRYPTO_IMPL_H
8 #define __CRYPTO_CRYPTO_IMPL_H
9
10 #include <crypto/crypto.h>
11 #include <tee_api_types.h>
12
13 /*
14 * The crypto context used by the crypto_hash_*() functions is defined by
15 * struct crypto_hash_ctx.
16 */
17 struct crypto_hash_ctx {
18 const struct crypto_hash_ops *ops;
19 };
20
21 struct crypto_hash_ops {
22 TEE_Result (*init)(struct crypto_hash_ctx *ctx);
23 TEE_Result (*update)(struct crypto_hash_ctx *ctx, const uint8_t *data,
24 size_t len);
25 TEE_Result (*final)(struct crypto_hash_ctx *ctx, uint8_t *digest,
26 size_t len);
27 void (*free_ctx)(struct crypto_hash_ctx *ctx);
28 void (*copy_state)(struct crypto_hash_ctx *dst_ctx,
29 struct crypto_hash_ctx *src_ctx);
30 };
31
32 #define CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(name, type) \
33 static inline TEE_Result \
34 crypto_##name##_alloc_ctx(struct crypto_##type##_ctx **ctx __unused) \
35 { return TEE_ERROR_NOT_IMPLEMENTED; }
36
37 #if defined(CFG_CRYPTO_MD5)
38 TEE_Result crypto_md5_alloc_ctx(struct crypto_hash_ctx **ctx);
39 #else
40 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(md5, hash)
41 #endif
42
43 #if defined(CFG_CRYPTO_SHA1)
44 TEE_Result crypto_sha1_alloc_ctx(struct crypto_hash_ctx **ctx);
45 #else
46 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha1, hash)
47 #endif
48
49 #if defined(CFG_CRYPTO_SHA224)
50 TEE_Result crypto_sha224_alloc_ctx(struct crypto_hash_ctx **ctx);
51 #else
52 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha224, hash)
53 #endif
54
55 #if defined(CFG_CRYPTO_SHA256)
56 TEE_Result crypto_sha256_alloc_ctx(struct crypto_hash_ctx **ctx);
57 #else
58 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha256, hash)
59 #endif
60
61 #if defined(CFG_CRYPTO_SHA384)
62 TEE_Result crypto_sha384_alloc_ctx(struct crypto_hash_ctx **ctx);
63 #else
64 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha384, hash)
65 #endif
66
67 #if defined(CFG_CRYPTO_SHA512)
68 TEE_Result crypto_sha512_alloc_ctx(struct crypto_hash_ctx **ctx);
69 #else
70 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha512, hash)
71 #endif
72
73 #if defined(CFG_CRYPTO_SM3)
74 TEE_Result crypto_sm3_alloc_ctx(struct crypto_hash_ctx **ctx);
75 #else
76 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm3, hash)
77 #endif
78
79 #if defined(CFG_CRYPTO_SHA3_224)
80 TEE_Result crypto_sha3_224_alloc_ctx(struct crypto_hash_ctx **ctx);
81 #else
82 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_224, hash)
83 #endif
84
85 #if defined(CFG_CRYPTO_SHA3_256)
86 TEE_Result crypto_sha3_256_alloc_ctx(struct crypto_hash_ctx **ctx);
87 #else
88 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_256, hash)
89 #endif
90
91 #if defined(CFG_CRYPTO_SHA3_384)
92 TEE_Result crypto_sha3_384_alloc_ctx(struct crypto_hash_ctx **ctx);
93 #else
94 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_384, hash)
95 #endif
96
97 #if defined(CFG_CRYPTO_SHA3_512)
98 TEE_Result crypto_sha3_512_alloc_ctx(struct crypto_hash_ctx **ctx);
99 #else
100 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha3_512, hash)
101 #endif
102
103 #if defined(CFG_CRYPTO_SHAKE128)
104 TEE_Result crypto_shake128_alloc_ctx(struct crypto_hash_ctx **ctx);
105 #else
106 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(shake128, hash)
107 #endif
108
109 #if defined(CFG_CRYPTO_SHAKE256)
110 TEE_Result crypto_shake256_alloc_ctx(struct crypto_hash_ctx **ctx);
111 #else
112 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(shake256, hash)
113 #endif
114
115 /*
116 * The crypto context used by the crypto_mac_*() functions is defined by
117 * struct crypto_mac_ctx.
118 */
119 struct crypto_mac_ctx {
120 const struct crypto_mac_ops *ops;
121 };
122
123 struct crypto_mac_ops {
124 TEE_Result (*init)(struct crypto_mac_ctx *ctx, const uint8_t *key,
125 size_t len);
126 TEE_Result (*update)(struct crypto_mac_ctx *ctx, const uint8_t *data,
127 size_t len);
128 TEE_Result (*final)(struct crypto_mac_ctx *ctx, uint8_t *digest,
129 size_t len);
130 void (*free_ctx)(struct crypto_mac_ctx *ctx);
131 void (*copy_state)(struct crypto_mac_ctx *dst_ctx,
132 struct crypto_mac_ctx *src_ctx);
133 };
134
135 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_MD5)
136 TEE_Result crypto_hmac_md5_alloc_ctx(struct crypto_mac_ctx **ctx);
137 #else
138 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_md5, mac)
139 #endif
140
141 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA1)
142 TEE_Result crypto_hmac_sha1_alloc_ctx(struct crypto_mac_ctx **ctx);
143 #else
144 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha1, mac)
145 #endif
146
147 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA224)
148 TEE_Result crypto_hmac_sha224_alloc_ctx(struct crypto_mac_ctx **ctx);
149 #else
150 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha224, mac)
151 #endif
152
153 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA256)
154 TEE_Result crypto_hmac_sha256_alloc_ctx(struct crypto_mac_ctx **ctx);
155 #else
156 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha256, mac)
157 #endif
158
159 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA384)
160 TEE_Result crypto_hmac_sha384_alloc_ctx(struct crypto_mac_ctx **ctx);
161 #else
162 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha384, mac)
163 #endif
164
165 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA512)
166 TEE_Result crypto_hmac_sha512_alloc_ctx(struct crypto_mac_ctx **ctx);
167 #else
168 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha512, mac)
169 #endif
170
171 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA3_224)
172 TEE_Result crypto_hmac_sha3_224_alloc_ctx(struct crypto_mac_ctx **ctx);
173 #else
174 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_224, mac)
175 #endif
176
177 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA3_256)
178 TEE_Result crypto_hmac_sha3_256_alloc_ctx(struct crypto_mac_ctx **ctx);
179 #else
180 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_256, mac)
181 #endif
182
183 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA3_384)
184 TEE_Result crypto_hmac_sha3_384_alloc_ctx(struct crypto_mac_ctx **ctx);
185 #else
186 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_384, mac)
187 #endif
188
189 #if defined(CFG_CRYPTO_HMAC) && defined(CFG_CRYPTO_SHA3_512)
190 TEE_Result crypto_hmac_sha3_512_alloc_ctx(struct crypto_mac_ctx **ctx);
191 #else
192 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sha3_512, mac)
193 #endif
194
195 #if defined(CFG_CRYPTO_SM3) && defined(CFG_CRYPTO_HMAC)
196 TEE_Result crypto_hmac_sm3_alloc_ctx(struct crypto_mac_ctx **ctx);
197 #else
198 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(hmac_sm3, mac)
199 #endif
200
201 #if defined(CFG_CRYPTO_CBC_MAC)
202 TEE_Result crypto_aes_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx);
203 TEE_Result crypto_aes_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx);
204 TEE_Result crypto_des_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx);
205 TEE_Result crypto_des_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx);
206 TEE_Result crypto_des3_cbc_mac_nopad_alloc_ctx(struct crypto_mac_ctx **ctx);
207 TEE_Result crypto_des3_cbc_mac_pkcs5_alloc_ctx(struct crypto_mac_ctx **ctx);
208 #else
209 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc_mac_nopad, mac)
210 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc_mac_pkcs5, mac)
211 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc_mac_nopad, mac)
212 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc_mac_pkcs5, mac)
213 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc_mac_nopad, mac)
214 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc_mac_pkcs5, mac)
215 #endif
216
217 #if defined(CFG_CRYPTO_CMAC)
218 TEE_Result crypto_aes_cmac_alloc_ctx(struct crypto_mac_ctx **ctx);
219 TEE_Result crypto_des3_cmac_alloc_ctx(struct crypto_mac_ctx **ctx);
220 #else
221 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cmac, mac)
222 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cmac, mac)
223 #endif
224
225 /*
226 * The crypto context used by the crypto_cipher_*() functions is defined by
227 * struct crypto_cipher_ctx.
228 */
229 struct crypto_cipher_ctx {
230 const struct crypto_cipher_ops *ops;
231 };
232
233 struct crypto_cipher_ops {
234 TEE_Result (*init)(struct crypto_cipher_ctx *ctx,
235 TEE_OperationMode mode,
236 const uint8_t *key1, size_t key1_len,
237 const uint8_t *key2, size_t key2_len,
238 const uint8_t *iv, size_t iv_len);
239 TEE_Result (*update)(struct crypto_cipher_ctx *ctx, bool last_block,
240 const uint8_t *data, size_t len, uint8_t *dst);
241 void (*final)(struct crypto_cipher_ctx *ctx);
242
243 void (*free_ctx)(struct crypto_cipher_ctx *ctx);
244 void (*copy_state)(struct crypto_cipher_ctx *dst_ctx,
245 struct crypto_cipher_ctx *src_ctx);
246 };
247
248 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_ECB)
249 TEE_Result crypto_aes_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx);
250 #else
251 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_ecb, cipher)
252 #endif
253
254 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CBC)
255 TEE_Result crypto_aes_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx);
256 #else
257 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cbc, cipher)
258 #endif
259
260 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CTR)
261 TEE_Result crypto_aes_ctr_alloc_ctx(struct crypto_cipher_ctx **ctx);
262 #else
263 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_ctr, cipher)
264 #endif
265
266 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_CTS)
267 TEE_Result crypto_aes_cts_alloc_ctx(struct crypto_cipher_ctx **ctx);
268 #else
269 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_cts, cipher)
270 #endif
271
272 #if defined(CFG_CRYPTO_AES) && defined(CFG_CRYPTO_XTS)
273 TEE_Result crypto_aes_xts_alloc_ctx(struct crypto_cipher_ctx **ctx);
274 #else
275 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(aes_xts, cipher)
276 #endif
277
278 #if defined(CFG_CRYPTO_DES) && defined(CFG_CRYPTO_ECB)
279 TEE_Result crypto_des_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx);
280 TEE_Result crypto_des3_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx);
281 #else
282 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_ecb, cipher)
283 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_ecb, cipher)
284 #endif
285
286 #if defined(CFG_CRYPTO_DES) && defined(CFG_CRYPTO_CBC)
287 TEE_Result crypto_des_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx);
288 TEE_Result crypto_des3_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx);
289 #else
290 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des_cbc, cipher)
291 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(des3_cbc, cipher)
292 #endif
293
294 #if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_ECB)
295 TEE_Result crypto_sm4_ecb_alloc_ctx(struct crypto_cipher_ctx **ctx);
296 #else
297 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_ecb, cipher)
298 #endif
299
300 #if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_CBC)
301 TEE_Result crypto_sm4_cbc_alloc_ctx(struct crypto_cipher_ctx **ctx);
302 #else
303 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_cbc, cipher)
304 #endif
305
306 #if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_CTR)
307 TEE_Result crypto_sm4_ctr_alloc_ctx(struct crypto_cipher_ctx **ctx);
308 #else
309 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_ctr, cipher)
310 #endif
311
312 #if defined(CFG_CRYPTO_SM4) && defined(CFG_CRYPTO_XTS)
313 TEE_Result crypto_sm4_xts_alloc_ctx(struct crypto_cipher_ctx **ctx);
314 #else
315 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sm4_xts, cipher)
316 #endif
317
318 /*
319 * The crypto context used by the crypto_authen_*() functions below is
320 * defined by struct crypto_authenc_ctx.
321 */
322 struct crypto_authenc_ctx {
323 const struct crypto_authenc_ops *ops;
324 };
325
326 struct crypto_authenc_ops {
327 TEE_Result (*init)(struct crypto_authenc_ctx *ctx,
328 TEE_OperationMode mode,
329 const uint8_t *key, size_t key_len,
330 const uint8_t *nonce, size_t nonce_len,
331 size_t tag_len, size_t aad_len,
332 size_t payload_len);
333 TEE_Result (*update_aad)(struct crypto_authenc_ctx *ctx,
334 const uint8_t *data, size_t len);
335 TEE_Result (*update_payload)(struct crypto_authenc_ctx *ctx,
336 TEE_OperationMode mode,
337 const uint8_t *src_data, size_t len,
338 uint8_t *dst_data);
339 TEE_Result (*enc_final)(struct crypto_authenc_ctx *ctx,
340 const uint8_t *src_data, size_t len,
341 uint8_t *dst_data, uint8_t *dst_tag,
342 size_t *dst_tag_len);
343 TEE_Result (*dec_final)(struct crypto_authenc_ctx *ctx,
344 const uint8_t *src_data, size_t len,
345 uint8_t *dst_data, const uint8_t *tag,
346 size_t tag_len);
347 void (*final)(struct crypto_authenc_ctx *ctx);
348 void (*free_ctx)(struct crypto_authenc_ctx *ctx);
349 void (*copy_state)(struct crypto_authenc_ctx *dst_ctx,
350 struct crypto_authenc_ctx *src_ctx);
351 };
352
353 TEE_Result crypto_aes_ccm_alloc_ctx(struct crypto_authenc_ctx **ctx);
354 TEE_Result crypto_aes_gcm_alloc_ctx(struct crypto_authenc_ctx **ctx);
355
356 #ifdef CFG_CRYPTO_DRV_HASH
357 TEE_Result drvcrypt_hash_alloc_ctx(struct crypto_hash_ctx **ctx, uint32_t algo);
358 #else
359 static inline TEE_Result
drvcrypt_hash_alloc_ctx(struct crypto_hash_ctx ** ctx __unused,uint32_t algo __unused)360 drvcrypt_hash_alloc_ctx(struct crypto_hash_ctx **ctx __unused,
361 uint32_t algo __unused)
362 {
363 return TEE_ERROR_NOT_IMPLEMENTED;
364 }
365 #endif /* CFG_CRYPTO_DRV_HASH */
366
367 #ifdef CFG_CRYPTO_DRV_CIPHER
368 TEE_Result drvcrypt_cipher_alloc_ctx(struct crypto_cipher_ctx **ctx,
369 uint32_t algo);
370 #else
371 static inline TEE_Result
drvcrypt_cipher_alloc_ctx(struct crypto_cipher_ctx ** ctx __unused,uint32_t algo __unused)372 drvcrypt_cipher_alloc_ctx(struct crypto_cipher_ctx **ctx __unused,
373 uint32_t algo __unused)
374 {
375 return TEE_ERROR_NOT_IMPLEMENTED;
376 }
377 #endif /* CFG_CRYPTO_DRV_CIPHER */
378
379 #ifdef CFG_CRYPTO_DRV_MAC
380 /* Cryptographic MAC driver context allocation */
381 TEE_Result drvcrypt_mac_alloc_ctx(struct crypto_mac_ctx **ctx, uint32_t algo);
382 #else
383 static inline TEE_Result
drvcrypt_mac_alloc_ctx(struct crypto_mac_ctx ** ctx __unused,uint32_t algo __unused)384 drvcrypt_mac_alloc_ctx(struct crypto_mac_ctx **ctx __unused,
385 uint32_t algo __unused)
386 {
387 return TEE_ERROR_NOT_IMPLEMENTED;
388 }
389 #endif /* CFG_CRYPTO_DRV_MAC */
390
391 #ifdef CFG_CRYPTO_DRV_AUTHENC
392 /* Cryptographic Authenticated Encryption driver context allocation */
393 TEE_Result drvcrypt_authenc_alloc_ctx(struct crypto_authenc_ctx **ctx,
394 uint32_t algo);
395 #else
396 static inline TEE_Result
drvcrypt_authenc_alloc_ctx(struct crypto_authenc_ctx ** ctx __unused,uint32_t algo __unused)397 drvcrypt_authenc_alloc_ctx(struct crypto_authenc_ctx **ctx __unused,
398 uint32_t algo __unused)
399 {
400 return TEE_ERROR_NOT_IMPLEMENTED;
401 }
402 #endif /* CFG_CRYPTO_DRV_AUTHENC */
403 /*
404 * The ECC public key operations used by the crypto_acipher_ecc_*() and
405 * crypto_acipher_free_ecc_*() functions.
406 * Reference set in ecc_public_key when key allocated.
407 *
408 * @free is mandatory
409 * @verify is optional
410 * @encrypt is optional
411 */
412 struct crypto_ecc_public_ops {
413 void (*free)(struct ecc_public_key *key);
414 TEE_Result (*verify)(uint32_t algo, struct ecc_public_key *key,
415 const uint8_t *msg, size_t msg_len,
416 const uint8_t *sig, size_t sig_len);
417 TEE_Result (*encrypt)(struct ecc_public_key *key, const uint8_t *src,
418 size_t src_len, uint8_t *dst, size_t *dst_len);
419 };
420
421 /*
422 * The ECC keypair operations used by the crypto_acipher_ecc_*() and
423 * crypto_acipher_gen_ecc_*() functions.
424 * Reference set in ecc_keypair when key allocated.
425 *
426 * @generate is mandatory
427 * @sign is optional
428 * @shared_secret is optional
429 * @decrypt is optional
430 */
431 struct crypto_ecc_keypair_ops {
432 TEE_Result (*generate)(struct ecc_keypair *key, size_t key_size_bits);
433 TEE_Result (*sign)(uint32_t algo, struct ecc_keypair *key,
434 const uint8_t *msg, size_t msg_len, uint8_t *sig,
435 size_t *sig_len);
436 TEE_Result (*shared_secret)(struct ecc_keypair *private_key,
437 struct ecc_public_key *public_key,
438 void *secret, unsigned long *secret_len);
439 TEE_Result (*decrypt)(struct ecc_keypair *key, const uint8_t *src,
440 size_t src_len, uint8_t *dst, size_t *dst_len);
441 };
442
443 #ifdef CFG_CRYPTO_ECC
444 const struct crypto_ecc_keypair_ops *
445 crypto_asym_get_ecc_keypair_ops(uint32_t key_type);
446
447 const struct crypto_ecc_public_ops *
448 crypto_asym_get_ecc_public_ops(uint32_t key_type);
449
450 TEE_Result crypto_asym_alloc_ecc_public_key(struct ecc_public_key *key,
451 uint32_t key_type,
452 size_t key_size_bits);
453 TEE_Result crypto_asym_alloc_ecc_keypair(struct ecc_keypair *key,
454 uint32_t key_type,
455 size_t key_size_bits);
456 #else
457 static inline TEE_Result
crypto_asym_alloc_ecc_public_key(struct ecc_public_key * key __unused,uint32_t key_type __unused,size_t key_size_bits __unused)458 crypto_asym_alloc_ecc_public_key(struct ecc_public_key *key __unused,
459 uint32_t key_type __unused,
460 size_t key_size_bits __unused)
461 {
462 return TEE_ERROR_NOT_IMPLEMENTED;
463 }
464
465 static inline const struct crypto_ecc_keypair_ops *
crypto_asym_get_ecc_keypair_ops(uint32_t key_type __unused)466 crypto_asym_get_ecc_keypair_ops(uint32_t key_type __unused)
467 {
468 return NULL;
469 }
470
471 static inline const struct crypto_ecc_public_ops *
crypto_asym_get_ecc_public_ops(uint32_t key_type __unused)472 crypto_asym_get_ecc_public_ops(uint32_t key_type __unused)
473 {
474 return NULL;
475 }
476
477 static inline TEE_Result
crypto_asym_alloc_ecc_keypair(struct ecc_keypair * key __unused,uint32_t key_type __unused,size_t key_size_bits __unused)478 crypto_asym_alloc_ecc_keypair(struct ecc_keypair *key __unused,
479 uint32_t key_type __unused,
480 size_t key_size_bits __unused)
481 {
482 return TEE_ERROR_NOT_IMPLEMENTED;
483 }
484 #endif /* CFG_CRYPTO_ECC */
485
486 #ifdef CFG_CRYPTO_DRV_ECC
487 TEE_Result drvcrypt_asym_alloc_ecc_public_key(struct ecc_public_key *key,
488 uint32_t key_type,
489 size_t key_size_bits);
490 TEE_Result drvcrypt_asym_alloc_ecc_keypair(struct ecc_keypair *key,
491 uint32_t key_type,
492 size_t key_size_bits);
493 #else
494 static inline TEE_Result
drvcrypt_asym_alloc_ecc_public_key(struct ecc_public_key * key __unused,uint32_t key_type __unused,size_t key_size_bits __unused)495 drvcrypt_asym_alloc_ecc_public_key(struct ecc_public_key *key __unused,
496 uint32_t key_type __unused,
497 size_t key_size_bits __unused)
498 {
499 return TEE_ERROR_NOT_IMPLEMENTED;
500 }
501
502 static inline TEE_Result
drvcrypt_asym_alloc_ecc_keypair(struct ecc_keypair * key __unused,uint32_t key_type __unused,size_t key_size_bits __unused)503 drvcrypt_asym_alloc_ecc_keypair(struct ecc_keypair *key __unused,
504 uint32_t key_type __unused,
505 size_t key_size_bits __unused)
506 {
507 return TEE_ERROR_NOT_IMPLEMENTED;
508 }
509 #endif /* CFG_CRYPTO_DRV_ECC */
510
511 TEE_Result sw_crypto_acipher_alloc_rsa_keypair(struct rsa_keypair *s,
512 size_t key_size_bits);
513
514 TEE_Result sw_crypto_acipher_alloc_rsa_public_key(struct rsa_public_key *s,
515 size_t key_size_bits);
516
517 void sw_crypto_acipher_free_rsa_public_key(struct rsa_public_key *s);
518
519 void sw_crypto_acipher_free_rsa_keypair(struct rsa_keypair *s);
520
521 TEE_Result sw_crypto_acipher_gen_rsa_key(struct rsa_keypair *key,
522 size_t key_size);
523
524 TEE_Result sw_crypto_acipher_rsanopad_decrypt(struct rsa_keypair *key,
525 const uint8_t *src,
526 size_t src_len, uint8_t *dst,
527 size_t *dst_len);
528 TEE_Result sw_crypto_acipher_rsanopad_encrypt(struct rsa_public_key *key,
529 const uint8_t *src,
530 size_t src_len, uint8_t *dst,
531 size_t *dst_len);
532 TEE_Result sw_crypto_acipher_rsaes_decrypt(uint32_t algo,
533 struct rsa_keypair *key,
534 const uint8_t *label,
535 size_t label_len,
536 uint32_t mgf_algo,
537 const uint8_t *src,
538 size_t src_len, uint8_t *dst,
539 size_t *dst_len);
540
541 TEE_Result sw_crypto_acipher_rsaes_encrypt(uint32_t algo,
542 struct rsa_public_key *key,
543 const uint8_t *label,
544 size_t label_len,
545 uint32_t mgf_algo,
546 const uint8_t *src,
547 size_t src_len, uint8_t *dst,
548 size_t *dst_len);
549
550 TEE_Result sw_crypto_acipher_rsassa_sign(uint32_t algo, struct rsa_keypair *key,
551 int salt_len, const uint8_t *msg,
552 size_t msg_len, uint8_t *sig,
553 size_t *sig_len);
554
555 TEE_Result sw_crypto_acipher_rsassa_verify(uint32_t algo,
556 struct rsa_public_key *key,
557 int salt_len, const uint8_t *msg,
558 size_t msg_len, const uint8_t *sig,
559 size_t sig_len);
560 #endif /*__CRYPTO_CRYPTO_IMPL_H*/
561