[crypto] PSA API: remove otPlatCryptoInit API

This commit removes otPlatCryptoInit API and moves responsibility of
initializing the Crypto subsystem to the platform.

Signed-off-by: Łukasz Duda <[email protected]>
This commit is contained in:
Łukasz Duda
2025-12-23 11:38:24 +08:00
committed by zwx
parent bdb751ee55
commit e49947f177
6 changed files with 15 additions and 16 deletions
+8 -1
View File
@@ -55,6 +55,10 @@
#include <openthread/platform/radio.h> #include <openthread/platform/radio.h>
#include <openthread/platform/toolchain.h> #include <openthread/platform/toolchain.h>
#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
#include <psa/crypto.h>
#endif
#include "simul_utils.h" #include "simul_utils.h"
uint32_t gNodeId = 1; uint32_t gNodeId = 1;
@@ -201,10 +205,13 @@ void otSysInit(int aArgCount, char *aArgVector[])
signal(SIGTERM, &handleSignal); signal(SIGTERM, &handleSignal);
signal(SIGHUP, &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_", snprintf(sNativeItsFileNamePrefix, sizeof(sNativeItsFileNamePrefix), "%s/%s_%d_",
OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId); OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId);
gItsFileNamePrefix = sNativeItsFileNamePrefix; gItsFileNamePrefix = sNativeItsFileNamePrefix;
#endif
#endif #endif
platformLoggingInit(basename(aArgVector[0])); platformLoggingInit(basename(aArgVector[0]));
@@ -51,6 +51,9 @@
#include <openthread/platform/alarm-milli.h> #include <openthread/platform/alarm-milli.h>
#include "../simul_utils.h" #include "../simul_utils.h"
#if (OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA)
#include <psa/crypto.h>
#endif
#include "lib/platform/exit_code.h" #include "lib/platform/exit_code.h"
#include "utils/uart.h" #include "utils/uart.h"
@@ -278,10 +281,13 @@ void otSysInit(int argc, char *argv[])
DieNow(OT_EXIT_FAILURE); 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_", snprintf(sNativeItsFileNamePrefix, sizeof(sNativeItsFileNamePrefix), "%s/%s_%d_",
OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId); OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH, getenv("PORT_OFFSET") ? getenv("PORT_OFFSET") : "0", gNodeId);
gItsFileNamePrefix = sNativeItsFileNamePrefix; gItsFileNamePrefix = sNativeItsFileNamePrefix;
#endif
#endif #endif
socket_init(); socket_init();
-5
View File
@@ -215,11 +215,6 @@ typedef struct otPlatCryptoEcdsaSignature otPlatCryptoEcdsaSignature;
*/ */
#define OT_CRYPTO_PBDKF2_MAX_SALT_SIZE 30 #define OT_CRYPTO_PBDKF2_MAX_SALT_SIZE 30
/**
* Initialize the Crypto module.
*/
void otPlatCryptoInit(void);
/** /**
* Import a key into PSA ITS. * Import a key into PSA ITS.
* *
@@ -78,11 +78,6 @@ static constexpr uint16_t kEntropyMinThreshold = 16;
#endif #endif
#endif #endif
OT_TOOL_WEAK void otPlatCryptoInit(void)
{
// Intentionally empty.
}
// AES Implementation // AES Implementation
OT_TOOL_WEAK otError otPlatCryptoAesInit(otCryptoContext *aContext) OT_TOOL_WEAK otError otPlatCryptoAesInit(otCryptoContext *aContext)
{ {
-2
View File
@@ -200,8 +200,6 @@ exit:
return error; return error;
} }
OT_TOOL_WEAK void otPlatCryptoInit(void) { psa_crypto_init(); }
OT_TOOL_WEAK otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef, OT_TOOL_WEAK otError otPlatCryptoImportKey(otCryptoKeyRef *aKeyRef,
otCryptoKeyType aKeyType, otCryptoKeyType aKeyType,
otCryptoKeyAlgorithm aKeyAlgorithm, otCryptoKeyAlgorithm aKeyAlgorithm,
-2
View File
@@ -176,8 +176,6 @@ KeyManager::KeyManager(Instance &aInstance)
, mKekFrameCounter(0) , mKekFrameCounter(0)
, mIsPskcSet(false) , mIsPskcSet(false)
{ {
otPlatCryptoInit();
#if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE
{ {
NetworkKey networkKey; NetworkKey networkKey;