Skip to content

Commit 9dd9acd

Browse files
committed
[crypto] introduce default port for PSA API
1 parent f42af4e commit 9dd9acd

File tree

6 files changed

+785
-82
lines changed

6 files changed

+785
-82
lines changed

include/openthread/platform/crypto.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ extern "C" {
5858
*/
5959
typedef enum
6060
{
61-
OT_CRYPTO_KEY_TYPE_RAW, ///< Key Type: Raw Data.
62-
OT_CRYPTO_KEY_TYPE_AES, ///< Key Type: AES.
63-
OT_CRYPTO_KEY_TYPE_HMAC, ///< Key Type: HMAC.
64-
OT_CRYPTO_KEY_TYPE_ECDSA, ///< Key Type: ECDSA.
61+
OT_CRYPTO_KEY_TYPE_RAW, ///< Key Type: Raw Data.
62+
OT_CRYPTO_KEY_TYPE_AES, ///< Key Type: AES.
63+
OT_CRYPTO_KEY_TYPE_HMAC, ///< Key Type: HMAC.
64+
OT_CRYPTO_KEY_TYPE_ECDSA, ///< Key Type: ECDSA.
65+
OT_CRYPTO_KEY_TYPE_DERIVE, ///< Key Type: Derive.
6566
} otCryptoKeyType;
6667

6768
/**
@@ -73,6 +74,7 @@ typedef enum
7374
OT_CRYPTO_KEY_ALG_AES_ECB, ///< Key Algorithm: AES ECB.
7475
OT_CRYPTO_KEY_ALG_HMAC_SHA_256, ///< Key Algorithm: HMAC SHA-256.
7576
OT_CRYPTO_KEY_ALG_ECDSA, ///< Key Algorithm: ECDSA.
77+
OT_CRYPTO_KEY_ALG_HKDF_SHA256, ///< Key Algorithm: HKDF SHA-256.
7678
} otCryptoKeyAlgorithm;
7779

7880
/**
@@ -86,6 +88,8 @@ enum
8688
OT_CRYPTO_KEY_USAGE_DECRYPT = 1 << 2, ///< Key Usage: AES ECB.
8789
OT_CRYPTO_KEY_USAGE_SIGN_HASH = 1 << 3, ///< Key Usage: Sign Hash.
8890
OT_CRYPTO_KEY_USAGE_VERIFY_HASH = 1 << 4, ///< Key Usage: Verify Hash.
91+
OT_CRYPTO_KEY_USAGE_DERIVE = 1 << 5, ///< Key Usage: Derive.
92+
8993
};
9094

9195
/**

src/core/BUILD.gn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,8 @@ openthread_core_files = [
464464
"crypto/aes_ecb.cpp",
465465
"crypto/aes_ecb.hpp",
466466
"crypto/context_size.hpp",
467-
"crypto/crypto_platform.cpp",
467+
"crypto/crypto_platform_mbedtls.cpp",
468+
"crypto/crypto_platform_psa.cpp",
468469
"crypto/ecdsa.hpp",
469470
"crypto/hkdf_sha256.cpp",
470471
"crypto/hkdf_sha256.hpp",
@@ -768,7 +769,8 @@ openthread_radio_sources = [
768769
"common/uptime.cpp",
769770
"crypto/aes_ccm.cpp",
770771
"crypto/aes_ecb.cpp",
771-
"crypto/crypto_platform.cpp",
772+
"crypto/crypto_platform_mbedtls.cpp",
773+
"crypto/crypto_platform_psa.cpp",
772774
"crypto/storage.cpp",
773775
"diags/factory_diags.cpp",
774776
"instance/instance.cpp",

src/core/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ set(COMMON_SOURCES
125125
common/uptime.cpp
126126
crypto/aes_ccm.cpp
127127
crypto/aes_ecb.cpp
128-
crypto/crypto_platform.cpp
128+
crypto/crypto_platform_mbedtls.cpp
129+
crypto/crypto_platform_psa.cpp
129130
crypto/hkdf_sha256.cpp
130131
crypto/hmac_sha256.cpp
131132
crypto/mbedtls.cpp
@@ -287,7 +288,8 @@ set(RADIO_COMMON_SOURCES
287288
common/uptime.cpp
288289
crypto/aes_ccm.cpp
289290
crypto/aes_ecb.cpp
290-
crypto/crypto_platform.cpp
291+
crypto/crypto_platform_mbedtls.cpp
292+
crypto/crypto_platform_psa.cpp
291293
crypto/storage.cpp
292294
diags/factory_diags.cpp
293295
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
@@ -750,74 +750,4 @@ OT_TOOL_WEAK otError otPlatCryptoPbkdf2GenerateKey(const uint8_t *aPassword,
750750

751751
#endif // #if OPENTHREAD_FTD
752752

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

0 commit comments

Comments
 (0)