Skip to content

Commit ca06ffb

Browse files
tomchyrlubos
authored andcommitted
Revert "[nrf noup] bootutil: Add support for KMU stored ED25519 signature key"
This reverts commit 26192ca. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent 3b34362 commit ca06ffb

File tree

5 files changed

+4
-96
lines changed

5 files changed

+4
-96
lines changed

boot/bootutil/src/ed25519_psa.c

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,13 @@
1212

1313
#include <psa/crypto.h>
1414
#include <psa/crypto_types.h>
15-
#if defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
16-
#include <cracen_psa_kmu.h>
17-
#endif
1815

1916
BOOT_LOG_MODULE_REGISTER(ed25519_psa);
2017

2118
#define SHA512_DIGEST_LENGTH 64
2219
#define EDDSA_KEY_LENGTH 32
2320
#define EDDSA_SIGNAGURE_LENGTH 64
2421

25-
#if defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
26-
/* List of KMU stored key ids available for MCUboot */
27-
#define MAKE_PSA_KMU_KEY_ID(id) PSA_KEY_HANDLE_FROM_CRACEN_KMU_SLOT(CRACEN_KMU_KEY_USAGE_SCHEME_RAW, id)
28-
static psa_key_id_t kmu_key_ids[3] = {
29-
MAKE_PSA_KMU_KEY_ID(226),
30-
MAKE_PSA_KMU_KEY_ID(228),
31-
MAKE_PSA_KMU_KEY_ID(230)
32-
};
33-
#define KMU_KEY_COUNT (sizeof(kmu_key_ids)/sizeof(kmu_key_ids[0]))
34-
#endif
35-
36-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
3722
int ED25519_verify(const uint8_t *message, size_t message_len,
3823
const uint8_t signature[EDDSA_SIGNAGURE_LENGTH],
3924
const uint8_t public_key[EDDSA_KEY_LENGTH])
@@ -86,39 +71,3 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
8671

8772
return ret;
8873
}
89-
#else
90-
int ED25519_verify(const uint8_t *message, size_t message_len,
91-
const uint8_t signature[EDDSA_SIGNAGURE_LENGTH],
92-
const uint8_t public_key[EDDSA_KEY_LENGTH])
93-
{
94-
ARG_UNUSED(public_key);
95-
/* Set to any error */
96-
psa_status_t status = PSA_ERROR_BAD_STATE;
97-
int ret = 0; /* Fail by default */
98-
99-
/* Initialize PSA Crypto */
100-
status = psa_crypto_init();
101-
if (status != PSA_SUCCESS) {
102-
BOOT_LOG_ERR("PSA crypto init failed %d", status);
103-
return 0;
104-
}
105-
106-
status = PSA_ERROR_BAD_STATE;
107-
108-
for (int i = 0; i < KMU_KEY_COUNT; ++i) {
109-
psa_key_id_t kid = kmu_key_ids[i];
110-
111-
status = psa_verify_message(kid, PSA_ALG_PURE_EDDSA, message,
112-
message_len, signature,
113-
EDDSA_SIGNAGURE_LENGTH);
114-
if (status == PSA_SUCCESS) {
115-
ret = 1;
116-
break;
117-
}
118-
119-
BOOT_LOG_ERR("ED25519 signature verification failed %d", status);
120-
}
121-
122-
return ret;
123-
}
124-
#endif

boot/bootutil/src/image_ed25519.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ extern int ED25519_verify(const uint8_t *message, size_t message_len,
3434
const uint8_t signature[EDDSA_SIGNATURE_LENGTH],
3535
const uint8_t public_key[NUM_ED25519_BYTES]);
3636

37-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
3837
#if !defined(MCUBOOT_KEY_IMPORT_BYPASS_ASN)
3938
/*
4039
* Parse the public key used for signing.
@@ -77,7 +76,6 @@ bootutil_import_key(uint8_t **cp, uint8_t *end)
7776
return 0;
7877
}
7978
#endif /* !defined(MCUBOOT_KEY_IMPORT_BYPASS_ASN) */
80-
#endif
8179

8280
/* Signature verification base function.
8381
* The function takes buffer of specified length and tries to verify
@@ -92,10 +90,8 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
9290
{
9391
int rc;
9492
FIH_DECLARE(fih_rc, FIH_FAILURE);
95-
uint8_t *pubkey = NULL;
96-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
93+
uint8_t *pubkey;
9794
uint8_t *end;
98-
#endif
9995

10096
BOOT_LOG_DBG("bootutil_verify: ED25519 key_id %d", (int)key_id);
10197

@@ -106,7 +102,6 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
106102
goto out;
107103
}
108104

109-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
110105
pubkey = (uint8_t *)bootutil_keys[key_id].key;
111106
end = pubkey + *bootutil_keys[key_id].len;
112107

@@ -130,8 +125,6 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
130125
}
131126

132127
pubkey = end - NUM_ED25519_BYTES;
133-
#endif
134-
135128
#endif
136129

137130
rc = ED25519_verify(buf, blen, sig, pubkey);

boot/bootutil/src/image_validate.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ bootutil_img_hash(struct boot_loader_state *state,
292292
# define KEY_BUF_SIZE (SIG_BUF_SIZE + 24)
293293
#endif /* !MCUBOOT_HW_KEY */
294294

295-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
296295
#if !defined(MCUBOOT_HW_KEY)
297296
static int
298297
bootutil_find_key(uint8_t *keyhash, uint8_t keyhash_len)
@@ -361,7 +360,6 @@ bootutil_find_key(uint8_t image_index, uint8_t *key, uint16_t key_len)
361360
}
362361
#endif /* !MCUBOOT_HW_KEY */
363362
#endif /* !MCUBOOT_BUILTIN_KEY */
364-
#endif /* !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) */
365363
#endif /* EXPECTED_SIG_TLV */
366364

