Skip to content

Commit 3aa497d

Browse files
frkvnordicjm
authored andcommitted
[nrf noup] bootloader: Add RSA FW encryption support
-Add encrypted_psa.c to build when RSA encryption and signature is used to get access to APIs used to encrypt/decrypt images using AES CTR. -Wrap boot_decrypt_key in encrypted_psa.c because it is only usable when ECDH using secp256r1 or X25519 is used. -Add Kconfig for selecting RSA encryption dependencies when BOOT_ENCRYPT_IMAGE and RSA signatures are enabled. Signed-off-by: Frank Audun Kvamtrø <frank.kvamtro@nordicsemi.no>
1 parent dcfcd37 commit 3aa497d

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

boot/bootutil/src/encrypted_psa.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ void bootutil_aes_ctr_init(bootutil_aes_ctr_context *ctx)
200200

201201
#if defined(MCUBOOT_ENC_IMAGES)
202202
extern const struct bootutil_key bootutil_enc_key;
203+
204+
#if defined(MCUBOOT_ENCRYPT_EC256) || defined(MCUBOOT_ENCRYPT_X25519)
203205
/*
204206
* Decrypt an encryption key TLV.
205207
*
@@ -389,6 +391,8 @@ boot_decrypt_key(const uint8_t *buf, uint8_t *enckey)
389391
return 0;
390392
}
391393

394+
#endif /* defined(MCUBOOT_ENCRYPT_EC256) || defined(MCUBOOT_ENCRYPT_X25519) */
395+
392396
int bootutil_aes_ctr_encrypt(bootutil_aes_ctr_context *ctx, uint8_t *counter,
393397
const uint8_t *m, uint32_t mlen, size_t blk_off, uint8_t *c)
394398
{

boot/zephyr/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ zephyr_library_sources(
128128
)
129129

130130
if((CONFIG_BOOT_ENCRYPT_X25519 AND CONFIG_BOOT_ED25519_PSA)
131-
OR (CONFIG_BOOT_ENCRYPT_EC256 AND CONFIG_BOOT_ECDSA_PSA))
131+
OR (CONFIG_BOOT_ENCRYPT_EC256 AND CONFIG_BOOT_ECDSA_PSA)
132+
OR (CONFIG_BOOT_ENCRYPT_RSA AND CONFIG_BOOT_SIGNATURE_TYPE_RSA))
132133
zephyr_library_sources(${BOOT_DIR}/bootutil/src/encrypted_psa.c)
133134
endif()
134135

boot/zephyr/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ config BOOT_X25519_PSA_DEPENDENCIES
131131
to use with it; the others are used for shared key decryption
132132
and derivation.
133133

134+
config BOOT_RSA_ENCRYPT_PSA_DEPENDENCIES
135+
bool
136+
select PSA_WANT_ALG_RSA_OAEP
137+
select PSA_WANT_ALG_CTR
138+
select PSA_WANT_KEY_TYPE_AES
139+
select PSA_WANT_AES_KEY_SIZE_128
140+
select PSA_WANT_AES_KEY_SIZE_256
141+
select PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_IMPORT
142+
help
143+
Dependencies for RSA encryption support.
144+
134145
endif # BOOT_ENCRYPT_IMAGE
135146

136147
config BOOT_ECDSA_PSA_DEPENDENCIES
@@ -278,6 +289,8 @@ config BOOT_SIGNATURE_TYPE_RSA
278289
select PSA_WANT_ALG_RSA_PSS
279290
select PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY
280291
select BOOT_IMG_HASH_ALG_SHA256_ALLOW
292+
select BOOT_ENCRYPTION_SUPPORT
293+
select BOOT_RSA_ENCRYPT_PSA_DEPENDENCIES if BOOT_ENCRYPT_IMAGE
281294

282295
if BOOT_SIGNATURE_TYPE_RSA
283296
config BOOT_SIGNATURE_TYPE_RSA_LEN

0 commit comments

Comments
 (0)