Skip to content

Commit 3929743

Browse files
committed
Add simulator support for RSA-3072 sigs
Signed-off-by: Fabio Utzig <utzig@apache.org>
1 parent 19fd79a commit 3929743

File tree

11 files changed

+217
-12
lines changed

11 files changed

+217
-12
lines changed

boot/bootutil/include/bootutil/caps.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ uint32_t bootutil_get_caps(void);
4040
#define BOOTUTIL_CAP_ENC_RSA (1<<5)
4141
#define BOOTUTIL_CAP_ENC_KW (1<<6)
4242
#define BOOTUTIL_CAP_VALIDATE_PRIMARY_SLOT (1<<7)
43+
#define BOOTUTIL_CAP_RSA3072 (1<<8)
4344

4445
/*
4546
* Query the number of images this bootloader is configured for. This

boot/bootutil/src/caps.c

+5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ uint32_t bootutil_get_caps(void)
2222
uint32_t res = 0;
2323

2424
#if defined(MCUBOOT_SIGN_RSA)
25+
#if MCUBOOT_SIGN_RSA_LEN == 2048
2526
res |= BOOTUTIL_CAP_RSA2048;
2627
#endif
28+
#if MCUBOOT_SIGN_RSA_LEN == 3072
29+
res |= BOOTUTIL_CAP_RSA3072;
30+
#endif
31+
#endif
2732
#if defined(MCUBOOT_SIGN_EC)
2833
res |= BOOTUTIL_CAP_ECDSA_P224;
2934
#endif

root-rsa-3072.pem

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIG5AIBAAKCAYEAtCwOmFgQpKdYmXwB3QgqKDQz+JYaNCBdRchxJiXl0pbqe7EV
3+
qqaKYyKLLU6Bc79uFWiMGvTvKo+MIp5xV0veD35y03q4px1ErYcAg1z9cwVyRj+L
4+
+RAA2G7Mhe35Sdt4NoBJOHbdX1QE2ow0pysTJW/RFU+twuGl0k5XDH6cm7pOaLLg
5+
JQKqANO0zC945b5HZx/IbiJsXmG2ms3lqLp6gBMbFy6W7c+zm+Qc6K2n9jpRZl6Z
6+
jofuYCX4jb7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T+Ot
38+
GtlLLU4J6+l07vVfueEofoJMfqWjDUpOr3FmnP+K2drZWFnzv/3Rgg==
39+
-----END RSA PRIVATE KEY-----

sim/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2018"
88
default = []
99

1010
sig-rsa = ["mcuboot-sys/sig-rsa"]
11+
sig-rsa3072 = ["mcuboot-sys/sig-rsa3072"]
1112
sig-ecdsa = ["mcuboot-sys/sig-ecdsa"]
1213
overwrite-only = ["mcuboot-sys/overwrite-only"]
1314
validate-primary-slot = ["mcuboot-sys/validate-primary-slot"]

sim/mcuboot-sys/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ default = []
1515
# compile with both sig-rsa and sig-ecdsa enabled.
1616
sig-rsa = []
1717

18+
# Verify RSA-3072 signatures.
19+
sig-rsa3072 = []
20+
1821
# Verify ECDSA (secp256r1) signatures.
1922
sig-ecdsa = []
2023

sim/mcuboot-sys/build.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use std::path::Path;
1010
fn main() {
1111
// Feature flags.
1212
let sig_rsa = env::var("CARGO_FEATURE_SIG_RSA").is_ok();
13+
let sig_rsa3072 = env::var("CARGO_FEATURE_SIG_RSA3072").is_ok();
1314
let sig_ecdsa = env::var("CARGO_FEATURE_SIG_ECDSA").is_ok();
1415
let overwrite_only = env::var("CARGO_FEATURE_OVERWRITE_ONLY").is_ok();
1516
let validate_primary_slot =
@@ -35,13 +36,23 @@ fn main() {
3536
conf.define("MCUBOOT_VALIDATE_PRIMARY_SLOT", None);
3637
}
3738

38-
// Currently, mbed TLS cannot build with both RSA and ECDSA.
39-
if sig_rsa && sig_ecdsa {
40-
panic!("mcuboot does not support RSA and ECDSA at the same time");
39+
// Currently no more than one sig type can be used simultaneously.
40+
if vec![sig_rsa, sig_rsa3072, sig_ecdsa].iter()
41+
.fold(0, |sum, &v| sum + v as i32) > 1 {
42+
panic!("mcuboot does not support more than one sig type at the same time");
4143
}
4244

43-
if sig_rsa {
45+
if sig_rsa || sig_rsa3072 {
4446
conf.define("MCUBOOT_SIGN_RSA", None);
47+
// The Kconfig style defines must be added here as well because
48+
// they are used internally by "config-rsa.h"
49+
if sig_rsa {
50+
conf.define("MCUBOOT_SIGN_RSA_LEN", "2048");
51+
conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_2048", None);
52+
} else {
53+
conf.define("MCUBOOT_SIGN_RSA_LEN", "3072");
54+
conf.define("CONFIG_BOOT_SIGNATURE_TYPE_RSA_3072", None);
55+
}
4556
conf.define("MCUBOOT_USE_MBED_TLS", None);
4657

4758
conf.include("mbedtls/include");
@@ -114,7 +125,7 @@ fn main() {
114125
conf.file("../../boot/bootutil/src/encrypted.c");
115126
conf.file("csupport/keys.c");
116127

117-
if sig_rsa {
128+
if sig_rsa || sig_rsa3072 {
118129
conf.file("mbedtls/library/sha256.c");
119130
}
120131

@@ -141,7 +152,7 @@ fn main() {
141152

142153
if sig_rsa && enc_kw {
143154
conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa-kw.h>"));
144-
} else if sig_rsa || enc_rsa {
155+
} else if sig_rsa || sig_rsa3072 || enc_rsa {
145156
conf.define("MBEDTLS_CONFIG_FILE", Some("<config-rsa.h>"));
146157
} else if sig_ecdsa && !enc_kw {
147158
conf.define("MBEDTLS_CONFIG_FILE", Some("<config-asn1.h>"));
@@ -150,7 +161,7 @@ fn main() {
150161
}
151162

152163
conf.file("../../boot/bootutil/src/image_validate.c");
153-
if sig_rsa {
164+
if sig_rsa || sig_rsa3072 {
154165
conf.file("../../boot/bootutil/src/image_rsa.c");
155166
} else if sig_ecdsa {
156167
conf.file("../../boot/bootutil/src/image_ec256.c");

sim/mcuboot-sys/csupport/keys.c

+57
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <mcuboot_config/mcuboot_config.h>
2323

2424
#if defined(MCUBOOT_SIGN_RSA)
25+
#if MCUBOOT_SIGN_RSA_LEN == 2048
2526
#define HAVE_KEYS
2627
const unsigned char root_pub_der[] = {
2728
0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xd1, 0x06, 0x08,
@@ -49,6 +50,62 @@ const unsigned char root_pub_der[] = {
4950
0xc9, 0x02, 0x03, 0x01, 0x00, 0x01
5051
};
5152
const unsigned int root_pub_der_len = 270;
53+
#elif MCUBOOT_SIGN_RSA_LEN == 3072
54+
#define HAVE_KEYS
55+
const unsigned char root_pub_der[] = {
56+
0x30, 0x82, 0x01, 0x8a, 0x02, 0x82, 0x01, 0x81,
57+
0x00, 0xb4, 0x2c, 0x0e, 0x98, 0x58, 0x10, 0xa4,
58+
0xa7, 0x58, 0x99, 0x7c, 0x01, 0xdd, 0x08, 0x2a,
59+
0x28, 0x34, 0x33, 0xf8, 0x96, 0x1a, 0x34, 0x20,
60+
0x5d, 0x45, 0xc8, 0x71, 0x26, 0x25, 0xe5, 0xd2,
61+
0x96, 0xea, 0x7b, 0xb1, 0x15, 0xaa, 0xa6, 0x8a,
62+
0x63, 0x22, 0x8b, 0x2d, 0x4e, 0x81, 0x73, 0xbf,
63+
0x6e, 0x15, 0x68, 0x8c, 0x1a, 0xf4, 0xef, 0x2a,
64+
0x8f, 0x8c, 0x22, 0x9e, 0x71, 0x57, 0x4b, 0xde,
65+
0x0f, 0x7e, 0x72, 0xd3, 0x7a, 0xb8, 0xa7, 0x1d,
66+
0x44, 0xad, 0x87, 0x00, 0x83, 0x5c, 0xfd, 0x73,
67+
0x05, 0x72, 0x46, 0x3f, 0x8b, 0xf9, 0x10, 0x00,
68+
0xd8, 0x6e, 0xcc, 0x85, 0xed, 0xf9, 0x49, 0xdb,
69+
0x78, 0x36, 0x80, 0x49, 0x38, 0x76, 0xdd, 0x5f,
70+
0x54, 0x04, 0xda, 0x8c, 0x34, 0xa7, 0x2b, 0x13,
71+
0x25, 0x6f, 0xd1, 0x15, 0x4f, 0xad, 0xc2, 0xe1,
72+
0xa5,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 0x85, 0xac, 0x2a, 0x22,
94+
0xf4, 0xcf, 0x15, 0x08, 0x80, 0x1f, 0x0d, 0xd0,
95+
0x1e, 0xa0, 0xa0, 0x94, 0xc8, 0xf7, 0xfa, 0x65,
96+
0xdd, 0x52, 0xe8, 0x96, 0x37, 0x23, 0x30, 0x57,
97+
0x36, 0xe6, 0x9d, 0xf4, 0x0c, 0x4a, 0x05, 0x75,
98+
0x1f, 0xad, 0x01, 0xca, 0xb7, 0x6d, 0x8c, 0x43,
99+
0x74, 0x06, 0x0a, 0x81, 0xf3, 0x01, 0x62, 0xff,
100+
0xf7, 0xf5, 0x5f, 0xaf, 0xe7, 0x2b, 0x0e, 0xf8,
101+
0x81, 0xb5, 0x65, 0xdd, 0x01, 0xd9, 0x9f, 0x07,
102+
0x17, 0x8a, 0x18, 0xcf, 0x23, 0x6e, 0x88, 0x65,
103+
0x91, 0xb5, 0x7b, 0xd3, 0xb0, 0x2d, 0xaf, 0x93,
104+
0x66, 0x63, 0x74, 0xac, 0x5a, 0xe6, 0x73, 0xde,
105+
0x3b, 0x02, 0x03, 0x01, 0x00, 0x01,
106+
};
107+
const unsigned int root_pub_der_len = 398;
108+
#endif
52109
#elif defined(MCUBOOT_SIGN_EC256)
53110
#define HAVE_KEYS
54111
const unsigned char root_pub_der[] = {

sim/src/caps.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub enum Caps {
1212
EncRsa = (1 << 5),
1313
EncKw = (1 << 6),
1414
ValidatePrimarySlot = (1 << 7),
15+
RSA3072 = (1 << 8),
1516
}
1617

1718
impl Caps {

sim/src/image.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,8 @@ fn make_tlv() -> TlvGen {
11411141
// The non-encrypted configuration.
11421142
if Caps::RSA2048.present() {
11431143
TlvGen::new_rsa_pss()
1144+
} else if Caps::RSA3072.present() {
1145+
TlvGen::new_rsa3072_pss()
11441146
} else if Caps::EcdsaP256.present() {
11451147
TlvGen::new_ecdsa()
11461148
} else {

sim/src/rsa3072_pub_key-rs.txt

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Autogenerated by imgtool.py, do not edit. */
2+
static RSA3072_PUB_KEY: &'static [u8] = &[
3+
0x30, 0x82, 0x01, 0x8a, 0x02, 0x82, 0x01, 0x81,
4+
0x00, 0xb4, 0x2c, 0x0e, 0x98, 0x58, 0x10, 0xa4,
5+
0xa7, 0x58, 0x99, 0x7c, 0x01, 0xdd, 0x08, 0x2a,
6+
0x28, 0x34, 0x33, 0xf8, 0x96, 0x1a, 0x34, 0x20,
7+
0x5d, 0x45, 0xc8, 0x71, 0x26, 0x25, 0xe5, 0xd2,
8+
0x96, 0xea, 0x7b, 0xb1, 0x15, 0xaa, 0xa6, 0x8a,
9+
0x63, 0x22, 0x8b, 0x2d, 0x4e, 0x81, 0x73, 0xbf,
10+
0x6e, 0x15, 0x68, 0x8c, 0x1a, 0xf4, 0xef, 0x2a,
11+
0x8f, 0x8c, 0x22, 0x9e, 0x71, 0x57, 0x4b, 0xde,
12+
0x0f, 0x7e, 0x72, 0xd3, 0x7a, 0xb8, 0xa7, 0x1d,
13+
0x44, 0xad, 0x87, 0x00, 0x83, 0x5c, 0xfd, 0x73,
14+
0x05, 0x72, 0x46, 0x3f, 0x8b, 0xf9, 0x10, 0x00,
15+
0xd8, 0x6e, 0xcc, 0x85, 0xed, 0xf9, 0x49, 0xdb,
16+
0x78, 0x36, 0x80, 0x49, 0x38, 0x76, 0xdd, 0x5f,
17+
0x54, 0x04, 0xda, 0x8c, 0x34, 0xa7, 0x2b, 0x13,
18+
0x25, 0x6f, 0xd1, 0x15, 0x4f, 0xad, 0xc2, 0xe1,
19+
0xa5, 0xd2, 0x4e, 0x57, 0x0c, 0x7e, 0x9c, 0x9b,
20+
0xba, 0x4e, 0x68, 0xb2, 0xe0, 0x25, 0x02, 0xaa,
21+
0x00, 0xd3, 0xb4, 0xcc, 0x2f, 0x78, 0xe5, 0xbe,
22+
0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, 0x37, 0x23, 0x30, 0x57,
44+
0x36, 0xe6, 0x9d, 0xf4, 0x0c, 0x4a, 0x05, 0x75,
45+
0x1f, 0xad, 0x01, 0xca, 0xb7, 0x6d, 0x8c, 0x43,
46+
0x74, 0x06, 0x0a, 0x81, 0xf3, 0x01, 0x62, 0xff,
47+
0xf7, 0xf5, 0x5f, 0xaf, 0xe7, 0x2b, 0x0e, 0xf8,
48+
0x81, 0xb5, 0x65, 0xdd, 0x01, 0xd9, 0x9f, 0x07,
49+
0x17, 0x8a, 0x18, 0xcf, 0x23, 0x6e, 0x88, 0x65,
50+
0x91, 0xb5, 0x7b, 0xd3, 0xb0, 0x2d, 0xaf, 0x93,
51+
0x66, 0x63, 0x74, 0xac, 0x5a, 0xe6, 0x73, 0xde,
52+
0x3b, 0x02, 0x03, 0x01, 0x00, 0x01,
53+
];

