Skip to content

Commit 0d263fa

Browse files
michalek-nonordicjm
authored andcommitted
[nrf noup] bootutil: ed25519_psa: multi verification revocation
take into account multiple verification done in one boot. Make sure only unused keys are revoked. Signed-off-by: Mateusz Michalek <[email protected]>
1 parent 82b1eee commit 0d263fa

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

boot/bootutil/src/ed25519_psa.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ static psa_key_id_t key_ids[] = {
4545

4646
#if defined(CONFIG_BOOT_KMU_KEYS_REVOCATION)
4747
#include <bootutil/key_revocation.h>
48-
static psa_key_id_t *validated_with = NULL;
48+
#define VALIDATED_WITH_UNINITIALIZED INT32_MAX
49+
static int32_t validated_with = VALIDATED_WITH_UNINITIALIZED;
4950
#endif
5051

5152
BUILD_ASSERT(CONFIG_BOOT_SIGNATURE_KMU_SLOTS <= ARRAY_SIZE(key_ids),
@@ -142,7 +143,9 @@ int ED25519_verify(const uint8_t *message, size_t message_len,
142143
EDDSA_SIGNAGURE_LENGTH);
143144
if (status == PSA_SUCCESS) {
144145
#if defined(CONFIG_BOOT_KMU_KEYS_REVOCATION)
145-
validated_with = key_ids + i;
146+
if(i < validated_with) {
147+
validated_with = i;
148+
}
146149
#endif
147150
return 1;
148151
}
@@ -159,7 +162,7 @@ int exec_revoke(void)
159162
int ret = BOOT_KEY_REVOKE_OK;
160163
psa_status_t status = psa_crypto_init();
161164

162-
if (!validated_with) {
165+
if (validated_with == VALIDATED_WITH_UNINITIALIZED) {
163166
ret = BOOT_KEY_REVOKE_INVALID;
164167
goto out;
165168
}
@@ -170,7 +173,7 @@ int exec_revoke(void)
170173
goto out;
171174
}
172175
for (int i = 0; i < CONFIG_BOOT_SIGNATURE_KMU_SLOTS; i++) {
173-
if ((key_ids + i) == validated_with) {
176+
if ( i == validated_with) {
174177
break;
175178
}
176179
BOOT_LOG_DBG("Invalidating key ID %d", i);
@@ -179,7 +182,7 @@ int exec_revoke(void)
179182
if (status == PSA_SUCCESS) {
180183
BOOT_LOG_DBG("Success on key ID %d", i);
181184
} else {
182-
BOOT_LOG_ERR("Key invalidation failed with: %d", status);
185+
BOOT_LOG_DBG("Key invalidation failed with: %d", status);
183186
}
184187
}
185188
out:

0 commit comments

Comments
 (0)