2015-04-02 15:44:20 +01:00
|
|
|
/*
|
2017-03-07 10:08:42 +00:00
|
|
|
* Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
|
2015-04-02 15:44:20 +01:00
|
|
|
*
|
2017-05-03 09:38:09 +01:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2015-04-02 15:44:20 +01:00
|
|
|
*/
|
|
|
|
|
2017-05-19 11:37:22 +01:00
|
|
|
#include <debug.h>
|
2015-04-02 15:44:20 +01:00
|
|
|
|
2015-11-05 09:24:53 +00:00
|
|
|
/* mbed TLS headers */
|
|
|
|
#include <mbedtls/memory_buffer_alloc.h>
|
2017-05-19 11:37:22 +01:00
|
|
|
#include <mbedtls/platform.h>
|
2015-04-02 15:44:20 +01:00
|
|
|
|
|
|
|
/*
|
2015-11-05 09:24:53 +00:00
|
|
|
* mbed TLS heap
|
2015-04-02 15:44:20 +01:00
|
|
|
*/
|
2017-05-10 16:38:44 +01:00
|
|
|
#if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA)
|
2015-04-02 15:44:20 +01:00
|
|
|
#define MBEDTLS_HEAP_SIZE (14*1024)
|
2017-05-10 16:38:44 +01:00
|
|
|
#elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA)
|
2017-05-19 16:57:54 +01:00
|
|
|
#define MBEDTLS_HEAP_SIZE (6*1024)
|
2015-04-02 15:44:20 +01:00
|
|
|
#endif
|
|
|
|
static unsigned char heap[MBEDTLS_HEAP_SIZE];
|
|
|
|
|
|
|
|
/*
|
2015-11-05 09:24:53 +00:00
|
|
|
* mbed TLS initialization function
|
2015-04-02 15:44:20 +01:00
|
|
|
*/
|
|
|
|
void mbedtls_init(void)
|
|
|
|
{
|
|
|
|
static int ready;
|
|
|
|
|
|
|
|
if (!ready) {
|
2015-11-05 09:24:53 +00:00
|
|
|
/* Initialize the mbed TLS heap */
|
|
|
|
mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE);
|
2017-05-19 11:37:22 +01:00
|
|
|
|
|
|
|
/* Use reduced version of snprintf to save space. */
|
|
|
|
mbedtls_platform_set_snprintf(tf_snprintf);
|
|
|
|
|
2015-11-05 09:24:53 +00:00
|
|
|
ready = 1;
|
2015-04-02 15:44:20 +01:00
|
|
|
}
|
|
|
|
}
|