Skip to content

Commit e73bf16

Browse files
Damian-Nordicadbridge
authored andcommitted
[crypto] Initial crypto backend using PSA crypto API (project-chip#23193)
* [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. * Code review comments
1 parent 66ce67d commit e73bf16

File tree

3 files changed

+1780
-4
lines changed

3 files changed

+1780
-4
lines changed

src/crypto/BUILD.gn

+21-4
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,24 @@ if (chip_crypto == "") {
3131
}
3232

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

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

4343
chip_crypto_mbedtls = chip_crypto == "mbedtls"
44+
chip_crypto_psa = chip_crypto == "psa"
4445
chip_crypto_openssl = chip_crypto == "openssl"
4546
chip_crypto_boringssl = chip_crypto == "boringssl"
4647
chip_crypto_platform = chip_crypto == "platform"
4748

4849
defines = [
4950
"CHIP_CRYPTO_MBEDTLS=${chip_crypto_mbedtls}",
51+
"CHIP_CRYPTO_PSA=${chip_crypto_psa}",
5052
"CHIP_CRYPTO_OPENSSL=${chip_crypto_openssl}",
5153
"CHIP_CRYPTO_BORINGSSL=${chip_crypto_boringssl}",
5254
"CHIP_CRYPTO_PLATFORM=${chip_crypto_platform}",
@@ -108,6 +110,19 @@ if (chip_crypto == "openssl") {
108110

109111
external_mbedtls = current_os == "zephyr"
110112

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

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

0 commit comments

Comments
 (0)