Skip to content

Commit

Permalink
samples: psa_crypto: fix setting of TF-M's CRYPTO_ENGINE_BUF_SIZE
Browse files Browse the repository at this point in the history
It used to be set as a CMake variable, but TF-M's build system does
not look at such a variable.
Instead, define an additional configuration header file that defines
CRYPTO_ENGINE_BUF_SIZE, and pass it to TF-M's build system.

Signed-off-by: Tomi Fontanilles <[email protected]>
  • Loading branch information
tomi-font authored and carlescufi committed May 29, 2024
1 parent 1eaa140 commit 6eccdb9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
6 changes: 2 additions & 4 deletions samples/tfm_integration/psa_crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ target_include_directories(app PRIVATE
$<TARGET_PROPERTY:tfm,TFM_BINARY_DIR>/api_ns/interface/include
)

# In TF-M, default value of CRYPTO_ENGINE_BUF_SIZE is 0x2080. It causes
# insufficient memory failure while verifying signature. Increase it to 0x2400.
set_property(TARGET zephyr_property_target
APPEND PROPERTY TFM_CMAKE_OPTIONS
-DCRYPTO_ENGINE_BUF_SIZE=0x2400
-DPROJECT_CONFIG_HEADER_FILE=${CMAKE_CURRENT_SOURCE_DIR}/src/configs/config_tfm.h
)

zephyr_include_directories(${APPLICATION_SOURCE_DIR}/src/tls_config)
zephyr_include_directories(${APPLICATION_SOURCE_DIR}/src/configs)
2 changes: 1 addition & 1 deletion samples/tfm_integration/psa_crypto/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=32768
CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y
CONFIG_MBEDTLS_USER_CONFIG_FILE="user-tls-conf.h"
CONFIG_MBEDTLS_USER_CONFIG_FILE="config_mbedtls.h"

CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_MBEDTLS_ENTROPY_ENABLED=y
Expand Down
10 changes: 10 additions & 0 deletions samples/tfm_integration/psa_crypto/src/configs/config_tfm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2024 Nordic Semiconductor
*
* SPDX-License-Identifier: Apache-2.0
*/

/* In TF-M the default value of CRYPTO_ENGINE_BUF_SIZE is 0x2080.
* It causes insufficient memory failure while verifying signature.
*/
#define CRYPTO_ENGINE_BUF_SIZE 0x2400
2 changes: 2 additions & 0 deletions samples/tfm_integration/psa_crypto/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ int main(void)
/* Dump any queued log messages, and wait for system events. */
al_dump_log();

LOG_INF("Done.");

return 0;
}
2 changes: 1 addition & 1 deletion samples/tfm_integration/psa_crypto/src/psa_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void crp_generate_csr(void)
LOG_INF("Certificate Signing Request in JSON:\n");
al_dump_log();

printf("%s\n", json_encoded_buf);
printf("%s\n\n", json_encoded_buf);

/* Close the key to free up the volatile slot. */
status = al_psa_status(
Expand Down

0 comments on commit 6eccdb9

Please sign in to comment.