Skip to content

Commit

Permalink
bootutil: Move encryption key function to common file
Browse files Browse the repository at this point in the history
Move the definition of boot_enc_retrieve_private_key() to a common file
to avoid code duplication and also endure seamless transition to this new
key handling approach for targets which don't use hardware keys.

Change-Id: I57e54e4332503c11d18762f8291c3cab53df3d20
Signed-off-by: David Vincze <[email protected]>
  • Loading branch information
davidvincze committed Jul 31, 2024
1 parent 0e5e1a9 commit 2a7565b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 56 deletions.
19 changes: 17 additions & 2 deletions boot/bootutil/src/encrypted.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (c) 2018-2019 JUUL Labs
* Copyright (c) 2019-2023 Arm Limited
* Copyright (c) 2019-2024 Arm Limited
*/

#include "mcuboot_config/mcuboot_config.h"
Expand Down Expand Up @@ -334,7 +334,22 @@ hkdf(uint8_t *ikm, uint16_t ikm_len, uint8_t *info, uint16_t info_len,
bootutil_hmac_sha256_drop(&hmac);
return -1;
}
#endif
#endif /* MCUBOOT_ENCRYPT_EC256 || MCUBOOT_ENCRYPT_X25519 */

#if !defined(MCUBOOT_HW_KEY)
extern const struct bootutil_key bootutil_enc_key;

/*
* Default implementation to retrieve the private encryption key which is
* embedded in the bootloader code (when MCUBOOT_HW_KEY is not defined).
*/
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
{
*private_key = (struct bootutil_key *)&bootutil_enc_key;

return 0;
}
#endif /* !MCUBOOT_HW_KEY */

int
boot_enc_init(struct enc_key_data *enc_state, uint8_t slot)
Expand Down
9 changes: 0 additions & 9 deletions boot/cypress/MCUBootApp/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,3 @@ const struct bootutil_key bootutil_enc_key = {
.key = enc_priv_key,
.len = &enc_priv_key_len,
};

#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
{
*private_key = (struct bootutil_key *)&bootutil_enc_key;

return 0;
}
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */
9 changes: 0 additions & 9 deletions boot/mbed/app_enc_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,3 @@ const struct bootutil_key bootutil_enc_key = {
#endif

#endif

#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
{
*private_key = (struct bootutil_key *)&bootutil_enc_key;

return 0;
}
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */
9 changes: 0 additions & 9 deletions boot/zephyr/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,3 @@ const struct bootutil_key bootutil_enc_key = {
#elif defined(MCUBOOT_ENCRYPT_KW)
#error "Encrypted images with AES-KW is not implemented yet."
#endif

#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
{
*private_key = (struct bootutil_key *)&bootutil_enc_key;

return 0;
}
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */
9 changes: 0 additions & 9 deletions ci/mynewt_keys/enc_kw/src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,3 @@ const struct bootutil_key bootutil_enc_key = {
.key = enc_key,
.len = &enc_key_len,
};

#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
{
*private_key = (struct bootutil_key *)&bootutil_enc_key;

return 0;
}
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */
9 changes: 0 additions & 9 deletions ci/mynewt_keys/enc_rsa/src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,3 @@ const struct bootutil_key bootutil_enc_key = {
.key = enc_key,
.len = &enc_key_len,
};

#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
{
*private_key = (struct bootutil_key *)&bootutil_enc_key;

return 0;
}
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */
9 changes: 0 additions & 9 deletions sim/mcuboot-sys/csupport/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,3 @@ const struct bootutil_key bootutil_enc_key = {
.len = &enc_key_len,
};
#endif

#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
{
*private_key = (struct bootutil_key *)&bootutil_enc_key;

return 0;
}
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */

0 comments on commit 2a7565b

Please sign in to comment.