367365
/**
@@ -734,7 +732,6 @@ bootutil_img_validate(struct boot_loader_state *state,
734732
break;
735733
}
736734
#endif /* defined(EXPECTED_HASH_TLV) && !defined(MCUBOOT_SIGN_PURE) */
737-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
738735
#ifdef EXPECTED_KEY_TLV
739736
case EXPECTED_KEY_TLV:
740737
{
@@ -766,18 +763,15 @@ bootutil_img_validate(struct boot_loader_state *state,
766763
break;
767764
}
768765
#endif /* EXPECTED_KEY_TLV */
769-
#endif /* !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) */
770766
#ifdef EXPECTED_SIG_TLV
771767
case EXPECTED_SIG_TLV:
772768
{
773769
BOOT_LOG_DBG("bootutil_img_validate: EXPECTED_SIG_TLV == %d", EXPECTED_SIG_TLV);
774-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
775770
/* Ignore this signature if it is out of bounds. */
776771
if (key_id < 0 || key_id >= bootutil_key_cnt) {
777772
key_id = -1;
778773
continue;
779774
}
780-
#endif /* !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) */
781775
if (!EXPECTED_SIG_LEN(len) || len > sizeof(buf)) {
782776
rc = -1;
783777
goto out;
@@ -952,7 +946,7 @@ bootutil_img_validate(struct boot_loader_state *state,
952946
}
953947

954948
#ifdef EXPECTED_SIG_TLV
955-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && defined(EXPECTED_KEY_TLV)
949+
#ifdef EXPECTED_KEY_TLV
956950
rc = bootutil_tlv_iter_begin(&it, hdr, fap, EXPECTED_KEY_TLV, false);
957951
if (rc) {
958952
goto out;
@@ -998,7 +992,7 @@ bootutil_img_validate(struct boot_loader_state *state,
998992
*/
999993
}
1000994
}
1001-
#endif /* !CONFIG_BOOT_SIGNATURE_USING_KMU && EXPECTED_KEY_TLV */
995+
#endif /* EXPECTED_KEY_TLV */
1002996

1003997
rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_DECOMP_SIGNATURE, true);
1004998
if (rc) {
@@ -1021,12 +1015,10 @@ bootutil_img_validate(struct boot_loader_state *state,
10211015

10221016
if (type == IMAGE_TLV_DECOMP_SIGNATURE) {
10231017
/* Ignore this signature if it is out of bounds. */
1024-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
10251018
if (key_id < 0 || key_id >= bootutil_key_cnt) {
10261019
key_id = -1;
10271020
continue;
10281021
}
1029-
#endif
10301022

10311023
if (!EXPECTED_SIG_LEN(len) || len > sizeof(buf)) {
10321024
rc = -1;

boot/zephyr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ if(CONFIG_MCUBOOT_SERIAL)
361361
endif()
362362
endif()
363363

364-
if(NOT CONFIG_BOOT_SIGNATURE_USING_KMU AND NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "")
364+
if(NOT CONFIG_BOOT_SIGNATURE_KEY_FILE STREQUAL "")
365365
# CONF_FILE points to the KConfig configuration files of the bootloader.
366366
foreach (filepath ${CONF_FILE})
367367
file(READ ${filepath} temp_text)

boot/zephyr/Kconfig

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -384,22 +384,6 @@ endif
384384

385385
endchoice
386386

387-
config BOOT_SIGNATURE_USING_KMU
388-
bool "Use KMU stored keys for signature verification"
389-
depends on NRF_SECURITY
390-
depends on CRACEN_LIB_KMU
391-
select PSA_WANT_ALG_GCM
392-
select PSA_WANT_KEY_TYPE_AES
393-
select PSA_WANT_AES_KEY_SIZE_256
394-
select PSA_WANT_ALG_SP800_108_COUNTER_CMAC
395-
select PSA_WANT_ALG_CMAC
396-
select PSA_WANT_ALG_ECB_NO_PADDING
397-
help
398-
MCUboot will use keys provisioned to the device key management unit for signature
399-
verification instead of compiling in key data from a file.
400-
401-
if !BOOT_SIGNATURE_USING_KMU
402-
403387
config BOOT_SIGNATURE_KEY_FILE
404388
string "PEM key file"
405389
default "root-ec-p256.pem" if BOOT_SIGNATURE_TYPE_ECDSA_P256
@@ -417,8 +401,6 @@ config BOOT_SIGNATURE_KEY_FILE
417401
with the public key information will be written in a format expected by
418402
MCUboot.
419403

420-
endif
421-
422404
config MCUBOOT_CLEANUP_ARM_CORE
423405
bool "Perform core cleanup before chain-load the application"
424406
depends on CPU_CORTEX_M
@@ -455,14 +437,6 @@ config MCUBOOT_INFINITE_LOOP_AFTER_RAM_CLEANUP
455437
Verification option that keeps execution in infinite loop after
456438
RAM cleanup has been performed.
457439

458-
# Disable MBEDTLS from being selected if NRF_SECURITY is enabled, and use default NRF_SECURITY
459-
# configuration file for MBEDTLS
460-
config MBEDTLS
461-
depends on !NRF_SECURITY
462-
463-
config NRF_SECURITY
464-
select MBEDTLS_PROMPTLESS
465-
466440
config MBEDTLS_CFG_FILE
467441
# It might be awkward to define an Mbed TLS header file when TinyCrypt
468442
# is used, but the fact is that Mbed TLS' ASN1 parse module is used

0 commit comments

Comments
 (0)