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 13 /* 14 * mbed TLS heap 15 */ 16 #if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA) 17 #define MBEDTLS_HEAP_SIZE (14*1024) 18 #elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA) 19 #define MBEDTLS_HEAP_SIZE (7*1024) 20 #endif 21 static unsigned char heap[MBEDTLS_HEAP_SIZE]; 22 23 /* 24 * mbed TLS initialization function 25 */ 26 void mbedtls_init(void) 27 { 28 static int ready; 29 30 if (!ready) { 31 /* Initialize the mbed TLS heap */ 32 mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE); 33 34 /* Use reduced version of snprintf to save space. */ 35 mbedtls_platform_set_snprintf(tf_snprintf); 36 37 ready = 1; 38 } 39 } 40