xref: /rk3399_ARM-atf/drivers/auth/mbedtls/mbedtls_common.c (revision b91926fd50f6d28fdb396f763165326cb3af17b8)
1 /*
2  * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <debug.h>
8 
9 /* mbed TLS headers */
10 #include <mbedtls/memory_buffer_alloc.h>
11 #include <mbedtls/platform.h>
12 #include <mbedtls_config.h>
13 
14 /*
15  * mbed TLS heap
16  */
17 #if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA)
18 #define MBEDTLS_HEAP_SIZE		(14*1024)
19 #elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA)
20 #define MBEDTLS_HEAP_SIZE		(7*1024)
21 #endif
22 static unsigned char heap[MBEDTLS_HEAP_SIZE];
23 
24 /*
25  * mbed TLS initialization function
26  */
27 void mbedtls_init(void)
28 {
29 	static int ready;
30 
31 	if (!ready) {
32 		/* Initialize the mbed TLS heap */
33 		mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
34 
35 #ifdef MBEDTLS_PLATFORM_SNPRINTF_ALT
36 		/* Use reduced version of snprintf to save space. */
37 		mbedtls_platform_set_snprintf(tf_snprintf);
38 #endif
39 
40 		ready = 1;
41 	}
42 }
43