Skip to content

Commit 3c2dd1d

Browse files
nquartonjhand2
authored andcommitted
Add runtime support for 1.0 and 1.1 RTL with single build
- removed hw-1.0 feature where possible - add test to ensure FMC and FW binaries do not change with hw-1.0 feature
1 parent 79474b4 commit 3c2dd1d

24 files changed

Lines changed: 93 additions & 93 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ caliptra-api-types.workspace = true
1717
ureg.workspace = true
1818

1919
[features]
20-
"hw-1.0" = ["caliptra-registers/hw-1.0"]

builder/src/firmware.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ pub const FMC_WITH_UART: FwId = FwId {
4545
features: &["emu"],
4646
};
4747

48+
pub const FMC_WITH_UART_HW_1_0: FwId = FwId {
49+
crate_name: "caliptra-fmc",
50+
bin_name: "caliptra-fmc",
51+
features: &["emu", "hw-1.0"],
52+
};
53+
4854
pub const FMC_FAKE_WITH_UART: FwId = FwId {
4955
crate_name: "caliptra-fmc",
5056
bin_name: "caliptra-fmc",
@@ -75,6 +81,12 @@ pub const APP_WITH_UART_FPGA: FwId = FwId {
7581
features: &["emu", "fips_self_test", "fpga_realtime"],
7682
};
7783

84+
pub const APP_WITH_UART_HW_1_0: FwId = FwId {
85+
crate_name: "caliptra-runtime",
86+
bin_name: "caliptra-runtime",
87+
features: &["emu", "fips_self_test", "hw-1.0"],
88+
};
89+
7890
pub const APP_ZEROS: FwId = FwId {
7991
crate_name: "caliptra-zeros",
8092
bin_name: "caliptra-zeros",
@@ -394,11 +406,13 @@ pub const REGISTERED_FW: &[&FwId] = &[
394406
&ROM_FAKE_WITH_UART,
395407
&ROM_WITH_FIPS_TEST_HOOKS,
396408
&FMC_WITH_UART,
409+
&FMC_WITH_UART_HW_1_0,
397410
&FMC_FAKE_WITH_UART,
398411
&APP,
399412
&APP_WITH_UART,
400413
&APP_WITH_UART_FIPS_TEST_HOOKS,
401414
&APP_WITH_UART_FPGA,
415+
&APP_WITH_UART_HW_1_0,
402416
&APP_ZEROS,
403417
&FMC_ZEROS,
404418
&caliptra_builder_tests::FWID,

cfi/lib/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ default = ["cfi", "cfi-counter", "cfi-test"]
2222
cfi = []
2323
cfi-counter = []
2424
cfi-test = []
25-
"hw-1.0" = ["caliptra-registers/hw-1.0"]
2625

2726

common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ std = []
2525
rom = []
2626
fmc = []
2727
runtime = []
28-
"hw-1.0" = ["caliptra-drivers/hw-1.0", "caliptra-registers/hw-1.0"]
28+
"hw-1.0" = ["caliptra-drivers/hw-1.0"]

common/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ pub use pcr::{PcrLogEntry, PcrLogEntryId, RT_FW_CURRENT_PCR, RT_FW_JOURNEY_PCR};
4040
pub const FMC_ORG: u32 = 0x40000000;
4141
pub const FMC_SIZE: u32 = 21 * 1024;
4242
pub const RUNTIME_ORG: u32 = FMC_ORG + FMC_SIZE;
43-
pub const RUNTIME_SIZE: u32 = 96 * 1024;
43+
pub const RUNTIME_SIZE: u32 = 97 * 1024;
4444

45-
// Max size of runtime code should be 118K to allow room for the manifest
45+
// Max size of runtime code should be 120K to allow 8k for the manifest
4646
#[allow(clippy::assertions_on_constants)]
47-
const _: () = assert!((FMC_SIZE + RUNTIME_SIZE) < (118 * 1024));
47+
const _: () = assert!((FMC_SIZE + RUNTIME_SIZE) < (120 * 1024));
4848

4949
pub use memory_layout::{DATA_ORG, PERSISTENT_DATA_ORG};
5050
pub use wdt::{restart_wdt, start_wdt, stop_wdt, WdtTimeout};

cpu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ edition = "2021"
1212
# --profile=firmware \
1313
# --features riscv
1414
riscv = []
15-
"hw-1.0" = ["caliptra-drivers/hw-1.0", "caliptra-registers/hw-1.0"]
15+
"hw-1.0" = ["caliptra-drivers/hw-1.0"]
1616

1717
[lib]
1818
test = false

drivers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fpga_realtime = ["caliptra-hw-model/fpga_realtime"]
3535
itrng = ["caliptra-hw-model/itrng"]
3636
verilator = ["caliptra-hw-model/verilator"]
3737
no-cfi = []
38-
"hw-1.0" = ["caliptra-builder/hw-1.0", "caliptra-registers/hw-1.0"]
38+
"hw-1.0" = ["caliptra-builder/hw-1.0", "caliptra-hw-model/hw-1.0"]
3939
fips-test-hooks = []
4040

4141
[dev-dependencies]

drivers/src/hmac384.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,17 @@ impl Hmac384 {
175175
let hmac = self.hmac.regs_mut();
176176

177177
let rand_data = trng.generate()?;
178-
cfg_if::cfg_if! {
179-
if #[cfg(feature="hw-1.0")] {
180-
use crate::Array4x5;
181-
let iv: [u32; 5] = rand_data.0[..5].try_into().unwrap();
182-
KvAccess::copy_from_arr(&Array4x5::from(iv), hmac.lfsr_seed())?;
183-
} else {
184-
let iv: [u32; 12] = rand_data.0[..12].try_into().unwrap();
185-
KvAccess::copy_from_arr(&Array4x12::from(iv), hmac.lfsr_seed())?;
186-
}
178+
179+
#[cfg(any(feature = "fmc", feature = "runtime"))]
180+
if crate::soc_ifc::is_hw_gen_1_0() {
181+
use crate::Array4x5;
182+
let iv: [u32; 5] = rand_data.0[..5].try_into().unwrap();
183+
KvAccess::copy_from_arr(&Array4x5::from(iv), hmac.lfsr_seed().truncate::<5>())?;
184+
return Ok(());
187185
}
186+
187+
let iv: [u32; 12] = rand_data.0[..12].try_into().unwrap();
188+
KvAccess::copy_from_arr(&Array4x12::from(iv), hmac.lfsr_seed())?;
188189
Ok(())
189190
}
190191

drivers/src/lms.rs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,6 @@ impl Lms {
310310
}
311311

312312
// This operation is accelerated in hardware by RTL1.1 and later.
313-
#[cfg(not(feature = "hw-1.0"))]
314313
fn hash_chain<const N: usize>(
315314
&self,
316315
sha256_driver: &mut impl Sha256Alg,
@@ -321,6 +320,26 @@ impl Lms {
321320
) -> CaliptraResult<HashValue<N>> {
322321
let iteration_count = ((1u16 << params.w) - 1) as u8;
323322

323+
#[cfg(any(feature = "fmc", feature = "runtime"))]
324+
if crate::soc_ifc::is_hw_gen_1_0() {
325+
// RTL 1.0 version (no HW acceleration)
326+
for j in coeff..iteration_count {
327+
let mut digest = Array4x8::default();
328+
let mut hasher = sha256_driver.digest_init()?;
329+
wnt_prefix[Self::ITER_COUNTER_OFFSET] = j;
330+
let mut i = Self::TMP_OFFSET;
331+
for val in tmp.0.iter().take(N) {
332+
wnt_prefix[i..i + 4].clone_from_slice(&val.to_be_bytes());
333+
i += 4;
334+
}
335+
hasher.update(&wnt_prefix[0..Self::TMP_OFFSET + N * 4])?;
336+
hasher.finalize(&mut digest)?;
337+
*tmp = HashValue::<N>::from(digest);
338+
}
339+
return Ok(*tmp);
340+
}
341+
342+
// RTL 1.1+ version (LMS HW acceleration)
324343
if coeff < iteration_count {
325344
let mut digest = Array4x8::default();
326345
let mut hasher = sha256_driver.digest_init()?;
@@ -342,33 +361,6 @@ impl Lms {
342361
Ok(*tmp)
343362
}
344363

345-
#[cfg(feature = "hw-1.0")]
346-
fn hash_chain<const N: usize>(
347-
&self,
348-
sha256_driver: &mut impl Sha256Alg,
349-
wnt_prefix: &mut [u8; Self::WNT_PREFIX_SIZE],
350-
coeff: u8,
351-
params: &LmotsParameter,
352-
tmp: &mut HashValue<N>,
353-
) -> CaliptraResult<HashValue<N>> {
354-
let iteration_count = ((1u16 << params.w) - 1) as u8;
355-
356-
for j in coeff..iteration_count {
357-
let mut digest = Array4x8::default();
358-
let mut hasher = sha256_driver.digest_init()?;
359-
wnt_prefix[Self::ITER_COUNTER_OFFSET] = j;
360-
let mut i = Self::TMP_OFFSET;
361-
for val in tmp.0.iter().take(N) {
362-
wnt_prefix[i..i + 4].clone_from_slice(&val.to_be_bytes());
363-
i += 4;
364-
}
365-
hasher.update(&wnt_prefix[0..Self::TMP_OFFSET + N * 4])?;
366-
hasher.finalize(&mut digest)?;
367-
*tmp = HashValue::<N>::from(digest);
368-
}
369-
Ok(*tmp)
370-
}
371-
372364
pub fn candidate_ots_signature<const N: usize, const P: usize>(
373365
&self,
374366
sha256_driver: &mut impl Sha256Alg,

0 commit comments

Comments
 (0)