Skip to content

Commit

Permalink
Make RT depend on caliptra-cfi and update DPE version
Browse files Browse the repository at this point in the history
  • Loading branch information
sree-revoori1 authored and jhand2 committed Feb 14, 2024
1 parent c64e913 commit 11edcf3
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 29 deletions.
27 changes: 25 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ bit-vec = "0.6.3"
caliptra-api = { path = "api" }
caliptra-cfi-lib = { path = "cfi/lib", default-features = false, features = ["cfi", "cfi-counter" ] }
caliptra-cfi-derive = { path = "cfi/derive" }
caliptra-cfi-lib-git = { git = "https://github.com/chipsalliance/caliptra-cfi.git", package = "caliptra-cfi-lib-git", rev = "9f315fcf11fe006e95e62149f54f98620e5244e7", default-features = false, features = ["cfi", "cfi-counter" ] }
caliptra-cfi-derive-git = { git = "https://github.com/chipsalliance/caliptra-cfi.git", package = "caliptra-cfi-derive-git", rev = "9f315fcf11fe006e95e62149f54f98620e5244e7"}
caliptra_common = { path = "common", default-features = false }
caliptra-coverage = { path = "coverage" }
caliptra-builder = { path = "builder" }
Expand Down
4 changes: 3 additions & 1 deletion drivers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ zerocopy.workspace = true
zeroize.workspace = true
caliptra-cfi-lib = { workspace = true, default-features = false, features = ["cfi", "cfi-counter" ] }
caliptra-cfi-derive.workspace = true
caliptra-cfi-lib-git = { workspace = true, default-features = false, features = ["cfi", "cfi-counter" ], optional = true }
caliptra-cfi-derive-git = { workspace = true, optional = true }

[features]
emu = []
runtime = ["dep:dpe"]
runtime = ["dep:dpe", "dep:caliptra-cfi-lib-git", "dep:caliptra-cfi-derive-git"]
fmc = []
fpga_realtime = ["caliptra-hw-model/fpga_realtime"]
itrng = ["caliptra-hw-model/itrng"]
Expand Down
13 changes: 13 additions & 0 deletions drivers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,19 @@ pub use sha384acc::{Sha384Acc, Sha384AccOp, ShaAccLockState};
pub use soc_ifc::{report_boot_status, Lifecycle, MfgFlags, ResetReason, SocIfc};
pub use trng::Trng;

#[allow(unused_imports)]
#[cfg(not(feature = "runtime"))]
use caliptra_cfi_derive;
#[allow(unused_imports)]
#[cfg(feature = "runtime")]
use caliptra_cfi_derive_git as caliptra_cfi_derive;
#[allow(unused_imports)]
#[cfg(not(feature = "runtime"))]
use caliptra_cfi_lib;
#[allow(unused_imports)]
#[cfg(feature = "runtime")]
use caliptra_cfi_lib_git as caliptra_cfi_lib;

