Skip to content

Commit

Permalink
Extract API logic from caliptra_common into new caliptra-api crate.
Browse files Browse the repository at this point in the history
Host libraries should not have transitive deps on caliptra-drivers.
  • Loading branch information
korran committed Oct 24, 2023
1 parent 8960eab commit 7279e28
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 12 deletions.
12 changes: 11 additions & 1 deletion 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 @@ -22,6 +22,7 @@ exclude = [
]

members = [
"api",
"builder",
"cfi/lib",
"cfi/derive",
Expand Down Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions FROZEN_IMAGES.sha384sum
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
2 changes: 1 addition & 1 deletion common/src/mailbox_api.rs → api/src/mailbox.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
1 change: 1 addition & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion hw-model/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions hw-model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -889,19 +889,19 @@ 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)..],
) {
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);
}

Expand Down

0 comments on commit 7279e28

Please sign in to comment.