Skip to content

Commit d01e51a

Browse files
committed
[nrf noup] Support for ed25519 signature verification using ITS
Thic commit introduces support for ed25519 signature verification when CONFIG_NCS_BOOT_SIGNATURE_USING_ITS is set (through PSA API). Signed-off-by: Michal Kozikowski <[email protected]>
1 parent 3b20ec3 commit d01e51a

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

boot/bootutil/src/ed25519_psa.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,18 @@ BUILD_ASSERT(CONFIG_BOOT_SIGNATURE_KMU_SLOTS <= ARRAY_SIZE(kmu_key_ids),
4141
"Invalid number of KMU slots, up to 3 are supported on nRF54L15");
4242
#endif
4343

44-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
44+
#if defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
45+
static const psa_key_id_t its_key_ids[] = {
46+
0x40022100,
47+
0x40022101,
48+
0x40022102,
49+
0x40022103
50+
};
51+
52+
#define BOOT_SIGNATURE_ITS_KEY_SLOTS ARRAY_SIZE(its_key_ids)
53+
#endif
54+
55+
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
4556
int ED25519_verify(const uint8_t *message, size_t message_len,
4657
const uint8_t signature[EDDSA_SIGNAGURE_LENGTH],
4758
const uint8_t public_key[EDDSA_KEY_LENGTH])
@@ -103,6 +114,13 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
103114
/* Set to any error */
104115
psa_status_t status = PSA_ERROR_BAD_STATE;
105116
int ret = 0; /* Fail by default */
117+
#if defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
118+
const int key_slots_count = CONFIG_BOOT_SIGNATURE_KMU_SLOTS;
119+
psa_key_id_t *key_ids = kmu_key_ids;
120+
#else
121+
const int key_slots_count = BOOT_SIGNATURE_ITS_KEY_SLOTS;
122+
psa_key_id_t const *key_ids = its_key_ids;
123+
#endif
106124

107125
/* Initialize PSA Crypto */
108126
status = psa_crypto_init();
@@ -113,23 +131,24 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
113131

114132
status = PSA_ERROR_BAD_STATE;
115133

116-
for (int i = 0; i < CONFIG_BOOT_SIGNATURE_KMU_SLOTS; ++i) {
117-
psa_key_id_t kid = kmu_key_ids[i];
134+
for (int i = 0; i < key_slots_count; ++i) {
135+
psa_key_id_t kid = key_ids[i];
118136

119137
status = psa_verify_message(kid, PSA_ALG_PURE_EDDSA, message,
120138
message_len, signature,
121139
EDDSA_SIGNAGURE_LENGTH);
122140
if (status == PSA_SUCCESS) {
123141
ret = 1;
124142
#if defined(CONFIG_BOOT_KMU_KEYS_REVOCATION)
125-
validated_with = kmu_key_ids + i;
143+
validated_with = key_ids + i;
126144
#endif
127-
break;
145+
return ret;
128146
}
129147

130-
BOOT_LOG_ERR("ED25519 signature verification failed %d", status);
131148
}
132149

150+
BOOT_LOG_ERR("ED25519 signature verification failed %d", status);
151+
133152
return ret;
134153
}
135154
#if defined(CONFIG_BOOT_KMU_KEYS_REVOCATION)

boot/bootutil/src/image_ed25519.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ extern int ED25519_verify(const uint8_t *message, size_t message_len,
3636

3737
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
3838
#if !defined(MCUBOOT_KEY_IMPORT_BYPASS_ASN)
39+
#if !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
3940
/*
4041
* Parse the public key used for signing.
4142
*/
@@ -78,6 +79,7 @@ bootutil_import_key(uint8_t **cp, uint8_t *end)
7879
}
7980
#endif /* !defined(MCUBOOT_KEY_IMPORT_BYPASS_ASN) */
8081
#endif
82+
#endif
8183

8284
/* Signature verification base function.
8385
* The function takes buffer of specified length and tries to verify
@@ -93,7 +95,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
9395
int rc;
9496
FIH_DECLARE(fih_rc, FIH_FAILURE);
9597
uint8_t *pubkey = NULL;
96-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
98+
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
9799
uint8_t *end;
98100
#endif
99101

@@ -106,7 +108,7 @@ bootutil_verify(uint8_t *buf, uint32_t blen,
106108
goto out;
107109
}
108110

109-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
111+
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
110112
pubkey = (uint8_t *)bootutil_keys[key_id].key;
111113
end = pubkey + *bootutil_keys[key_id].len;
112114

boot/bootutil/src/image_validate.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,13 +772,13 @@ bootutil_img_validate(struct boot_loader_state *state,
772772
case EXPECTED_SIG_TLV:
773773
{
774774
BOOT_LOG_DBG("bootutil_img_validate: EXPECTED_SIG_TLV == %d", EXPECTED_SIG_TLV);
775-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
775+
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
776776
/* Ignore this signature if it is out of bounds. */
777777
if (key_id < 0 || key_id >= bootutil_key_cnt) {
778778
key_id = -1;
779779
continue;
780780
}
781-
#endif /* !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) */
781+
#endif /* !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS) */
782782
if (!EXPECTED_SIG_LEN(len) || len > sizeof(buf)) {
783783
rc = -1;
784784
goto out;
@@ -1022,7 +1022,7 @@ bootutil_img_validate(struct boot_loader_state *state,
10221022

10231023
if (type == IMAGE_TLV_DECOMP_SIGNATURE) {
10241024
/* Ignore this signature if it is out of bounds. */
1025-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
1025+
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
10261026
if (key_id < 0 || key_id >= bootutil_key_cnt) {
10271027
key_id = -1;
10281028
continue;

0 commit comments

Comments
 (0)