Skip to content

Commit 3a4c9e4

Browse files
frkvrlubos
authored andcommitted
[nrf fromtree dirty] Crypto: Allow turning off MBEDTLS_MEMORY_BUFFER_ALLOC_C
This commit disables initialization of Mbed TLS heap in the crypto library when MBEDTLS_MEMORY_BUFFER_ALLOC_C is not enabled. Before this commit Mbed TLS heap was always required. Note that this cherry-pick is not clean as the code is changed from TF-M 2.2 to main (2.3) around logging. This fromlist is taken from a commit to main. Change-Id: Id6f3fc4dee2c2512ba8bcd346b38bac69b890a73 Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no> (cherry picked from commit 3776100)
1 parent 471f3b5 commit 3a4c9e4

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

secure_fw/partitions/crypto/crypto_library.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ static char mbedtls_version_full[18];
5656
* \brief Static buffer to be used by Mbed Crypto for memory allocations
5757
*
5858
*/
59+
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
5960
#include "config_engine_buf.h"
6061
static uint8_t mbedtls_mem_buf[CRYPTO_ENGINE_BUF_SIZE] = {0};
62+
#endif
6163

6264
/* Make sure the library won't print anything through mbedtls_printf */
6365
static int null_printf(const char *fmt, ...)
@@ -89,12 +91,18 @@ psa_status_t tfm_crypto_core_library_init(void)
8991
/* Initialise the Mbed Crypto memory allocator to use static memory
9092
* allocation from the provided buffer instead of using the heap
9193
*/
94+
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
9295
mbedtls_memory_buffer_alloc_init(mbedtls_mem_buf,
9396
CRYPTO_ENGINE_BUF_SIZE);
97+
#endif
9498

9599
mbedtls_platform_set_printf(null_printf);
96100

101+
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
97102
LOG_DBGFMT("[DBG][Crypto] Internal heap size is %d bytes\r\n", sizeof(mbedtls_mem_buf));
103+
#else
104+
LOG_DBGFMT("[DBG][Crypto] No internal heap\r\n");
105+
#endif
98106

99107
return PSA_SUCCESS;
100108
}

0 commit comments

Comments
 (0)