From 6b167f1cd377fba48bca8e5d6433347eced6d609 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Duda?= Date: Wed, 7 May 2025 00:19:43 +0200 Subject: [PATCH] [crypto] PSA API: remove otPlatCryptoInit API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit removes otPlatCryptoInit API and moves responsibility of initializing the Crypto subsystem to the platform. Signed-off-by: Ɓukasz Duda --- examples/platforms/simulation/system.c | 9 ++++++++- .../platforms/simulation/virtual_time/platform-sim.c | 9 ++++++++- include/openthread/instance.h | 2 +- include/openthread/platform/crypto.h | 5 ----- src/core/crypto/crypto_platform_mbedtls.cpp | 5 ----- src/core/crypto/crypto_platform_psa.cpp | 2 -- src/core/thread/key_manager.cpp | 2 -- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/platforms/simulation/system.c b/examples/platforms/simulation/system.c index 68e921691..62e8be8b3 100644 --- a/examples/platforms/simulation/system.c +++ b/examples/platforms/simulation/system.c @@ -52,6 +52,10 @@ #include #include +#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) +#include +#endif + #include "simul_utils.h" uint32_t gNodeId = 1; @@ -198,10 +202,13 @@ void otSysInit(int aArgCount, char *aArgVector[]) signal(SIGTERM, &handleSignal); signal(SIGHUP, &handleSignal); -#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) +#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) + psa_crypto_init(); +#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE snprintf(sNativeItsFileNamePrefix, sizeof(sNativeItsFileNamePrefix), "%s/%s_%d_", OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId); gItsFileNamePrefix = sNativeItsFileNamePrefix; +#endif #endif platformLoggingInit(basename(aArgVector[0])); diff --git a/examples/platforms/simulation/virtual_time/platform-sim.c b/examples/platforms/simulation/virtual_time/platform-sim.c index 2c77bc396..12030744a 100644 --- a/examples/platforms/simulation/virtual_time/platform-sim.c +++ b/examples/platforms/simulation/virtual_time/platform-sim.c @@ -50,6 +50,10 @@ #include #include +#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) +#include +#endif + #include "lib/platform/exit_code.h" #include "utils/uart.h" @@ -278,10 +282,13 @@ void otSysInit(int argc, char *argv[]) DieNow(OT_EXIT_FAILURE); } -#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE && (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) +#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA) + psa_crypto_init(); +#if OPENTHREAD_PSA_CRYPTO_NATIVE_ITS_FILE snprintf(sNativeItsFileNamePrefix, sizeof(sNativeItsFileNamePrefix), "%s/%s_%d_", OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId); gItsFileNamePrefix = sNativeItsFileNamePrefix; +#endif #endif socket_init(); diff --git a/include/openthread/instance.h b/include/openthread/instance.h index d67bcb8f9..3df8a9c71 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (549) +#define OPENTHREAD_API_VERSION (550) /** * @addtogroup api-instance diff --git a/include/openthread/platform/crypto.h b/include/openthread/platform/crypto.h index fa3c4e7ba..6ee439979 100644 --- a/include/openthread/platform/crypto.h +++ b/include/openthread/platform/crypto.h @@ -215,11 +215,6 @@ typedef struct otPlatCryptoEcdsaSignature otPlatCryptoEcdsaSignature; */ #define OT_CRYPTO_PBDKF2_MAX_SALT_SIZE 30 -/** - * Initialize the Crypto module. - */ -void otPlatCryptoInit(void); - /** * Import a key into PSA ITS. * diff --git a/src/core/crypto/crypto_platform_mbedtls.cpp b/src/core/crypto/crypto_platform_mbedtls.cpp index 3ebfd5691..a72c04988 100644 --- a/src/core/crypto/crypto_platform_mbedtls.cpp +++ b/src/core/crypto/crypto_platform_mbedtls.cpp @@ -78,11 +78,6 @@ static constexpr uint16_t kEntropyMinThreshold = 16; #endif #endif -OT_TOOL_WEAK void otPlatCryptoInit(void) -{ - // Intentionally empty. -} - // AES Implementation OT_TOOL_WEAK otError otPlatCryptoAesInit(otCryptoContext *aContext) { diff --git a/src/core/crypto/crypto_platform_psa.cpp b/src/core/crypto/crypto_platform_psa.cpp index 9d617ea04..ce79ca0ab 100644 --- a/src/core/crypto/crypto_platform_psa.cpp +++ b/src/core/crypto/crypto_platform_psa.cpp @@ -200,8 +200,6 @@ exit: return error; } -OT_TOOL_WEAK void otPlatCryptoInit(void) { psa_crypto_init(); } - OT_TOOL_WEAK otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef, otCryptoKeyType aKeyType, otCryptoKeyAlgorithm aKeyAlgorithm, diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index 4a5cb74ac..f709b29a7 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -176,8 +176,6 @@ KeyManager::KeyManager(Instance &aInstance) , mKekFrameCounter(0) , mIsPskcSet(false) { - otPlatCryptoInit(); - #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE { NetworkKey networkKey;