Antonio de Angelis | 8908f47 | 2018-08-31 15:44:25 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "tfm_crypto_defs.h" |
| 9 | #include "tfm_crypto_api.h" |
| 10 | |
| 11 | /* Pre include Mbed TLS headers */ |
| 12 | #define LIB_PREFIX_NAME __tfm_crypto__ |
| 13 | #include "mbedtls_global_symbols.h" |
| 14 | |
| 15 | /* Include the Mbed TLS configuration file, the way Mbed TLS does it |
| 16 | * in each of its header files. |
| 17 | */ |
| 18 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 19 | #include "platform/ext/common/tfm_mbedtls_config.h" |
| 20 | #else |
| 21 | #include MBEDTLS_CONFIG_FILE |
| 22 | #endif |
| 23 | |
| 24 | #include "mbedtls/memory_buffer_alloc.h" |
| 25 | |
| 26 | /** |
| 27 | * \brief Buffer size used by Mbed TLS for its allocations |
| 28 | */ |
| 29 | #define TFM_CRYPTO_MBEDTLS_MEM_BUF_LEN (1024) |
| 30 | |
| 31 | /** |
| 32 | * \brief Static buffer to be used by Mbed TLS for memory allocations |
| 33 | * |
| 34 | */ |
| 35 | static uint8_t mbedtls_mem_buf[TFM_CRYPTO_MBEDTLS_MEM_BUF_LEN] = {0}; |
| 36 | |
| 37 | enum tfm_crypto_err_t tfm_crypto_init(void) |
| 38 | { |
| 39 | /* Initialise everything that is needed */ |
| 40 | |
| 41 | /* Initialise the Mbed TLS static memory allocator so that Mbed TLS |
| 42 | * allocates memory from the provided static buffer instead of from |
| 43 | * the heap. |
| 44 | */ |
| 45 | mbedtls_memory_buffer_alloc_init(mbedtls_mem_buf, |
| 46 | TFM_CRYPTO_MBEDTLS_MEM_BUF_LEN); |
| 47 | |
| 48 | return TFM_CRYPTO_ERR_PSA_SUCCESS; |
| 49 | } |