Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Zero copy from 0.6.6 to 0.8.3 #360

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ members = [
[workspace.dependencies]
caliptra-cfi-lib-git = { git = "https://github.com/chipsalliance/caliptra-cfi.git", package = "caliptra-cfi-lib-git", rev = "a98e499d279e81ae85881991b1e9eee354151189", 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 = "a98e499d279e81ae85881991b1e9eee354151189"}
zerocopy = "0.6.6"
zerocopy = { version = "0.8.3", features = ["derive"] }
openssl = "0.10.64"

[profile.firmware]
inherits = "release"
panic = "abort"
lto = true
opt-level = "s"
codegen-units = 1
codegen-units = 1
4 changes: 3 additions & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ run_verification_tests dpe_profile_p384_sha384 rustcrypto
cargo fmt --check
cargo clippy --features libfuzzer-sys
cargo clippy --features afl
cargo +nightly-2023-11-16 fuzz build --features libfuzzer-sys
# https://github.com/google/zerocopy/issues/1867
# Currently this fuzzer fails to compile when using zerocopy v0.8.3.
# cargo +nightly-2023-11-16 fuzz build --features libfuzzer-sys
cargo +nightly-2023-11-16 afl build --features afl
)

Expand Down
22 changes: 19 additions & 3 deletions dpe/src/commands/certify_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ use platform::MAX_ISSUER_NAME_SIZE;
use platform::{Platform, PlatformError, MAX_KEY_IDENTIFIER_SIZE};

#[repr(C)]
#[derive(Debug, PartialEq, Eq, zerocopy::FromBytes, zerocopy::AsBytes)]
#[derive(
Debug,
PartialEq,
Eq,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
)]
pub struct CertifyKeyFlags(u32);

