Skip to content

Commit 0accf98

Browse files
davidvinczeadeaarm
authored andcommitted
BL2: provision raw keys instead of RFC5480 encoded ones
Instead of provisioning encoded public keys (as described in RFC5480) provision only the raw key bit string (subjectPublicKey). Signed-off-by: David Vincze <[email protected]> Change-Id: Ic94ed76b28f408e78c7d6a6c90057c490fdf0915
1 parent 5171fa5 commit 0accf98

File tree

3 files changed

+81
-67
lines changed

3 files changed

+81
-67
lines changed

bl2/src/provisioning.c

+50-60
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
#ifdef MCUBOOT_SIGN_EC384
2121
#define PUB_KEY_HASH_SIZE (48)
22-
#define PUB_KEY_SIZE (120)
22+
#define PUB_KEY_SIZE (100) /* Size must be aligned to 4 Bytes */
2323
#else
2424
#define PUB_KEY_HASH_SIZE (32)
25-
#define PUB_KEY_SIZE (92) /* Size must be aligned to 4 Bytes */
25+
#define PUB_KEY_SIZE (68) /* Size must be aligned to 4 Bytes */
2626
#endif /* MCUBOOT_SIGN_EC384 */
2727

2828
#ifdef MCUBOOT_BUILTIN_KEY
@@ -132,76 +132,66 @@ __PACKED_STRUCT bl2_assembly_and_test_provisioning_data_t {
132132
#else /* !MCUBOOT_BUILTIN_KEY */
133133
/* List of BL2 Root of Trust public keys */
134134
#if defined(MCUBOOT_SIGN_EC256)
135-
/* EC-P256 public keys (in SubjectPublicKeyInfo format, see RFC5480)
135+
/* EC-P256 public keys
136+
* (raw keys as subjectPublicKey (bit string), see RFC5480)
136137
* DATA_KIND_0: PK(bl2/ext/mcuboot/root-EC-P256.pem)
137138
* DATA_KIND_1: PK(bl2/ext/mcuboot/root-EC-P256_1.pem)
138139
*/
139140
#define ASSEMBLY_AND_TEST_PROV_DATA_KIND_0 { \
140-
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, \
141-
0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, \
142-
0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, \
143-
0x42, 0x00, 0x04, 0x2a, 0xcb, 0x40, 0x3c, 0xe8, \
144-
0xfe, 0xed, 0x5b, 0xa4, 0x49, 0x95, 0xa1, 0xa9, \
145-
0x1d, 0xae, 0xe8, 0xdb, 0xbe, 0x19, 0x37, 0xcd, \
146-
0x14, 0xfb, 0x2f, 0x24, 0x57, 0x37, 0xe5, 0x95, \
147-
0x39, 0x88, 0xd9, 0x94, 0xb9, 0xd6, 0x5a, 0xeb, \
148-
0xd7, 0xcd, 0xd5, 0x30, 0x8a, 0xd6, 0xfe, 0x48, \
149-
0xb2, 0x4a, 0x6a, 0x81, 0x0e, 0xe5, 0xf0, 0x7d, \
150-
0x8b, 0x68, 0x34, 0xcc, 0x3a, 0x6a, 0xfc, 0x53, \
151-
0x8e, 0xfa, 0xc1, \
141+
0x04, 0x2a, 0xcb, 0x40, 0x3c, 0xe8, 0xfe, 0xed, \
142+
0x5b, 0xa4, 0x49, 0x95, 0xa1, 0xa9, 0x1d, 0xae, \
143+
0xe8, 0xdb, 0xbe, 0x19, 0x37, 0xcd, 0x14, 0xfb, \
144+
0x2f, 0x24, 0x57, 0x37, 0xe5, 0x95, 0x39, 0x88, \
145+
0xd9, 0x94, 0xb9, 0xd6, 0x5a, 0xeb, 0xd7, 0xcd, \
146+
0xd5, 0x30, 0x8a, 0xd6, 0xfe, 0x48, 0xb2, 0x4a, \
147+
0x6a, 0x81, 0x0e, 0xe5, 0xf0, 0x7d, 0x8b, 0x68, \
148+
0x34, 0xcc, 0x3a, 0x6a, 0xfc, 0x53, 0x8e, 0xfa, \
149+
0xc1, \
152150
}
153151
#define ASSEMBLY_AND_TEST_PROV_DATA_KIND_1 { \
154-
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, \
155-
0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, \
156-
0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, \
157-
0x42, 0x00, 0x04, 0xe8, 0x09, 0x08, 0x12, 0x3a, \
158-
0x0f, 0xad, 0x40, 0xe0, 0x33, 0x8a, 0xa6, 0x54, \
159-
0xf8, 0x83, 0x95, 0x41, 0x8e, 0x44, 0x99, 0xa2, \
160-
0x0f, 0xae, 0x85, 0x69, 0x2b, 0xf9, 0x26, 0xb5, \
161-
0xe9, 0x9e, 0x16, 0x2c, 0x87, 0x76, 0x62, 0x7f, \
162-
0x32, 0x6c, 0x9b, 0x70, 0x78, 0x06, 0x52, 0x52, \
163-
0x52, 0xca, 0x2b, 0xd2, 0xb7, 0xc7, 0x50, 0x07, \
164-
0x66, 0x3b, 0x3b, 0xdf, 0xe1, 0x99, 0x69, 0x00, \
165-
0x26, 0x2c, 0x33, \
152+
0x04, 0xe8, 0x09, 0x08, 0x12, 0x3a, 0x0f, 0xad, \
153+
0x40, 0xe0, 0x33, 0x8a, 0xa6, 0x54, 0xf8, 0x83, \
154+
0x95, 0x41, 0x8e, 0x44, 0x99, 0xa2, 0x0f, 0xae, \
155+
0x85, 0x69, 0x2b, 0xf9, 0x26, 0xb5, 0xe9, 0x9e, \
156+
0x16, 0x2c, 0x87, 0x76, 0x62, 0x7f, 0x32, 0x6c, \
157+
0x9b, 0x70, 0x78, 0x06, 0x52, 0x52, 0x52, 0xca, \
158+
0x2b, 0xd2, 0xb7, 0xc7, 0x50, 0x07, 0x66, 0x3b, \
159+
0x3b, 0xdf, 0xe1, 0x99, 0x69, 0x00, 0x26, 0x2c, \
160+
0x33, \
166161
}
167162
#elif defined(MCUBOOT_SIGN_EC384)
168-
/* EC-P384 public keys (in SubjectPublicKeyInfo format, see RFC5480)
163+
/* EC-P384 public keys
164+
* (raw keys as subjectPublicKey (bit string), see RFC5480)
169165
* DATA_KIND_0: PK(bl2/ext/mcuboot/root-EC-P384.pem)
170166
* DATA_KIND_1: PK(bl2/ext/mcuboot/root-EC-P384_1.pem)
171167
*/
172-
#define ASSEMBLY_AND_TEST_PROV_DATA_KIND_0 { \
173-
0x30, 0x76, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, \
174-
0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, \
175-
0x81, 0x04, 0x00, 0x22, 0x03, 0x62, 0x00, 0x04, \
176-
0x0c, 0x76, 0xca, 0xae, 0x72, 0x3a, 0xa5, 0xe8, \
177-
0xf0, 0xd4, 0xf1, 0x16, 0xb5, 0x02, 0xef, 0x77, \
178-
0xa1, 0x1b, 0x93, 0x61, 0x78, 0xc0, 0x09, 0x26, \
179-
0x7b, 0x3b, 0x40, 0x9c, 0xee, 0x49, 0x85, 0xe0, \
180-
0xc9, 0x4f, 0xe7, 0xf2, 0xba, 0x97, 0x6c, 0xf3, \
181-
0x82, 0x65, 0x14, 0x2c, 0xf5, 0x0c, 0x73, 0x33, \
182-
0x4d, 0x32, 0xe7, 0x9b, 0xd3, 0x42, 0xcc, 0x95, \
183-
0x5a, 0xe5, 0xe2, 0xf5, 0xf4, 0x6e, 0x45, 0xe0, \
184-
0xed, 0x20, 0x35, 0x5c, 0xaf, 0x52, 0x35, 0x81, \
185-
0xd4, 0xdc, 0x9c, 0xe3, 0x9e, 0x22, 0x3e, 0xfb, \
186-
0x3f, 0x22, 0x10, 0xda, 0x70, 0x03, 0x37, 0xad, \
187-
0xa8, 0xf2, 0x48, 0xfe, 0x3a, 0x60, 0x69, 0xa5, \
168+
#define ASSEMBLY_AND_TEST_PROV_DATA_KIND_0 { 0x04, \
169+
0x0c, 0x76, 0xca, 0xae, 0x72, 0x3a, 0xa5, 0xe8, \
170+
0xf0, 0xd4, 0xf1, 0x16, 0xb5, 0x02, 0xef, 0x77, \
171+
0xa1, 0x1b, 0x93, 0x61, 0x78, 0xc0, 0x09, 0x26, \
172+
0x7b, 0x3b, 0x40, 0x9c, 0xee, 0x49, 0x85, 0xe0, \
173+
0xc9, 0x4f, 0xe7, 0xf2, 0xba, 0x97, 0x6c, 0xf3, \
174+
0x82, 0x65, 0x14, 0x2c, 0xf5, 0x0c, 0x73, 0x33, \
175+
0x4d, 0x32, 0xe7, 0x9b, 0xd3, 0x42, 0xcc, 0x95, \
176+
0x5a, 0xe5, 0xe2, 0xf5, 0xf4, 0x6e, 0x45, 0xe0, \
177+
0xed, 0x20, 0x35, 0x5c, 0xaf, 0x52, 0x35, 0x81, \
178+
0xd4, 0xdc, 0x9c, 0xe3, 0x9e, 0x22, 0x3e, 0xfb, \
179+
0x3f, 0x22, 0x10, 0xda, 0x70, 0x03, 0x37, 0xad, \
180+
0xa8, 0xf2, 0x48, 0xfe, 0x3a, 0x60, 0x69, 0xa5, \
188181
}
189-
#define ASSEMBLY_AND_TEST_PROV_DATA_KIND_1 { \
190-
0x30, 0x76, 0x30, 0x10, 0x06, 0x07, 0x2a, 0x86, \
191-
0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x05, 0x2b, \
192-
0x81, 0x04, 0x00, 0x22, 0x03, 0x62, 0x00, 0x04, \
193-
0x34, 0x43, 0xad, 0x59, 0x83, 0xd9, 0x41, 0x65, \
194-
0xdc, 0x20, 0xb8, 0x62, 0x35, 0xf8, 0x7d, 0x94, \
195-
0x13, 0x5e, 0x75, 0xe6, 0xa8, 0x79, 0xe9, 0xcb, \
196-
0xfd, 0xa7, 0x2e, 0x92, 0x95, 0x82, 0xa6, 0xc5, \
197-
0xdd, 0x53, 0xc7, 0x3d, 0x46, 0xed, 0x75, 0xd5, \
198-
0x20, 0xb5, 0xbe, 0x74, 0x2a, 0x6d, 0x30, 0xe2, \
199-
0x31, 0x50, 0x1c, 0x7f, 0xc7, 0x7b, 0x4a, 0x73, \
200-
0x55, 0xf8, 0x92, 0x60, 0xff, 0x2f, 0x18, 0x04, \
201-
0xbc, 0xc7, 0xd9, 0xce, 0xda, 0xa6, 0x36, 0x52, \
202-
0xec, 0x2b, 0x64, 0x6e, 0x7a, 0x97, 0x60, 0x9d, \
203-
0x8c, 0xba, 0xfe, 0xec, 0x9a, 0xb0, 0xc2, 0x6e, \
204-
0x3d, 0x75, 0x2a, 0x98, 0xb2, 0xa3, 0x09, 0x84, \
182+
#define ASSEMBLY_AND_TEST_PROV_DATA_KIND_1 { 0x04, \
183+
0x34, 0x43, 0xad, 0x59, 0x83, 0xd9, 0x41, 0x65, \
184+
0xdc, 0x20, 0xb8, 0x62, 0x35, 0xf8, 0x7d, 0x94, \
185+
0x13, 0x5e, 0x75, 0xe6, 0xa8, 0x79, 0xe9, 0xcb, \
186+
0xfd, 0xa7, 0x2e, 0x92, 0x95, 0x82, 0xa6, 0xc5, \
187+
0xdd, 0x53, 0xc7, 0x3d, 0x46, 0xed, 0x75, 0xd5, \
188+
0x20, 0xb5, 0xbe, 0x74, 0x2a, 0x6d, 0x30, 0xe2, \
189+
0x31, 0x50, 0x1c, 0x7f, 0xc7, 0x7b, 0x4a, 0x73, \
190+
0x55, 0xf8, 0x92, 0x60, 0xff, 0x2f, 0x18, 0x04, \
191+
0xbc, 0xc7, 0xd9, 0xce, 0xda, 0xa6, 0x36, 0x52, \
192+
0xec, 0x2b, 0x64, 0x6e, 0x7a, 0x97, 0x60, 0x9d, \
193+
0x8c, 0xba, 0xfe, 0xec, 0x9a, 0xb0, 0xc2, 0x6e, \
194+
0x3d, 0x75, 0x2a, 0x98, 0xb2, 0xa3, 0x09, 0x84, \
205195
}
206196
#endif /* MCUBOOT_SIGN_EC256 */
207197
#endif /* !MCUBOOT_BUILTIN_KEY */

