Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 1 | /* |
dp-arm | 52b1fe5 | 2017-03-07 10:08:42 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved. |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 5 | */ |
6 | |||||
Antonio Nino Diaz | 6b90f5e | 2017-05-19 11:37:22 +0100 | [diff] [blame] | 7 | #include <debug.h> |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 8 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 9 | /* mbed TLS headers */ |
10 | #include <mbedtls/memory_buffer_alloc.h> | ||||
Antonio Nino Diaz | 6b90f5e | 2017-05-19 11:37:22 +0100 | [diff] [blame] | 11 | #include <mbedtls/platform.h> |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 12 | |
13 | /* | ||||
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 14 | * mbed TLS heap |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 15 | */ |
David Cunado | c7a1b19 | 2017-05-10 16:38:44 +0100 | [diff] [blame] | 16 | #if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 17 | #define MBEDTLS_HEAP_SIZE (14*1024) |
David Cunado | c7a1b19 | 2017-05-10 16:38:44 +0100 | [diff] [blame] | 18 | #elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA) |
Soby Mathew | cd4a5a9 | 2017-06-05 12:18:04 +0100 | [diff] [blame] | 19 | #define MBEDTLS_HEAP_SIZE (7*1024) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 20 | #endif |
21 | static unsigned char heap[MBEDTLS_HEAP_SIZE]; | ||||
22 | |||||
23 | /* | ||||
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 24 | * mbed TLS initialization function |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 25 | */ |
26 | void mbedtls_init(void) | ||||
27 | { | ||||
28 | static int ready; | ||||
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 29 | |
30 | if (!ready) { | ||||
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 31 | /* Initialize the mbed TLS heap */ |
32 | mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE); | ||||
Antonio Nino Diaz | 6b90f5e | 2017-05-19 11:37:22 +0100 | [diff] [blame] | 33 | |
34 | /* Use reduced version of snprintf to save space. */ | ||||
35 | mbedtls_platform_set_snprintf(tf_snprintf); | ||||
36 | |||||
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 37 | ready = 1; |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 38 | } |
39 | } |