Skip to content

Commit

Permalink
Convert the new code to zerocopy
Browse files Browse the repository at this point in the history
  • Loading branch information
swenson committed Feb 12, 2025
1 parent 721037e commit 621f273
Show file tree
Hide file tree
Showing 34 changed files with 246 additions and 273 deletions.
81 changes: 27 additions & 54 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions api/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ impl Response for AuthorizeAndStashResp {}

// MANUF_DEBUG_UNLOCK_REQ_TOKEN
#[repr(C)]
#[derive(Debug, AsBytes, FromBytes, PartialEq, Eq, Default)]
#[derive(Debug, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq, Default)]
pub struct ManufDebugUnlockTokenReq {
pub hdr: MailboxReqHeader,
pub token: [u8; 16],
Expand All @@ -1107,7 +1107,7 @@ impl Request for ManufDebugUnlockTokenReq {

// PRODUCTION_AUTH_DEBUG_UNLOCK_REQ
#[repr(C)]
#[derive(Debug, AsBytes, FromBytes, PartialEq, Eq, Default)]
#[derive(Debug, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq, Default)]
pub struct ProductionAuthDebugUnlockReq {
pub hdr: MailboxReqHeader,
pub vendor_id: u16, // Vendor ID (2 bytes)
Expand All @@ -1126,7 +1126,7 @@ impl Request for ProductionAuthDebugUnlockReq {

// PRODUCTION_AUTH_DEBUG_UNLOCK_CHALLENGE
#[repr(C)]
#[derive(Debug, AsBytes, FromBytes, PartialEq, Eq)]
#[derive(Debug, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq)]
pub struct ProductionAuthDebugUnlockChallenge {
pub hdr: MailboxRespHeader,
pub vendor_id: u16, // Vendor ID (2 bytes)
Expand Down Expand Up @@ -1155,7 +1155,7 @@ impl Response for ProductionAuthDebugUnlockChallenge {}

// PRODUCTION_AUTH_DEBUG_UNLOCK_TOKEN
#[repr(C)]
#[derive(Debug, AsBytes, FromBytes, PartialEq, Eq)]
#[derive(Debug, FromBytes, Immutable, IntoBytes, KnownLayout, PartialEq, Eq)]
pub struct ProductionAuthDebugUnlockToken {
pub hdr: MailboxReqHeader,
pub vendor_id: u16, // Vendor ID (2 bytes)
Expand Down
2 changes: 1 addition & 1 deletion auth-manifest/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub struct AuthorizationManifest {
#[cfg(test)]
mod test {
use crate::{AuthManifestPreamble, AUTH_MANIFEST_PREAMBLE_SIZE};
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

#[test]
fn test_auth_preamble_size() {
Expand Down
12 changes: 7 additions & 5 deletions common/src/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use caliptra_drivers::*;
use caliptra_image_types::*;
use caliptra_image_verify::ImageVerificationEnv;
use core::ops::Range;
use zerocopy::{AsBytes, FromBytes};
use zerocopy::{FromBytes, IntoBytes};

use caliptra_drivers::memory_layout::ICCM_RANGE;

Expand Down Expand Up @@ -104,17 +104,19 @@ impl<'a, 'b> ImageVerificationEnv for &mut FirmwareImageVerificationEnv<'a, 'b>
.as_bytes()
.try_into()
.map_err(|_| CaliptraError::IMAGE_VERIFIER_ERR_MLDSA_TYPE_CONVERSION_FAILED)?;
let pub_key = Mldsa87PubKey::read_from(pub_key_bytes.as_bytes())
.ok_or(CaliptraError::IMAGE_VERIFIER_ERR_MLDSA_TYPE_CONVERSION_FAILED)?;
let pub_key = Mldsa87PubKey::read_from_bytes(pub_key_bytes.as_bytes()).or(Err(
CaliptraError::IMAGE_VERIFIER_ERR_MLDSA_TYPE_CONVERSION_FAILED,
))?;

// Signature is received in hw format from the image. No conversion needed.
let sig_bytes: [u8; MLDSA87_SIGNATURE_BYTE_SIZE] = sig
.0
.as_bytes()
.try_into()
.map_err(|_| CaliptraError::IMAGE_VERIFIER_ERR_MLDSA_TYPE_CONVERSION_FAILED)?;
let sig = Mldsa87Signature::read_from(sig_bytes.as_bytes())
.ok_or(CaliptraError::IMAGE_VERIFIER_ERR_MLDSA_TYPE_CONVERSION_FAILED)?;
let sig = Mldsa87Signature::read_from_bytes(sig_bytes.as_bytes()).or(Err(
CaliptraError::IMAGE_VERIFIER_ERR_MLDSA_TYPE_CONVERSION_FAILED,
))?;

// digest is received in hw format. No conversion needed.
let msg = digest.into();
Expand Down
2 changes: 1 addition & 1 deletion common/src/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Abstract:
use caliptra_drivers::*;
use core::mem::size_of;
use core::usize;
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

use crate::crypto::PubKey;

Expand Down
Loading

0 comments on commit 621f273

Please sign in to comment.