Skip to content

Commit 2a7565b

Browse files
committed
bootutil: Move encryption key function to common file
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]>
1 parent 0e5e1a9 commit 2a7565b

File tree

7 files changed

+17
-56
lines changed

7 files changed

+17
-56
lines changed

boot/bootutil/src/encrypted.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* SPDX-License-Identifier: Apache-2.0
33
*
44
* Copyright (c) 2018-2019 JUUL Labs
5-
* Copyright (c) 2019-2023 Arm Limited
5+
* Copyright (c) 2019-2024 Arm Limited
66
*/
77

88
#include "mcuboot_config/mcuboot_config.h"
@@ -334,7 +334,22 @@ hkdf(uint8_t *ikm, uint16_t ikm_len, uint8_t *info, uint16_t info_len,
334334
bootutil_hmac_sha256_drop(&hmac);
335335
return -1;
336336
}
337-
#endif
337+
#endif /* MCUBOOT_ENCRYPT_EC256 || MCUBOOT_ENCRYPT_X25519 */
338+
339+
#if !defined(MCUBOOT_HW_KEY)
340+
extern const struct bootutil_key bootutil_enc_key;
341+
342+
/*
343+
* Default implementation to retrieve the private encryption key which is
344+
* embedded in the bootloader code (when MCUBOOT_HW_KEY is not defined).
345+
*/
346+
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
347+
{
348+
*private_key = (struct bootutil_key *)&bootutil_enc_key;
349+
350+
return 0;
351+
}
352+
#endif /* !MCUBOOT_HW_KEY */
338353

339354
int
340355
boot_enc_init(struct enc_key_data *enc_state, uint8_t slot)

boot/cypress/MCUBootApp/keys.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,3 @@ const struct bootutil_key bootutil_enc_key = {
167167
.key = enc_priv_key,
168168
.len = &enc_priv_key_len,
169169
};
170-
171-
#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
172-
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
173-
{
174-
*private_key = (struct bootutil_key *)&bootutil_enc_key;
175-
176-
return 0;
177-
}
178-
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */

boot/mbed/app_enc_keys.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,3 @@ const struct bootutil_key bootutil_enc_key = {
6969
#endif
7070

7171
#endif
72-
73-
#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
74-
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
75-
{
76-
*private_key = (struct bootutil_key *)&bootutil_enc_key;
77-
78-
return 0;
79-
}
80-
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */

boot/zephyr/keys.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,3 @@ const struct bootutil_key bootutil_enc_key = {
8686
#elif defined(MCUBOOT_ENCRYPT_KW)
8787
#error "Encrypted images with AES-KW is not implemented yet."
8888
#endif
89-
90-
#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
91-
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
92-
{
93-
*private_key = (struct bootutil_key *)&bootutil_enc_key;
94-
95-
return 0;
96-
}
97-
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */

ci/mynewt_keys/enc_kw/src/keys.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,3 @@ const struct bootutil_key bootutil_enc_key = {
2828
.key = enc_key,
2929
.len = &enc_key_len,
3030
};
31-
32-
#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
33-
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
34-
{
35-
*private_key = (struct bootutil_key *)&bootutil_enc_key;
36-
37-
return 0;
38-
}
39-
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */

ci/mynewt_keys/enc_rsa/src/keys.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,3 @@ const struct bootutil_key bootutil_enc_key = {
126126
.key = enc_key,
127127
.len = &enc_key_len,
128128
};
129-
130-
#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
131-
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
132-
{
133-
*private_key = (struct bootutil_key *)&bootutil_enc_key;
134-
135-
return 0;
136-
}
137-
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */

sim/mcuboot-sys/csupport/keys.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,3 @@ const struct bootutil_key bootutil_enc_key = {
328328
.len = &enc_key_len,
329329
};
330330
#endif
331-
332-
#if !defined(MCUBOOT_HW_KEY) && defined(MCUBOOT_ENC_IMAGES)
333-
int boot_enc_retrieve_private_key(struct bootutil_key **private_key)
334-
{
335-
*private_key = (struct bootutil_key *)&bootutil_enc_key;
336-
337-
return 0;
338-
}
339-
#endif /* !MCUBOOT_HW_KEY && MCUBOOT_ENC_IMAGES */

0 commit comments

Comments
 (0)