Skip to content

Commit 70a2662

Browse files
committed
[crypto] PSA API: introduce default OpenThread crypto platform port
This commit adds a default implementation of the OpenThread crypto platform API for the PSA Crypto API. Signed-off-by: Łukasz Duda <lukasz.duda@nordicsemi.no>
1 parent 3061fa1 commit 70a2662

File tree

5 files changed

+844
-75
lines changed

5 files changed

+844
-75
lines changed

etc/cmake/options.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ if(ot_index EQUAL -1)
302302
message(FATAL_ERROR "Invalid value for OT_PLATFORM - valid values are:" "${OT_PLATFORM_VALUES}")
303303
endif()
304304

305+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
306+
set(OT_CRYPTO_LIB_VALUES "MBEDTLS" "PSA" "PLATFORM")
307+
ot_multi_option(OT_CRYPTO_LIB OT_CRYPTO_LIB_VALUES OPENTHREAD_CONFIG_CRYPTO_LIB OPENTHREAD_CONFIG_CRYPTO_LIB_ "set Crypto backend library")
308+
305309
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
306310
set(OT_THREAD_VERSION_VALUES "1.1" "1.2" "1.3" "1.3.1" "1.4")
307311
set(OT_THREAD_VERSION "1.4" CACHE STRING "set Thread version")
@@ -359,7 +363,7 @@ ot_int_option(OT_RCP_TX_WAIT_TIME_SECS OPENTHREAD_SPINEL_CONFIG_RCP_TX_WAIT_TIME
359363
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
360364

361365
if(NOT OT_EXTERNAL_MBEDTLS)
362-
set(OT_MBEDTLS mbedtls)
366+
set(OT_MBEDTLS mbedtls mbedcrypto)
363367
target_compile_definitions(ot-config INTERFACE "OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS=1")
364368
else()
365369
set(OT_MBEDTLS ${OT_EXTERNAL_MBEDTLS})

src/core/BUILD.gn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ openthread_core_files = [
341341
"crypto/aes_ecb.cpp",
342342
"crypto/aes_ecb.hpp",
343343
"crypto/context_size.hpp",
344-
"crypto/crypto_platform.cpp",
344+
"crypto/crypto_platform_mbedtls.cpp",
345+
"crypto/crypto_platform_psa.cpp",
345346
"crypto/ecdsa.hpp",
346347
"crypto/hkdf_sha256.cpp",
347348
"crypto/hkdf_sha256.hpp",
@@ -673,7 +674,8 @@ openthread_radio_sources = [
673674
"common/uptime.cpp",
674675
"crypto/aes_ccm.cpp",
675676
"crypto/aes_ecb.cpp",
676-
"crypto/crypto_platform.cpp",
677+
"crypto/crypto_platform_mbedtls.cpp",
678+
"crypto/crypto_platform_psa.cpp",
677679
"crypto/storage.cpp",
678680
"diags/factory_diags.cpp",
679681
"instance/instance.cpp",

src/core/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ set(COMMON_SOURCES
138138
common/uptime.cpp
139139
crypto/aes_ccm.cpp
140140
crypto/aes_ecb.cpp
141-
crypto/crypto_platform.cpp
141+
crypto/crypto_platform_mbedtls.cpp
142+
crypto/crypto_platform_psa.cpp
142143
crypto/hkdf_sha256.cpp
143144
crypto/hmac_sha256.cpp
144145
crypto/mbedtls.cpp
@@ -315,7 +316,8 @@ set(RADIO_COMMON_SOURCES
315316
common/uptime.cpp
316317
crypto/aes_ccm.cpp
317318
crypto/aes_ecb.cpp
318-
crypto/crypto_platform.cpp
319+
crypto/crypto_platform_mbedtls.cpp
320+
crypto/crypto_platform_psa.cpp
319321
crypto/storage.cpp
320322
diags/factory_diags.cpp
321323
instance/instance.cpp

src/core/crypto/crypto_platform.cpp renamed to src/core/crypto/crypto_platform_mbedtls.cpp

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -755,74 +755,4 @@ OT_TOOL_WEAK otError otPlatCryptoPbkdf2GenerateKey(const uint8_t *aPassword,
755755

756756
#endif // #if OPENTHREAD_FTD
757757

758-
#elif OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_PSA
759-
760-
#if OPENTHREAD_FTD || OPENTHREAD_MTD
761-
#if OPENTHREAD_CONFIG_ECDSA_ENABLE
762-
763-
OT_TOOL_WEAK otError otPlatCryptoEcdsaGenerateKey(otPlatCryptoEcdsaKeyPair *aKeyPair)
764-
{
765-
OT_UNUSED_VARIABLE(aKeyPair);
766-
767-
return OT_ERROR_NOT_CAPABLE;
768-
}
769-
770-
OT_TOOL_WEAK otError otPlatCryptoEcdsaGetPublicKey(const otPlatCryptoEcdsaKeyPair *aKeyPair,
771-
otPlatCryptoEcdsaPublicKey *aPublicKey)
772-
{
773-
OT_UNUSED_VARIABLE(aKeyPair);
774-
OT_UNUSED_VARIABLE(aPublicKey);
775-
776-
return OT_ERROR_NOT_CAPABLE;
777-
}
778-
779-
OT_TOOL_WEAK otError otPlatCryptoEcdsaSign(const otPlatCryptoEcdsaKeyPair *aKeyPair,
780-
const otPlatCryptoSha256Hash *aHash,
781-
otPlatCryptoEcdsaSignature *aSignature)
782-
{
783-
OT_UNUSED_VARIABLE(aKeyPair);
784-
OT_UNUSED_VARIABLE(aHash);
785-
OT_UNUSED_VARIABLE(aSignature);
786-
787-
return OT_ERROR_NOT_CAPABLE;
788-
}
789-
790-
OT_TOOL_WEAK otError otPlatCryptoEcdsaVerify(const otPlatCryptoEcdsaPublicKey *aPublicKey,
791-
const otPlatCryptoSha256Hash *aHash,
792-
const otPlatCryptoEcdsaSignature *aSignature)
793-
794-
{
795-
OT_UNUSED_VARIABLE(aPublicKey);
796-
OT_UNUSED_VARIABLE(aHash);
797-
OT_UNUSED_VARIABLE(aSignature);
798-
799-
return OT_ERROR_NOT_CAPABLE;
800-
}
801-
#endif // #if OPENTHREAD_CONFIG_ECDSA_ENABLE
802-
803-
#endif // #if OPENTHREAD_FTD || OPENTHREAD_MTD
804-
805-
#if OPENTHREAD_FTD
806-
807-
OT_TOOL_WEAK otError otPlatCryptoPbkdf2GenerateKey(const uint8_t *aPassword,
808-
uint16_t aPasswordLen,
809-
const uint8_t *aSalt,
810-
uint16_t aSaltLen,
811-
uint32_t aIterationCounter,
812-
uint16_t aKeyLen,
813-
uint8_t *aKey)
814-
{
815-
OT_UNUSED_VARIABLE(aPassword);
816-
OT_UNUSED_VARIABLE(aPasswordLen);
817-
OT_UNUSED_VARIABLE(aSalt);
818-
OT_UNUSED_VARIABLE(aSaltLen);
819-
OT_UNUSED_VARIABLE(aIterationCounter);
820-
OT_UNUSED_VARIABLE(aKeyLen);
821-
OT_UNUSED_VARIABLE(aKey);
822-
823-
return OT_ERROR_NOT_CAPABLE;
824-
}
825-
826-
#endif // #if OPENTHREAD_FTD
827-
828758
#endif // #if OPENTHREAD_CONFIG_CRYPTO_LIB == OPENTHREAD_CONFIG_CRYPTO_LIB_MBEDTLS

0 commit comments

Comments
 (0)