mbedtls_common.c 1.03 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
#include <stdio.h>
10

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

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

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

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

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

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

48
#ifdef MBEDTLS_PLATFORM_SNPRINTF_ALT
49
		mbedtls_platform_set_snprintf(snprintf);
50
#endif
Juan Castillo's avatar
Juan Castillo committed
51
		ready = 1;
52
53
	}
}