cfg_if::cfg_if! {
if #[cfg(feature = "emu")] {
mod uart;
Expand Down
6 changes: 3 additions & 3 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ version = "0.1.0"
edition = "2021"

[dependencies]
caliptra-cfi-lib = { workspace = true, default-features = false, features = ["cfi", "cfi-counter" ] }
caliptra-cfi-derive.workspace = true
caliptra-cfi-lib-git = { workspace = true, default-features = false, features = ["cfi", "cfi-counter" ] }
caliptra-cfi-derive-git.workspace = true
caliptra_common = { workspace = true, default-features = false, features = ["runtime"] }
caliptra-cpu.workspace = true
caliptra-drivers = { workspace = true, features = ["runtime"] }
Expand Down Expand Up @@ -38,7 +38,7 @@ caliptra-image-fake-keys.workspace = true
caliptra-image-gen.workspace = true
caliptra-image-openssl.workspace = true
caliptra-image-serde.workspace = true
caliptra-cfi-lib = { workspace = true, features = ["cfi-test"] }
caliptra-cfi-lib-git = { workspace = true, features = ["cfi-test"] }
openssl.workspace = true
sha2 = { version = "0.10.2", default-features = false, features = ["compress"] }
cms.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/disable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Abstract:
--*/

use crate::Drivers;
use caliptra_cfi_derive::cfi_impl_fn;
use caliptra_cfi_derive_git::cfi_impl_fn;
use caliptra_common::mailbox_api::MailboxResp;
use caliptra_drivers::{
hmac384_kdf, Array4x12, CaliptraError, CaliptraResult, Ecc384Seed, Hmac384Key, KeyReadArgs,
Expand Down
5 changes: 4 additions & 1 deletion runtime/src/dpe_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Abstract:

use core::cmp::min;

use caliptra_cfi_lib::{cfi_assert, cfi_assert_eq, cfi_launder};
use caliptra_cfi_derive_git::cfi_impl_fn;
use caliptra_cfi_lib_git::{cfi_assert, cfi_assert_eq, cfi_launder};
use caliptra_common::keyids::{KEY_ID_DPE_CDI, KEY_ID_DPE_PRIV_KEY, KEY_ID_TMP};
use caliptra_drivers::{
cprintln, hmac384_kdf, Array4x12, Ecc384, Ecc384PrivKeyIn, Ecc384PubKey, Ecc384Scalar,
Expand Down Expand Up @@ -128,6 +129,7 @@ impl<'a> Crypto for DpeCrypto<'a> {
}
}

#[cfg_attr(not(feature = "no-cfi"), cfi_impl_fn)]
fn derive_cdi(
&mut self,
algs: AlgLen,
Expand Down Expand Up @@ -162,6 +164,7 @@ impl<'a> Crypto for DpeCrypto<'a> {
}
}

#[cfg_attr(not(feature = "no-cfi"), cfi_impl_fn)]
fn derive_key_pair(
&mut self,
algs: AlgLen,
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use crate::{
};

use arrayvec::ArrayVec;
use caliptra_cfi_derive::{cfi_impl_fn, cfi_mod_fn};
use caliptra_cfi_lib::{cfi_assert, cfi_assert_eq, cfi_assert_eq_12_words, cfi_launder};
use caliptra_cfi_derive_git::{cfi_impl_fn, cfi_mod_fn};
use caliptra_cfi_lib_git::{cfi_assert, cfi_assert_eq, cfi_assert_eq_12_words, cfi_launder};
use caliptra_drivers::KeyId;
use caliptra_drivers::{
cprint, cprintln, pcr_log::RT_FW_JOURNEY_PCR, Array4x12, CaliptraError, CaliptraResult,
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/fips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Abstract:
File contains FIPS module and FIPS self test.
--*/
use caliptra_cfi_derive::{cfi_impl_fn, cfi_mod_fn};
use caliptra_cfi_derive_git::{cfi_impl_fn, cfi_mod_fn};
use caliptra_common::cprintln;
use caliptra_common::mailbox_api::{MailboxResp, MailboxRespHeader};
use caliptra_drivers::CaliptraError;
Expand Down Expand Up @@ -57,7 +57,7 @@ impl FipsModule {
pub mod fips_self_test_cmd {
use super::*;
use crate::RtBootStatus::{RtFipSelfTestComplete, RtFipSelfTestStarted};
use caliptra_cfi_lib::cfi_assert_eq_8_words;
use caliptra_cfi_lib_git::cfi_assert_eq_8_words;
use caliptra_common::HexBytes;
use caliptra_common::{
verifier::FirmwareImageVerificationEnv, FMC_ORG, FMC_SIZE, RUNTIME_ORG, RUNTIME_SIZE,
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/hmac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Abstract:
--*/

use caliptra_cfi_derive::{cfi_impl_fn, cfi_mod_fn};
use caliptra_cfi_lib::{cfi_assert, cfi_assert_eq, cfi_launder};
use caliptra_cfi_derive_git::{cfi_impl_fn, cfi_mod_fn};
use caliptra_cfi_lib_git::{cfi_assert, cfi_assert_eq, cfi_launder};
use caliptra_common::{crypto::Ecc384KeyPair, keyids::KEY_ID_TMP};
use caliptra_drivers::{
hmac384_kdf, Array4x12, Ecc384PrivKeyOut, Ecc384PubKey, Hmac384Data, Hmac384Key, Hmac384Tag,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/invoke_dpe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Abstract:
--*/

use crate::{CptraDpeTypes, DpeCrypto, DpeEnv, DpePlatform, Drivers, PL0_PAUSER_FLAG};
use caliptra_cfi_derive::cfi_impl_fn;
use caliptra_cfi_derive_git::cfi_impl_fn;
use caliptra_common::mailbox_api::{InvokeDpeReq, InvokeDpeResp, MailboxResp, MailboxRespHeader};
use caliptra_drivers::{CaliptraError, CaliptraResult};
use crypto::{AlgLen, Crypto};
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod verify;

// Used by runtime tests
pub mod mailbox;
use caliptra_cfi_lib::{cfi_assert, cfi_assert_eq, cfi_assert_ne, cfi_launder, CfiCounter};
use caliptra_cfi_lib_git::{cfi_assert, cfi_assert_eq, cfi_assert_ne, cfi_launder, CfiCounter};
use caliptra_registers::soc_ifc::SocIfcReg;
pub use drivers::Drivers;
use mailbox::Mailbox;
Expand Down
10 changes: 8 additions & 2 deletions runtime/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Abstract:
#[cfg(target_arch = "riscv32")]
core::arch::global_asm!(include_str!("ext_intr.S"));

use caliptra_cfi_lib::CfiCounter;
use caliptra_cfi_lib_git::CfiCounter;
use caliptra_common::{cprintln, handle_fatal_error};
use caliptra_cpu::{log_trap_record, TrapRecord};
use caliptra_error::CaliptraError;
Expand Down Expand Up @@ -65,7 +65,13 @@ pub extern "C" fn entry_point() -> ! {

if !cfg!(feature = "no-cfi") {
cprintln!("[state] CFI Enabled");
let mut entropy_gen = || drivers.trng.generate().map(|a| a.0);
let mut entropy_gen = || {
drivers
.trng
.generate()
.map(|a| a.0)
.map_err(|_| caliptra_cfi_lib_git::CfiPanicInfo::TrngError)
};
CfiCounter::reset(&mut entropy_gen);
CfiCounter::reset(&mut entropy_gen);
CfiCounter::reset(&mut entropy_gen);
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/pcr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Abstract:
--*/

use crate::Drivers;
use caliptra_cfi_derive::cfi_impl_fn;
use caliptra_cfi_derive_git::cfi_impl_fn;
use caliptra_common::mailbox_api::{
ExtendPcrReq, IncrementPcrResetCounterReq, MailboxResp, MailboxRespHeader, QuotePcrsReq,
QuotePcrsResp,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/stash_measurement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Abstract:
--*/

use crate::{dpe_crypto::DpeCrypto, CptraDpeTypes, DpePlatform, Drivers};
use caliptra_cfi_derive::cfi_impl_fn;
use caliptra_cfi_derive_git::cfi_impl_fn;
use caliptra_common::mailbox_api::{
MailboxResp, MailboxRespHeader, StashMeasurementReq, StashMeasurementResp,
};
Expand Down
3 changes: 2 additions & 1 deletion runtime/src/tagging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Abstract:
--*/

use caliptra_cfi_derive::cfi_impl_fn;
use crate::CfiCounter;
use caliptra_cfi_derive_git::cfi_impl_fn;
use caliptra_common::mailbox_api::{
GetTaggedTciReq, GetTaggedTciResp, MailboxResp, MailboxRespHeader, TagTciReq,
};
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Abstract:
--*/

use crate::Drivers;
use caliptra_cfi_derive::cfi_mod_fn;
use caliptra_cfi_derive_git::cfi_mod_fn;
use caliptra_drivers::{CaliptraError, CaliptraResult};

#[cfg_attr(not(feature = "no-cfi"), cfi_mod_fn)]
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Abstract:
--*/

use crate::Drivers;
use caliptra_cfi_derive::cfi_impl_fn;
use caliptra_cfi_derive_git::cfi_impl_fn;
#[cfg(feature = "test_only_commands")]
use caliptra_common::mailbox_api::HmacVerifyReq;
use caliptra_common::mailbox_api::{EcdsaVerifyReq, MailboxResp};
Expand Down
10 changes: 5 additions & 5 deletions test/tests/caliptra_integration_tests/smoke_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,11 +667,11 @@ fn test_rt_wdt_timeout() {

// TODO: Don't hard-code these; maybe measure from a previous boot?
let rt_wdt_timeout_cycles = if cfg!(any(feature = "verilator", feature = "fpga_realtime")) {
27_200_000
27_300_000
} else if firmware::rom_from_env() == &firmware::ROM_WITH_UART {
3_200_000
3_300_000
} else {
3_000_000
3_100_000
};

let security_state = *caliptra_hw_model::SecurityState::default().set_debug_locked(true);
Expand Down Expand Up @@ -716,9 +716,9 @@ fn test_fmc_wdt_timeout() {

// TODO: Don't hard-code these; maybe measure from a previous boot?
let fmc_wdt_timeout_cycles = if cfg!(any(feature = "verilator", feature = "fpga_realtime")) {
25_200_000
25_300_000
} else {
2_920_000
3_020_000
};

let rom = caliptra_builder::build_firmware_rom(firmware::rom_from_env()).unwrap();
Expand Down

0 comments on commit 11edcf3

Please sign in to comment.