blob: 336e44be6f4cce8ed47f25904a1e7288021ceb6e [file] [log] [blame]
Juan Castilloa57a4d52015-04-02 15:44:20 +01001/*
dp-arm52b1fe52017-03-07 10:08:42 +00002 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Juan Castilloa57a4d52015-04-02 15:44:20 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Juan Castilloa57a4d52015-04-02 15:44:20 +01005 */
6
Antonio Nino Diaz6b90f5e2017-05-19 11:37:22 +01007#include <debug.h>
Juan Castilloa57a4d52015-04-02 15:44:20 +01008
Juan Castillobae6b2a2015-11-05 09:24:53 +00009/* mbed TLS headers */
10#include <mbedtls/memory_buffer_alloc.h>
Antonio Nino Diaz6b90f5e2017-05-19 11:37:22 +010011#include <mbedtls/platform.h>
Juan Castilloa57a4d52015-04-02 15:44:20 +010012
13/*
Juan Castillobae6b2a2015-11-05 09:24:53 +000014 * mbed TLS heap
Juan Castilloa57a4d52015-04-02 15:44:20 +010015 */
David Cunadoc7a1b192017-05-10 16:38:44 +010016#if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA)
Juan Castilloa57a4d52015-04-02 15:44:20 +010017#define MBEDTLS_HEAP_SIZE (14*1024)
David Cunadoc7a1b192017-05-10 16:38:44 +010018#elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA)
Antonio Nino Diaz45fc0e12017-05-19 16:57:54 +010019#define MBEDTLS_HEAP_SIZE (6*1024)
Juan Castilloa57a4d52015-04-02 15:44:20 +010020#endif
21static unsigned char heap[MBEDTLS_HEAP_SIZE];
22
23/*
Juan Castillobae6b2a2015-11-05 09:24:53 +000024 * mbed TLS initialization function
Juan Castilloa57a4d52015-04-02 15:44:20 +010025 */
26void mbedtls_init(void)
27{
28 static int ready;
Juan Castilloa57a4d52015-04-02 15:44:20 +010029
30 if (!ready) {
Juan Castillobae6b2a2015-11-05 09:24:53 +000031 /* Initialize the mbed TLS heap */
32 mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
Antonio Nino Diaz6b90f5e2017-05-19 11:37:22 +010033
34 /* Use reduced version of snprintf to save space. */
35 mbedtls_platform_set_snprintf(tf_snprintf);
36
Juan Castillobae6b2a2015-11-05 09:24:53 +000037 ready = 1;
Juan Castilloa57a4d52015-04-02 15:44:20 +010038 }
39}