Skip to content

Commit

Permalink
Moving mailbox_api to common from runtime (chipsalliance#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
nquarton authored Aug 18, 2023
1 parent 4a9529f commit 38cd0a7
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 34 deletions.
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod crypto;
pub mod dice;
pub mod fuse;
pub mod keyids;
pub mod mailbox_api;
pub mod pcr;
pub mod wdt;

Expand Down
3 changes: 1 addition & 2 deletions runtime/src/mailbox_api.rs → common/src/mailbox_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ impl MailboxResp {
/// Takes into account the size override for variable-lenth payloads
pub fn populate_chksum(&mut self) -> CaliptraResult<()> {
// Calc checksum, use the size override if provided
let checksum =
caliptra_common::checksum::calc_checksum(0, &self.as_bytes()[size_of::<i32>()..]);
let checksum = crate::checksum::calc_checksum(0, &self.as_bytes()[size_of::<i32>()..]);

// cast as header struct
let hdr: &mut MailboxRespHeader = LayoutVerified::<&mut [u8], MailboxRespHeader>::new(
Expand Down
4 changes: 3 additions & 1 deletion runtime/src/dice.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed under the Apache-2.0 license
#[cfg(feature = "test_only_commands")]
use crate::{GetLdevCertResp, MailboxResp, MailboxRespHeader, TestGetFmcAliasCertResp};
use caliptra_common::mailbox_api::{
GetLdevCertResp, MailboxResp, MailboxRespHeader, TestGetFmcAliasCertResp,
};
use caliptra_drivers::{CaliptraError, CaliptraResult, DataVault};
use caliptra_x509::{Ecdsa384CertBuilder, Ecdsa384Signature, FmcAliasCertTbs, LocalDevIdCertTbs};

Expand Down
3 changes: 2 additions & 1 deletion runtime/src/disable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Licensed under the Apache-2.0 license

use crate::{Drivers, MailboxResp};
use crate::Drivers;
use caliptra_common::keyids::{KEY_ID_RT_CDI, KEY_ID_RT_PRIV_KEY};
use caliptra_common::mailbox_api::MailboxResp;
use caliptra_drivers::{
hmac384_kdf, CaliptraError, CaliptraResult, KeyReadArgs, KeyUsage, KeyWriteArgs,
};
Expand Down
3 changes: 2 additions & 1 deletion runtime/src/fips.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed under the Apache-2.0 license

use caliptra_common::cprintln;
use caliptra_common::mailbox_api::{FipsVersionResp, MailboxResp, MailboxRespHeader};
use caliptra_drivers::CaliptraError;
use caliptra_drivers::CaliptraResult;
use caliptra_drivers::Ecc384;
Expand All @@ -12,7 +13,7 @@ use caliptra_drivers::Sha384Acc;
use caliptra_kat::{Ecc384Kat, Hmac384Kat, Sha256Kat, Sha384AccKat, Sha384Kat};
use caliptra_registers::mbox::enums::MboxStatusE;

use crate::{Drivers, FipsVersionResp, MailboxResp, MailboxRespHeader};
use crate::Drivers;

pub struct FipsModule;

Expand Down
3 changes: 2 additions & 1 deletion runtime/src/info.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed under the Apache-2.0 license

use crate::{Drivers, FwInfoResp, MailboxResp, MailboxRespHeader};
use crate::Drivers;
use caliptra_common::mailbox_api::{FwInfoResp, MailboxResp, MailboxRespHeader};
use caliptra_drivers::CaliptraResult;

pub struct FwInfoCmd;
Expand Down
6 changes: 2 additions & 4 deletions runtime/src/invoke_dpe.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// Licensed under the Apache-2.0 license

use crate::{
CptraDpeTypes, DpeCrypto, DpeEnv, DpePlatform, Drivers, InvokeDpeReq, InvokeDpeResp,
MailboxResp, MailboxRespHeader,
};
use crate::{CptraDpeTypes, DpeCrypto, DpeEnv, DpePlatform, Drivers};
use caliptra_common::mailbox_api::{InvokeDpeReq, InvokeDpeResp, MailboxResp, MailboxRespHeader};
use caliptra_drivers::{CaliptraError, CaliptraResult};
use zerocopy::FromBytes;

Expand Down
13 changes: 3 additions & 10 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,19 @@ mod verify;
pub mod mailbox;
use mailbox::Mailbox;

pub mod mailbox_api;
pub use mailbox_api::{
CommandId, EcdsaVerifyReq, FipsVersionResp, FwInfoResp, GetIdevCsrResp, GetLdevCertResp,
HmacVerifyReq, InvokeDpeReq, InvokeDpeResp, MailboxReqHeader, MailboxResp, MailboxRespHeader,
StashMeasurementReq, StashMeasurementResp, TestGetFmcAliasCertResp,
};

use dpe_crypto::DpeCrypto;
pub use dpe_platform::{DpePlatform, VENDOR_ID, VENDOR_SKU};

#[cfg(feature = "test_only_commands")]
pub use dice::{GetLdevCertCmd, TestGetFmcAliasCertCmd};
pub use disable::DisableAttestationCmd;
use dpe_crypto::DpeCrypto;
pub use dpe_platform::{DpePlatform, VENDOR_ID, VENDOR_SKU};
pub use fips::{FipsSelfTestCmd, FipsShutdownCmd, FipsVersionCmd};
pub use info::FwInfoCmd;
pub use invoke_dpe::InvokeDpeCmd;
pub use verify::EcdsaVerifyCmd;
pub mod packet;
use packet::Packet;

use caliptra_common::mailbox_api::CommandId;
use caliptra_common::memory_layout::{
FHT_ORG, FHT_SIZE, FMCALIAS_TBS_ORG, FMCALIAS_TBS_SIZE, FUSE_LOG_ORG, FUSE_LOG_SIZE,
LDEVID_TBS_ORG, LDEVID_TBS_SIZE, MAN1_ORG, MAN1_SIZE, MAN2_ORG, MAN2_SIZE, PCR_LOG_ORG,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// License by Apache-2.0
use caliptra_drivers::CaliptraResult;

use crate::mailbox_api::{MailboxReqHeader, MailboxResp};
use caliptra_common::mailbox_api::{MailboxReqHeader, MailboxResp};
use caliptra_drivers::CaliptraError;
use zerocopy::{AsBytes, LayoutVerified};

Expand Down
5 changes: 3 additions & 2 deletions runtime/src/verify.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Licensed under the Apache-2.0 license

use crate::Drivers;
#[cfg(feature = "test_only_commands")]
use crate::HmacVerifyReq;
use crate::{Drivers, EcdsaVerifyReq, MailboxResp};
use caliptra_common::mailbox_api::HmacVerifyReq;
use caliptra_common::mailbox_api::{EcdsaVerifyReq, MailboxResp};
use caliptra_drivers::{
Array4x12, CaliptraError, CaliptraResult, Ecc384PubKey, Ecc384Result, Ecc384Scalar,
Ecc384Signature,
Expand Down
3 changes: 2 additions & 1 deletion runtime/test-fw/src/cert_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#![no_main]
#![no_std]

use caliptra_common::mailbox_api::CommandId;
use caliptra_registers::mbox::enums::MboxStatusE;
use caliptra_runtime::{dice, CommandId, Drivers};
use caliptra_runtime::{dice, Drivers};
use caliptra_test_harness::{runtime_handlers, test_suite};
use zerocopy::AsBytes;

Expand Down
4 changes: 3 additions & 1 deletion runtime/tests/ecdsa.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Licensed under the Apache-2.0 license.
pub mod common;

use caliptra_common::mailbox_api::{
CommandId, EcdsaVerifyReq, MailboxReqHeader, MailboxRespHeader,
};
use caliptra_hw_model::{HwModel, ShaAccMode};
use caliptra_runtime::{CommandId, EcdsaVerifyReq, MailboxReqHeader, MailboxRespHeader};
use common::run_rom_test;
use zerocopy::{AsBytes, FromBytes};

Expand Down
2 changes: 1 addition & 1 deletion runtime/tests/hmac.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Licensed under the Apache-2.0 license.
pub mod common;

use caliptra_common::mailbox_api::{CommandId, HmacVerifyReq, MailboxReqHeader, MailboxRespHeader};
use caliptra_hw_model::HwModel;
use caliptra_runtime::{CommandId, HmacVerifyReq, MailboxReqHeader, MailboxRespHeader};
use common::run_rt_test;
use zerocopy::{AsBytes, FromBytes};

Expand Down
10 changes: 5 additions & 5 deletions runtime/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
pub mod common;

use caliptra_builder::{ImageOptions, APP_WITH_UART, FMC_WITH_UART};
use caliptra_common::mailbox_api::{
CommandId, EcdsaVerifyReq, FipsVersionResp, FwInfoResp, InvokeDpeReq, InvokeDpeResp,
MailboxReqHeader, MailboxRespHeader,
};
use caliptra_drivers::Ecc384PubKey;
use caliptra_hw_model::{HwModel, ModelError, ShaAccMode};
use caliptra_runtime::{
CommandId, EcdsaVerifyReq, FipsVersionCmd, FipsVersionResp, FwInfoResp, InvokeDpeReq,
InvokeDpeResp, MailboxReqHeader, MailboxRespHeader, RtBootStatus, DPE_SUPPORT, VENDOR_ID,
VENDOR_SKU,
};
use caliptra_runtime::{FipsVersionCmd, RtBootStatus, DPE_SUPPORT, VENDOR_ID, VENDOR_SKU};
use common::{run_rom_test, run_rt_test};
use dpe::{
commands::{Command, CommandHdr},
Expand Down
6 changes: 3 additions & 3 deletions test/tests/smoke_test.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Licensed under the Apache-2.0 license

use caliptra_builder::{ImageOptions, APP_WITH_UART, FMC_WITH_UART, ROM_WITH_UART};
use caliptra_hw_model::{BootParams, HwModel, InitParams, SecurityState};
use caliptra_hw_model_types::{DeviceLifecycle, Fuses};
use caliptra_runtime::{
use caliptra_common::mailbox_api::{
CommandId, GetLdevCertResp, MailboxReqHeader, MailboxRespHeader, TestGetFmcAliasCertResp,
};
use caliptra_hw_model::{BootParams, HwModel, InitParams, SecurityState};
use caliptra_hw_model_types::{DeviceLifecycle, Fuses};
use caliptra_test::{
derive::{DoeInput, DoeOutput, FmcAliasKey, IDevId, LDevId, Pcr0, Pcr0Input},
swap_word_bytes, swap_word_bytes_inplace,
Expand Down

0 comments on commit 38cd0a7

Please sign in to comment.