Skip to content

Commit

Permalink
sw-emulator: Add dilithium peripheral (#1623)
Browse files Browse the repository at this point in the history
This change contains the Dilithium peripheral.
  • Loading branch information
ArthurHeymans authored Aug 27, 2024
1 parent ef83a0d commit 79aeef2
Show file tree
Hide file tree
Showing 8 changed files with 1,292 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ dpe = { path = "dpe/dpe", default-features = false, features = ["dpe_profile_p38
crypto = { path = "dpe/crypto", default-features = false }
platform = { path = "dpe/platform", default-features = false }
elf = "0.7.2"
fips204 = "0.2.1"
gdbstub = "0.6.3"
gdbstub_arch = "0.2.4"
getrandom = "0.2"
Expand Down
2 changes: 2 additions & 0 deletions sw-emulator/lib/periph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ caliptra-emu-derive.workspace = true
caliptra-emu-types.workspace = true
caliptra-hw-model-types.workspace = true
caliptra-registers.workspace = true
fips204.workspace = true
lazy_static.workspace = true
rand.workspace = true
sha3.workspace = true
smlang.workspace = true
tock-registers.workspace = true
Expand Down
14 changes: 11 additions & 3 deletions sw-emulator/lib/periph/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pub trait U32Array: AsRef<[u32]> {
}
pub trait U32ArrayBytes: AsRef<[u8]> {
const WORD_LEN: usize;
type WordArray: AsMut<[u32]> + Default;
type WordArray: AsMut<[u32]>;
// Required because Default isn't implemented for [u32; 64 and higher]
fn default_result() -> Self::WordArray;
}
macro_rules! u32_array_impl {
($word_len:literal) => {
Expand All @@ -37,6 +39,9 @@ macro_rules! u32_array_impl {
impl U32ArrayBytes for [u8; $word_len * 4] {
const WORD_LEN: usize = $word_len;
type WordArray = [u32; $word_len];
fn default_result() -> Self::WordArray {
[0u32; $word_len]
}
}
};
}
Expand All @@ -58,17 +63,20 @@ u32_array_impl!(14);
u32_array_impl!(15);
u32_array_impl!(16);
u32_array_impl!(32);
u32_array_impl!(648);
u32_array_impl!(1157);
u32_array_impl!(1224);

pub fn words_from_bytes_le<A: U32ArrayBytes>(arr: &A) -> A::WordArray {
let mut result = A::WordArray::default();
let mut result = A::default_result();
for i in 0..result.as_mut().len() {
result.as_mut()[i] = u32::from_le_bytes(arr.as_ref()[i * 4..][..4].try_into().unwrap())
}
result
}

pub fn words_from_bytes_be<A: U32ArrayBytes>(arr: &A) -> A::WordArray {
let mut result = A::WordArray::default();
let mut result = A::default_result();
for i in 0..result.as_mut().len() {
result.as_mut()[i] = u32::from_be_bytes(arr.as_ref()[i * 4..][..4].try_into().unwrap())
}
Expand Down
1 change: 1 addition & 0 deletions sw-emulator/lib/periph/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mod hmac_sha384;
mod iccm;
mod key_vault;
mod mailbox;
mod ml_dsa87;
mod root_bus;
mod sha512_acc;
pub mod soc_reg;
Expand Down
Loading

0 comments on commit 79aeef2

Please sign in to comment.