xref: /optee_os/core/lib/libtomcrypt/acipher_helpers.h (revision c0691130969b2629f6a772dd9543244e6c92a57b)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014-2019, Linaro Limited
4  */
5 
6 #ifndef ACIPHER_HELPERS_H
7 #define ACIPHER_HELPERS_H
8 
9 #include <crypto/crypto.h>
10 #include <tee_api_defines.h>
11 #include <tee_api_types.h>
12 #include <tomcrypt_private.h>
13 #include <types_ext.h>
14 
15 static inline bool bn_alloc_max(struct bignum **s)
16 {
17 	*s = crypto_bignum_allocate(_CFG_CORE_LTC_BIGNUM_MAX_BITS);
18 
19 	return *s;
20 }
21 
22 static inline TEE_Result convert_ltc_verify_status(int ltc_res, int ltc_stat)
23 {
24 	switch (ltc_res) {
25 	case CRYPT_OK:
26 		if (ltc_stat == 1)
27 			return TEE_SUCCESS;
28 		else
29 			return TEE_ERROR_SIGNATURE_INVALID;
30 	case CRYPT_INVALID_PACKET:
31 		return TEE_ERROR_SIGNATURE_INVALID;
32 	default:
33 		return TEE_ERROR_GENERIC;
34 	}
35 }
36 
37 #ifdef CFG_CRYPTOLIB_NAME_tomcrypt
38 TEE_Result ecc_populate_ltc_private_key(ecc_key *ltc_key,
39 					struct ecc_keypair *key,
40 					uint32_t algo, size_t *key_size_bytes);
41 TEE_Result ecc_populate_ltc_public_key(ecc_key *ltc_key,
42 				       struct ecc_public_key *key,
43 				       uint32_t algo, size_t *key_size_bytes);
44 #endif
45 
46 #endif /* ACIPHER_HELPERS_H */
47