Skip to content

Add support for multiple same-type signatures with key ID parsing #2305

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 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions boot/bootutil/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,32 @@ target_include_directories(bootutil
src
)

target_sources(bootutil
PRIVATE
src/boot_record.c
src/bootutil_misc.c
src/bootutil_public.c
src/caps.c
src/encrypted.c
src/fault_injection_hardening.c
src/fault_injection_hardening_delay_rng_mbedtls.c
src/image_ecdsa.c
src/image_ed25519.c
src/image_rsa.c
src/image_validate.c
src/loader.c
src/swap_misc.c
src/swap_move.c
src/swap_scratch.c
src/tlv.c
set(BOOTUTIL_SOURCES
src/boot_record.c
src/bootutil_misc.c
src/bootutil_public.c
src/caps.c
src/encrypted.c
src/fault_injection_hardening.c
src/fault_injection_hardening_delay_rng_mbedtls.c
src/image_ecdsa.c
src/image_ed25519.c
src/image_rsa.c
src/loader.c
src/swap_misc.c
src/swap_move.c
src/swap_scratch.c
src/tlv.c
)

if(CONFIG_BOOT_RAM_LOAD)
target_sources(bootutil
PRIVATE
src/ram_load.c
)
list(APPEND BOOTUTIL_SOURCES src/ram_load.c)
endif()

if(MCUBOOT_IMAGE_MULTI_SIG_SUPPORT)
list(APPEND BOOTUTIL_SOURCES src/image_multi_sig.c)
else()
list(APPEND BOOTUTIL_SOURCES src/image_validate.c)
endif()

target_sources(bootutil PRIVATE ${BOOTUTIL_SOURCES})
5 changes: 0 additions & 5 deletions boot/bootutil/include/bootutil/crypto/ecdsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,6 @@ static inline void bootutil_ecdsa_init(bootutil_ecdsa_context *ctx)
ctx->required_algorithm = 0;

#else /* !MCUBOOT_BUILTIN_KEY */
/* The incoming key ID is equal to the image index. The key ID value must be
* shifted (by one in this case) because zero is reserved (PSA_KEY_ID_NULL)
* and considered invalid.
*/
ctx->key_id++; /* Make sure it is not equal to 0. */
#if defined(MCUBOOT_SIGN_EC256)
ctx->curve_byte_count = 32;
ctx->required_algorithm = PSA_ALG_SHA_256;
Expand Down
1 change: 1 addition & 0 deletions boot/bootutil/include/bootutil/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct flash_area;
*/
#define IMAGE_TLV_KEYHASH 0x01 /* hash of the public key */
#define IMAGE_TLV_PUBKEY 0x02 /* public key */
#define IMAGE_TLV_KEYID 0x03 /* Key ID */
#define IMAGE_TLV_SHA256 0x10 /* SHA256 of image hdr and body */
#define IMAGE_TLV_SHA384 0x11 /* SHA384 of image hdr and body */
#define IMAGE_TLV_SHA512 0x12 /* SHA512 of image hdr and body */
Expand Down
14 changes: 14 additions & 0 deletions boot/bootutil/include/bootutil/sign_key.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ struct bootutil_key {
};

extern const struct bootutil_key bootutil_keys[];
#ifdef MCUBOOT_BUILTIN_KEY
/**
* Verify that the specified key ID is valid for authenticating the given image.
*
* @param[in] image_index Index of the image to be verified.
* @param[in] key_id Identifier of the key to be verified against the image.
*
* @return 0 if the key ID is valid for the image; nonzero on failure.
*/
int boot_verify_key_id_for_image(uint8_t image_index, int32_t key_id);
#endif /* MCUBOOT_BUILTIN_KEY */
#else
struct bootutil_key {
uint8_t *key;
Expand All @@ -51,15 +62,18 @@ extern struct bootutil_key bootutil_keys[];
* Retrieve the hash of the corresponding public key for image authentication.
*
* @param[in] image_index Index of the image to be authenticated.
* @param[in] key_index Index of the key to be used.
* @param[out] public_key_hash Buffer to store the key-hash in.
* @param[in,out] key_hash_size As input the size of the buffer. As output
* the actual key-hash length.
*
* @return 0 on success; nonzero on failure.
*/
int boot_retrieve_public_key_hash(uint8_t image_index,
uint8_t key_index,
uint8_t *public_key_hash,
size_t *key_hash_size);

#endif /* !MCUBOOT_HW_KEY */

extern const int bootutil_key_cnt;
Expand Down
Loading