Skip to content

Allow bypasing signature hash key matching #2310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

de-nordic
Copy link
Collaborator

Currently MCUboot checks whether key hash in TLV matches any known builtin public keys.
When only one key in compiled in, most cases, then this match is pointless as image signature verification will just verify validity of the key anyway.
The PR adds MCUBOOT_BYPASS_KEY_MATCH option that allows to turn of the key matching and slightly reduces the binary size.

@de-nordic de-nordic force-pushed the bypass-key-match branch 3 times, most recently from 29e6bcb to 2825070 Compare May 20, 2025 13:19
@de-nordic de-nordic requested a review from nvlsianpu May 20, 2025 13:19
@de-nordic de-nordic marked this pull request as ready for review May 20, 2025 13:19
@@ -325,6 +325,18 @@ endif

endchoice

config BOOT_BYPASS_KEY_MATCH
bool "Do not match TLV key hash against built in key"
depends on !BOOT_SIGNATURE_TYPE_NONE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

depends on !hw key?

@de-nordic de-nordic requested a review from Copilot May 22, 2025 14:39
@de-nordic de-nordic changed the title Allow bypasing signature has key matching Allow bypasing signature hash key matching May 22, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces an option to skip matching the TLV key hash against built-in public keys when only one key is compiled in, reducing code size.

  • Adds MCUBOOT_BYPASS_KEY_MATCH config flag in mcuboot_config.h
  • Wraps bootutil_find_key and its call in image_validate.c with #if !defined(MCUBOOT_BYPASS_KEY_MATCH)
  • Defaults key_id to 0 when bypassing key match

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
boot/zephyr/include/mcuboot_config/mcuboot_config.h Added MCUBOOT_BYPASS_KEY_MATCH option
boot/bootutil/src/image_validate.c Conditionalized key-hash matching and lookup logic
Files not reviewed (1)
  • boot/zephyr/Kconfig: Language not supported
Comments suppressed due to low confidence (2)

boot/bootutil/src/image_validate.c:274

  • There are no tests covering the bypass logic. Please add unit tests for both paths (with and without MCUBOOT_BYPASS_KEY_MATCH) to verify correct key lookup and fallback behavior.
#if !defined(MCUBOOT_BYPASS_KEY_MATCH)

boot/bootutil/src/image_validate.c:641

  • When bypassing the key‐match, we unconditionally set key_id = 0. Consider adding a compile-time or runtime assertion to ensure exactly one built-in key is present when this option is enabled to avoid inadvertently using the wrong key.
key_id = 0;

de-nordic added 2 commits May 22, 2025 14:44
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]>
Add Zephyr support for MCUBOOT_BYPASS_KEY_MATCH

Signed-off-by: Dominik Ermel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants