mbedtls_common.c 1.07 KB
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>
Roberto Vargas's avatar
Roberto Vargas committed
8
#include <stdlib.h>
9

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

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

Roberto Vargas's avatar
Roberto Vargas committed
27
28
29
30
31
32
static void cleanup(void)
{
	ERROR("EXIT from BL2\n");
	panic();
}

33
/*
Juan Castillo's avatar
Juan Castillo committed
34
 * mbed TLS initialization function
35
36
37
38
39
40
 */
void mbedtls_init(void)
{
	static int ready;

	if (!ready) {
Roberto Vargas's avatar
Roberto Vargas committed
41
42
43
		if (atexit(cleanup))
			panic();

Juan Castillo's avatar
Juan Castillo committed
44
45
		/* Initialize the mbed TLS heap */
		mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
46

47
#ifdef MBEDTLS_PLATFORM_SNPRINTF_ALT
48
49
		/* Use reduced version of snprintf to save space. */
		mbedtls_platform_set_snprintf(tf_snprintf);
50
#endif
51

Juan Castillo's avatar
Juan Castillo committed
52
		ready = 1;
53
54
	}
}