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 9, 2025
1 parent 0eba271 commit 79b5081
Show file tree
Hide file tree
Showing 31 changed files with 233 additions and 260 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.

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
8 changes: 4 additions & 4 deletions drivers/src/data_vault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Abstract:
--*/

use crate::{Array4x12, Ecc384PubKey, Ecc384Signature, Mldsa87PubKey, Mldsa87Signature};
use zerocopy::{AsBytes, FromBytes};
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use zeroize::Zeroize;

#[repr(C)]
#[derive(FromBytes, AsBytes, Zeroize, Default)]
#[derive(Default, FromBytes, Immutable, IntoBytes, KnownLayout, Zeroize)]
pub struct ColdResetEntries {
ldev_dice_ecc_sig: Ecc384Signature,
ldev_dice_ecc_pk: Ecc384PubKey,
Expand All @@ -37,7 +37,7 @@ pub struct ColdResetEntries {
}

#[repr(C)]
#[derive(FromBytes, AsBytes, Zeroize, Default)]
#[derive(Default, FromBytes, Immutable, IntoBytes, KnownLayout, Zeroize)]
pub struct WarmResetEntries {
rt_tci: Array4x12,
fw_svn: u32,
Expand All @@ -48,7 +48,7 @@ pub struct WarmResetEntries {
}

#[repr(C)]
#[derive(FromBytes, AsBytes, Zeroize, Default)]
#[derive(Default, FromBytes, Immutable, IntoBytes, KnownLayout, Zeroize)]
pub struct DataVault {
cold_reset_entries: ColdResetEntries,
warm_reset_entries: WarmResetEntries,
Expand Down
4 changes: 2 additions & 2 deletions drivers/src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use caliptra_registers::i3ccsr::RegisterBlock as I3CRegisterBlock;
use core::cell::Cell;
use core::ops::Add;
use ureg::{Mmio, MmioMut, RealMmioMut};
use zerocopy::AsBytes;
use zerocopy::IntoBytes;

use crate::cprintln;

Expand Down Expand Up @@ -298,7 +298,7 @@ impl Dma {
/// * `CaliptraResult<u32>` - Read value or error code
pub fn read_dword(&self, read_addr: AxiAddr) -> CaliptraResult<u32> {
let mut read_val: u32 = 0;
self.read_buffer(read_addr, read_val.as_bytes_mut())?;
self.read_buffer(read_addr, read_val.as_mut_bytes())?;
Ok(read_val)
}

Expand Down
Loading

0 comments on commit 79b5081

Please sign in to comment.