Skip to content

Commit 1908d00

Browse files
committed
bootutil: Support for MCUBOOT_BYPASS_KEY_MATCH
This MCUboot configuration option turns off matching of public key hash, taken from image TLV, against built in public key. Such verification is not needed when there is only one key built in as the signature verification will reject image signed with unknown key anyway. Enabling the option allows to slightly reduce MCUboot binary size by removing the code that does the key matching. Boot time improvement is not really significant. Signed-off-by: Dominik Ermel <[email protected]>
1 parent cfd876f commit 1908d00

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

boot/bootutil/src/image_validate.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ bootutil_img_hash(struct boot_loader_state *state,
271271
# define KEY_BUF_SIZE (SIG_BUF_SIZE + 24)
272272
#endif /* !MCUBOOT_HW_KEY */
273273

274+
#if !defined(MCUBOOT_BYPASS_KEY_MATCH)
275+
/* Find funcitions are only needed when key is checked first */
274276
#if !defined(MCUBOOT_HW_KEY)
275277
static int
276278
bootutil_find_key(uint8_t *keyhash, uint8_t keyhash_len)
@@ -337,6 +339,7 @@ bootutil_find_key(uint8_t image_index, uint8_t *key, uint16_t key_len)
337339
#endif /* !MCUBOOT_HW_KEY */
338340
#endif /* !MCUBOOT_BUILTIN_KEY */
339341
#endif /* EXPECTED_SIG_TLV */
342+
#endif /* !MCUBOOT_BYPASS_KEY_MATCH */
340343

341344
/**
342345
* Reads the value of an image's security counter.
@@ -631,7 +634,12 @@ bootutil_img_validate(struct boot_loader_state *state,
631634
if (rc) {
632635
goto out;
633636
}
637+
#if !defined(MCUBOOT_BYPASS_KEY_MATCH)
634638
key_id = bootutil_find_key(buf, len);
639+
#else
640+
/* There is only one key */
641+
key_id = 0;
642+
#endif
635643
#else
636644
rc = LOAD_IMAGE_DATA(hdr, fap, off, key_buf, len);
637645
if (rc) {

0 commit comments

Comments
 (0)