1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3 * Copyright (C) 2018, ARM Limited
4 * Copyright (C) 2019, Linaro Limited
5 */
6
7 #ifndef MBED_HELPERS_H
8 #define MBED_HELPERS_H
9
10 #include <crypto/crypto.h>
11 #include <mbedtls/aes.h>
12 #include <mbedtls/bignum.h>
13 #include <mbedtls/ctr_drbg.h>
14 #include <tee_api_types.h>
15
mbd_rand(void * rng_state __unused,unsigned char * output,size_t len)16 static inline int mbd_rand(void *rng_state __unused, unsigned char *output,
17 size_t len)
18 {
19 if (crypto_rng_read(output, len))
20 return MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED;
21 return 0;
22 }
23
mbed_copy_mbedtls_aes_context(mbedtls_aes_context * dst,mbedtls_aes_context * src)24 static inline void mbed_copy_mbedtls_aes_context(mbedtls_aes_context *dst,
25 mbedtls_aes_context *src)
26 {
27 *dst = *src;
28 }
29
30 TEE_Result mbed_gen_random_upto(mbedtls_mpi *n, mbedtls_mpi *max);
31 #endif /*MBED_HELPERS_H*/
32