mbedtls_common.c 974 Bytes
Newer Older
1
/*
Roberto Vargas's avatar
Roberto Vargas committed
2
 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
#include <debug.h>
8

Juan Castillo's avatar
Juan Castillo committed
9
10
/* mbed TLS headers */
#include <mbedtls/memory_buffer_alloc.h>
11
#include <mbedtls/platform.h>
12
#include <mbedtls_config.h>
Roberto Vargas's avatar
Roberto Vargas committed
13
#include <mbedtls_common.h>
14
15

/*
Juan Castillo's avatar
Juan Castillo committed
16
 * mbed TLS heap
17
 */
Qixiang Xu's avatar
Qixiang Xu committed
18
19
#if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA) \
	|| (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA_AND_ECDSA)
20
#define MBEDTLS_HEAP_SIZE		(13*1024)
21
#elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA)
22
#define MBEDTLS_HEAP_SIZE		(7*1024)
23
24
25
26
#endif
static unsigned char heap[MBEDTLS_HEAP_SIZE];

/*
Juan Castillo's avatar
Juan Castillo committed
27
 * mbed TLS initialization function
28
29
30
31
32
33
 */
void mbedtls_init(void)
{
	static int ready;

	if (!ready) {
Juan Castillo's avatar
Juan Castillo committed
34
35
		/* Initialize the mbed TLS heap */
		mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
36

37
#ifdef MBEDTLS_PLATFORM_SNPRINTF_ALT
38
39
		/* Use reduced version of snprintf to save space. */
		mbedtls_platform_set_snprintf(tf_snprintf);
40
#endif
41

Juan Castillo's avatar
Juan Castillo committed
42
		ready = 1;
43
44
	}
}