blob: 9a97785b1e44decf1baf830a81b2f183b3f0a2ab [file] [log] [blame]
David Brownc8d62012021-10-27 15:03:48 -06001// Copyright (c) 2017-2021 Linaro LTD
David Browne2acfae2020-01-21 16:45:01 -07002// Copyright (c) 2017-2020 JUUL Labs
Salome Thirot6fdbf552021-05-14 16:46:14 +01003// Copyright (c) 2021 Arm Limited
David Browne2acfae2020-01-21 16:45:01 -07004//
5// SPDX-License-Identifier: Apache-2.0
6
David Brown187dd882017-07-11 11:15:23 -06007//! TLV Support
8//!
9//! mcuboot images are followed immediately by a list of TLV items that contain integrity
10//! information about the image. Their generation is made a little complicated because the size of
11//! the TLV block is in the image header, which is included in the hash. Since some signatures can
12//! vary in size, we just make them the largest size possible.
13//!
14//! Because of this header, we have to make two passes. The first pass will compute the size of
15//! the TLV, and the second pass will build the data for the TLV.
16
David Brown91d68632019-07-29 14:32:13 -060017use byteorder::{
18 LittleEndian, WriteBytesExt,
19};
David Brown9c6322f2021-08-19 13:03:39 -060020use cipher::FromBlockCipher;
David Brown8a4e23b2021-06-11 10:29:01 -060021use crate::caps::Caps;
David Brown7a81c4b2019-07-29 15:20:21 -060022use crate::image::ImageVersion;
Fabio Utzige84f0ef2019-11-22 12:29:32 -030023use log::info;
Fabio Utzig90f449e2019-10-24 07:43:53 -030024use ring::{digest, rand, agreement, hkdf, hmac};
Fabio Utzige84f0ef2019-11-22 12:29:32 -030025use ring::rand::SecureRandom;
Fabio Utzig05ab0142018-07-10 09:15:28 -030026use ring::signature::{
27 RsaKeyPair,
28 RSA_PSS_SHA256,
29 EcdsaKeyPair,
30 ECDSA_P256_SHA256_ASN1_SIGNING,
Fabio Utzig97710282019-05-24 17:44:49 -030031 Ed25519KeyPair,
Fabio Utzig05ab0142018-07-10 09:15:28 -030032};
David Brown9c6322f2021-08-19 13:03:39 -060033use aes::{
34 Aes128,
Fabio Utzig90f449e2019-10-24 07:43:53 -030035 Aes128Ctr,
David Brown9c6322f2021-08-19 13:03:39 -060036 Aes256,
Salome Thirot6fdbf552021-05-14 16:46:14 +010037 Aes256Ctr,
David Brown9c6322f2021-08-19 13:03:39 -060038 NewBlockCipher
39};
40use cipher::{
41 generic_array::GenericArray,
42 StreamCipher,
Fabio Utzig90f449e2019-10-24 07:43:53 -030043};
Fabio Utzig80fde2f2017-12-05 09:25:31 -020044use mcuboot_sys::c;
Salome Thirot6fdbf552021-05-14 16:46:14 +010045use typenum::{U16, U32};
David Brown187dd882017-07-11 11:15:23 -060046
David Brown69721182019-12-04 14:50:52 -070047#[repr(u16)]
David Brownc3898d62019-08-05 14:20:02 -060048#[derive(Copy, Clone, Debug, PartialEq, Eq)]
David Brown187dd882017-07-11 11:15:23 -060049#[allow(dead_code)] // TODO: For now
50pub enum TlvKinds {
David Brown43cda332017-09-01 09:53:23 -060051 KEYHASH = 0x01,
David Brown27648b82017-08-31 10:40:29 -060052 SHA256 = 0x10,
53 RSA2048 = 0x20,
54 ECDSA224 = 0x21,
55 ECDSA256 = 0x22,
Fabio Utzig39297432019-05-08 18:51:10 -030056 RSA3072 = 0x23,
Fabio Utzig97710282019-05-24 17:44:49 -030057 ED25519 = 0x24,
Fabio Utzig1e48b912018-09-18 09:04:18 -030058 ENCRSA2048 = 0x30,
Salome Thirot0f641972021-05-14 11:19:55 +010059 ENCKW = 0x31,
Fabio Utzig90f449e2019-10-24 07:43:53 -030060 ENCEC256 = 0x32,
Fabio Utzig3fa72ca2020-04-02 11:20:37 -030061 ENCX25519 = 0x33,
David Brown7a81c4b2019-07-29 15:20:21 -060062 DEPENDENCY = 0x40,
Fabio Utzig1e48b912018-09-18 09:04:18 -030063}
64
65#[allow(dead_code, non_camel_case_types)]
66pub enum TlvFlags {
67 PIC = 0x01,
68 NON_BOOTABLE = 0x02,
Salome Thirot6fdbf552021-05-14 16:46:14 +010069 ENCRYPTED_AES128 = 0x04,
Salome Thirot6fdbf552021-05-14 16:46:14 +010070 ENCRYPTED_AES256 = 0x08,
David Brownd8713a52021-10-22 16:27:23 -060071 RAM_LOAD = 0x20,
David Brown187dd882017-07-11 11:15:23 -060072}
73
David Brown43643dd2019-01-11 15:43:28 -070074/// A generator for manifests. The format of the manifest can be either a
75/// traditional "TLV" or a SUIT-style manifest.
76pub trait ManifestGen {
David Brownac46e262019-01-11 15:46:18 -070077 /// Retrieve the header magic value for this manifest type.
78 fn get_magic(&self) -> u32;
79
David Brown43643dd2019-01-11 15:43:28 -070080 /// Retrieve the flags value for this particular manifest type.
81 fn get_flags(&self) -> u32;
82
David Brown7a81c4b2019-07-29 15:20:21 -060083 /// Retrieve the number of bytes of this manifest that is "protected".
84 /// This field is stored in the outside image header instead of the
85 /// manifest header.
86 fn protect_size(&self) -> u16;
87
88 /// Add a dependency on another image.
89 fn add_dependency(&mut self, id: u8, version: &ImageVersion);
90
David Brown43643dd2019-01-11 15:43:28 -070091 /// Add a sequence of bytes to the payload that the manifest is
92 /// protecting.
93 fn add_bytes(&mut self, bytes: &[u8]);
94
David Browne90b13f2019-12-06 15:04:00 -070095 /// Set an internal flag indicating that the next `make_tlv` should
96 /// corrupt the signature.
97 fn corrupt_sig(&mut self);
98
David Brownef4f0742021-10-22 17:09:50 -060099 /// Estimate the size of the TLV. This can be called before the payload is added (but after
100 /// other information is added). Some of the signature algorithms can generate variable sized
101 /// data, and therefore, this can slightly overestimate the size.
102 fn estimate_size(&self) -> usize;
103
David Brown43643dd2019-01-11 15:43:28 -0700104 /// Construct the manifest for this payload.
105 fn make_tlv(self: Box<Self>) -> Vec<u8>;
Fabio Utzig90f449e2019-10-24 07:43:53 -0300106
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300107 /// Generate a new encryption random key
108 fn generate_enc_key(&mut self);
Fabio Utzig90f449e2019-10-24 07:43:53 -0300109
110 /// Return the current encryption key
111 fn get_enc_key(&self) -> Vec<u8>;
David Brown43643dd2019-01-11 15:43:28 -0700112}
113
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300114#[derive(Debug, Default)]
David Brown187dd882017-07-11 11:15:23 -0600115pub struct TlvGen {
David Brown43cda332017-09-01 09:53:23 -0600116 flags: u32,
David Brown187dd882017-07-11 11:15:23 -0600117 kinds: Vec<TlvKinds>,
David Brown4243ab02017-07-11 12:24:23 -0600118 payload: Vec<u8>,
David Brown7a81c4b2019-07-29 15:20:21 -0600119 dependencies: Vec<Dependency>,
Fabio Utzig90f449e2019-10-24 07:43:53 -0300120 enc_key: Vec<u8>,
David Browne90b13f2019-12-06 15:04:00 -0700121 /// Should this signature be corrupted.
122 gen_corrupted: bool,
David Brown7a81c4b2019-07-29 15:20:21 -0600123}
124
David Brownc3898d62019-08-05 14:20:02 -0600125#[derive(Debug)]
David Brown7a81c4b2019-07-29 15:20:21 -0600126struct Dependency {
127 id: u8,
128 version: ImageVersion,
David Brown187dd882017-07-11 11:15:23 -0600129}
130
131impl TlvGen {
132 /// Construct a new tlv generator that will only contain a hash of the data.
David Brown7e701d82017-07-11 13:24:25 -0600133 #[allow(dead_code)]
David Brown187dd882017-07-11 11:15:23 -0600134 pub fn new_hash_only() -> TlvGen {
135 TlvGen {
David Brown187dd882017-07-11 11:15:23 -0600136 kinds: vec![TlvKinds::SHA256],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300137 ..Default::default()
David Brown187dd882017-07-11 11:15:23 -0600138 }
139 }
140
David Brown7e701d82017-07-11 13:24:25 -0600141 #[allow(dead_code)]
142 pub fn new_rsa_pss() -> TlvGen {
143 TlvGen {
Fabio Utzig754438d2018-12-14 06:39:58 -0200144 kinds: vec![TlvKinds::SHA256, TlvKinds::RSA2048],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300145 ..Default::default()
David Brown7e701d82017-07-11 13:24:25 -0600146 }
147 }
148
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200149 #[allow(dead_code)]
Fabio Utzig39297432019-05-08 18:51:10 -0300150 pub fn new_rsa3072_pss() -> TlvGen {
151 TlvGen {
Fabio Utzig39297432019-05-08 18:51:10 -0300152 kinds: vec![TlvKinds::SHA256, TlvKinds::RSA3072],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300153 ..Default::default()
Fabio Utzig39297432019-05-08 18:51:10 -0300154 }
155 }
156
157 #[allow(dead_code)]
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200158 pub fn new_ecdsa() -> TlvGen {
159 TlvGen {
Fabio Utzig754438d2018-12-14 06:39:58 -0200160 kinds: vec![TlvKinds::SHA256, TlvKinds::ECDSA256],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300161 ..Default::default()
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200162 }
163 }
164
Fabio Utzig1e48b912018-09-18 09:04:18 -0300165 #[allow(dead_code)]
Fabio Utzig97710282019-05-24 17:44:49 -0300166 pub fn new_ed25519() -> TlvGen {
167 TlvGen {
Fabio Utzig97710282019-05-24 17:44:49 -0300168 kinds: vec![TlvKinds::SHA256, TlvKinds::ED25519],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300169 ..Default::default()
Fabio Utzig97710282019-05-24 17:44:49 -0300170 }
171 }
172
173 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100174 pub fn new_enc_rsa(aes_key_size: u32) -> TlvGen {
175 let flag = if aes_key_size == 256 {
176 TlvFlags::ENCRYPTED_AES256 as u32
177 } else {
178 TlvFlags::ENCRYPTED_AES128 as u32
179 };
Fabio Utzig1e48b912018-09-18 09:04:18 -0300180 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100181 flags: flag,
Fabio Utzig1e48b912018-09-18 09:04:18 -0300182 kinds: vec![TlvKinds::SHA256, TlvKinds::ENCRSA2048],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300183 ..Default::default()
Fabio Utzig1e48b912018-09-18 09:04:18 -0300184 }
185 }
186
187 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100188 pub fn new_sig_enc_rsa(aes_key_size: u32) -> TlvGen {
189 let flag = if aes_key_size == 256 {
190 TlvFlags::ENCRYPTED_AES256 as u32
191 } else {
192 TlvFlags::ENCRYPTED_AES128 as u32
193 };
Fabio Utzig754438d2018-12-14 06:39:58 -0200194 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100195 flags: flag,
Fabio Utzig754438d2018-12-14 06:39:58 -0200196 kinds: vec![TlvKinds::SHA256, TlvKinds::RSA2048, TlvKinds::ENCRSA2048],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300197 ..Default::default()
Fabio Utzig754438d2018-12-14 06:39:58 -0200198 }
199 }
200
201 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100202 pub fn new_enc_kw(aes_key_size: u32) -> TlvGen {
203 let flag = if aes_key_size == 256 {
204 TlvFlags::ENCRYPTED_AES256 as u32
205 } else {
206 TlvFlags::ENCRYPTED_AES128 as u32
207 };
Fabio Utzig1e48b912018-09-18 09:04:18 -0300208 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100209 flags: flag,
Salome Thirot0f641972021-05-14 11:19:55 +0100210 kinds: vec![TlvKinds::SHA256, TlvKinds::ENCKW],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300211 ..Default::default()
Fabio Utzig1e48b912018-09-18 09:04:18 -0300212 }
213 }
214
Fabio Utzig251ef1d2018-12-18 17:20:19 -0200215 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100216 pub fn new_rsa_kw(aes_key_size: u32) -> TlvGen {
217 let flag = if aes_key_size == 256 {
218 TlvFlags::ENCRYPTED_AES256 as u32
219 } else {
220 TlvFlags::ENCRYPTED_AES128 as u32
221 };
Fabio Utzig251ef1d2018-12-18 17:20:19 -0200222 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100223 flags: flag,
Salome Thirot0f641972021-05-14 11:19:55 +0100224 kinds: vec![TlvKinds::SHA256, TlvKinds::RSA2048, TlvKinds::ENCKW],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300225 ..Default::default()
Fabio Utzig251ef1d2018-12-18 17:20:19 -0200226 }
227 }
228
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200229 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100230 pub fn new_ecdsa_kw(aes_key_size: u32) -> TlvGen {
231 let flag = if aes_key_size == 256 {
232 TlvFlags::ENCRYPTED_AES256 as u32
233 } else {
234 TlvFlags::ENCRYPTED_AES128 as u32
235 };
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200236 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100237 flags: flag,
Salome Thirot0f641972021-05-14 11:19:55 +0100238 kinds: vec![TlvKinds::SHA256, TlvKinds::ECDSA256, TlvKinds::ENCKW],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300239 ..Default::default()
Fabio Utzig90f449e2019-10-24 07:43:53 -0300240 }
241 }
242
243 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100244 pub fn new_ecies_p256(aes_key_size: u32) -> TlvGen {
245 let flag = if aes_key_size == 256 {
246 TlvFlags::ENCRYPTED_AES256 as u32
247 } else {
248 TlvFlags::ENCRYPTED_AES128 as u32
249 };
Fabio Utzig66b4caa2020-01-04 20:19:28 -0300250 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100251 flags: flag,
Fabio Utzig66b4caa2020-01-04 20:19:28 -0300252 kinds: vec![TlvKinds::SHA256, TlvKinds::ENCEC256],
Fabio Utzig66b4caa2020-01-04 20:19:28 -0300253 ..Default::default()
254 }
255 }
256
257 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100258 pub fn new_ecdsa_ecies_p256(aes_key_size: u32) -> TlvGen {
259 let flag = if aes_key_size == 256 {
260 TlvFlags::ENCRYPTED_AES256 as u32
261 } else {
262 TlvFlags::ENCRYPTED_AES128 as u32
263 };
Fabio Utzig90f449e2019-10-24 07:43:53 -0300264 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100265 flags: flag,
Fabio Utzig90f449e2019-10-24 07:43:53 -0300266 kinds: vec![TlvKinds::SHA256, TlvKinds::ECDSA256, TlvKinds::ENCEC256],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300267 ..Default::default()
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200268 }
269 }
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300270
271 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100272 pub fn new_ecies_x25519(aes_key_size: u32) -> TlvGen {
273 let flag = if aes_key_size == 256 {
274 TlvFlags::ENCRYPTED_AES256 as u32
275 } else {
276 TlvFlags::ENCRYPTED_AES128 as u32
277 };
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300278 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100279 flags: flag,
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300280 kinds: vec![TlvKinds::SHA256, TlvKinds::ENCX25519],
281 ..Default::default()
282 }
283 }
284
285 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100286 pub fn new_ed25519_ecies_x25519(aes_key_size: u32) -> TlvGen {
287 let flag = if aes_key_size == 256 {
288 TlvFlags::ENCRYPTED_AES256 as u32
289 } else {
290 TlvFlags::ENCRYPTED_AES128 as u32
291 };
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300292 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100293 flags: flag,
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300294 kinds: vec![TlvKinds::SHA256, TlvKinds::ED25519, TlvKinds::ENCX25519],
295 ..Default::default()
296 }
297 }
David Brown43643dd2019-01-11 15:43:28 -0700298}
299
300impl ManifestGen for TlvGen {
David Brownac46e262019-01-11 15:46:18 -0700301 fn get_magic(&self) -> u32 {
302 0x96f3b83d
303 }
304
David Brown43643dd2019-01-11 15:43:28 -0700305 /// Retrieve the header flags for this configuration. This can be called at any time.
306 fn get_flags(&self) -> u32 {
David Brown8a4e23b2021-06-11 10:29:01 -0600307 // For the RamLoad case, add in the flag for this feature.
308 if Caps::RamLoad.present() {
309 self.flags | (TlvFlags::RAM_LOAD as u32)
310 } else {
311 self.flags
312 }
David Brown43643dd2019-01-11 15:43:28 -0700313 }
David Brown187dd882017-07-11 11:15:23 -0600314
315 /// Add bytes to the covered hash.
David Brown43643dd2019-01-11 15:43:28 -0700316 fn add_bytes(&mut self, bytes: &[u8]) {
David Brown4243ab02017-07-11 12:24:23 -0600317 self.payload.extend_from_slice(bytes);
David Brown187dd882017-07-11 11:15:23 -0600318 }
319
David Brown7a81c4b2019-07-29 15:20:21 -0600320 fn protect_size(&self) -> u16 {
David Brown2b73ed92020-01-08 17:01:22 -0700321 if self.dependencies.is_empty() {
David Brown7a81c4b2019-07-29 15:20:21 -0600322 0
323 } else {
David Brown2b73ed92020-01-08 17:01:22 -0700324 // Include the header and space for each dependency.
325 4 + (self.dependencies.len() as u16) * (4 + 4 + 8)
David Brown7a81c4b2019-07-29 15:20:21 -0600326 }
327 }
328
329 fn add_dependency(&mut self, id: u8, version: &ImageVersion) {
David Brown7a81c4b2019-07-29 15:20:21 -0600330 self.dependencies.push(Dependency {
David Brown4dfb33c2021-03-10 05:15:45 -0700331 id,
David Brown7a81c4b2019-07-29 15:20:21 -0600332 version: version.clone(),
333 });
334 }
335
David Browne90b13f2019-12-06 15:04:00 -0700336 fn corrupt_sig(&mut self) {
337 self.gen_corrupted = true;
338 }
339
David Brownef4f0742021-10-22 17:09:50 -0600340 fn estimate_size(&self) -> usize {
341 // Begin the estimate with the 4 byte header.
342 let mut estimate = 4;
343 // A very poor estimate.
344
345 // Estimate the size of the image hash.
346 if self.kinds.contains(&TlvKinds::SHA256) {
347 estimate += 4 + 32;
348 }
349
350 // Add an estimate in for each of the signature algorithms.
351 if self.kinds.contains(&TlvKinds::RSA2048) {
352 estimate += 4 + 32; // keyhash
353 estimate += 4 + 256; // RSA2048
354 }
355 if self.kinds.contains(&TlvKinds::RSA3072) {
356 estimate += 4 + 32; // keyhash
357 estimate += 4 + 384; // RSA3072
358 }
359 if self.kinds.contains(&TlvKinds::ECDSA256) {
360 estimate += 4 + 32; // keyhash
361
362 // ECDSA signatures are encoded as ASN.1 with the x and y values stored as signed
363 // integers. As such, the size can vary by 2 bytes, if the 256-bit value has the high
364 // bit, it takes an extra 0 byte to avoid it being seen as a negative number.
365 estimate += 4 + 72; // ECDSA256 (varies)
366 }
367 if self.kinds.contains(&TlvKinds::ED25519) {
368 estimate += 4 + 32; // keyhash
369 estimate += 4 + 64; // ED25519 signature.
370 }
371
372 // Estimate encryption.
373 let flag = TlvFlags::ENCRYPTED_AES256 as u32;
374 let aes256 = (self.get_flags() & flag) == flag;
375
376 if self.kinds.contains(&TlvKinds::ENCRSA2048) {
377 estimate += 4 + 256;
378 }
379 if self.kinds.contains(&TlvKinds::ENCKW) {
380 estimate += 4 + if aes256 { 40 } else { 24 };
381 }
382 if self.kinds.contains(&TlvKinds::ENCEC256) {
383 estimate += 4 + if aes256 { 129 } else { 113 };
384 }
385 if self.kinds.contains(&TlvKinds::ENCX25519) {
386 estimate += 4 + if aes256 { 96 } else { 80 };
387 }
388
389 // Gather the size of the dependency information.
390 if self.protect_size() > 0 {
391 estimate += 4 + (16 * self.dependencies.len());
392 }
393
394 estimate
395 }
396
David Brown187dd882017-07-11 11:15:23 -0600397 /// Compute the TLV given the specified block of data.
David Brown43643dd2019-01-11 15:43:28 -0700398 fn make_tlv(self: Box<Self>) -> Vec<u8> {
David Brownef4f0742021-10-22 17:09:50 -0600399 let size_estimate = self.estimate_size();
400
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300401 let mut protected_tlv: Vec<u8> = vec![];
David Brown187dd882017-07-11 11:15:23 -0600402
David Brown2b73ed92020-01-08 17:01:22 -0700403 if self.protect_size() > 0 {
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300404 protected_tlv.push(0x08);
405 protected_tlv.push(0x69);
David Brown2b73ed92020-01-08 17:01:22 -0700406 let size = self.protect_size();
407 protected_tlv.write_u16::<LittleEndian>(size).unwrap();
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300408 for dep in &self.dependencies {
David Brown69721182019-12-04 14:50:52 -0700409 protected_tlv.write_u16::<LittleEndian>(TlvKinds::DEPENDENCY as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700410 protected_tlv.write_u16::<LittleEndian>(12).unwrap();
David Brownf5b33d82017-09-01 10:58:27 -0600411
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300412 // The dependency.
413 protected_tlv.push(dep.id);
David Brownf66b2052021-03-10 05:26:36 -0700414 protected_tlv.push(0);
415 protected_tlv.write_u16::<LittleEndian>(0).unwrap();
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300416 protected_tlv.push(dep.version.major);
417 protected_tlv.push(dep.version.minor);
418 protected_tlv.write_u16::<LittleEndian>(dep.version.revision).unwrap();
419 protected_tlv.write_u32::<LittleEndian>(dep.version.build_num).unwrap();
David Brown7a81c4b2019-07-29 15:20:21 -0600420 }
David Brown2b73ed92020-01-08 17:01:22 -0700421
422 assert_eq!(size, protected_tlv.len() as u16, "protected TLV length incorrect");
David Brown7a81c4b2019-07-29 15:20:21 -0600423 }
424
425 // Ring does the signature itself, which means that it must be
426 // given a full, contiguous payload. Although this does help from
427 // a correct usage perspective, it is fairly stupid from an
428 // efficiency view. If this is shown to be a performance issue
429 // with the tests, the protected data could be appended to the
430 // payload, and then removed after the signature is done. For now,
431 // just make a signed payload.
432 let mut sig_payload = self.payload.clone();
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300433 sig_payload.extend_from_slice(&protected_tlv);
434
435 let mut result: Vec<u8> = vec![];
436
437 // add back signed payload
438 result.extend_from_slice(&protected_tlv);
439
440 // add non-protected payload
David Brown3dc86c92020-01-08 17:22:55 -0700441 let npro_pos = result.len();
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300442 result.push(0x07);
443 result.push(0x69);
David Brown3dc86c92020-01-08 17:22:55 -0700444 // Placeholder for the size.
445 result.write_u16::<LittleEndian>(0).unwrap();
David Brown7a81c4b2019-07-29 15:20:21 -0600446
David Brown187dd882017-07-11 11:15:23 -0600447 if self.kinds.contains(&TlvKinds::SHA256) {
David Browne90b13f2019-12-06 15:04:00 -0700448 // If a signature is not requested, corrupt the hash we are
449 // generating. But, if there is a signature, output the
450 // correct hash. We want the hash test to pass so that the
451 // signature verification can be validated.
452 let mut corrupt_hash = self.gen_corrupted;
453 for k in &[TlvKinds::RSA2048, TlvKinds::RSA3072,
454 TlvKinds::ECDSA224, TlvKinds::ECDSA256,
455 TlvKinds::ED25519]
456 {
457 if self.kinds.contains(k) {
458 corrupt_hash = false;
459 break;
460 }
461 }
462
463 if corrupt_hash {
464 sig_payload[0] ^= 1;
465 }
466
David Brown7a81c4b2019-07-29 15:20:21 -0600467 let hash = digest::digest(&digest::SHA256, &sig_payload);
David Brown8054ce22017-07-11 12:12:09 -0600468 let hash = hash.as_ref();
David Brown187dd882017-07-11 11:15:23 -0600469
David Brown8054ce22017-07-11 12:12:09 -0600470 assert!(hash.len() == 32);
David Brown69721182019-12-04 14:50:52 -0700471 result.write_u16::<LittleEndian>(TlvKinds::SHA256 as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700472 result.write_u16::<LittleEndian>(32).unwrap();
David Brown8054ce22017-07-11 12:12:09 -0600473 result.extend_from_slice(hash);
David Browne90b13f2019-12-06 15:04:00 -0700474
475 // Undo the corruption.
476 if corrupt_hash {
477 sig_payload[0] ^= 1;
478 }
479
480 }
481
482 if self.gen_corrupted {
483 // Corrupt what is signed by modifying the input to the
484 // signature code.
485 sig_payload[0] ^= 1;
David Brown187dd882017-07-11 11:15:23 -0600486 }
487
Fabio Utzig39297432019-05-08 18:51:10 -0300488 if self.kinds.contains(&TlvKinds::RSA2048) ||
489 self.kinds.contains(&TlvKinds::RSA3072) {
490
491 let is_rsa2048 = self.kinds.contains(&TlvKinds::RSA2048);
492
David Brown43cda332017-09-01 09:53:23 -0600493 // Output the hash of the public key.
Fabio Utzig39297432019-05-08 18:51:10 -0300494 let hash = if is_rsa2048 {
495 digest::digest(&digest::SHA256, RSA_PUB_KEY)
496 } else {
497 digest::digest(&digest::SHA256, RSA3072_PUB_KEY)
498 };
David Brown43cda332017-09-01 09:53:23 -0600499 let hash = hash.as_ref();
500
501 assert!(hash.len() == 32);
David Brown69721182019-12-04 14:50:52 -0700502 result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700503 result.write_u16::<LittleEndian>(32).unwrap();
David Brown43cda332017-09-01 09:53:23 -0600504 result.extend_from_slice(hash);
505
David Brown7e701d82017-07-11 13:24:25 -0600506 // For now assume PSS.
Fabio Utzig39297432019-05-08 18:51:10 -0300507 let key_bytes = if is_rsa2048 {
508 pem::parse(include_bytes!("../../root-rsa-2048.pem").as_ref()).unwrap()
509 } else {
510 pem::parse(include_bytes!("../../root-rsa-3072.pem").as_ref()).unwrap()
511 };
David Brown7e701d82017-07-11 13:24:25 -0600512 assert_eq!(key_bytes.tag, "RSA PRIVATE KEY");
Fabio Utzig90f449e2019-10-24 07:43:53 -0300513 let key_pair = RsaKeyPair::from_der(&key_bytes.contents).unwrap();
David Brown7e701d82017-07-11 13:24:25 -0600514 let rng = rand::SystemRandom::new();
Fabio Utzig05ab0142018-07-10 09:15:28 -0300515 let mut signature = vec![0; key_pair.public_modulus_len()];
Fabio Utzig39297432019-05-08 18:51:10 -0300516 if is_rsa2048 {
517 assert_eq!(signature.len(), 256);
518 } else {
519 assert_eq!(signature.len(), 384);
520 }
David Brown7a81c4b2019-07-29 15:20:21 -0600521 key_pair.sign(&RSA_PSS_SHA256, &rng, &sig_payload, &mut signature).unwrap();
David Brown7e701d82017-07-11 13:24:25 -0600522
Fabio Utzig39297432019-05-08 18:51:10 -0300523 if is_rsa2048 {
David Brown69721182019-12-04 14:50:52 -0700524 result.write_u16::<LittleEndian>(TlvKinds::RSA2048 as u16).unwrap();
Fabio Utzig39297432019-05-08 18:51:10 -0300525 } else {
David Brown69721182019-12-04 14:50:52 -0700526 result.write_u16::<LittleEndian>(TlvKinds::RSA3072 as u16).unwrap();
Fabio Utzig39297432019-05-08 18:51:10 -0300527 }
David Brown91d68632019-07-29 14:32:13 -0600528 result.write_u16::<LittleEndian>(signature.len() as u16).unwrap();
David Brown7e701d82017-07-11 13:24:25 -0600529 result.extend_from_slice(&signature);
530 }
531
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200532 if self.kinds.contains(&TlvKinds::ECDSA256) {
533 let keyhash = digest::digest(&digest::SHA256, ECDSA256_PUB_KEY);
534 let keyhash = keyhash.as_ref();
535
536 assert!(keyhash.len() == 32);
David Brown69721182019-12-04 14:50:52 -0700537 result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700538 result.write_u16::<LittleEndian>(32).unwrap();
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200539 result.extend_from_slice(keyhash);
540
Fabio Utzig05ab0142018-07-10 09:15:28 -0300541 let key_bytes = pem::parse(include_bytes!("../../root-ec-p256-pkcs8.pem").as_ref()).unwrap();
542 assert_eq!(key_bytes.tag, "PRIVATE KEY");
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200543
Fabio Utzig05ab0142018-07-10 09:15:28 -0300544 let key_pair = EcdsaKeyPair::from_pkcs8(&ECDSA_P256_SHA256_ASN1_SIGNING,
Fabio Utzig90f449e2019-10-24 07:43:53 -0300545 &key_bytes.contents).unwrap();
Fabio Utzig05ab0142018-07-10 09:15:28 -0300546 let rng = rand::SystemRandom::new();
Fabio Utzig90f449e2019-10-24 07:43:53 -0300547 let signature = key_pair.sign(&rng, &sig_payload).unwrap();
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200548
David Brown69721182019-12-04 14:50:52 -0700549 result.write_u16::<LittleEndian>(TlvKinds::ECDSA256 as u16).unwrap();
Fabio Utzig05ab0142018-07-10 09:15:28 -0300550
David Browna4c58642019-12-12 17:28:33 -0700551 let signature = signature.as_ref().to_vec();
Fabio Utzig05ab0142018-07-10 09:15:28 -0300552
David Brown91d68632019-07-29 14:32:13 -0600553 result.write_u16::<LittleEndian>(signature.len() as u16).unwrap();
Fabio Utzig05ab0142018-07-10 09:15:28 -0300554 result.extend_from_slice(signature.as_ref());
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200555 }
556
Fabio Utzig97710282019-05-24 17:44:49 -0300557 if self.kinds.contains(&TlvKinds::ED25519) {
558 let keyhash = digest::digest(&digest::SHA256, ED25519_PUB_KEY);
559 let keyhash = keyhash.as_ref();
560
561 assert!(keyhash.len() == 32);
David Brown69721182019-12-04 14:50:52 -0700562 result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700563 result.write_u16::<LittleEndian>(32).unwrap();
Fabio Utzig97710282019-05-24 17:44:49 -0300564 result.extend_from_slice(keyhash);
565
David Brown7a81c4b2019-07-29 15:20:21 -0600566 let hash = digest::digest(&digest::SHA256, &sig_payload);
Fabio Utzig97710282019-05-24 17:44:49 -0300567 let hash = hash.as_ref();
568 assert!(hash.len() == 32);
569
570 let key_bytes = pem::parse(include_bytes!("../../root-ed25519.pem").as_ref()).unwrap();
571 assert_eq!(key_bytes.tag, "PRIVATE KEY");
572
Fabio Utzig90f449e2019-10-24 07:43:53 -0300573 let key_pair = Ed25519KeyPair::from_seed_and_public_key(
574 &key_bytes.contents[16..48], &ED25519_PUB_KEY[12..44]).unwrap();
Fabio Utzig97710282019-05-24 17:44:49 -0300575 let signature = key_pair.sign(&hash);
576
David Brown69721182019-12-04 14:50:52 -0700577 result.write_u16::<LittleEndian>(TlvKinds::ED25519 as u16).unwrap();
Fabio Utzig97710282019-05-24 17:44:49 -0300578
579 let signature = signature.as_ref().to_vec();
David Brown91d68632019-07-29 14:32:13 -0600580 result.write_u16::<LittleEndian>(signature.len() as u16).unwrap();
Fabio Utzig97710282019-05-24 17:44:49 -0300581 result.extend_from_slice(signature.as_ref());
582 }
583
Fabio Utzig1e48b912018-09-18 09:04:18 -0300584 if self.kinds.contains(&TlvKinds::ENCRSA2048) {
585 let key_bytes = pem::parse(include_bytes!("../../enc-rsa2048-pub.pem")
586 .as_ref()).unwrap();
587 assert_eq!(key_bytes.tag, "PUBLIC KEY");
588
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300589 let cipherkey = self.get_enc_key();
590 let cipherkey = cipherkey.as_slice();
591 let encbuf = match c::rsa_oaep_encrypt(&key_bytes.contents, cipherkey) {
Fabio Utzig1e48b912018-09-18 09:04:18 -0300592 Ok(v) => v,
593 Err(_) => panic!("Failed to encrypt secret key"),
594 };
595
596 assert!(encbuf.len() == 256);
David Brown69721182019-12-04 14:50:52 -0700597 result.write_u16::<LittleEndian>(TlvKinds::ENCRSA2048 as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700598 result.write_u16::<LittleEndian>(256).unwrap();
Fabio Utzig1e48b912018-09-18 09:04:18 -0300599 result.extend_from_slice(&encbuf);
600 }
601
Salome Thirot0f641972021-05-14 11:19:55 +0100602 if self.kinds.contains(&TlvKinds::ENCKW) {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100603 let flag = TlvFlags::ENCRYPTED_AES256 as u32;
604 let aes256 = (self.get_flags() & flag) == flag;
605 let key_bytes = if aes256 {
606 base64::decode(
607 include_str!("../../enc-aes256kw.b64").trim()).unwrap()
608 } else {
609 base64::decode(
610 include_str!("../../enc-aes128kw.b64").trim()).unwrap()
611 };
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300612 let cipherkey = self.get_enc_key();
613 let cipherkey = cipherkey.as_slice();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100614 let keylen = if aes256 { 32 } else { 16 };
615 let encbuf = match c::kw_encrypt(&key_bytes, cipherkey, keylen) {
Fabio Utzig1e48b912018-09-18 09:04:18 -0300616 Ok(v) => v,
617 Err(_) => panic!("Failed to encrypt secret key"),
618 };
619
Salome Thirot6fdbf552021-05-14 16:46:14 +0100620 let size = if aes256 { 40 } else { 24 };
621 assert!(encbuf.len() == size);
Salome Thirot0f641972021-05-14 11:19:55 +0100622 result.write_u16::<LittleEndian>(TlvKinds::ENCKW as u16).unwrap();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100623 result.write_u16::<LittleEndian>(size as u16).unwrap();
Fabio Utzig1e48b912018-09-18 09:04:18 -0300624 result.extend_from_slice(&encbuf);
625 }
626
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300627 if self.kinds.contains(&TlvKinds::ENCEC256) || self.kinds.contains(&TlvKinds::ENCX25519) {
628 let key_bytes = if self.kinds.contains(&TlvKinds::ENCEC256) {
629 pem::parse(include_bytes!("../../enc-ec256-pub.pem").as_ref()).unwrap()
630 } else {
631 pem::parse(include_bytes!("../../enc-x25519-pub.pem").as_ref()).unwrap()
632 };
Fabio Utzig90f449e2019-10-24 07:43:53 -0300633 assert_eq!(key_bytes.tag, "PUBLIC KEY");
Fabio Utzig90f449e2019-10-24 07:43:53 -0300634 let rng = rand::SystemRandom::new();
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300635 let alg = if self.kinds.contains(&TlvKinds::ENCEC256) {
636 &agreement::ECDH_P256
637 } else {
638 &agreement::X25519
639 };
640 let pk = match agreement::EphemeralPrivateKey::generate(alg, &rng) {
Fabio Utzig90f449e2019-10-24 07:43:53 -0300641 Ok(v) => v,
642 Err(_) => panic!("Failed to generate ephemeral keypair"),
643 };
644
645 let pubk = match pk.compute_public_key() {
646 Ok(pubk) => pubk,
647 Err(_) => panic!("Failed computing ephemeral public key"),
648 };
649
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300650 let peer_pubk = if self.kinds.contains(&TlvKinds::ENCEC256) {
651 agreement::UnparsedPublicKey::new(&agreement::ECDH_P256, &key_bytes.contents[26..])
652 } else {
653 agreement::UnparsedPublicKey::new(&agreement::X25519, &key_bytes.contents[12..])
654 };
Fabio Utzig90f449e2019-10-24 07:43:53 -0300655
656 #[derive(Debug, PartialEq)]
657 struct OkmLen<T: core::fmt::Debug + PartialEq>(T);
658
659 impl hkdf::KeyType for OkmLen<usize> {
660 fn len(&self) -> usize {
661 self.0
662 }
663 }
664
Salome Thirot6fdbf552021-05-14 16:46:14 +0100665 let flag = TlvFlags::ENCRYPTED_AES256 as u32;
666 let aes256 = (self.get_flags() & flag) == flag;
667
Fabio Utzig90f449e2019-10-24 07:43:53 -0300668 let derived_key = match agreement::agree_ephemeral(
669 pk, &peer_pubk, ring::error::Unspecified, |shared| {
670 let salt = hkdf::Salt::new(hkdf::HKDF_SHA256, &[]);
671 let prk = salt.extract(&shared);
Salome Thirot6fdbf552021-05-14 16:46:14 +0100672 let okm_len = if aes256 { 64 } else { 48 };
673 let okm = match prk.expand(&[b"MCUBoot_ECIES_v1"], OkmLen(okm_len)) {
Fabio Utzig90f449e2019-10-24 07:43:53 -0300674 Ok(okm) => okm,
675 Err(_) => panic!("Failed building HKDF OKM"),
676 };
Salome Thirot6fdbf552021-05-14 16:46:14 +0100677 let mut buf = if aes256 { vec![0u8; 64] } else { vec![0u8; 48] };
Fabio Utzig90f449e2019-10-24 07:43:53 -0300678 match okm.fill(&mut buf) {
679 Ok(_) => Ok(buf),
680 Err(_) => panic!("Failed generating HKDF output"),
681 }
682 },
683 ) {
684 Ok(v) => v,
685 Err(_) => panic!("Failed building HKDF"),
686 };
687
Fabio Utzig90f449e2019-10-24 07:43:53 -0300688 let nonce = GenericArray::from_slice(&[0; 16]);
Fabio Utzig90f449e2019-10-24 07:43:53 -0300689 let mut cipherkey = self.get_enc_key();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100690 if aes256 {
691 let key: &GenericArray<u8, U32> = GenericArray::from_slice(&derived_key[..32]);
David Brown9c6322f2021-08-19 13:03:39 -0600692 let block = Aes256::new(&key);
693 let mut cipher = Aes256Ctr::from_block_cipher(block, &nonce);
Salome Thirot6fdbf552021-05-14 16:46:14 +0100694 cipher.apply_keystream(&mut cipherkey);
695 } else {
696 let key: &GenericArray<u8, U16> = GenericArray::from_slice(&derived_key[..16]);
David Brown9c6322f2021-08-19 13:03:39 -0600697 let block = Aes128::new(&key);
698 let mut cipher = Aes128Ctr::from_block_cipher(block, &nonce);
Salome Thirot6fdbf552021-05-14 16:46:14 +0100699 cipher.apply_keystream(&mut cipherkey);
700 }
Fabio Utzig90f449e2019-10-24 07:43:53 -0300701
Salome Thirot6fdbf552021-05-14 16:46:14 +0100702 let size = if aes256 { 32 } else { 16 };
703 let key = hmac::Key::new(hmac::HMAC_SHA256, &derived_key[size..]);
Fabio Utzig90f449e2019-10-24 07:43:53 -0300704 let tag = hmac::sign(&key, &cipherkey);
705
706 let mut buf = vec![];
707 buf.append(&mut pubk.as_ref().to_vec());
708 buf.append(&mut tag.as_ref().to_vec());
709 buf.append(&mut cipherkey);
710
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300711 if self.kinds.contains(&TlvKinds::ENCEC256) {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100712 let size = if aes256 { 129 } else { 113 };
713 assert!(buf.len() == size);
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300714 result.write_u16::<LittleEndian>(TlvKinds::ENCEC256 as u16).unwrap();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100715 result.write_u16::<LittleEndian>(size as u16).unwrap();
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300716 } else {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100717 let size = if aes256 { 96 } else { 80 };
718 assert!(buf.len() == size);
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300719 result.write_u16::<LittleEndian>(TlvKinds::ENCX25519 as u16).unwrap();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100720 result.write_u16::<LittleEndian>(size as u16).unwrap();
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300721 }
Fabio Utzig90f449e2019-10-24 07:43:53 -0300722 result.extend_from_slice(&buf);
723 }
724
David Brown3dc86c92020-01-08 17:22:55 -0700725 // Patch the size back into the TLV header.
726 let size = (result.len() - npro_pos) as u16;
727 let mut size_buf = &mut result[npro_pos + 2 .. npro_pos + 4];
728 size_buf.write_u16::<LittleEndian>(size).unwrap();
729
David Brownef4f0742021-10-22 17:09:50 -0600730 // The size estimate must not be less than the given size, and no more than 3 bytes larger.
731 if size_estimate < result.len() || size_estimate > result.len() + 3 {
732 panic!("Incorrect size estimate: {} (actual {})", size_estimate, result.len());
733 }
734 if size_estimate != result.len() {
735 log::warn!("Size off: {} actual {}", size_estimate, result.len());
736 }
737
David Brown187dd882017-07-11 11:15:23 -0600738 result
739 }
Fabio Utzig90f449e2019-10-24 07:43:53 -0300740
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300741 fn generate_enc_key(&mut self) {
742 let rng = rand::SystemRandom::new();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100743 let flag = TlvFlags::ENCRYPTED_AES256 as u32;
744 let aes256 = (self.get_flags() & flag) == flag;
745 let mut buf = if aes256 {
746 vec![0u8; 32]
747 } else {
748 vec![0u8; 16]
749 };
David Brown26edaf32021-03-10 05:27:38 -0700750 if rng.fill(&mut buf).is_err() {
751 panic!("Error generating encrypted key");
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300752 }
753 info!("New encryption key: {:02x?}", buf);
754 self.enc_key = buf;
Fabio Utzig90f449e2019-10-24 07:43:53 -0300755 }
756
757 fn get_enc_key(&self) -> Vec<u8> {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100758 if self.enc_key.len() != 32 && self.enc_key.len() != 16 {
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300759 panic!("No random key was generated");
760 }
761 self.enc_key.clone()
Fabio Utzig90f449e2019-10-24 07:43:53 -0300762 }
David Brown187dd882017-07-11 11:15:23 -0600763}
David Brown43cda332017-09-01 09:53:23 -0600764
765include!("rsa_pub_key-rs.txt");
Fabio Utzig39297432019-05-08 18:51:10 -0300766include!("rsa3072_pub_key-rs.txt");
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200767include!("ecdsa_pub_key-rs.txt");
Fabio Utzig97710282019-05-24 17:44:49 -0300768include!("ed25519_pub_key-rs.txt");