sim/src/tlv.rs

+37-5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub enum TlvKinds {
2929
RSA2048 = 0x20,
3030
ECDSA224 = 0x21,
3131
ECDSA256 = 0x22,
32+
RSA3072 = 0x23,
3233
ENCRSA2048 = 0x30,
3334
ENCKW128 = 0x31,
3435
}
@@ -89,6 +90,16 @@ impl TlvGen {
8990
}
9091
}
9192

93+
#[allow(dead_code)]
94+
pub fn new_rsa3072_pss() -> TlvGen {
95+
TlvGen {
96+
flags: 0,
97+
kinds: vec![TlvKinds::SHA256, TlvKinds::RSA3072],
98+
size: 4 + 32 + 4 + 32 + 4 + 384,
99+
payload: vec![],
100+
}
101+
}
102+
92103
#[allow(dead_code)]
93104
pub fn new_ecdsa() -> TlvGen {
94105
TlvGen {
@@ -192,9 +203,17 @@ impl ManifestGen for TlvGen {
192203
result.extend_from_slice(hash);
193204
}
194205

195-
if self.kinds.contains(&TlvKinds::RSA2048) {
206+
if self.kinds.contains(&TlvKinds::RSA2048) ||
207+
self.kinds.contains(&TlvKinds::RSA3072) {
208+
209+
let is_rsa2048 = self.kinds.contains(&TlvKinds::RSA2048);
210+
196211
// Output the hash of the public key.
197-
let hash = digest::digest(&digest::SHA256, RSA_PUB_KEY);
212+
let hash = if is_rsa2048 {
213+
digest::digest(&digest::SHA256, RSA_PUB_KEY)
214+
} else {
215+
digest::digest(&digest::SHA256, RSA3072_PUB_KEY)
216+
};
198217
let hash = hash.as_ref();
199218

200219
assert!(hash.len() == 32);
@@ -205,16 +224,28 @@ impl ManifestGen for TlvGen {
205224
result.extend_from_slice(hash);
206225

207226
// For now assume PSS.
208-
let key_bytes = pem::parse(include_bytes!("../../root-rsa-2048.pem").as_ref()).unwrap();
227+
let key_bytes = if is_rsa2048 {
228+
pem::parse(include_bytes!("../../root-rsa-2048.pem").as_ref()).unwrap()
229+
} else {
230+
pem::parse(include_bytes!("../../root-rsa-3072.pem").as_ref()).unwrap()
231+
};
209232
assert_eq!(key_bytes.tag, "RSA PRIVATE KEY");
210233
let key_bytes = untrusted::Input::from(&key_bytes.contents);
211234
let key_pair = RsaKeyPair::from_der(key_bytes).unwrap();
212235
let rng = rand::SystemRandom::new();
213236
let mut signature = vec![0; key_pair.public_modulus_len()];
214-
assert_eq!(signature.len(), 256);
237+
if is_rsa2048 {
238+
assert_eq!(signature.len(), 256);
239+
} else {
240+
assert_eq!(signature.len(), 384);
241+
}
215242
key_pair.sign(&RSA_PSS_SHA256, &rng, &self.payload, &mut signature).unwrap();
216243

217-
result.push(TlvKinds::RSA2048 as u8);
244+
if is_rsa2048 {
245+
result.push(TlvKinds::RSA2048 as u8);
246+
} else {
247+
result.push(TlvKinds::RSA3072 as u8);
248+
}
218249
result.push(0);
219250
result.push((signature.len() & 0xFF) as u8);
220251
result.push(((signature.len() >> 8) & 0xFF) as u8);
@@ -297,4 +328,5 @@ impl ManifestGen for TlvGen {
297328
}
298329

299330
include!("rsa_pub_key-rs.txt");
331+
include!("rsa3072_pub_key-rs.txt");
300332
include!("ecdsa_pub_key-rs.txt");

0 commit comments

Comments
 (0)