Skip to content

Commit f99c51e

Browse files
maulik-armadeaarm
authored andcommitted
BL2: Enable Multi-Signature Support for Built-in keys
This patch introduces multi-signature support for built-in keys, enabling the use of multiple keys per image (of the same type) for signature verification. -> All changes enabled when MCUBOOT_IMAGE_MULTI_SIG_SUPPORT is defined. -> Secure image is signed with additional key (NS key). Related key id is added to the image TLV and parsed by MCUboot to retrieve the material from OTP. Signed-off-by: Maulik Patel <maulik.patel@arm.com> Change-Id: Ia27d0d4b630069cf2d2372bf7b31e9b86a2f4a1e
1 parent 439be35 commit f99c51e

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

bl2/ext/mcuboot/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ target_compile_definitions(bl2
8080
$<$<BOOL:${MCUBOOT_BUILTIN_KEY}>:TFM_S_KEY_ID=${TFM_S_KEY_ID}>
8181
$<$<BOOL:${MCUBOOT_BUILTIN_KEY}>:TFM_NS_KEY_ID=${TFM_NS_KEY_ID}>
8282
MCUBOOT_ROTPK_MAX_KEYS_PER_IMAGE=${MCUBOOT_ROTPK_MAX_KEYS_PER_IMAGE}
83+
$<$<BOOL:${MCUBOOT_IMAGE_MULTI_SIG_SUPPORT}>:MCUBOOT_IMAGE_MULTI_SIG_SUPPORT>
8384
)
8485

8586
target_link_libraries(bl2
@@ -220,6 +221,13 @@ if (PLATFORM_DEFAULT_IMAGE_SIGNING)
220221
221222
if(MCUBOOT_BUILTIN_KEY)
222223
set(wrapper_args ${wrapper_args} --psa-key-ids ${TFM_S_KEY_ID})
224+
if(MCUBOOT_IMAGE_MULTI_SIG_SUPPORT AND PLATFORM_DEFAULT_ROTPK)
225+
set(wrapper_args ${wrapper_args} --psa-key-ids ${TFM_NS_KEY_ID})
226+
endif()
227+
endif()
228+
229+
if(MCUBOOT_IMAGE_MULTI_SIG_SUPPORT)
230+
set(wrapper_args ${wrapper_args} -k ${MCUBOOT_KEY_NS})
223231
endif()
224232
225233
add_custom_command(OUTPUT tfm_s_signed.bin

bl2/ext/mcuboot/keys.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,32 @@ typedef struct {
634634
uint32_t key_id[MAX_KEYS_PER_IMAGE]; /*!< Key id of built in keys */
635635
}image_key_id_mapping_t;
636636

637+
#ifdef MCUBOOT_IMAGE_MULTI_SIG_SUPPORT
638+
/* Platform specific image to key id (otp id offset) map */
639+
static const image_key_id_mapping_t tfm_image_key_map[] = {
640+
{
641+
/* Image 0: Two keys provided; both keys are required */
642+
.key_id = { TFM_S_KEY_ID, TFM_NS_KEY_ID},
643+
},
644+
{
645+
/* Image 1: Only one key is provided and required, the second slot is unused */
646+
.key_id = { TFM_NS_KEY_ID, PSA_KEY_ID_NULL },
647+
},
648+
#if (MCUBOOT_IMAGE_NUMBER > 2)
649+
{
650+
/* Image 2: Only one key is provided and required, the second slot is unused */
651+
.key_id = { TFM_S_KEY_ID, PSA_KEY_ID_NULL },
652+
},
653+
#endif /* MCUBOOT_IMAGE_NUMBER > 2 */
654+
#if (MCUBOOT_IMAGE_NUMBER > 3)
655+
{
656+
/* Image 3: Only one key is provided and required, the second slot is unused */
657+
.key_id = { TFM_S_KEY_ID, PSA_KEY_ID_NULL },
658+
},
659+
#endif /* MCUBOOT_IMAGE_NUMBER > 3 */
660+
};
661+
662+
#else
637663
/* Platform specific image to key id (otp id offset) map */
638664
static const image_key_id_mapping_t tfm_image_key_map[] = {
639665
{
@@ -647,16 +673,17 @@ static const image_key_id_mapping_t tfm_image_key_map[] = {
647673
#if (MCUBOOT_IMAGE_NUMBER > 2)
648674
{
649675
/* Image 2: Only one key is provided and required */
650-
.key_id = { TFM_S_KEY_ID_3 },
676+
.key_id = { TFM_S_KEY_ID },
651677
},
652678
#endif /* MCUBOOT_IMAGE_NUMBER > 2 */
653679
#if (MCUBOOT_IMAGE_NUMBER > 3)
654680
{
655681
/* Image 3: Only one key is provided and required */
656-
.key_id = { TFM_S_KEY_ID_4 },
682+
.key_id = { TFM_S_KEY_ID },
657683
},
658684
#endif /* MCUBOOT_IMAGE_NUMBER > 3 */
659685
};
686+
#endif /* MCUBOOT_IMAGE_MULTI_SIG_SUPPORT */
660687

661688
static int get_key_id(uint8_t img_idx, uint8_t key_idx)
662689
{

bl2/ext/mcuboot/mcuboot_default_config.cmake

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ set(MCUBOOT_KEY_S "${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/roo
5757
set(MCUBOOT_KEY_NS "${CMAKE_SOURCE_DIR}/bl2/ext/mcuboot/root-${MCUBOOT_SIGNATURE_TYPE}_1.pem" CACHE FILEPATH "Path to key with which to sign non-secure binary")
5858
set(TFM_S_KEY_ID 0 CACHE STRING "Key ID of the key used to sign the secure image")
5959
set(TFM_NS_KEY_ID 1 CACHE STRING "Key ID of the key used to sign the non-secure image")
60-
set(MCUBOOT_ROTPK_MAX_KEYS_PER_IMAGE 1 CACHE STRING "Maximum number of RoTPK keys per image to be used in BL2")
60+
set(MCUBOOT_IMAGE_MULTI_SIG_SUPPORT OFF CACHE BOOL "Enable multiple signature support for images")
61+
if(MCUBOOT_IMAGE_MULTI_SIG_SUPPORT)
62+
set(MCUBOOT_ROTPK_MAX_KEYS_PER_IMAGE 2 CACHE STRING "Maximum number of RoTPK keys per image to be used in BL2")
63+
else()
64+
set(MCUBOOT_ROTPK_MAX_KEYS_PER_IMAGE 1 CACHE STRING "Maximum number of RoTPK keys per image to be used in BL2")
65+
endif()
6166

6267
if (MCUBOOT_SIGNATURE_TYPE STREQUAL EC-P384)
6368
set(MCUBOOT_ROTPK_HASH_ALG SHA384 CACHE STRING "Algoritm to use to hash mcuboot ROTPKs")

platform/ext/common/provisioning_bundle/provisioning_bundle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2024, Arm Limited. All rights reserved.
2+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*

platform/ext/common/provisioning_bundle/provisioning_code.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Arm Limited. All rights reserved.
2+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*

0 commit comments

Comments
 (0)