blob: aad49a7152ef58789eadb25371a9ee24240cf416 [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
7#include <assert.h>
8
Juan Castillobae6b2a2015-11-05 09:24:53 +00009/* mbed TLS headers */
10#include <mbedtls/memory_buffer_alloc.h>
Juan Castilloa57a4d52015-04-02 15:44:20 +010011
12/*
Juan Castillobae6b2a2015-11-05 09:24:53 +000013 * mbed TLS heap
Juan Castilloa57a4d52015-04-02 15:44:20 +010014 */
David Cunadoc7a1b192017-05-10 16:38:44 +010015#if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA)
Juan Castilloa57a4d52015-04-02 15:44:20 +010016#define MBEDTLS_HEAP_SIZE (14*1024)
David Cunadoc7a1b192017-05-10 16:38:44 +010017#elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA)
Juan Castilloa57a4d52015-04-02 15:44:20 +010018#define MBEDTLS_HEAP_SIZE (8*1024)
19#endif
20static unsigned char heap[MBEDTLS_HEAP_SIZE];
21
22/*
Juan Castillobae6b2a2015-11-05 09:24:53 +000023 * mbed TLS initialization function
Juan Castilloa57a4d52015-04-02 15:44:20 +010024 */
25void mbedtls_init(void)
26{
27 static int ready;
Juan Castilloa57a4d52015-04-02 15:44:20 +010028
29 if (!ready) {
Juan Castillobae6b2a2015-11-05 09:24:53 +000030 /* Initialize the mbed TLS heap */
31 mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
32 ready = 1;
Juan Castilloa57a4d52015-04-02 15:44:20 +010033 }
34}