Skip to content

Commit 227eb0a

Browse files
nordic-mik7rlubos
authored andcommitted
[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]> (cherry picked from commit 391f093)
1 parent a4bae13 commit 227eb0a

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

boot/bootutil/src/ed25519_psa.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,35 @@ BOOT_LOG_MODULE_REGISTER(ed25519_psa);
2626
#if defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
2727
/* List of KMU stored key ids available for MCUboot */
2828
#define MAKE_PSA_KMU_KEY_ID(id) PSA_KEY_HANDLE_FROM_CRACEN_KMU_SLOT(CRACEN_KMU_KEY_USAGE_SCHEME_RAW, id)
29-
static psa_key_id_t kmu_key_ids[3] = {
29+
static psa_key_id_t key_ids[] = {
3030
MAKE_PSA_KMU_KEY_ID(226),
3131
MAKE_PSA_KMU_KEY_ID(228),
3232
MAKE_PSA_KMU_KEY_ID(230)
3333
};
3434

35+
#define KEY_SLOTS_COUNT CONFIG_BOOT_SIGNATURE_KMU_SLOTS
36+
3537
#if defined(CONFIG_BOOT_KMU_KEYS_REVOCATION)
3638
#include <bootutil/key_revocation.h>
3739
static psa_key_id_t *validated_with = NULL;
3840
#endif
3941

40-
BUILD_ASSERT(CONFIG_BOOT_SIGNATURE_KMU_SLOTS <= ARRAY_SIZE(kmu_key_ids),
42+
BUILD_ASSERT(CONFIG_BOOT_SIGNATURE_KMU_SLOTS <= ARRAY_SIZE(key_ids),
4143
"Invalid number of KMU slots, up to 3 are supported on nRF54L15");
4244
#endif
4345

44-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
46+
#if defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
47+
static const psa_key_id_t key_ids[] = {
48+
0x40022100,
49+
0x40022101,
50+
0x40022102,
51+
0x40022103
52+
};
53+
54+
#define KEY_SLOTS_COUNT ARRAY_SIZE(key_ids)
55+
#endif
56+
57+
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
4558
int ED25519_verify(const uint8_t *message, size_t message_len,
4659
const uint8_t signature[EDDSA_SIGNAGURE_LENGTH],
4760
const uint8_t public_key[EDDSA_KEY_LENGTH])
@@ -102,7 +115,6 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
102115
ARG_UNUSED(public_key);
103116
/* Set to any error */
104117
psa_status_t status = PSA_ERROR_BAD_STATE;
105-
int ret = 0; /* Fail by default */
106118

107119
/* Initialize PSA Crypto */
108120
status = psa_crypto_init();
@@ -113,24 +125,24 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
113125

114126
status = PSA_ERROR_BAD_STATE;
115127

116-
for (int i = 0; i < CONFIG_BOOT_SIGNATURE_KMU_SLOTS; ++i) {
117-
psa_key_id_t kid = kmu_key_ids[i];
128+
for (int i = 0; i < KEY_SLOTS_COUNT; ++i) {
129+
psa_key_id_t kid = key_ids[i];
118130

119131
status = psa_verify_message(kid, PSA_ALG_PURE_EDDSA, message,
120132
message_len, signature,
121133
EDDSA_SIGNAGURE_LENGTH);
122134
if (status == PSA_SUCCESS) {
123-
ret = 1;
124135
#if defined(CONFIG_BOOT_KMU_KEYS_REVOCATION)
125-
validated_with = kmu_key_ids + i;
136+
validated_with = key_ids + i;
126137
#endif
127-
break;
138+
return 1;
128139
}
129140

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

133-
return ret;
143+
BOOT_LOG_ERR("ED25519 signature verification failed %d", status);
144+
145+
return 0;
134146
}
135147
#if defined(CONFIG_BOOT_KMU_KEYS_REVOCATION)
136148
int exec_revoke(void)
@@ -149,12 +161,12 @@ int exec_revoke(void)
149161
goto out;
150162
}
151163
for (int i = 0; i < CONFIG_BOOT_SIGNATURE_KMU_SLOTS; i++) {
152-
if ((kmu_key_ids + i) == validated_with) {
164+
if ((key_ids + i) == validated_with) {
153165
break;
154166
}
155167
BOOT_LOG_DBG("Invalidating key ID %d", i);
156168

157-
status = psa_destroy_key(kmu_key_ids[i]);
169+
status = psa_destroy_key(key_ids[i]);
158170
if (status == PSA_SUCCESS) {
159171
BOOT_LOG_DBG("Success on key ID %d", i);
160172
} else {

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
@@ -784,13 +784,13 @@ bootutil_img_validate(struct boot_loader_state *state,
784784
case EXPECTED_SIG_TLV:
785785
{
786786
BOOT_LOG_DBG("bootutil_img_validate: EXPECTED_SIG_TLV == %d", EXPECTED_SIG_TLV);
787-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
787+
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
788788
/* Ignore this signature if it is out of bounds. */
789789
if (key_id < 0 || key_id >= bootutil_key_cnt) {
790790
key_id = -1;
791791
continue;
792792
}
793-
#endif /* !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) */
793+
#endif /* !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS) */
794794
if (!EXPECTED_SIG_LEN(len) || len > sizeof(buf)) {
795795
rc = -1;
796796
goto out;
@@ -1105,7 +1105,7 @@ bootutil_img_validate(struct boot_loader_state *state,
11051105

11061106
if (type == IMAGE_TLV_DECOMP_SIGNATURE) {
11071107
/* Ignore this signature if it is out of bounds. */
1108-
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU)
1108+
#if !defined(CONFIG_BOOT_SIGNATURE_USING_KMU) && !defined(CONFIG_NCS_BOOT_SIGNATURE_USING_ITS)
11091109
if (key_id < 0 || key_id >= bootutil_key_cnt) {
11101110
key_id = -1;
11111111
continue;

0 commit comments

Comments
 (0)