blob: cc5165af25a06920ae8c0a810d593f255f80ece9 [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
Roland Mikhel75c7c312023-02-23 15:39:14 +01003// Copyright (c) 2021-2023 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,
Fabio Utzig39297432019-05-08 18:51:10 -030054 RSA3072 = 0x23,
Fabio Utzig97710282019-05-24 17:44:49 -030055 ED25519 = 0x24,
Roland Mikhel6205c102023-02-06 13:32:02 +010056 ECDSASIG = 0x25,
Fabio Utzig1e48b912018-09-18 09:04:18 -030057 ENCRSA2048 = 0x30,
Salome Thirot0f641972021-05-14 11:19:55 +010058 ENCKW = 0x31,
Fabio Utzig90f449e2019-10-24 07:43:53 -030059 ENCEC256 = 0x32,
Fabio Utzig3fa72ca2020-04-02 11:20:37 -030060 ENCX25519 = 0x33,
David Brown7a81c4b2019-07-29 15:20:21 -060061 DEPENDENCY = 0x40,
Fabio Utzig1e48b912018-09-18 09:04:18 -030062}
63
64#[allow(dead_code, non_camel_case_types)]
65pub enum TlvFlags {
66 PIC = 0x01,
67 NON_BOOTABLE = 0x02,
Salome Thirot6fdbf552021-05-14 16:46:14 +010068 ENCRYPTED_AES128 = 0x04,
Salome Thirot6fdbf552021-05-14 16:46:14 +010069 ENCRYPTED_AES256 = 0x08,
David Brownd8713a52021-10-22 16:27:23 -060070 RAM_LOAD = 0x20,
David Brown187dd882017-07-11 11:15:23 -060071}
72
David Brown43643dd2019-01-11 15:43:28 -070073/// A generator for manifests. The format of the manifest can be either a
74/// traditional "TLV" or a SUIT-style manifest.
75pub trait ManifestGen {
David Brownac46e262019-01-11 15:46:18 -070076 /// Retrieve the header magic value for this manifest type.
77 fn get_magic(&self) -> u32;
78
David Brown43643dd2019-01-11 15:43:28 -070079 /// Retrieve the flags value for this particular manifest type.
80 fn get_flags(&self) -> u32;
81
David Brown7a81c4b2019-07-29 15:20:21 -060082 /// Retrieve the number of bytes of this manifest that is "protected".
83 /// This field is stored in the outside image header instead of the
84 /// manifest header.
85 fn protect_size(&self) -> u16;
86
87 /// Add a dependency on another image.
88 fn add_dependency(&mut self, id: u8, version: &ImageVersion);
89
David Brown43643dd2019-01-11 15:43:28 -070090 /// Add a sequence of bytes to the payload that the manifest is
91 /// protecting.
92 fn add_bytes(&mut self, bytes: &[u8]);
93
David Browne90b13f2019-12-06 15:04:00 -070094 /// Set an internal flag indicating that the next `make_tlv` should
95 /// corrupt the signature.
96 fn corrupt_sig(&mut self);
97
David Brownef4f0742021-10-22 17:09:50 -060098 /// Estimate the size of the TLV. This can be called before the payload is added (but after
99 /// other information is added). Some of the signature algorithms can generate variable sized
100 /// data, and therefore, this can slightly overestimate the size.
101 fn estimate_size(&self) -> usize;
102
David Brown43643dd2019-01-11 15:43:28 -0700103 /// Construct the manifest for this payload.
104 fn make_tlv(self: Box<Self>) -> Vec<u8>;
Fabio Utzig90f449e2019-10-24 07:43:53 -0300105
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300106 /// Generate a new encryption random key
107 fn generate_enc_key(&mut self);
Fabio Utzig90f449e2019-10-24 07:43:53 -0300108
109 /// Return the current encryption key
110 fn get_enc_key(&self) -> Vec<u8>;
David Brown43643dd2019-01-11 15:43:28 -0700111}
112
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300113#[derive(Debug, Default)]
David Brown187dd882017-07-11 11:15:23 -0600114pub struct TlvGen {
David Brown43cda332017-09-01 09:53:23 -0600115 flags: u32,
David Brown187dd882017-07-11 11:15:23 -0600116 kinds: Vec<TlvKinds>,
David Brown4243ab02017-07-11 12:24:23 -0600117 payload: Vec<u8>,
David Brown7a81c4b2019-07-29 15:20:21 -0600118 dependencies: Vec<Dependency>,
Fabio Utzig90f449e2019-10-24 07:43:53 -0300119 enc_key: Vec<u8>,
David Browne90b13f2019-12-06 15:04:00 -0700120 /// Should this signature be corrupted.
121 gen_corrupted: bool,
David Brown7a81c4b2019-07-29 15:20:21 -0600122}
123
David Brownc3898d62019-08-05 14:20:02 -0600124#[derive(Debug)]
David Brown7a81c4b2019-07-29 15:20:21 -0600125struct Dependency {
126 id: u8,
127 version: ImageVersion,
David Brown187dd882017-07-11 11:15:23 -0600128}
129
130impl TlvGen {
131 /// Construct a new tlv generator that will only contain a hash of the data.
David Brown7e701d82017-07-11 13:24:25 -0600132 #[allow(dead_code)]
David Brown187dd882017-07-11 11:15:23 -0600133 pub fn new_hash_only() -> TlvGen {
134 TlvGen {
David Brown187dd882017-07-11 11:15:23 -0600135 kinds: vec![TlvKinds::SHA256],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300136 ..Default::default()
David Brown187dd882017-07-11 11:15:23 -0600137 }
138 }
139
David Brown7e701d82017-07-11 13:24:25 -0600140 #[allow(dead_code)]
141 pub fn new_rsa_pss() -> TlvGen {
142 TlvGen {
Fabio Utzig754438d2018-12-14 06:39:58 -0200143 kinds: vec![TlvKinds::SHA256, TlvKinds::RSA2048],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300144 ..Default::default()
David Brown7e701d82017-07-11 13:24:25 -0600145 }
146 }
147
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200148 #[allow(dead_code)]
Fabio Utzig39297432019-05-08 18:51:10 -0300149 pub fn new_rsa3072_pss() -> TlvGen {
150 TlvGen {
Fabio Utzig39297432019-05-08 18:51:10 -0300151 kinds: vec![TlvKinds::SHA256, TlvKinds::RSA3072],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300152 ..Default::default()
Fabio Utzig39297432019-05-08 18:51:10 -0300153 }
154 }
155
156 #[allow(dead_code)]
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200157 pub fn new_ecdsa() -> TlvGen {
158 TlvGen {
Roland Mikhel30978512023-02-08 14:06:58 +0100159 kinds: vec![TlvKinds::SHA256, TlvKinds::ECDSASIG],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300160 ..Default::default()
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200161 }
162 }
163
Fabio Utzig1e48b912018-09-18 09:04:18 -0300164 #[allow(dead_code)]
Fabio Utzig97710282019-05-24 17:44:49 -0300165 pub fn new_ed25519() -> TlvGen {
166 TlvGen {
Fabio Utzig97710282019-05-24 17:44:49 -0300167 kinds: vec![TlvKinds::SHA256, TlvKinds::ED25519],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300168 ..Default::default()
Fabio Utzig97710282019-05-24 17:44:49 -0300169 }
170 }
171
172 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100173 pub fn new_enc_rsa(aes_key_size: u32) -> TlvGen {
174 let flag = if aes_key_size == 256 {
175 TlvFlags::ENCRYPTED_AES256 as u32
176 } else {
177 TlvFlags::ENCRYPTED_AES128 as u32
178 };
Fabio Utzig1e48b912018-09-18 09:04:18 -0300179 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100180 flags: flag,
Fabio Utzig1e48b912018-09-18 09:04:18 -0300181 kinds: vec![TlvKinds::SHA256, TlvKinds::ENCRSA2048],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300182 ..Default::default()
Fabio Utzig1e48b912018-09-18 09:04:18 -0300183 }
184 }
185
186 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100187 pub fn new_sig_enc_rsa(aes_key_size: u32) -> TlvGen {
188 let flag = if aes_key_size == 256 {
189 TlvFlags::ENCRYPTED_AES256 as u32
190 } else {
191 TlvFlags::ENCRYPTED_AES128 as u32
192 };
Fabio Utzig754438d2018-12-14 06:39:58 -0200193 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100194 flags: flag,
Fabio Utzig754438d2018-12-14 06:39:58 -0200195 kinds: vec![TlvKinds::SHA256, TlvKinds::RSA2048, TlvKinds::ENCRSA2048],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300196 ..Default::default()
Fabio Utzig754438d2018-12-14 06:39:58 -0200197 }
198 }
199
200 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100201 pub fn new_enc_kw(aes_key_size: u32) -> TlvGen {
202 let flag = if aes_key_size == 256 {
203 TlvFlags::ENCRYPTED_AES256 as u32
204 } else {
205 TlvFlags::ENCRYPTED_AES128 as u32
206 };
Fabio Utzig1e48b912018-09-18 09:04:18 -0300207 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100208 flags: flag,
Salome Thirot0f641972021-05-14 11:19:55 +0100209 kinds: vec![TlvKinds::SHA256, TlvKinds::ENCKW],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300210 ..Default::default()
Fabio Utzig1e48b912018-09-18 09:04:18 -0300211 }
212 }
213
Fabio Utzig251ef1d2018-12-18 17:20:19 -0200214 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100215 pub fn new_rsa_kw(aes_key_size: u32) -> TlvGen {
216 let flag = if aes_key_size == 256 {
217 TlvFlags::ENCRYPTED_AES256 as u32
218 } else {
219 TlvFlags::ENCRYPTED_AES128 as u32
220 };
Fabio Utzig251ef1d2018-12-18 17:20:19 -0200221 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100222 flags: flag,
Salome Thirot0f641972021-05-14 11:19:55 +0100223 kinds: vec![TlvKinds::SHA256, TlvKinds::RSA2048, TlvKinds::ENCKW],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300224 ..Default::default()
Fabio Utzig251ef1d2018-12-18 17:20:19 -0200225 }
226 }
227
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200228 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100229 pub fn new_ecdsa_kw(aes_key_size: u32) -> TlvGen {
230 let flag = if aes_key_size == 256 {
231 TlvFlags::ENCRYPTED_AES256 as u32
232 } else {
233 TlvFlags::ENCRYPTED_AES128 as u32
234 };
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200235 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100236 flags: flag,
Roland Mikhel30978512023-02-08 14:06:58 +0100237 kinds: vec![TlvKinds::SHA256, TlvKinds::ECDSASIG, TlvKinds::ENCKW],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300238 ..Default::default()
Fabio Utzig90f449e2019-10-24 07:43:53 -0300239 }
240 }
241
242 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100243 pub fn new_ecies_p256(aes_key_size: u32) -> TlvGen {
244 let flag = if aes_key_size == 256 {
245 TlvFlags::ENCRYPTED_AES256 as u32
246 } else {
247 TlvFlags::ENCRYPTED_AES128 as u32
248 };
Fabio Utzig66b4caa2020-01-04 20:19:28 -0300249 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100250 flags: flag,
Fabio Utzig66b4caa2020-01-04 20:19:28 -0300251 kinds: vec![TlvKinds::SHA256, TlvKinds::ENCEC256],
Fabio Utzig66b4caa2020-01-04 20:19:28 -0300252 ..Default::default()
253 }
254 }
255
256 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100257 pub fn new_ecdsa_ecies_p256(aes_key_size: u32) -> TlvGen {
258 let flag = if aes_key_size == 256 {
259 TlvFlags::ENCRYPTED_AES256 as u32
260 } else {
261 TlvFlags::ENCRYPTED_AES128 as u32
262 };
Fabio Utzig90f449e2019-10-24 07:43:53 -0300263 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100264 flags: flag,
Roland Mikhel30978512023-02-08 14:06:58 +0100265 kinds: vec![TlvKinds::SHA256, TlvKinds::ECDSASIG, TlvKinds::ENCEC256],
Fabio Utzig9a2b5de2019-11-22 12:50:02 -0300266 ..Default::default()
Fabio Utzigb4d20c82018-12-27 16:08:39 -0200267 }
268 }
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300269
270 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100271 pub fn new_ecies_x25519(aes_key_size: u32) -> TlvGen {
272 let flag = if aes_key_size == 256 {
273 TlvFlags::ENCRYPTED_AES256 as u32
274 } else {
275 TlvFlags::ENCRYPTED_AES128 as u32
276 };
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300277 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100278 flags: flag,
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300279 kinds: vec![TlvKinds::SHA256, TlvKinds::ENCX25519],
280 ..Default::default()
281 }
282 }
283
284 #[allow(dead_code)]
Salome Thirot6fdbf552021-05-14 16:46:14 +0100285 pub fn new_ed25519_ecies_x25519(aes_key_size: u32) -> TlvGen {
286 let flag = if aes_key_size == 256 {
287 TlvFlags::ENCRYPTED_AES256 as u32
288 } else {
289 TlvFlags::ENCRYPTED_AES128 as u32
290 };
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300291 TlvGen {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100292 flags: flag,
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300293 kinds: vec![TlvKinds::SHA256, TlvKinds::ED25519, TlvKinds::ENCX25519],
294 ..Default::default()
295 }
296 }
David Brown43643dd2019-01-11 15:43:28 -0700297}
298
299impl ManifestGen for TlvGen {
David Brownac46e262019-01-11 15:46:18 -0700300 fn get_magic(&self) -> u32 {
301 0x96f3b83d
302 }
303
David Brown43643dd2019-01-11 15:43:28 -0700304 /// Retrieve the header flags for this configuration. This can be called at any time.
305 fn get_flags(&self) -> u32 {
David Brown8a4e23b2021-06-11 10:29:01 -0600306 // For the RamLoad case, add in the flag for this feature.
307 if Caps::RamLoad.present() {
308 self.flags | (TlvFlags::RAM_LOAD as u32)
309 } else {
310 self.flags
311 }
David Brown43643dd2019-01-11 15:43:28 -0700312 }
David Brown187dd882017-07-11 11:15:23 -0600313
314 /// Add bytes to the covered hash.
David Brown43643dd2019-01-11 15:43:28 -0700315 fn add_bytes(&mut self, bytes: &[u8]) {
David Brown4243ab02017-07-11 12:24:23 -0600316 self.payload.extend_from_slice(bytes);
David Brown187dd882017-07-11 11:15:23 -0600317 }
318
David Brown7a81c4b2019-07-29 15:20:21 -0600319 fn protect_size(&self) -> u16 {
David Brown2b73ed92020-01-08 17:01:22 -0700320 if self.dependencies.is_empty() {
David Brown7a81c4b2019-07-29 15:20:21 -0600321 0
322 } else {
David Brown2b73ed92020-01-08 17:01:22 -0700323 // Include the header and space for each dependency.
324 4 + (self.dependencies.len() as u16) * (4 + 4 + 8)
David Brown7a81c4b2019-07-29 15:20:21 -0600325 }
326 }
327
328 fn add_dependency(&mut self, id: u8, version: &ImageVersion) {
David Brown7a81c4b2019-07-29 15:20:21 -0600329 self.dependencies.push(Dependency {
David Brown4dfb33c2021-03-10 05:15:45 -0700330 id,
David Brown7a81c4b2019-07-29 15:20:21 -0600331 version: version.clone(),
332 });
333 }
334
David Browne90b13f2019-12-06 15:04:00 -0700335 fn corrupt_sig(&mut self) {
336 self.gen_corrupted = true;
337 }
338
David Brownef4f0742021-10-22 17:09:50 -0600339 fn estimate_size(&self) -> usize {
340 // Begin the estimate with the 4 byte header.
341 let mut estimate = 4;
342 // A very poor estimate.
343
344 // Estimate the size of the image hash.
345 if self.kinds.contains(&TlvKinds::SHA256) {
346 estimate += 4 + 32;
347 }
348
349 // Add an estimate in for each of the signature algorithms.
350 if self.kinds.contains(&TlvKinds::RSA2048) {
351 estimate += 4 + 32; // keyhash
352 estimate += 4 + 256; // RSA2048
353 }
354 if self.kinds.contains(&TlvKinds::RSA3072) {
355 estimate += 4 + 32; // keyhash
356 estimate += 4 + 384; // RSA3072
357 }
David Brownef4f0742021-10-22 17:09:50 -0600358 if self.kinds.contains(&TlvKinds::ED25519) {
359 estimate += 4 + 32; // keyhash
360 estimate += 4 + 64; // ED25519 signature.
361 }
Roland Mikhel6205c102023-02-06 13:32:02 +0100362 if self.kinds.contains(&TlvKinds::ECDSASIG) {
363 estimate += 4 + 32; // keyhash
Roland Mikhel30978512023-02-08 14:06:58 +0100364
365 // ECDSA signatures are encoded as ASN.1 with the x and y values stored as signed
366 // integers. As such, the size can vary by 2 bytes, if the 256-bit value has the high
367 // bit, it takes an extra 0 byte to avoid it being seen as a negative number.
Roland Mikhel6205c102023-02-06 13:32:02 +0100368 estimate += 4 + 72; // ECDSA256 (varies)
369 }
David Brownef4f0742021-10-22 17:09:50 -0600370
371 // Estimate encryption.
372 let flag = TlvFlags::ENCRYPTED_AES256 as u32;
373 let aes256 = (self.get_flags() & flag) == flag;
374
375 if self.kinds.contains(&TlvKinds::ENCRSA2048) {
376 estimate += 4 + 256;
377 }
378 if self.kinds.contains(&TlvKinds::ENCKW) {
379 estimate += 4 + if aes256 { 40 } else { 24 };
380 }
381 if self.kinds.contains(&TlvKinds::ENCEC256) {
382 estimate += 4 + if aes256 { 129 } else { 113 };
383 }
384 if self.kinds.contains(&TlvKinds::ENCX25519) {
385 estimate += 4 + if aes256 { 96 } else { 80 };
386 }
387
388 // Gather the size of the dependency information.
389 if self.protect_size() > 0 {
390 estimate += 4 + (16 * self.dependencies.len());
391 }
392
393 estimate
394 }
395
David Brown187dd882017-07-11 11:15:23 -0600396 /// Compute the TLV given the specified block of data.
David Brown43643dd2019-01-11 15:43:28 -0700397 fn make_tlv(self: Box<Self>) -> Vec<u8> {
David Brownef4f0742021-10-22 17:09:50 -0600398 let size_estimate = self.estimate_size();
399
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300400 let mut protected_tlv: Vec<u8> = vec![];
David Brown187dd882017-07-11 11:15:23 -0600401
David Brown2b73ed92020-01-08 17:01:22 -0700402 if self.protect_size() > 0 {
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300403 protected_tlv.push(0x08);
404 protected_tlv.push(0x69);
David Brown2b73ed92020-01-08 17:01:22 -0700405 let size = self.protect_size();
406 protected_tlv.write_u16::<LittleEndian>(size).unwrap();
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300407 for dep in &self.dependencies {
David Brown69721182019-12-04 14:50:52 -0700408 protected_tlv.write_u16::<LittleEndian>(TlvKinds::DEPENDENCY as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700409 protected_tlv.write_u16::<LittleEndian>(12).unwrap();
David Brownf5b33d82017-09-01 10:58:27 -0600410
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300411 // The dependency.
412 protected_tlv.push(dep.id);
David Brownf66b2052021-03-10 05:26:36 -0700413 protected_tlv.push(0);
414 protected_tlv.write_u16::<LittleEndian>(0).unwrap();
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300415 protected_tlv.push(dep.version.major);
416 protected_tlv.push(dep.version.minor);
417 protected_tlv.write_u16::<LittleEndian>(dep.version.revision).unwrap();
418 protected_tlv.write_u32::<LittleEndian>(dep.version.build_num).unwrap();
David Brown7a81c4b2019-07-29 15:20:21 -0600419 }
David Brown2b73ed92020-01-08 17:01:22 -0700420
421 assert_eq!(size, protected_tlv.len() as u16, "protected TLV length incorrect");
David Brown7a81c4b2019-07-29 15:20:21 -0600422 }
423
424 // Ring does the signature itself, which means that it must be
425 // given a full, contiguous payload. Although this does help from
426 // a correct usage perspective, it is fairly stupid from an
427 // efficiency view. If this is shown to be a performance issue
428 // with the tests, the protected data could be appended to the
429 // payload, and then removed after the signature is done. For now,
430 // just make a signed payload.
431 let mut sig_payload = self.payload.clone();
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300432 sig_payload.extend_from_slice(&protected_tlv);
433
434 let mut result: Vec<u8> = vec![];
435
436 // add back signed payload
437 result.extend_from_slice(&protected_tlv);
438
439 // add non-protected payload
David Brown3dc86c92020-01-08 17:22:55 -0700440 let npro_pos = result.len();
Fabio Utzigea3d3ab2019-09-11 19:35:33 -0300441 result.push(0x07);
442 result.push(0x69);
David Brown3dc86c92020-01-08 17:22:55 -0700443 // Placeholder for the size.
444 result.write_u16::<LittleEndian>(0).unwrap();
David Brown7a81c4b2019-07-29 15:20:21 -0600445
David Brown187dd882017-07-11 11:15:23 -0600446 if self.kinds.contains(&TlvKinds::SHA256) {
David Browne90b13f2019-12-06 15:04:00 -0700447 // If a signature is not requested, corrupt the hash we are
448 // generating. But, if there is a signature, output the
449 // correct hash. We want the hash test to pass so that the
450 // signature verification can be validated.
451 let mut corrupt_hash = self.gen_corrupted;
452 for k in &[TlvKinds::RSA2048, TlvKinds::RSA3072,
Roland Mikhel30978512023-02-08 14:06:58 +0100453 TlvKinds::ED25519, TlvKinds::ECDSASIG]
David Browne90b13f2019-12-06 15:04:00 -0700454 {
455 if self.kinds.contains(k) {
456 corrupt_hash = false;
457 break;
458 }
459 }
460
461 if corrupt_hash {
462 sig_payload[0] ^= 1;
463 }
464
David Brown7a81c4b2019-07-29 15:20:21 -0600465 let hash = digest::digest(&digest::SHA256, &sig_payload);
David Brown8054ce22017-07-11 12:12:09 -0600466 let hash = hash.as_ref();
David Brown187dd882017-07-11 11:15:23 -0600467
David Brown8054ce22017-07-11 12:12:09 -0600468 assert!(hash.len() == 32);
David Brown69721182019-12-04 14:50:52 -0700469 result.write_u16::<LittleEndian>(TlvKinds::SHA256 as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700470 result.write_u16::<LittleEndian>(32).unwrap();
David Brown8054ce22017-07-11 12:12:09 -0600471 result.extend_from_slice(hash);
David Browne90b13f2019-12-06 15:04:00 -0700472
473 // Undo the corruption.
474 if corrupt_hash {
475 sig_payload[0] ^= 1;
476 }
477
478 }
479
480 if self.gen_corrupted {
481 // Corrupt what is signed by modifying the input to the
482 // signature code.
483 sig_payload[0] ^= 1;
David Brown187dd882017-07-11 11:15:23 -0600484 }
485
Fabio Utzig39297432019-05-08 18:51:10 -0300486 if self.kinds.contains(&TlvKinds::RSA2048) ||
487 self.kinds.contains(&TlvKinds::RSA3072) {
488
489 let is_rsa2048 = self.kinds.contains(&TlvKinds::RSA2048);
490
David Brown43cda332017-09-01 09:53:23 -0600491 // Output the hash of the public key.
Fabio Utzig39297432019-05-08 18:51:10 -0300492 let hash = if is_rsa2048 {
493 digest::digest(&digest::SHA256, RSA_PUB_KEY)
494 } else {
495 digest::digest(&digest::SHA256, RSA3072_PUB_KEY)
496 };
David Brown43cda332017-09-01 09:53:23 -0600497 let hash = hash.as_ref();
498
499 assert!(hash.len() == 32);
David Brown69721182019-12-04 14:50:52 -0700500 result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700501 result.write_u16::<LittleEndian>(32).unwrap();
David Brown43cda332017-09-01 09:53:23 -0600502 result.extend_from_slice(hash);
503
David Brown7e701d82017-07-11 13:24:25 -0600504 // For now assume PSS.
Fabio Utzig39297432019-05-08 18:51:10 -0300505 let key_bytes = if is_rsa2048 {
506 pem::parse(include_bytes!("../../root-rsa-2048.pem").as_ref()).unwrap()
507 } else {
508 pem::parse(include_bytes!("../../root-rsa-3072.pem").as_ref()).unwrap()
509 };
David Brown7e701d82017-07-11 13:24:25 -0600510 assert_eq!(key_bytes.tag, "RSA PRIVATE KEY");
Fabio Utzig90f449e2019-10-24 07:43:53 -0300511 let key_pair = RsaKeyPair::from_der(&key_bytes.contents).unwrap();
David Brown7e701d82017-07-11 13:24:25 -0600512 let rng = rand::SystemRandom::new();
Fabio Utzig05ab0142018-07-10 09:15:28 -0300513 let mut signature = vec![0; key_pair.public_modulus_len()];
Fabio Utzig39297432019-05-08 18:51:10 -0300514 if is_rsa2048 {
515 assert_eq!(signature.len(), 256);
516 } else {
517 assert_eq!(signature.len(), 384);
518 }
David Brown7a81c4b2019-07-29 15:20:21 -0600519 key_pair.sign(&RSA_PSS_SHA256, &rng, &sig_payload, &mut signature).unwrap();
David Brown7e701d82017-07-11 13:24:25 -0600520
Fabio Utzig39297432019-05-08 18:51:10 -0300521 if is_rsa2048 {
David Brown69721182019-12-04 14:50:52 -0700522 result.write_u16::<LittleEndian>(TlvKinds::RSA2048 as u16).unwrap();
Fabio Utzig39297432019-05-08 18:51:10 -0300523 } else {
David Brown69721182019-12-04 14:50:52 -0700524 result.write_u16::<LittleEndian>(TlvKinds::RSA3072 as u16).unwrap();
Fabio Utzig39297432019-05-08 18:51:10 -0300525 }
David Brown91d68632019-07-29 14:32:13 -0600526 result.write_u16::<LittleEndian>(signature.len() as u16).unwrap();
David Brown7e701d82017-07-11 13:24:25 -0600527 result.extend_from_slice(&signature);
528 }
529
Roland Mikhel6205c102023-02-06 13:32:02 +0100530 if self.kinds.contains(&TlvKinds::ECDSASIG) {
531 let rng = rand::SystemRandom::new();
532 let keyhash = digest::digest(&digest::SHA256, ECDSA256_PUB_KEY);
533 let key_bytes = pem::parse(include_bytes!("../../root-ec-p256-pkcs8.pem").as_ref()).unwrap();
534 let sign_algo = &ECDSA_P256_SHA256_ASN1_SIGNING;
535 let key_pair = EcdsaKeyPair::from_pkcs8(sign_algo, &key_bytes.contents).unwrap();
536 let signature = key_pair.sign(&rng,&sig_payload).unwrap();
537
538 // Write public key
539 let keyhash_slice = keyhash.as_ref();
540 assert!(keyhash_slice.len() == 32);
541 result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
542 result.write_u16::<LittleEndian>(32).unwrap();
543 result.extend_from_slice(keyhash_slice);
544
545 // Write signature
546 result.write_u16::<LittleEndian>(TlvKinds::ECDSASIG as u16).unwrap();
547 let signature = signature.as_ref().to_vec();
548 result.write_u16::<LittleEndian>(signature.len() as u16).unwrap();
549 result.extend_from_slice(&signature);
550 }
Fabio Utzig97710282019-05-24 17:44:49 -0300551 if self.kinds.contains(&TlvKinds::ED25519) {
552 let keyhash = digest::digest(&digest::SHA256, ED25519_PUB_KEY);
553 let keyhash = keyhash.as_ref();
554
555 assert!(keyhash.len() == 32);
David Brown69721182019-12-04 14:50:52 -0700556 result.write_u16::<LittleEndian>(TlvKinds::KEYHASH as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700557 result.write_u16::<LittleEndian>(32).unwrap();
Fabio Utzig97710282019-05-24 17:44:49 -0300558 result.extend_from_slice(keyhash);
559
David Brown7a81c4b2019-07-29 15:20:21 -0600560 let hash = digest::digest(&digest::SHA256, &sig_payload);
Fabio Utzig97710282019-05-24 17:44:49 -0300561 let hash = hash.as_ref();
562 assert!(hash.len() == 32);
563
564 let key_bytes = pem::parse(include_bytes!("../../root-ed25519.pem").as_ref()).unwrap();
565 assert_eq!(key_bytes.tag, "PRIVATE KEY");
566
Fabio Utzig90f449e2019-10-24 07:43:53 -0300567 let key_pair = Ed25519KeyPair::from_seed_and_public_key(
568 &key_bytes.contents[16..48], &ED25519_PUB_KEY[12..44]).unwrap();
Fabio Utzig97710282019-05-24 17:44:49 -0300569 let signature = key_pair.sign(&hash);
570
David Brown69721182019-12-04 14:50:52 -0700571 result.write_u16::<LittleEndian>(TlvKinds::ED25519 as u16).unwrap();
Fabio Utzig97710282019-05-24 17:44:49 -0300572
573 let signature = signature.as_ref().to_vec();
David Brown91d68632019-07-29 14:32:13 -0600574 result.write_u16::<LittleEndian>(signature.len() as u16).unwrap();
Fabio Utzig97710282019-05-24 17:44:49 -0300575 result.extend_from_slice(signature.as_ref());
576 }
577
Fabio Utzig1e48b912018-09-18 09:04:18 -0300578 if self.kinds.contains(&TlvKinds::ENCRSA2048) {
579 let key_bytes = pem::parse(include_bytes!("../../enc-rsa2048-pub.pem")
580 .as_ref()).unwrap();
581 assert_eq!(key_bytes.tag, "PUBLIC KEY");
582
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300583 let cipherkey = self.get_enc_key();
584 let cipherkey = cipherkey.as_slice();
585 let encbuf = match c::rsa_oaep_encrypt(&key_bytes.contents, cipherkey) {
Fabio Utzig1e48b912018-09-18 09:04:18 -0300586 Ok(v) => v,
587 Err(_) => panic!("Failed to encrypt secret key"),
588 };
589
590 assert!(encbuf.len() == 256);
David Brown69721182019-12-04 14:50:52 -0700591 result.write_u16::<LittleEndian>(TlvKinds::ENCRSA2048 as u16).unwrap();
David Brown4fae8b82019-12-05 11:26:59 -0700592 result.write_u16::<LittleEndian>(256).unwrap();
Fabio Utzig1e48b912018-09-18 09:04:18 -0300593 result.extend_from_slice(&encbuf);
594 }
595
Salome Thirot0f641972021-05-14 11:19:55 +0100596 if self.kinds.contains(&TlvKinds::ENCKW) {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100597 let flag = TlvFlags::ENCRYPTED_AES256 as u32;
598 let aes256 = (self.get_flags() & flag) == flag;
599 let key_bytes = if aes256 {
600 base64::decode(
601 include_str!("../../enc-aes256kw.b64").trim()).unwrap()
602 } else {
603 base64::decode(
604 include_str!("../../enc-aes128kw.b64").trim()).unwrap()
605 };
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300606 let cipherkey = self.get_enc_key();
607 let cipherkey = cipherkey.as_slice();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100608 let keylen = if aes256 { 32 } else { 16 };
609 let encbuf = match c::kw_encrypt(&key_bytes, cipherkey, keylen) {
Fabio Utzig1e48b912018-09-18 09:04:18 -0300610 Ok(v) => v,
611 Err(_) => panic!("Failed to encrypt secret key"),
612 };
613
Salome Thirot6fdbf552021-05-14 16:46:14 +0100614 let size = if aes256 { 40 } else { 24 };
615 assert!(encbuf.len() == size);
Salome Thirot0f641972021-05-14 11:19:55 +0100616 result.write_u16::<LittleEndian>(TlvKinds::ENCKW as u16).unwrap();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100617 result.write_u16::<LittleEndian>(size as u16).unwrap();
Fabio Utzig1e48b912018-09-18 09:04:18 -0300618 result.extend_from_slice(&encbuf);
619 }
620
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300621 if self.kinds.contains(&TlvKinds::ENCEC256) || self.kinds.contains(&TlvKinds::ENCX25519) {
622 let key_bytes = if self.kinds.contains(&TlvKinds::ENCEC256) {
623 pem::parse(include_bytes!("../../enc-ec256-pub.pem").as_ref()).unwrap()
624 } else {
625 pem::parse(include_bytes!("../../enc-x25519-pub.pem").as_ref()).unwrap()
626 };
Fabio Utzig90f449e2019-10-24 07:43:53 -0300627 assert_eq!(key_bytes.tag, "PUBLIC KEY");
Fabio Utzig90f449e2019-10-24 07:43:53 -0300628 let rng = rand::SystemRandom::new();
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300629 let alg = if self.kinds.contains(&TlvKinds::ENCEC256) {
630 &agreement::ECDH_P256
631 } else {
632 &agreement::X25519
633 };
634 let pk = match agreement::EphemeralPrivateKey::generate(alg, &rng) {
Fabio Utzig90f449e2019-10-24 07:43:53 -0300635 Ok(v) => v,
636 Err(_) => panic!("Failed to generate ephemeral keypair"),
637 };
638
639 let pubk = match pk.compute_public_key() {
640 Ok(pubk) => pubk,
641 Err(_) => panic!("Failed computing ephemeral public key"),
642 };
643
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300644 let peer_pubk = if self.kinds.contains(&TlvKinds::ENCEC256) {
645 agreement::UnparsedPublicKey::new(&agreement::ECDH_P256, &key_bytes.contents[26..])
646 } else {
647 agreement::UnparsedPublicKey::new(&agreement::X25519, &key_bytes.contents[12..])
648 };
Fabio Utzig90f449e2019-10-24 07:43:53 -0300649
650 #[derive(Debug, PartialEq)]
651 struct OkmLen<T: core::fmt::Debug + PartialEq>(T);
652
653 impl hkdf::KeyType for OkmLen<usize> {
654 fn len(&self) -> usize {
655 self.0
656 }
657 }
658
Salome Thirot6fdbf552021-05-14 16:46:14 +0100659 let flag = TlvFlags::ENCRYPTED_AES256 as u32;
660 let aes256 = (self.get_flags() & flag) == flag;
661
Fabio Utzig90f449e2019-10-24 07:43:53 -0300662 let derived_key = match agreement::agree_ephemeral(
663 pk, &peer_pubk, ring::error::Unspecified, |shared| {
664 let salt = hkdf::Salt::new(hkdf::HKDF_SHA256, &[]);
665 let prk = salt.extract(&shared);
Salome Thirot6fdbf552021-05-14 16:46:14 +0100666 let okm_len = if aes256 { 64 } else { 48 };
667 let okm = match prk.expand(&[b"MCUBoot_ECIES_v1"], OkmLen(okm_len)) {
Fabio Utzig90f449e2019-10-24 07:43:53 -0300668 Ok(okm) => okm,
669 Err(_) => panic!("Failed building HKDF OKM"),
670 };
Salome Thirot6fdbf552021-05-14 16:46:14 +0100671 let mut buf = if aes256 { vec![0u8; 64] } else { vec![0u8; 48] };
Fabio Utzig90f449e2019-10-24 07:43:53 -0300672 match okm.fill(&mut buf) {
673 Ok(_) => Ok(buf),
674 Err(_) => panic!("Failed generating HKDF output"),
675 }
676 },
677 ) {
678 Ok(v) => v,
679 Err(_) => panic!("Failed building HKDF"),
680 };
681
Fabio Utzig90f449e2019-10-24 07:43:53 -0300682 let nonce = GenericArray::from_slice(&[0; 16]);
Fabio Utzig90f449e2019-10-24 07:43:53 -0300683 let mut cipherkey = self.get_enc_key();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100684 if aes256 {
685 let key: &GenericArray<u8, U32> = GenericArray::from_slice(&derived_key[..32]);
David Brown9c6322f2021-08-19 13:03:39 -0600686 let block = Aes256::new(&key);
687 let mut cipher = Aes256Ctr::from_block_cipher(block, &nonce);
Salome Thirot6fdbf552021-05-14 16:46:14 +0100688 cipher.apply_keystream(&mut cipherkey);
689 } else {
690 let key: &GenericArray<u8, U16> = GenericArray::from_slice(&derived_key[..16]);
David Brown9c6322f2021-08-19 13:03:39 -0600691 let block = Aes128::new(&key);
692 let mut cipher = Aes128Ctr::from_block_cipher(block, &nonce);
Salome Thirot6fdbf552021-05-14 16:46:14 +0100693 cipher.apply_keystream(&mut cipherkey);
694 }
Fabio Utzig90f449e2019-10-24 07:43:53 -0300695
Salome Thirot6fdbf552021-05-14 16:46:14 +0100696 let size = if aes256 { 32 } else { 16 };
697 let key = hmac::Key::new(hmac::HMAC_SHA256, &derived_key[size..]);
Fabio Utzig90f449e2019-10-24 07:43:53 -0300698 let tag = hmac::sign(&key, &cipherkey);
699
700 let mut buf = vec![];
701 buf.append(&mut pubk.as_ref().to_vec());
702 buf.append(&mut tag.as_ref().to_vec());
703 buf.append(&mut cipherkey);
704
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300705 if self.kinds.contains(&TlvKinds::ENCEC256) {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100706 let size = if aes256 { 129 } else { 113 };
707 assert!(buf.len() == size);
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300708 result.write_u16::<LittleEndian>(TlvKinds::ENCEC256 as u16).unwrap();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100709 result.write_u16::<LittleEndian>(size as u16).unwrap();
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300710 } else {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100711 let size = if aes256 { 96 } else { 80 };
712 assert!(buf.len() == size);
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300713 result.write_u16::<LittleEndian>(TlvKinds::ENCX25519 as u16).unwrap();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100714 result.write_u16::<LittleEndian>(size as u16).unwrap();
Fabio Utzig3fa72ca2020-04-02 11:20:37 -0300715 }
Fabio Utzig90f449e2019-10-24 07:43:53 -0300716 result.extend_from_slice(&buf);
717 }
718
David Brown3dc86c92020-01-08 17:22:55 -0700719 // Patch the size back into the TLV header.
720 let size = (result.len() - npro_pos) as u16;
721 let mut size_buf = &mut result[npro_pos + 2 .. npro_pos + 4];
722 size_buf.write_u16::<LittleEndian>(size).unwrap();
723
David Brownb408b432021-10-27 15:55:39 -0600724 // ECDSA is stored as an ASN.1 integer. For a 128-bit value, this maximally results in 33
725 // bytes of storage for each of the two values. If the high bit is zero, it will take 32
726 // bytes, if the top 8 bits are zero, it will take 31 bits, and so on. The smaller size
727 // will occur with decreasing likelihood. We'll allow this to get a bit smaller, hopefully
728 // allowing the tests to pass with false failures rare. For this case, we'll handle up to
729 // the top 16 bits of both numbers being all zeros (1 in 2^32).
730 if !Caps::has_ecdsa() {
731 if size_estimate != result.len() {
732 panic!("Incorrect size estimate: {} (actual {})", size_estimate, result.len());
733 }
734 } else {
735 if size_estimate < result.len() || size_estimate > result.len() + 6 {
736 panic!("Incorrect size estimate: {} (actual {})", size_estimate, result.len());
737 }
David Brownef4f0742021-10-22 17:09:50 -0600738 }
739 if size_estimate != result.len() {
740 log::warn!("Size off: {} actual {}", size_estimate, result.len());
741 }
742
David Brown187dd882017-07-11 11:15:23 -0600743 result
744 }
Fabio Utzig90f449e2019-10-24 07:43:53 -0300745
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300746 fn generate_enc_key(&mut self) {
747 let rng = rand::SystemRandom::new();
Salome Thirot6fdbf552021-05-14 16:46:14 +0100748 let flag = TlvFlags::ENCRYPTED_AES256 as u32;
749 let aes256 = (self.get_flags() & flag) == flag;
750 let mut buf = if aes256 {
751 vec![0u8; 32]
752 } else {
753 vec![0u8; 16]
754 };
David Brown26edaf32021-03-10 05:27:38 -0700755 if rng.fill(&mut buf).is_err() {
756 panic!("Error generating encrypted key");
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300757 }
758 info!("New encryption key: {:02x?}", buf);
759 self.enc_key = buf;
Fabio Utzig90f449e2019-10-24 07:43:53 -0300760 }
761
762 fn get_enc_key(&self) -> Vec<u8> {
Salome Thirot6fdbf552021-05-14 16:46:14 +0100763 if self.enc_key.len() != 32 && self.enc_key.len() != 16 {
Fabio Utzige84f0ef2019-11-22 12:29:32 -0300764 panic!("No random key was generated");
765 }
766 self.enc_key.clone()
Fabio Utzig90f449e2019-10-24 07:43:53 -0300767 }
David Brown187dd882017-07-11 11:15:23 -0600768}
David Brown43cda332017-09-01 09:53:23 -0600769
770include!("rsa_pub_key-rs.txt");
Fabio Utzig39297432019-05-08 18:51:10 -0300771include!("rsa3072_pub_key-rs.txt");
Fabio Utzig80fde2f2017-12-05 09:25:31 -0200772include!("ecdsa_pub_key-rs.txt");
Fabio Utzig97710282019-05-24 17:44:49 -0300773include!("ed25519_pub_key-rs.txt");