Skip to content

Commit 7089e85

Browse files
committed
[crypto] Add initial implementation for PSA crypto API
Implement most cryptographic operations using PSA crypto API. Make it unit-testable using the following manual steps (until we all agree to update mbedTLS to 3.X): 1. Update mbedTLS submodule to 3.2.1 and update mbedtls.gni accordingly. 2. Use scripts/generate_driver_wrappers.py to generate psa_crypto_driver_wrappers.c and include it in mbedTLS library build. 3. Increase CHIP_CONFIG_SHA256_CONTEXT_SIZE to 256B 4. gn gen out/ut --args='chip_crypto="psa"' 5. ninja -C out/ut tests/CHIPCryptoPALTest 6. out/ut/tests/CHIPCryptoPALTest [crypto] Implement PBKDF2 using PSA crypto API PBKDF2 PSA crypto API is not yet implemented in mbedTLS 3.1 nor 3.2 so for now use a handcrafted implementation using HMAC directly. [crypto] Implement ECDSA and ECDH using PSA crypto API The ECDSA and ECDH operations specified by P256Keypair and P256PublicKey classes have been implemented using PSA crypto API provided by mbedTLS 3.X.
1 parent bc6b438 commit 7089e85

File tree

3 files changed

+1782
-5
lines changed

3 files changed

+1782
-5
lines changed

src/crypto/BUILD.gn

+22-5
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,31 @@ import("crypto.gni")
2323
if (chip_crypto == "") {
2424
if (current_os == "android" || current_os == "freertos" ||
2525
current_os == "zephyr" || current_os == "mbed" || current_os == "webos") {
26-
chip_crypto = "mbedtls"
26+
chip_crypto = "psa"
2727
} else {
2828
chip_crypto = "openssl"
2929
}
3030
}
3131

3232
assert(
33-
chip_crypto == "mbedtls" || chip_crypto == "openssl" ||
34-
chip_crypto == "tinycrypt" || chip_crypto == "boringssl" ||
35-
chip_crypto == "platform",
36-
"Please select a valid crypto implementation: mbedtls, openssl, tinycrypt, boringssl, platform")
33+
chip_crypto == "mbedtls" || chip_crypto == "psa" ||
34+
chip_crypto == "openssl" || chip_crypto == "tinycrypt" ||
35+
chip_crypto == "boringssl" || chip_crypto == "platform",
36+
"Please select a valid crypto implementation: mbedtls, psa, openssl, tinycrypt, boringssl, platform")
3737

3838
buildconfig_header("crypto_buildconfig") {
3939
header = "CryptoBuildConfig.h"
4040
header_dir = "crypto"
4141

4242
chip_crypto_mbedtls = chip_crypto == "mbedtls"
43+
chip_crypto_psa = chip_crypto == "psa"
4344
chip_crypto_openssl = chip_crypto == "openssl"
4445
chip_crypto_boringssl = chip_crypto == "boringssl"
4546
chip_crypto_platform = chip_crypto == "platform"
4647

4748
defines = [
4849
"CHIP_CRYPTO_MBEDTLS=${chip_crypto_mbedtls}",
50+
"CHIP_CRYPTO_PSA=${chip_crypto_psa}",
4951
"CHIP_CRYPTO_OPENSSL=${chip_crypto_openssl}",
5052
"CHIP_CRYPTO_BORINGSSL=${chip_crypto_boringssl}",
5153
"CHIP_CRYPTO_PLATFORM=${chip_crypto_platform}",
@@ -107,6 +109,19 @@ if (chip_crypto == "openssl") {
107109

108110
external_mbedtls = current_os == "zephyr"
109111

112+
if (!external_mbedtls) {
113+
public_deps += [ "${mbedtls_root}:mbedtls" ]
114+
}
115+
}
116+
} else if (chip_crypto == "psa") {
117+
import("//build_overrides/mbedtls.gni")
118+
119+
source_set("cryptopal_psa") {
120+
sources = [ "CHIPCryptoPALPSA.cpp" ]
121+
public_deps = [ ":public_headers" ]
122+
123+
external_mbedtls = current_os == "zephyr"
124+
110125
if (!external_mbedtls) {
111126
public_deps += [ "${mbedtls_root}:mbedtls" ]
112127
}
@@ -142,6 +157,8 @@ static_library("crypto") {
142157

143158
if (chip_crypto == "mbedtls") {
144159
public_deps += [ ":cryptopal_mbedtls" ]
160+
} else if (chip_crypto == "psa") {
161+
public_deps += [ ":cryptopal_psa" ]
145162
} else if (chip_crypto == "openssl") {
146163
public_deps += [ ":cryptopal_openssl" ]
147164
} else if (chip_crypto == "boringssl") {

0 commit comments

Comments
 (0)