xref: /optee_os/core/lib/libtomcrypt/acipher_helpers.h (revision a1cbb728630308fcf902a8953a32cc972d14757e)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2014-2019, Linaro Limited
4  */
5 
6 #include <crypto/crypto.h>
7 #include <tee_api_defines.h>
8 #include <types_ext.h>
9 
10 static inline bool bn_alloc_max(struct bignum **s)
11 {
12 	*s = crypto_bignum_allocate(_CFG_CORE_LTC_BIGNUM_MAX_BITS);
13 
14 	return *s;
15 }
16 
17 static inline TEE_Result convert_ltc_verify_status(int ltc_res, int ltc_stat)
18 {
19 	switch (ltc_res) {
20 	case CRYPT_OK:
21 		if (ltc_stat == 1)
22 			return TEE_SUCCESS;
23 		else
24 			return TEE_ERROR_SIGNATURE_INVALID;
25 	case CRYPT_INVALID_PACKET:
26 		return TEE_ERROR_SIGNATURE_INVALID;
27 	default:
28 		return TEE_ERROR_GENERIC;
29 	}
30 }
31