diff --git a/Cargo.lock b/Cargo.lock index 0ba8c3d287..b2e847380f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -187,6 +187,15 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +[[package]] +name = "caliptra-api" +version = "0.1.0" +dependencies = [ + "bitflags 2.4.0", + "caliptra-error", + "zerocopy", +] + [[package]] name = "caliptra-builder" version = "0.1.0" @@ -415,6 +424,7 @@ version = "0.1.0" dependencies = [ "bit-vec", "bitfield", + "caliptra-api", "caliptra-builder", "caliptra-emu-bus", "caliptra-emu-cpu", @@ -424,7 +434,6 @@ dependencies = [ "caliptra-registers", "caliptra-test-harness-types", "caliptra-verilated", - "caliptra_common", "libc", "nix 0.26.2", "rand", @@ -758,6 +767,7 @@ version = "0.1.0" dependencies = [ "bitfield", "bitflags 2.4.0", + "caliptra-api", "caliptra-cpu", "caliptra-drivers", "caliptra-image-types", diff --git a/Cargo.toml b/Cargo.toml index 1ecacc6850..ba1581392d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ exclude = [ ] members = [ + "api", "builder", "cfi/lib", "cfi/derive", @@ -83,6 +84,7 @@ asn1 = "0.13.0" bitfield = "0.14.0" bitflags = "2.0.1" 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_common = { path = "common", default-features = false } diff --git a/FROZEN_IMAGES.sha384sum b/FROZEN_IMAGES.sha384sum index b6c71e695c..5427bb1453 100644 --- a/FROZEN_IMAGES.sha384sum +++ b/FROZEN_IMAGES.sha384sum @@ -1,3 +1,3 @@ # WARNING: Do not update this file without the approval of the Caliptra TAC -3b3d2e3fc803aebed8334ddb2db470403b232a7de70a1394e19149ae5280e6c357235cec2f64ebd8d229efa2f8f4cac9 caliptra-rom-no-log.bin -a309276ecd74586409d9f0c01a75c3c1ab43a72fa3a5fee6527a3dc6a3bfc5e6334ddf73e58dd2cb3ab142b273cb6b20 caliptra-rom-with-log.bin +2c7b77ae40e6c760a26fe37d1a3b45910435196f642ef76f1df96e49eec5cf710fb7159d89189a0b4eae47007ddc2b98 caliptra-rom-no-log.bin +0c518139f1cd88acbd06ff4e24b28823008347ce5186e84af54adabedcd00c52b3ad9b6a0e6aaf8514b4dfafed5b64cb caliptra-rom-with-log.bin diff --git a/api/Cargo.toml b/api/Cargo.toml new file mode 100644 index 0000000000..f1d082579d --- /dev/null +++ b/api/Cargo.toml @@ -0,0 +1,13 @@ +# Licensed under the Apache-2.0 license + +[package] +name = "caliptra-api" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bitflags.workspace = true +caliptra-error.workspace = true +zerocopy.workspace = true diff --git a/common/src/capabilities.rs b/api/src/capabilities.rs similarity index 100% rename from common/src/capabilities.rs rename to api/src/capabilities.rs diff --git a/common/src/checksum.rs b/api/src/checksum.rs similarity index 100% rename from common/src/checksum.rs rename to api/src/checksum.rs diff --git a/api/src/lib.rs b/api/src/lib.rs new file mode 100644 index 0000000000..5bf5d67ac6 --- /dev/null +++ b/api/src/lib.rs @@ -0,0 +1,11 @@ +// Licensed under the Apache-2.0 license + +#![no_std] + +mod capabilities; +mod checksum; +pub mod mailbox; + +pub use caliptra_error as error; +pub use capabilities::Capabilities; +pub use checksum::{calc_checksum, verify_checksum}; diff --git a/common/src/mailbox_api.rs b/api/src/mailbox.rs similarity index 99% rename from common/src/mailbox_api.rs rename to api/src/mailbox.rs index 6580cd2346..eb745238dc 100644 --- a/common/src/mailbox_api.rs +++ b/api/src/mailbox.rs @@ -1,6 +1,6 @@ // Licensed under the Apache-2.0 license -use caliptra_drivers::{CaliptraError, CaliptraResult}; +use caliptra_error::{CaliptraError, CaliptraResult}; use core::mem::size_of; use zerocopy::{AsBytes, FromBytes, LayoutVerified}; diff --git a/common/Cargo.toml b/common/Cargo.toml index aee64dacfc..475d8593bd 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -13,6 +13,7 @@ caliptra-cpu.workspace = true caliptra-drivers.workspace = true caliptra-image-types = { workspace = true, default-features = false } caliptra-image-verify.workspace = true +caliptra-api.workspace = true caliptra-registers.workspace = true ufmt.workspace = true zerocopy.workspace = true diff --git a/common/src/lib.rs b/common/src/lib.rs index 37ae413126..c1ebd6f0c6 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -3,14 +3,17 @@ #![cfg_attr(not(feature = "std"), no_std)] pub mod boot_status; -pub mod capabilities; -pub mod checksum; +pub mod capabilities { + pub use caliptra_api::Capabilities; +} +pub mod checksum { + pub use caliptra_api::{calc_checksum, verify_checksum}; +} pub mod crypto; pub mod dice; pub mod error_handler; pub mod fips; pub mod keyids; -pub mod mailbox_api; pub mod verifier; pub mod wdt; @@ -21,6 +24,7 @@ pub use hand_off::{ }; pub use boot_status::RomBootStatus; +pub use caliptra_api::mailbox as mailbox_api; pub use caliptra_drivers::cprint; pub use caliptra_drivers::cprintln; pub use caliptra_drivers::fuse_log as fuse; diff --git a/hw-model/Cargo.toml b/hw-model/Cargo.toml index 206440064d..8b57295f60 100644 --- a/hw-model/Cargo.toml +++ b/hw-model/Cargo.toml @@ -16,12 +16,12 @@ itrng = ["caliptra-verilated?/itrng"] [dependencies] bitfield.workspace = true bit-vec.workspace = true -caliptra_common = { workspace = true, default-features = false } caliptra-emu-bus.workspace = true caliptra-emu-cpu.workspace = true caliptra-emu-periph.workspace = true caliptra-emu-types.workspace = true caliptra-hw-model-types.workspace = true +caliptra-api.workspace = true caliptra-registers.workspace = true caliptra-verilated = { workspace = true, optional = true } rand.workspace = true diff --git a/hw-model/src/lib.rs b/hw-model/src/lib.rs index 7f714b2e5d..fb51f961dc 100644 --- a/hw-model/src/lib.rs +++ b/hw-model/src/lib.rs @@ -7,7 +7,7 @@ use std::{ io::{stdout, ErrorKind, Write}, }; -use caliptra_common::mailbox_api::{self, StashMeasurementResp}; +use caliptra_api as api; use caliptra_emu_bus::Bus; use caliptra_hw_model_types::{ ErrorInjectionMode, EtrngResponse, RandomEtrngResponses, RandomNibbles, DEFAULT_CPTRA_OBF_KEY, @@ -889,11 +889,11 @@ pub trait HwModel { let response = response.ok_or(ModelError::UploadMeasurementResponseError)?; // Get response as a response header struct - let response = StashMeasurementResp::read_from(response.as_slice()) + let response = api::mailbox::StashMeasurementResp::read_from(response.as_slice()) .ok_or(ModelError::UploadMeasurementResponseError)?; // Verify checksum and FIPS status - if !caliptra_common::checksum::verify_checksum( + if !api::verify_checksum( response.hdr.chksum, 0x0, &response.as_bytes()[core::mem::size_of_val(&response.hdr.chksum)..], @@ -901,7 +901,7 @@ pub trait HwModel { return Err(ModelError::UploadMeasurementResponseError); } - if response.hdr.fips_status != mailbox_api::MailboxRespHeader::FIPS_STATUS_APPROVED { + if response.hdr.fips_status != api::mailbox::MailboxRespHeader::FIPS_STATUS_APPROVED { return Err(ModelError::UploadMeasurementResponseError); }