bitflags! {
Expand All @@ -31,7 +39,15 @@ bitflags! {
}

#[repr(C)]
#[derive(Debug, PartialEq, Eq, zerocopy::FromBytes, zerocopy::AsBytes)]
#[derive(
Debug,
PartialEq,
Eq,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
)]
pub struct CertifyKeyCmd {
pub handle: ContextHandle,
pub flags: CertifyKeyFlags,
Expand Down Expand Up @@ -322,7 +338,7 @@ mod tests {
use x509_parser::prelude::X509CertificateParser;
use x509_parser::prelude::X509CertificationRequest;
use x509_parser::prelude::*;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

const TEST_CERTIFY_KEY_CMD: CertifyKeyCmd = CertifyKeyCmd {
handle: SIMULATION_HANDLE,
Expand Down
22 changes: 19 additions & 3 deletions dpe/src/commands/derive_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ use caliptra_cfi_lib_git::{cfi_assert, cfi_assert_eq};
use cfg_if::cfg_if;

#[repr(C)]
#[derive(Debug, PartialEq, Eq, zerocopy::FromBytes, zerocopy::AsBytes)]
#[derive(
Debug,
PartialEq,
Eq,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
)]
pub struct DeriveContextFlags(u32);

bitflags! {
Expand All @@ -32,7 +40,15 @@ bitflags! {
}

#[repr(C)]
#[derive(Debug, PartialEq, Eq, zerocopy::FromBytes, zerocopy::AsBytes)]
#[derive(
Debug,
PartialEq,
Eq,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
)]
pub struct DeriveContextCmd {
pub handle: ContextHandle,
pub data: [u8; DPE_PROFILE.get_hash_size()],
Expand Down Expand Up @@ -356,7 +372,7 @@ mod tests {
use openssl::x509::X509;
use openssl::{bn::BigNum, ecdsa::EcdsaSig};
use platform::default::DefaultPlatform;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

const TEST_DERIVE_CONTEXT_CMD: DeriveContextCmd = DeriveContextCmd {
handle: SIMULATION_HANDLE,
Expand Down
12 changes: 10 additions & 2 deletions dpe/src/commands/destroy_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ use caliptra_cfi_lib_git::cfi_launder;
use caliptra_cfi_lib_git::{cfi_assert, cfi_assert_eq};

#[repr(C)]
#[derive(Debug, PartialEq, Eq, zerocopy::FromBytes, zerocopy::AsBytes)]
#[derive(
Debug,
PartialEq,
Eq,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
)]
pub struct DestroyCtxCmd {
pub handle: ContextHandle,
}
Expand Down Expand Up @@ -97,7 +105,7 @@ mod tests {
use caliptra_cfi_lib_git::CfiCounter;
use crypto::OpensslCrypto;
use platform::default::DefaultPlatform;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

const TEST_DESTROY_CTX_CMD: DestroyCtxCmd = DestroyCtxCmd {
handle: SIMULATION_HANDLE,
Expand Down
12 changes: 10 additions & 2 deletions dpe/src/commands/get_certificate_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ use caliptra_cfi_derive_git::cfi_impl_fn;
use platform::{Platform, MAX_CHUNK_SIZE};

#[repr(C)]
#[derive(Debug, PartialEq, Eq, zerocopy::FromBytes, zerocopy::AsBytes)]
#[derive(
Debug,
PartialEq,
Eq,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
)]
pub struct GetCertificateChainCmd {
pub offset: u32,
pub size: u32,
Expand Down Expand Up @@ -51,7 +59,7 @@ mod tests {
use caliptra_cfi_lib_git::CfiCounter;
use crypto::OpensslCrypto;
use platform::default::DefaultPlatform;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

const TEST_GET_CERTIFICATE_CHAIN_CMD: GetCertificateChainCmd = GetCertificateChainCmd {
offset: 0,
Expand Down
12 changes: 10 additions & 2 deletions dpe/src/commands/initialize_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ use caliptra_cfi_lib_git::{cfi_assert, cfi_assert_eq};
use cfg_if::cfg_if;

#[repr(C)]
#[derive(Debug, PartialEq, Eq, zerocopy::FromBytes, zerocopy::AsBytes)]
#[derive(
Debug,
PartialEq,
Eq,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
)]
pub struct InitCtxCmd(u32);

bitflags! {
Expand Down Expand Up @@ -112,7 +120,7 @@ mod tests {
use caliptra_cfi_lib_git::CfiCounter;
use crypto::OpensslCrypto;
use platform::default::DefaultPlatform;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

const TEST_INIT_CTX_CMD: InitCtxCmd = InitCtxCmd(0x1234_5678);

Expand Down
21 changes: 15 additions & 6 deletions dpe/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ impl Command {
build: impl FnOnce(T) -> Command,
bytes: &[u8],
) -> Result<Command, DpeErrorCode> {
Ok(build(
T::read_from_prefix(bytes).ok_or(DpeErrorCode::InvalidArgument)?,
))
let (prefix, _remaining_bytes) =
T::read_from_prefix(bytes).map_err(|_| DpeErrorCode::InvalidArgument)?;
Ok(build(prefix))
}
}

Expand Down Expand Up @@ -130,7 +130,15 @@ pub trait CommandExecution {
// ABI Command structures

#[repr(C)]
#[derive(Debug, PartialEq, Eq, zerocopy::FromBytes, zerocopy::AsBytes)]
#[derive(
Debug,
PartialEq,
Eq,
zerocopy::FromBytes,
zerocopy::IntoBytes,
zerocopy::Immutable,
zerocopy::KnownLayout,
)]
pub struct CommandHdr {
pub magic: u32,
pub cmd_id: u32,
Expand All @@ -153,7 +161,8 @@ impl TryFrom<&[u8]> for CommandHdr {
type Error = DpeErrorCode;

fn try_from(raw: &[u8]) -> Result<Self, Self::Error> {
let header = CommandHdr::read_from_prefix(raw).ok_or(DpeErrorCode::InvalidCommand)?;
let (header, _remaining_bytes) =
CommandHdr::read_from_prefix(raw).map_err(|_| DpeErrorCode::InvalidCommand)?;
if header.magic != Self::DPE_COMMAND_MAGIC {
return Err(DpeErrorCode::InvalidCommand);
}
Expand All @@ -171,7 +180,7 @@ pub mod tests {
use super::*;
use crate::{DpeProfile, DPE_PROFILE};
use caliptra_cfi_lib_git::CfiCounter;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

#[cfg(feature = "dpe_profile_p256_sha256")]
pub const TEST_DIGEST: [u8; DPE_PROFILE.get_hash_size()] = [
Expand Down
Loading
Loading