platform/ext/common/template/flash_otp_nv_counters_backend.h

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2022, Arm Limited. All rights reserved.
2+
* Copyright (c) 2021-2024, Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -17,6 +17,30 @@ extern "C" {
1717
#endif
1818
#define OTP_NV_COUNTERS_INITIALIZED 0xC0DE8112U
1919

20+
#ifdef BL2
21+
#if defined(MCUBOOT_SIGN_EC384)
22+
#define BL2_ROTPK_HASH_SIZE (48)
23+
#define BL2_ROTPK_KEY_SIZE (100) /* Aligned to 4 bytes */
24+
#else
25+
#define BL2_ROTPK_HASH_SIZE (32)
26+
#endif /* MCUBOOT_SIGN_EC384 */
27+
#if defined(MCUBOOT_SIGN_EC256)
28+
#define BL2_ROTPK_KEY_SIZE (68) /* Aligned to 4 bytes */
29+
#endif /* MCUBOOT_SIGN_EC256 */
30+
31+
#ifdef MCUBOOT_BUILTIN_KEY
32+
#define BL2_ROTPK_SIZE BL2_ROTPK_KEY_SIZE
33+
#else
34+
#define BL2_ROTPK_SIZE BL2_ROTPK_HASH_SIZE
35+
#endif /* MCUBOOT_BUILTIN_KEY */
36+
#endif /* BL2 */
37+
38+
#if (defined(BL2_ROTPK_SIZE) && (BL2_ROTPK_SIZE > 64))
39+
#define OTP_ELEMENT_SIZE_MAX BL2_ROTPK_SIZE
40+
#else
41+
#define OTP_ELEMENT_SIZE_MAX (64)
42+
#endif
43+
2044
__PACKED_STRUCT flash_otp_nv_counters_region_t {
2145
/* Must be the first item */
2246
uint32_t init_value;
@@ -37,16 +61,16 @@ __PACKED_STRUCT flash_otp_nv_counters_region_t {
3761
uint8_t profile_definition[32];
3862

3963
#ifdef BL2
40-
uint8_t bl2_rotpk_0[32];
41-
uint8_t bl2_rotpk_1[32];
64+
uint8_t bl2_rotpk_0[BL2_ROTPK_SIZE];
65+
uint8_t bl2_rotpk_1[BL2_ROTPK_SIZE];
4266

4367
uint8_t bl2_nv_counter_0[64];
4468
uint8_t bl2_nv_counter_1[64];
4569
uint8_t bl2_nv_counter_2[64];
4670
uint8_t bl2_nv_counter_3[64];
4771

48-
uint8_t bl2_rotpk_2[32];
49-
uint8_t bl2_rotpk_3[32];
72+
uint8_t bl2_rotpk_2[BL2_ROTPK_SIZE];
73+
uint8_t bl2_rotpk_3[BL2_ROTPK_SIZE];
5074
#endif /* BL2 */
5175

5276
#ifdef BL1

platform/ext/common/template/otp_flash.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2023, Arm Limited. All rights reserved.
2+
* Copyright (c) 2021-2024, Arm Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -134,7 +134,7 @@ static enum tfm_plat_err_t read_from_input(enum tfm_otp_element_id_t id,
134134
{
135135
enum tfm_plat_err_t err = TFM_PLAT_ERR_SUCCESS;
136136
size_t value_size;
137-
uint8_t buffer[64];
137+
uint8_t buffer[OTP_ELEMENT_SIZE_MAX];
138138
size_t idx;
139139

140140
err = tfm_plat_otp_get_size(id, &value_size);

0 commit comments

Comments
 (0)