Skip to content

Commit 3cdcdb3

Browse files
de-nordicrlubos
authored andcommitted
[nrf noup] PSA configuration required changes
Set of changes to Kconfig, CMakeLists.txt and some of headers that are required for the PSA support to compile. Signed-off-by: Dominik Ermel <[email protected]> (cherry picked from commit 6400cc8)
1 parent 106ade3 commit 3cdcdb3

File tree

4 files changed

+112
-16
lines changed

4 files changed

+112
-16
lines changed

boot/bootutil/zephyr/CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@ zephyr_library_link_libraries(MCUBOOT_BOOTUTIL)
2929
target_link_libraries(MCUBOOT_BOOTUTIL INTERFACE zephyr_interface)
3030

3131
if(CONFIG_BOOT_USE_TINYCRYPT)
32-
target_include_directories(MCUBOOT_BOOTUTIL INTERFACE
33-
../../../ext/tinycrypt/lib/include
34-
)
32+
target_include_directories(MCUBOOT_BOOTUTIL INTERFACE
33+
../../../ext/tinycrypt/lib/include
34+
)
35+
endif()
36+
37+
if(CONFIG_BOOT_USE_PSA_CRYPTO)
38+
target_include_directories(MCUBOOT_BOOTUTIL INTERFACE
39+
${ZEPHYR_MBEDTLS_MODULE_DIR}/include
40+
)
3541
endif()
3642

37-
if(CONFIG_BOOT_USE_MBEDTLS)
43+
if(CONFIG_BOOT_USE_MBEDTLS OR CONFIG_BOOT_USE_PSA_CRYPTO AND NOT CONFIG_PSA_CORE_OBERON)
3844
zephyr_link_libraries(mbedTLS)
3945
endif()
4046
endif()

boot/zephyr/CMakeLists.txt

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ if(EXISTS targets/${BOARD}.h)
5151
zephyr_library_compile_definitions(MCUBOOT_TARGET_CONFIG="${BOARD}.h")
5252
endif()
5353

