From be483d76d76c54c83c4511dc27de0fe050569a85 Mon Sep 17 00:00:00 2001 From: Maciej Baczmanski Date: Mon, 28 Aug 2023 08:28:20 +0200 Subject: [PATCH] modules: openthread: initialize settings in `otPlatCryptoInit()` In OpenThread, Settings are initialized after KeyManager by default. If device uses PSA with emulated TFM, Settings have to be initialized at the end of otPlatCryptoInit(), to be available before storing Network Key. Signed-off-by: Maciej Baczmanski --- modules/openthread/platform/crypto_psa.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/openthread/platform/crypto_psa.c b/modules/openthread/platform/crypto_psa.c index b5a63d60e43..e61177ef4c4 100644 --- a/modules/openthread/platform/crypto_psa.c +++ b/modules/openthread/platform/crypto_psa.c @@ -8,9 +8,14 @@ #include +#include + +#if !defined(CONFIG_BUILD_WITH_TFM) && defined(CONFIG_OPENTHREAD_CRYPTO_PSA) +#include +#endif + #if defined(CONFIG_OPENTHREAD_ECDSA) #include -#include #endif static otError psaToOtError(psa_status_t aStatus) @@ -125,6 +130,17 @@ static void ensureKeyIsLoaded(otCryptoKeyRef aKeyRef) void otPlatCryptoInit(void) { psa_crypto_init(); + +#if !defined(CONFIG_BUILD_WITH_TFM) && defined(CONFIG_OPENTHREAD_CRYPTO_PSA) + /* + * In OpenThread, Settings are initialized after KeyManager by default. If device uses + * PSA with emulated TFM, Settings have to be initialized at the end of otPlatCryptoInit(), + * to be available before storing Network Key. + */ + int err = settings_subsys_init(); + + __ASSERT(!err, "Failed to initialize settings"); +#endif } otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef,