xref: /optee_os/core/crypto/crypto.c (revision 96098f011f7cc334d2c9eb694e1cc45ded4f64cf)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2017, Linaro Limited
4  */
5 
6 #include <assert.h>
7 #include <compiler.h>
8 #include <crypto/aes-ccm.h>
9 #include <crypto/aes-gcm.h>
10 #include <crypto/crypto.h>
11 #include <crypto/crypto_impl.h>
12 #include <kernel/panic.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <utee_defines.h>
16 
17 TEE_Result crypto_hash_alloc_ctx(void **ctx, uint32_t algo)
18 {
19 	TEE_Result res = TEE_SUCCESS;
20 	struct crypto_hash_ctx *c = NULL;
21 
22 	switch (algo) {
23 	case TEE_ALG_MD5:
24 		res = crypto_md5_alloc_ctx(&c);
25 		break;
26 	case TEE_ALG_SHA1:
27 		res = crypto_sha1_alloc_ctx(&c);
28 		break;
29 	case TEE_ALG_SHA224:
30 		res = crypto_sha224_alloc_ctx(&c);
31 		break;
32 	case TEE_ALG_SHA256:
33 		res = crypto_sha256_alloc_ctx(&c);
34 		break;
35 	case TEE_ALG_SHA384:
36 		res = crypto_sha384_alloc_ctx(&c);
37 		break;
38 	case TEE_ALG_SHA512:
39 		res = crypto_sha512_alloc_ctx(&c);
40 		break;
41 	default:
42 		return TEE_ERROR_NOT_IMPLEMENTED;
43 	}
44 
45 	if (!res)
46 		*ctx = c;
47 
48 	return res;
49 }
50 
51 static const struct crypto_hash_ops *hash_ops(void *ctx)
52 {
53 	struct crypto_hash_ctx *c = ctx;
54 
55 	assert(c && c->ops);
56 
57 	return c->ops;
58 }
59 
60 void crypto_hash_free_ctx(void *ctx, uint32_t algo __unused)
61 {
62 	if (ctx)
63 		hash_ops(ctx)->free_ctx(ctx);
64 }
65 
66 void crypto_hash_copy_state(void *dst_ctx, void *src_ctx,
67 			    uint32_t algo __unused)
68 {
69 	hash_ops(dst_ctx)->copy_state(dst_ctx, src_ctx);
70 }
71 
72 TEE_Result crypto_hash_init(void *ctx, uint32_t algo __unused)
73 {
74 	return hash_ops(ctx)->init(ctx);
75 }
76 
77 TEE_Result crypto_hash_update(void *ctx, uint32_t algo __unused,
78 			      const uint8_t *data, size_t len)
79 {
80 	return hash_ops(ctx)->update(ctx, data, len);
81 }
82 
83 TEE_Result crypto_hash_final(void *ctx, uint32_t algo __unused,
84 			     uint8_t *digest, size_t len)
85 {
86 	return hash_ops(ctx)->final(ctx, digest, len);
87 }
88 
89 TEE_Result crypto_cipher_alloc_ctx(void **ctx, uint32_t algo)
90 {
91 	TEE_Result res = TEE_SUCCESS;
92 	struct crypto_cipher_ctx *c = NULL;
93 
94 	switch (algo) {
95 	case TEE_ALG_AES_ECB_NOPAD:
96 		res = crypto_aes_ecb_alloc_ctx(&c);
97 		break;
98 	case TEE_ALG_AES_CBC_NOPAD:
99 		res = crypto_aes_cbc_alloc_ctx(&c);
100 		break;
101 	case TEE_ALG_AES_CTR:
102 		res = crypto_aes_ctr_alloc_ctx(&c);
103 		break;
104 	case TEE_ALG_AES_CTS:
105 		res = crypto_aes_cts_alloc_ctx(&c);
106 		break;
107 	case TEE_ALG_AES_XTS:
108 		res = crypto_aes_xts_alloc_ctx(&c);
109 		break;
110 	case TEE_ALG_DES_ECB_NOPAD:
111 		res = crypto_des_ecb_alloc_ctx(&c);
112 		break;
113 	case TEE_ALG_DES3_ECB_NOPAD:
114 		res = crypto_des3_ecb_alloc_ctx(&c);
115 		break;
116 	case TEE_ALG_DES_CBC_NOPAD:
117 		res = crypto_des_cbc_alloc_ctx(&c);
118 		break;
119 	case TEE_ALG_DES3_CBC_NOPAD:
120 		res = crypto_des3_cbc_alloc_ctx(&c);
121 		break;
122 	default:
123 		return TEE_ERROR_NOT_IMPLEMENTED;
124 	}
125 
126 	if (!res)
127 		*ctx = c;
128 
129 	return res;
130 }
131 
132 static const struct crypto_cipher_ops *cipher_ops(void *ctx)
133 {
134 	struct crypto_cipher_ctx *c = ctx;
135 
136 	assert(c && c->ops);
137 
138 	return c->ops;
139 }
140 
141 void crypto_cipher_free_ctx(void *ctx, uint32_t algo __unused)
142 {
143 	if (ctx)
144 		cipher_ops(ctx)->free_ctx(ctx);
145 }
146 
147 void crypto_cipher_copy_state(void *dst_ctx, void *src_ctx,
148 			      uint32_t algo __unused)
149 {
150 	cipher_ops(dst_ctx)->copy_state(dst_ctx, src_ctx);
151 }
152 
153 TEE_Result crypto_cipher_init(void *ctx __unused, uint32_t algo __unused,
154 			      TEE_OperationMode mode, const uint8_t *key1,
155 			      size_t key1_len, const uint8_t *key2,
156 			      size_t key2_len, const uint8_t *iv, size_t iv_len)
157 {
158 	if (mode != TEE_MODE_DECRYPT && mode != TEE_MODE_ENCRYPT)
159 		return TEE_ERROR_BAD_PARAMETERS;
160 
161 	return cipher_ops(ctx)->init(ctx, mode, key1, key1_len, key2, key2_len,
162 				     iv, iv_len);
163 }
164 
165 TEE_Result crypto_cipher_update(void *ctx, uint32_t algo __unused,
166 				TEE_OperationMode mode __unused,
167 				bool last_block, const uint8_t *data,
168 				size_t len, uint8_t *dst)
169 {
170 	return cipher_ops(ctx)->update(ctx, last_block, data, len, dst);
171 }
172 
173 void crypto_cipher_final(void *ctx, uint32_t algo __unused)
174 {
175 	cipher_ops(ctx)->final(ctx);
176 }
177 
178 TEE_Result crypto_cipher_get_block_size(uint32_t algo, size_t *size)
179 {
180 	uint32_t class = TEE_ALG_GET_CLASS(algo);
181 
182 	if (class != TEE_OPERATION_CIPHER && class != TEE_OPERATION_MAC &&
183 	    class != TEE_OPERATION_AE)
184 		return TEE_ERROR_BAD_PARAMETERS;
185 
186 	switch (TEE_ALG_GET_MAIN_ALG(algo)) {
187 	case TEE_MAIN_ALGO_AES:
188 		*size = TEE_AES_BLOCK_SIZE;
189 		return TEE_SUCCESS;
190 	case TEE_MAIN_ALGO_DES:
191 	case TEE_MAIN_ALGO_DES3:
192 		*size = TEE_DES_BLOCK_SIZE;
193 		return TEE_SUCCESS;
194 	default:
195 		return TEE_ERROR_NOT_SUPPORTED;
196 	}
197 }
198 
199 TEE_Result crypto_mac_alloc_ctx(void **ctx, uint32_t algo)
200 {
201 	TEE_Result res = TEE_SUCCESS;
202 	struct crypto_mac_ctx *c = NULL;
203 
204 	switch (algo) {
205 	case TEE_ALG_HMAC_MD5:
206 		res = crypto_hmac_md5_alloc_ctx(&c);
207 		break;
208 	case TEE_ALG_HMAC_SHA1:
209 		res = crypto_hmac_sha1_alloc_ctx(&c);
210 		break;
211 	case TEE_ALG_HMAC_SHA224:
212 		res = crypto_hmac_sha224_alloc_ctx(&c);
213 		break;
214 	case TEE_ALG_HMAC_SHA256:
215 		res = crypto_hmac_sha256_alloc_ctx(&c);
216 		break;
217 	case TEE_ALG_HMAC_SHA384:
218 		res = crypto_hmac_sha384_alloc_ctx(&c);
219 		break;
220 	case TEE_ALG_HMAC_SHA512:
221 		res = crypto_hmac_sha512_alloc_ctx(&c);
222 		break;
223 	case TEE_ALG_AES_CBC_MAC_NOPAD:
224 		res = crypto_aes_cbc_mac_nopad_alloc_ctx(&c);
225 		break;
226 	case TEE_ALG_AES_CBC_MAC_PKCS5:
227 		res = crypto_aes_cbc_mac_pkcs5_alloc_ctx(&c);
228 		break;
229 	case TEE_ALG_DES_CBC_MAC_NOPAD:
230 		res = crypto_des_cbc_mac_nopad_alloc_ctx(&c);
231 		break;
232 	case TEE_ALG_DES_CBC_MAC_PKCS5:
233 		res = crypto_des_cbc_mac_pkcs5_alloc_ctx(&c);
234 		break;
235 	case TEE_ALG_DES3_CBC_MAC_NOPAD:
236 		res = crypto_des3_cbc_mac_nopad_alloc_ctx(&c);
237 		break;
238 	case TEE_ALG_DES3_CBC_MAC_PKCS5:
239 		res = crypto_des3_cbc_mac_pkcs5_alloc_ctx(&c);
240 		break;
241 	case TEE_ALG_AES_CMAC:
242 		res = crypto_aes_cmac_alloc_ctx(&c);
243 		break;
244 	default:
245 		return TEE_ERROR_NOT_SUPPORTED;
246 	}
247 
248 	if (!res)
249 		*ctx = c;
250 
251 	return res;
252 }
253 
254 static const struct crypto_mac_ops *mac_ops(void *ctx)
255 {
256 	struct crypto_mac_ctx *c = ctx;
257 
258 	assert(c && c->ops);
259 
260 	return c->ops;
261 }
262 
263 void crypto_mac_free_ctx(void *ctx, uint32_t algo __unused)
264 {
265 	if (ctx)
266 		mac_ops(ctx)->free_ctx(ctx);
267 }
268 
269 void crypto_mac_copy_state(void *dst_ctx, void *src_ctx, uint32_t algo __unused)
270 {
271 	mac_ops(dst_ctx)->copy_state(dst_ctx, src_ctx);
272 }
273 
274 TEE_Result crypto_mac_init(void *ctx, uint32_t algo __unused,
275 			   const uint8_t *key, size_t len)
276 {
277 	return mac_ops(ctx)->init(ctx, key, len);
278 }
279 
280 TEE_Result crypto_mac_update(void *ctx, uint32_t algo __unused,
281 			     const uint8_t *data, size_t len)
282 {
283 	if (!len)
284 		return TEE_SUCCESS;
285 
286 	return mac_ops(ctx)->update(ctx, data, len);
287 }
288 
289 TEE_Result crypto_mac_final(void *ctx, uint32_t algo __unused,
290 			    uint8_t *digest, size_t digest_len)
291 {
292 	return mac_ops(ctx)->final(ctx, digest, digest_len);
293 }
294 
295 TEE_Result crypto_authenc_alloc_ctx(void **ctx, uint32_t algo)
296 {
297 	switch (algo) {
298 #if defined(CFG_CRYPTO_CCM)
299 	case TEE_ALG_AES_CCM:
300 		return crypto_aes_ccm_alloc_ctx(ctx);
301 #endif
302 #if defined(CFG_CRYPTO_GCM)
303 	case TEE_ALG_AES_GCM:
304 		return crypto_aes_gcm_alloc_ctx(ctx);
305 #endif
306 	default:
307 		return TEE_ERROR_NOT_IMPLEMENTED;
308 	}
309 }
310 
311 void crypto_authenc_free_ctx(void *ctx, uint32_t algo)
312 {
313 	switch (algo) {
314 #if defined(CFG_CRYPTO_CCM)
315 	case TEE_ALG_AES_CCM:
316 		crypto_aes_ccm_free_ctx(ctx);
317 		break;
318 #endif
319 #if defined(CFG_CRYPTO_GCM)
320 	case TEE_ALG_AES_GCM:
321 		crypto_aes_gcm_free_ctx(ctx);
322 		break;
323 #endif
324 	default:
325 		if (ctx)
326 			assert(0);
327 	}
328 }
329 
330 void crypto_authenc_copy_state(void *dst_ctx, void *src_ctx, uint32_t algo)
331 {
332 	switch (algo) {
333 #if defined(CFG_CRYPTO_CCM)
334 	case TEE_ALG_AES_CCM:
335 		crypto_aes_ccm_copy_state(dst_ctx, src_ctx);
336 		break;
337 #endif
338 #if defined(CFG_CRYPTO_GCM)
339 	case TEE_ALG_AES_GCM:
340 		crypto_aes_gcm_copy_state(dst_ctx, src_ctx);
341 		break;
342 #endif
343 	default:
344 		assert(0);
345 	}
346 }
347 
348 TEE_Result crypto_authenc_init(void *ctx __maybe_unused,
349 			       uint32_t algo __maybe_unused,
350 			       TEE_OperationMode mode __maybe_unused,
351 			       const uint8_t *key __maybe_unused,
352 			       size_t key_len __maybe_unused,
353 			       const uint8_t *nonce __maybe_unused,
354 			       size_t nonce_len __maybe_unused,
355 			       size_t tag_len __maybe_unused,
356 			       size_t aad_len __maybe_unused,
357 			       size_t payload_len __maybe_unused)
358 {
359 	switch (algo) {
360 #if defined(CFG_CRYPTO_CCM)
361 	case TEE_ALG_AES_CCM:
362 		return crypto_aes_ccm_init(ctx, mode, key, key_len, nonce,
363 					   nonce_len, tag_len, aad_len,
364 					   payload_len);
365 #endif
366 #if defined(CFG_CRYPTO_GCM)
367 	case TEE_ALG_AES_GCM:
368 		return crypto_aes_gcm_init(ctx, mode, key, key_len, nonce,
369 					   nonce_len, tag_len);
370 #endif
371 	default:
372 		return TEE_ERROR_NOT_IMPLEMENTED;
373 	}
374 }
375 
376 TEE_Result crypto_authenc_update_aad(void *ctx __maybe_unused,
377 				     uint32_t algo __maybe_unused,
378 				     TEE_OperationMode mode __unused,
379 				     const uint8_t *data __maybe_unused,
380 				     size_t len __maybe_unused)
381 {
382 	switch (algo) {
383 #if defined(CFG_CRYPTO_CCM)
384 	case TEE_ALG_AES_CCM:
385 		return crypto_aes_ccm_update_aad(ctx, data, len);
386 #endif
387 #if defined(CFG_CRYPTO_GCM)
388 	case TEE_ALG_AES_GCM:
389 		return crypto_aes_gcm_update_aad(ctx, data, len);
390 #endif
391 	default:
392 		return TEE_ERROR_NOT_IMPLEMENTED;
393 	}
394 }
395 
396 TEE_Result crypto_authenc_update_payload(void *ctx __maybe_unused,
397 					 uint32_t algo __maybe_unused,
398 					 TEE_OperationMode mode __maybe_unused,
399 					 const uint8_t *src_data __maybe_unused,
400 					 size_t src_len __maybe_unused,
401 					 uint8_t *dst_data __maybe_unused,
402 					 size_t *dst_len __maybe_unused)
403 {
404 	size_t dl = *dst_len;
405 
406 	*dst_len = src_len;
407 	if (dl < src_len)
408 		return TEE_ERROR_SHORT_BUFFER;
409 
410 	switch (algo) {
411 #if defined(CFG_CRYPTO_CCM)
412 	case TEE_ALG_AES_CCM:
413 		return crypto_aes_ccm_update_payload(ctx, mode, src_data,
414 						     src_len, dst_data);
415 #endif
416 #if defined(CFG_CRYPTO_GCM)
417 	case TEE_ALG_AES_GCM:
418 		return crypto_aes_gcm_update_payload(ctx, mode, src_data,
419 						     src_len, dst_data);
420 #endif
421 	default:
422 		return TEE_ERROR_NOT_IMPLEMENTED;
423 	}
424 }
425 
426 TEE_Result crypto_authenc_enc_final(void *ctx __maybe_unused,
427 				    uint32_t algo __maybe_unused,
428 				    const uint8_t *src_data __maybe_unused,
429 				    size_t src_len __maybe_unused,
430 				    uint8_t *dst_data __maybe_unused,
431 				    size_t *dst_len __maybe_unused,
432 				    uint8_t *dst_tag __maybe_unused,
433 				    size_t *dst_tag_len __maybe_unused)
434 {
435 	size_t dl = *dst_len;
436 
437 	*dst_len = src_len;
438 	if (dl < src_len)
439 		return TEE_ERROR_SHORT_BUFFER;
440 
441 	switch (algo) {
442 #if defined(CFG_CRYPTO_CCM)
443 	case TEE_ALG_AES_CCM:
444 		return crypto_aes_ccm_enc_final(ctx, src_data, src_len,
445 						dst_data, dst_tag, dst_tag_len);
446 #endif
447 #if defined(CFG_CRYPTO_GCM)
448 	case TEE_ALG_AES_GCM:
449 		return crypto_aes_gcm_enc_final(ctx, src_data, src_len,
450 						dst_data, dst_tag, dst_tag_len);
451 #endif
452 	default:
453 		return TEE_ERROR_NOT_IMPLEMENTED;
454 	}
455 }
456 
457 TEE_Result crypto_authenc_dec_final(void *ctx __maybe_unused,
458 				    uint32_t algo __maybe_unused,
459 				    const uint8_t *src_data __maybe_unused,
460 				    size_t src_len __maybe_unused,
461 				    uint8_t *dst_data __maybe_unused,
462 				    size_t *dst_len __maybe_unused,
463 				    const uint8_t *tag __maybe_unused,
464 				    size_t tag_len __maybe_unused)
465 {
466 	size_t dl = *dst_len;
467 
468 	*dst_len = src_len;
469 	if (dl < src_len)
470 		return TEE_ERROR_SHORT_BUFFER;
471 
472 	switch (algo) {
473 #if defined(CFG_CRYPTO_CCM)
474 	case TEE_ALG_AES_CCM:
475 		return crypto_aes_ccm_dec_final(ctx, src_data, src_len,
476 						dst_data, tag, tag_len);
477 #endif
478 #if defined(CFG_CRYPTO_GCM)
479 	case TEE_ALG_AES_GCM:
480 		return crypto_aes_gcm_dec_final(ctx, src_data, src_len,
481 						dst_data, tag, tag_len);
482 #endif
483 	default:
484 		return TEE_ERROR_NOT_IMPLEMENTED;
485 	}
486 }
487 
488 void crypto_authenc_final(void *ctx __maybe_unused,
489 			  uint32_t algo __maybe_unused)
490 {
491 	switch (algo) {
492 #if defined(CFG_CRYPTO_CCM)
493 	case TEE_ALG_AES_CCM:
494 		crypto_aes_ccm_final(ctx);
495 		break;
496 #endif
497 #if defined(CFG_CRYPTO_GCM)
498 	case TEE_ALG_AES_GCM:
499 		crypto_aes_gcm_final(ctx);
500 		break;
501 #endif
502 	default:
503 		break;
504 	}
505 }
506 
507 #if !defined(_CFG_CRYPTO_WITH_ACIPHER)
508 struct bignum *crypto_bignum_allocate(size_t size_bits __unused)
509 {
510 	return NULL;
511 }
512 
513 TEE_Result crypto_bignum_bin2bn(const uint8_t *from __unused,
514 				size_t fromsize __unused,
515 				struct bignum *to __unused)
516 {
517 	return TEE_ERROR_NOT_IMPLEMENTED;
518 }
519 
520 size_t crypto_bignum_num_bytes(struct bignum *a __unused)
521 {
522 	return 0;
523 }
524 
525 size_t crypto_bignum_num_bits(struct bignum *a __unused)
526 {
527 	return 0;
528 }
529 
530 /*
531  * crypto_bignum_allocate() and crypto_bignum_bin2bn() failing should be
532  * enough to guarantee that the functions calling this function aren't
533  * called, but just in case add a panic() here to avoid unexpected
534  * behavoir.
535  */
536 static void bignum_cant_happen(void)
537 {
538 	volatile bool b = true;
539 
540 	/* Avoid warning about function does not return */
541 	if (b)
542 		panic();
543 }
544 
545 void crypto_bignum_bn2bin(const struct bignum *from __unused,
546 			  uint8_t *to __unused)
547 {
548 	bignum_cant_happen();
549 }
550 
551 void crypto_bignum_copy(struct bignum *to __unused,
552 			const struct bignum *from __unused)
553 {
554 	bignum_cant_happen();
555 }
556 
557 void crypto_bignum_free(struct bignum *a)
558 {
559 	if (a)
560 		panic();
561 }
562 
563 void crypto_bignum_clear(struct bignum *a __unused)
564 {
565 	bignum_cant_happen();
566 }
567 
568 /* return -1 if a<b, 0 if a==b, +1 if a>b */
569 int32_t crypto_bignum_compare(struct bignum *a __unused,
570 			      struct bignum *b __unused)
571 {
572 	bignum_cant_happen();
573 	return -1;
574 }
575 #endif /*!_CFG_CRYPTO_WITH_ACIPHER*/
576 
577 #if !defined(CFG_CRYPTO_RSA) || !defined(_CFG_CRYPTO_WITH_ACIPHER)
578 TEE_Result crypto_acipher_alloc_rsa_keypair(struct rsa_keypair *s __unused,
579 					    size_t key_size_bits __unused)
580 {
581 	return TEE_ERROR_NOT_IMPLEMENTED;
582 }
583 
584 TEE_Result
585 crypto_acipher_alloc_rsa_public_key(struct rsa_public_key *s __unused,
586 				    size_t key_size_bits __unused)
587 {
588 	return TEE_ERROR_NOT_IMPLEMENTED;
589 }
590 
591 void crypto_acipher_free_rsa_public_key(struct rsa_public_key *s __unused)
592 {
593 }
594 
595 TEE_Result crypto_acipher_gen_rsa_key(struct rsa_keypair *key __unused,
596 				      size_t key_size __unused)
597 {
598 	return TEE_ERROR_NOT_IMPLEMENTED;
599 }
600 
601 TEE_Result crypto_acipher_rsanopad_decrypt(struct rsa_keypair *key __unused,
602 					   const uint8_t *src __unused,
603 					   size_t src_len __unused,
604 					   uint8_t *dst __unused,
605 					   size_t *dst_len __unused)
606 {
607 	return TEE_ERROR_NOT_IMPLEMENTED;
608 }
609 
610 TEE_Result crypto_acipher_rsanopad_encrypt(struct rsa_public_key *key __unused,
611 					   const uint8_t *src __unused,
612 					   size_t src_len __unused,
613 					   uint8_t *dst __unused,
614 					   size_t *dst_len __unused)
615 {
616 	return TEE_ERROR_NOT_IMPLEMENTED;
617 }
618 
619 TEE_Result crypto_acipher_rsaes_decrypt(uint32_t algo __unused,
620 					struct rsa_keypair *key __unused,
621 					const uint8_t *label __unused,
622 					size_t label_len __unused,
623 					const uint8_t *src __unused,
624 					size_t src_len __unused,
625 					uint8_t *dst __unused,
626 					size_t *dst_len __unused)
627 {
628 	return TEE_ERROR_NOT_IMPLEMENTED;
629 }
630 
631 TEE_Result crypto_acipher_rsaes_encrypt(uint32_t algo __unused,
632 					struct rsa_public_key *key __unused,
633 					const uint8_t *label __unused,
634 					size_t label_len __unused,
635 					const uint8_t *src __unused,
636 					size_t src_len __unused,
637 					uint8_t *dst __unused,
638 					size_t *dst_len __unused)
639 {
640 	return TEE_ERROR_NOT_IMPLEMENTED;
641 }
642 
643 TEE_Result crypto_acipher_rsassa_sign(uint32_t algo __unused,
644 				      struct rsa_keypair *key __unused,
645 				      int salt_len __unused,
646 				      const uint8_t *msg __unused,
647 				      size_t msg_len __unused,
648 				      uint8_t *sig __unused,
649 				      size_t *sig_len __unused)
650 {
651 	return TEE_ERROR_NOT_IMPLEMENTED;
652 }
653 
654 TEE_Result crypto_acipher_rsassa_verify(uint32_t algo __unused,
655 					struct rsa_public_key *key __unused,
656 					int salt_len __unused,
657 					const uint8_t *msg __unused,
658 					size_t msg_len __unused,
659 					const uint8_t *sig __unused,
660 					size_t sig_len __unused)
661 {
662 	return TEE_ERROR_NOT_IMPLEMENTED;
663 }
664 #endif /*!CFG_CRYPTO_RSA || !_CFG_CRYPTO_WITH_ACIPHER*/
665 
666 #if !defined(CFG_CRYPTO_DSA) || !defined(_CFG_CRYPTO_WITH_ACIPHER)
667 TEE_Result crypto_acipher_alloc_dsa_keypair(struct dsa_keypair *s __unused,
668 					    size_t key_size_bits __unused)
669 {
670 	return TEE_ERROR_NOT_IMPLEMENTED;
671 }
672 
673 TEE_Result
674 crypto_acipher_alloc_dsa_public_key(struct dsa_public_key *s __unused,
675 				    size_t key_size_bits __unused)
676 {
677 	return TEE_ERROR_NOT_IMPLEMENTED;
678 }
679 
680 TEE_Result crypto_acipher_gen_dsa_key(struct dsa_keypair *key __unused,
681 				      size_t key_size __unused)
682 {
683 	return TEE_ERROR_NOT_IMPLEMENTED;
684 }
685 
686 TEE_Result crypto_acipher_dsa_sign(uint32_t algo __unused,
687 				   struct dsa_keypair *key __unused,
688 				   const uint8_t *msg __unused,
689 				   size_t msg_len __unused,
690 				   uint8_t *sig __unused,
691 				   size_t *sig_len __unused)
692 {
693 	return TEE_ERROR_NOT_IMPLEMENTED;
694 }
695 
696 TEE_Result crypto_acipher_dsa_verify(uint32_t algo __unused,
697 				     struct dsa_public_key *key __unused,
698 				     const uint8_t *msg __unused,
699 				     size_t msg_len __unused,
700 				     const uint8_t *sig __unused,
701 				     size_t sig_len __unused)
702 {
703 	return TEE_ERROR_NOT_IMPLEMENTED;
704 }
705 #endif /*!CFG_CRYPTO_DSA || !_CFG_CRYPTO_WITH_ACIPHER*/
706 
707 #if !defined(CFG_CRYPTO_DH) || !defined(_CFG_CRYPTO_WITH_ACIPHER)
708 TEE_Result crypto_acipher_alloc_dh_keypair(struct dh_keypair *s __unused,
709 					   size_t key_size_bits __unused)
710 {
711 	return TEE_ERROR_NOT_IMPLEMENTED;
712 }
713 
714 TEE_Result crypto_acipher_gen_dh_key(struct dh_keypair *key __unused,
715 				     struct bignum *q __unused,
716 				     size_t xbits __unused)
717 {
718 	return TEE_ERROR_NOT_IMPLEMENTED;
719 }
720 
721 TEE_Result
722 crypto_acipher_dh_shared_secret(struct dh_keypair *private_key __unused,
723 				struct bignum *public_key __unused,
724 				struct bignum *secret __unused)
725 {
726 	return TEE_ERROR_NOT_IMPLEMENTED;
727 }
728 #endif /*!CFG_CRYPTO_DH || !_CFG_CRYPTO_WITH_ACIPHER*/
729 
730 #if !defined(CFG_CRYPTO_ECC) || !defined(_CFG_CRYPTO_WITH_ACIPHER)
731 TEE_Result
732 crypto_acipher_alloc_ecc_public_key(struct ecc_public_key *s __unused,
733 				    size_t key_size_bits __unused)
734 {
735 	return TEE_ERROR_NOT_IMPLEMENTED;
736 }
737 
738 TEE_Result crypto_acipher_alloc_ecc_keypair(struct ecc_keypair *s __unused,
739 					    size_t key_size_bits __unused)
740 {
741 	return TEE_ERROR_NOT_IMPLEMENTED;
742 }
743 
744 void crypto_acipher_free_ecc_public_key(struct ecc_public_key *s __unused)
745 {
746 }
747 
748 TEE_Result crypto_acipher_gen_ecc_key(struct ecc_keypair *key __unused)
749 {
750 	return TEE_ERROR_NOT_IMPLEMENTED;
751 }
752 
753 TEE_Result crypto_acipher_ecc_sign(uint32_t algo __unused,
754 				   struct ecc_keypair *key __unused,
755 				   const uint8_t *msg __unused,
756 				   size_t msg_len __unused,
757 				   uint8_t *sig __unused,
758 				   size_t *sig_len __unused)
759 {
760 	return TEE_ERROR_NOT_IMPLEMENTED;
761 }
762 
763 TEE_Result crypto_acipher_ecc_verify(uint32_t algo __unused,
764 				     struct ecc_public_key *key __unused,
765 				     const uint8_t *msg __unused,
766 				     size_t msg_len __unused,
767 				     const uint8_t *sig __unused,
768 				     size_t sig_len __unused)
769 {
770 	return TEE_ERROR_NOT_IMPLEMENTED;
771 }
772 
773 TEE_Result
774 crypto_acipher_ecc_shared_secret(struct ecc_keypair *private_key __unused,
775 				 struct ecc_public_key *public_key __unused,
776 				 void *secret __unused,
777 				 unsigned long *secret_len __unused)
778 {
779 	return TEE_ERROR_NOT_IMPLEMENTED;
780 }
781 #endif /*!CFG_CRYPTO_ECC || !_CFG_CRYPTO_WITH_ACIPHER*/
782