Skip to content
Open
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
2 changes: 2 additions & 0 deletions libcrux-iot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ readme = "README.md"
[workspace.dependencies]
libcrux-secrets = { version = "0.0.4" }
libcrux-macros = { version = "0.0.3" }
libcrux-traits = { version = "0.0.4" }

cavp = { version = "0.0.2" }
hax-lib = { version = "0.3.2" }

Expand Down
3 changes: 2 additions & 1 deletion libcrux-iot/sha3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bench = false # so libtest doesn't eat the arguments to criterion

[dependencies]
libcrux-secrets.workspace = true
libcrux-traits.workspace = true

# This is only required for verification.
# The hax config is set by the hax toolchain.
Expand All @@ -25,7 +26,7 @@ hax-lib = { version = "0.3.0", git = "https://github.com/hacspec/hax/" }

[features]
full-unroll = []
check-secret-independence = ["libcrux-secrets/check-secret-independence"]
check-secret-independence = ["libcrux-secrets/check-secret-independence", "libcrux-traits/check-secret-independence"]

[dev-dependencies]
criterion = "0.5.1"
Expand Down
56 changes: 56 additions & 0 deletions libcrux-iot/sha3/src/impl_digest_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::*;

const SHA3_224_LEN: usize = 28;
const SHA3_256_LEN: usize = 32;
const SHA3_384_LEN: usize = 48;
const SHA3_512_LEN: usize = 64;

macro_rules! impl_hash_traits {
($type:ident, $hasher:ident, $len:expr, $method:expr) => {
#[doc = concat!("A struct that implements [`libcrux_traits::digest`] traits.")]
#[doc = concat!("\n\n")]
#[doc = concat!("[`",stringify!($hasher), "`] is a convenient hasher for this struct.")]
pub struct $type;

#[doc = concat!("A hasher for [`",stringify!($type), "`].")]
pub type $hasher = libcrux_traits::digest::Hasher<$len, $type>;

impl libcrux_traits::digest::arrayref::Hash<$len> for $type {
#[inline(always)]
fn hash(
digest: &mut [u8; $len],
payload: &[u8],
) -> Result<(), libcrux_traits::digest::arrayref::HashError> {
use libcrux_traits::libcrux_secrets::{ClassifyRef, ClassifyRefMut};

if payload.len() > u32::MAX as usize {
return Err(libcrux_traits::digest::arrayref::HashError::InvalidPayloadLength);
}

$method(
digest.as_mut_slice().classify_ref_mut(),
payload.classify_ref(),
);

Ok(())
}
}
};
}

impl_hash_traits!(Sha3_224, Sha3_224Hasher, SHA3_224_LEN, portable::sha224);
impl_hash_traits!(Sha3_256, Sha3_256Hasher, SHA3_256_LEN, portable::sha256);
impl_hash_traits!(Sha3_384, Sha3_384Hasher, SHA3_384_LEN, portable::sha384);
impl_hash_traits!(Sha3_512, Sha3_512Hasher, SHA3_512_LEN, portable::sha512);

// Implement the slice hash trait
// This is excluded for the hax extraction
#[cfg_attr(hax, hax_lib::exclude)]
mod slice {
use super::*;

libcrux_traits::digest::slice::impl_hash_trait!(Sha3_224 => SHA3_224_LEN);
libcrux_traits::digest::slice::impl_hash_trait!(Sha3_256 => SHA3_256_LEN);
libcrux_traits::digest::slice::impl_hash_trait!(Sha3_384 => SHA3_384_LEN);
libcrux_traits::digest::slice::impl_hash_trait!(Sha3_512 => SHA3_512_LEN);
}
4 changes: 4 additions & 0 deletions libcrux-iot/sha3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ mod keccak;
mod lane;
mod state;

#[cfg(not(any(hax, eurydice)))]
mod impl_digest_trait;
#[cfg(not(any(hax, eurydice)))]
pub use impl_digest_trait::*;
/// Size in bytes of a SHA3 244 digest.
pub const SHA3_224_DIGEST_SIZE: usize = 28;
/// Size in bytes of a SHA3 256 digest.
Expand Down
4 changes: 4 additions & 0 deletions libcrux-nrf52810/src/bin/mldsa_keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
#![no_std]
#![cfg(feature = "mldsa87")]

use embedded_alloc::LlffHeap as Heap;
use libcrux_iot_ml_dsa::ml_dsa_87 as mldsa;
use libcrux_nrf52810 as board; // global logger + panicking-behavior + memory layout

#[global_allocator]
static HEAP: Heap = Heap::empty();

#[cortex_m_rt::entry]
fn main() -> ! {
let randomness_gen = [1u8; 32];
Expand Down
4 changes: 4 additions & 0 deletions libcrux-nrf52810/src/bin/mldsa_sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

use libcrux_nrf52810 as board; // global logger + panicking-behavior + memory layout

use embedded_alloc::LlffHeap as Heap;
use libcrux_iot_ml_dsa::ml_dsa_87 as mldsa;

#[global_allocator]
static HEAP: Heap = Heap::empty();

static SK: [u8; 4896] = [
158, 41, 234, 146, 185, 41, 27, 225, 46, 178, 46, 248, 151, 40, 73, 59, 147, 27, 116, 81, 248,
8, 158, 148, 78, 73, 68, 45, 224, 13, 255, 41, 95, 188, 191, 236, 222, 219, 178, 26, 88, 255,
Expand Down
4 changes: 4 additions & 0 deletions libcrux-nrf52810/src/bin/mldsa_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
#![no_std]
#![cfg(feature = "mldsa87")]

use embedded_alloc::LlffHeap as Heap;
use libcrux_iot_ml_dsa::ml_dsa_87 as mldsa;
use libcrux_nrf52810 as board; // global logger + panicking-behavior + memory layout

#[global_allocator]
static HEAP: Heap = Heap::empty();

static SIGNATURE: [u8; 4627] = [
154, 87, 4, 180, 140, 33, 3, 215, 213, 217, 228, 43, 218, 42, 215, 237, 7, 157, 76, 158, 95,
99, 76, 148, 89, 217, 144, 153, 38, 64, 136, 242, 52, 135, 216, 113, 40, 160, 202, 2, 182, 152,
Expand Down
Loading