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 | |
| 7 | #include <assert.h> |
| 8 | |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 9 | /* mbed TLS headers */ |
| 10 | #include <mbedtls/memory_buffer_alloc.h> |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 11 | |
| 12 | /* |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 13 | * mbed TLS heap |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 14 | */ |
David Cunado | c7a1b19 | 2017-05-10 16:38:44 +0100 | [diff] [blame] | 15 | #if (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_ECDSA) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 16 | #define MBEDTLS_HEAP_SIZE (14*1024) |
David Cunado | c7a1b19 | 2017-05-10 16:38:44 +0100 | [diff] [blame] | 17 | #elif (TF_MBEDTLS_KEY_ALG_ID == TF_MBEDTLS_RSA) |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 18 | #define MBEDTLS_HEAP_SIZE (8*1024) |
| 19 | #endif |
| 20 | static unsigned char heap[MBEDTLS_HEAP_SIZE]; |
| 21 | |
| 22 | /* |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 23 | * mbed TLS initialization function |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 24 | */ |
| 25 | void mbedtls_init(void) |
| 26 | { |
| 27 | static int ready; |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 28 | |
| 29 | if (!ready) { |
Juan Castillo | bae6b2a | 2015-11-05 09:24:53 +0000 | [diff] [blame] | 30 | /* Initialize the mbed TLS heap */ |
| 31 | mbedtls_memory_buffer_alloc_init(heap, MBEDTLS_HEAP_SIZE); |
| 32 | ready = 1; |
Juan Castillo | a57a4d5 | 2015-04-02 15:44:20 +0100 | [diff] [blame] | 33 | } |
| 34 | } |