54+
if(DEFINED CONFIG_MBEDTLS)
55+
zephyr_library_include_directories(
56+
${ZEPHYR_MBEDTLS_MODULE_DIR}/include
57+
)
58+
endif()
59+
5460
# Zephyr port-specific sources.
5561
zephyr_library_sources(
5662
main.c
@@ -102,6 +108,10 @@ zephyr_library_sources(
102108
${BOOT_DIR}/bootutil/src/fault_injection_hardening.c
103109
)
104110

111+
if(DEFINED CONFIG_BOOT_ENCRYPT_X25519 AND DEFINED CONFIG_BOOT_ED25519_PSA)
112+
zephyr_library_sources(${BOOT_DIR}/bootutil/src/encrypted_psa.c)
113+
endif()
114+
105115
if(DEFINED CONFIG_MEASURED_BOOT OR DEFINED CONFIG_BOOT_SHARE_DATA)
106116
zephyr_library_sources(
107117
${BOOT_DIR}/bootutil/src/boot_record.c
@@ -230,19 +240,28 @@ elseif(CONFIG_BOOT_SIGNATURE_TYPE_ED25519 OR CONFIG_BOOT_ENCRYPT_X25519)
230240
${FIAT_DIR}/include/
231241
)
232242

233-
zephyr_library_sources(
234-
${FIAT_DIR}/src/curve25519.c
235-
)
243+
if(NOT CONFIG_BOOT_ED25519_PSA)
244+
zephyr_library_sources(
245+
${FIAT_DIR}/src/curve25519.c
246+
)
247+
else()
248+
zephyr_library_sources(
249+
${MBEDTLS_ASN1_DIR}/src/asn1parse.c
250+
${BOOT_DIR}/bootutil/src/ed25519_psa.c
251+
)
252+
endif()
236253
endif()
237254

238-
if(CONFIG_BOOT_ENCRYPT_EC256 OR CONFIG_BOOT_ENCRYPT_X25519)
239-
zephyr_library_sources(
240-
${TINYCRYPT_DIR}/source/aes_encrypt.c
241-
${TINYCRYPT_DIR}/source/aes_decrypt.c
242-
${TINYCRYPT_DIR}/source/ctr_mode.c
243-
${TINYCRYPT_DIR}/source/hmac.c
244-
${TINYCRYPT_DIR}/source/ecc_dh.c
255+
if(NOT CONFIG_BOOT_ED25519_PSA)
256+
if(CONFIG_BOOT_ENCRYPT_EC256 OR CONFIG_BOOT_ENCRYPT_X25519)
257+
zephyr_library_sources(
258+
${TINYCRYPT_DIR}/source/aes_encrypt.c
259+
${TINYCRYPT_DIR}/source/aes_decrypt.c
260+
${TINYCRYPT_DIR}/source/ctr_mode.c
261+
${TINYCRYPT_DIR}/source/hmac.c
262+
${TINYCRYPT_DIR}/source/ecc_dh.c
245263
)
264+
endif()
246265
endif()
247266

248267
if(CONFIG_BOOT_ENCRYPT_EC256)

boot/zephyr/Kconfig

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ config BOOT_USE_MBEDTLS
2929

3030
config BOOT_USE_PSA_CRYPTO
3131
bool
32-
# Hidden option
32+
default y if NRF_SECURITY
33+
# This is counter intuitive but that is how PSA heap is enabled.
34+
select MBEDTLS_ENABLE_HEAP
35+
select MBEDTLS_PSA_CRYPTO_C
3336
help
3437
Hidden option set if using PSA crypt for cryptography functionality
3538

@@ -66,6 +69,58 @@ config NRF_CC310_BL
6669
bool
6770
default n
6871

72+
if BOOT_USE_PSA_CRYPTO
73+
74+
config BOOT_PSA_IMG_HASH_ALG_SHA256_DEPENDENCIES
75+
bool
76+
default y if BOOT_IMG_HASH_ALG_SHA256
77+
select PSA_WANT_ALG_SHA_256
78+
help
79+
Dependencies for hashing with SHA256
80+
81+
config BOOT_ED25519_PSA_DEPENDENCIES
82+
bool
83+
select PSA_WANT_ALG_SHA_256
84+
select PSA_WANT_ALG_SHA_512
85+
select PSA_WANT_ALG_PURE_EDDSA
86+
select PSA_WANT_ECC_TWISTED_EDWARDS_255
87+
select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT
88+
help
89+
Dependencies for ed25519 signature
90+
91+
if BOOT_ENCRYPT_IMAGE
92+
93+
config BOOT_X25519_PSA_DEPENDENCIES
94+
bool
95+
select PSA_WANT_ALG_ECDH
96+
select PSA_WANT_ALG_HMAC
97+
select PSA_WANT_ALG_HKDF
98+
select PSA_WANT_ALG_CTR
99+
select PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT
100+
select PSA_WANT_KEY_TYPE_DERIVE
101+
select PSA_WANT_KEY_TYPE_AES
102+
select PSA_WANT_ECC_MONTGOMERY_255
103+
help
104+
Dependencies for x25519 shared-random key encryption and AES
105+
encryption. The PSA_WANT_ALG_CTR and PSA_WANT_KEY_TYPE_AES
106+
enable Counter based block cipher and AES key, and algorithm support,
107+
to use with it; the others are used for shared key decryption
108+
and derivation.
109+
110+
endif # BOOT_ENCRYPT_IMAGE
111+
112+
if MBEDTLS_ENABLE_HEAP
113+
114+
config MBEDTLS_HEAP_SIZE
115+
default 2048 if BOOT_USE_PSA_CRYPTO
116+
help
117+
The PSA internals need to be able to allocate memory for operation
118+
and it uses mbedTLS heap for that.
119+
120+
endif # MBEDTLS_ENABLE_HEAP
121+
122+
endif # BOOT_USE_PSA_CRYPTO
123+
69124
menu "MCUBoot settings"
70125

71126
config SINGLE_APPLICATION_SLOT
@@ -123,6 +178,7 @@ endchoice # BOOT_IMG_HASH_ALG
123178

124179
choice BOOT_SIGNATURE_TYPE
125180
prompt "Signature type"
181+
default BOOT_SIGNATURE_TYPE_ED25519 if BOARD_NRF54L15PDK_NRF54L15_CPUAPP
126182
default BOOT_SIGNATURE_TYPE_RSA
127183

128184
config BOOT_SIGNATURE_TYPE_NONE
@@ -177,13 +233,24 @@ if BOOT_SIGNATURE_TYPE_ED25519
177233
choice BOOT_ED25519_IMPLEMENTATION
178234
prompt "Ecdsa implementation"
179235
default BOOT_ED25519_TINYCRYPT
236+
180237
config BOOT_ED25519_TINYCRYPT
181238
bool "Use tinycrypt"
182239
select BOOT_USE_TINYCRYPT
240+
depends on !NRF_SECURITY
241+
183242
config BOOT_ED25519_MBEDTLS
184243
bool "Use mbedTLS"
185244
select BOOT_USE_MBEDTLS
186245
select MBEDTLS
246+
depends on !NRF_SECURITY
247+
248+
config BOOT_ED25519_PSA
249+
bool "Use PSA crypto"
250+
select BOOT_USE_PSA_CRYPTO
251+
select BOOT_ED25519_PSA_DEPENDENCIES
252+
select BOOT_X25519_PSA_DEPENDENCIES if BOOT_ENCRYPT_IMAGE
253+
187254
endchoice
188255
endif
189256

@@ -222,9 +289,13 @@ config MCUBOOT_CLEANUP_ARM_CORE
222289
start-up code which can cause a module fault and potentially make the
223290
module irrecoverable.
224291

292+
if MBEDTLS
293+
225294
config MBEDTLS_CFG_FILE
226295
default "mcuboot-mbedtls-cfg.h"
227296

297+
endif
298+
228299
config BOOT_HW_KEY
229300
bool "Use HW key for image verification"
230301
default n

boot/zephyr/include/mcuboot-mbedtls-cfg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
#if defined(CONFIG_BOOT_SIGNATURE_TYPE_RSA) || defined(CONFIG_BOOT_ENCRYPT_RSA)
2525
#include "config-rsa.h"
26-
#elif defined(CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256) || \
26+
#elif defined(CONFIG_BOOT_USE_PSA_CRYPTO) || defined(CONFIG_BOOT_SIGNATURE_TYPE_ECDSA_P256) || \
2727
defined(CONFIG_BOOT_ENCRYPT_EC256) || \
2828
(defined(CONFIG_BOOT_ENCRYPT_X25519) && !defined(CONFIG_BOOT_SIGNATURE_TYPE_ED25519))
2929
#include "config-asn1.h"

0 commit comments

Comments
 (0)