Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikbhargavan committed Oct 29, 2024
1 parent fbefc8d commit 443ec96
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 158 deletions.
2 changes: 1 addition & 1 deletion libcrux-ml-dsa/src/encoding/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn deserialize<SIMDUnit: Operations, const ETA: usize>(
result.simd_units[i] =
SIMDUnit::error_deserialize::<ETA>(&serialized_chunks.next().unwrap());
}

result
}

Expand Down
4 changes: 2 additions & 2 deletions libcrux-ml-dsa/src/encoding/signature.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
constants::COEFFICIENTS_IN_RING_ELEMENT, encoding, types::Signature,
polynomial::PolynomialRingElement, simd::traits::Operations, VerificationError,
constants::COEFFICIENTS_IN_RING_ELEMENT, encoding, polynomial::PolynomialRingElement,
simd::traits::Operations, types::Signature, VerificationError,
};

impl<
Expand Down
54 changes: 23 additions & 31 deletions libcrux-ml-dsa/src/hash_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub(crate) mod portable {
[u8; shake128::BLOCK_SIZE],
) {
squeeze_next_block(self)
}
}
}

/// Portable SHAKE 128 state
Expand All @@ -177,7 +177,7 @@ pub(crate) mod portable {
fn shake128<const OUTPUT_LENGTH: usize>(input: &[u8], out: &mut [u8; OUTPUT_LENGTH]) {
libcrux_sha3::portable::shake128(out, input);
}

impl shake128::Xof for Shake128 {
fn shake128<const OUTPUT_LENGTH: usize>(input: &[u8], out: &mut [u8; OUTPUT_LENGTH]) {
shake128(input, out);
Expand All @@ -190,7 +190,6 @@ pub(crate) mod portable {
state: libcrux_sha3::portable::KeccakState,
}


fn shake256<const OUTPUT_LENGTH: usize>(input: &[u8], out: &mut [u8; OUTPUT_LENGTH]) {
libcrux_sha3::portable::shake256(out, input);
}
Expand Down Expand Up @@ -302,9 +301,7 @@ pub(crate) mod portable {
(out0, out1, out2, out3)
}


impl shake256::XofX4 for Shake256X4 {

fn init_absorb_x4(input0: &[u8], input1: &[u8], input2: &[u8], input3: &[u8]) -> Self {
init_absorb_x4(input0, input1, input2, input3)
}
Expand Down Expand Up @@ -350,38 +347,41 @@ pub(crate) mod portable {

#[cfg_attr(hax, hax_lib::opaque_type)]
pub(crate) struct Shake256Absorb {
state: libcrux_sha3::portable::incremental::Shake256Absorb
state: libcrux_sha3::portable::incremental::Shake256Absorb,
}

#[cfg_attr(hax, hax_lib::opaque_type)]
pub(crate) struct Shake256Squeeze {
state: libcrux_sha3::portable::incremental::Shake256Squeeze
state: libcrux_sha3::portable::incremental::Shake256Squeeze,
}

use libcrux_sha3::portable::incremental::{XofAbsorb, XofSqueeze};

pub(crate) fn shake256_init() -> Shake256Absorb {
Shake256Absorb {state: libcrux_sha3::portable::incremental::Shake256Absorb::new ()}
pub(crate) fn shake256_init() -> Shake256Absorb {
Shake256Absorb {
state: libcrux_sha3::portable::incremental::Shake256Absorb::new(),
}
}
pub(crate) fn shake256_absorb(st:&mut Shake256Absorb, input:&[u8]) {
st.state.absorb (input)
pub(crate) fn shake256_absorb(st: &mut Shake256Absorb, input: &[u8]) {
st.state.absorb(input)
}
pub(crate) fn shake256_absorb_final(st:Shake256Absorb, input:&[u8]) -> Shake256Squeeze {
Shake256Squeeze {state: st.state.absorb_final (input)}
pub(crate) fn shake256_absorb_final(st: Shake256Absorb, input: &[u8]) -> Shake256Squeeze {
Shake256Squeeze {
state: st.state.absorb_final(input),
}
}
pub(crate) fn shake256_squeeze(st:&mut Shake256Squeeze, out: &mut [u8]) {
st.state.squeeze (out)
pub(crate) fn shake256_squeeze(st: &mut Shake256Squeeze, out: &mut [u8]) {
st.state.squeeze(out)
}
}

/// A SIMD256 implementation of [`shake128::XofX4`] and [`shake256::Xof`] for AVX2.
#[cfg(feature = "simd256")]
pub(crate) mod simd256 {

use super::{shake128, shake256};
use libcrux_sha3::avx2::x4;
use libcrux_sha3::portable;
use super::{shake128, shake256};


/// AVX2 SHAKE 128 state
///
Expand All @@ -406,13 +406,7 @@ pub(crate) mod simd256 {
out2: &mut [u8; shake128::FIVE_BLOCKS_SIZE],
out3: &mut [u8; shake128::FIVE_BLOCKS_SIZE],
) {
x4::incremental::shake128_squeeze_first_five_blocks(
&mut x.state,
out0,
out1,
out2,
out3,
);
x4::incremental::shake128_squeeze_first_five_blocks(&mut x.state, out0, out1, out2, out3);
}

fn squeeze_next_block(
Expand Down Expand Up @@ -443,7 +437,7 @@ pub(crate) mod simd256 {
fn init_absorb(input0: &[u8], input1: &[u8], input2: &[u8], input3: &[u8]) -> Self {
init_absorb(input0, input1, input2, input3)
}

fn squeeze_first_five_blocks(
&mut self,
out0: &mut [u8; shake128::FIVE_BLOCKS_SIZE],
Expand Down Expand Up @@ -471,7 +465,6 @@ pub(crate) mod simd256 {

/// AVX2 SHAKE 256 state
pub(crate) type Shake256 = super::portable::Shake256;


// impl shake256::Xof for Shake256 {
// fn shake256<const OUTPUT_LENGTH: usize>(input: &[u8], out: &mut [u8; OUTPUT_LENGTH]) {
Expand Down Expand Up @@ -570,11 +563,10 @@ pub(crate) mod simd256 {
}

impl shake256::XofX4 for Shake256x4 {

fn init_absorb_x4(input0: &[u8], input1: &[u8], input2: &[u8], input3: &[u8]) -> Self {
init_absorb_x4(input0, input2, input2, input3)
}

fn squeeze_first_block_x4(
&mut self,
) -> (
Expand Down Expand Up @@ -616,8 +608,8 @@ pub(crate) mod simd256 {
#[cfg(feature = "simd128")]
pub(crate) mod neon {

use libcrux_sha3::neon::x2;
use super::{shake128, shake256};
use libcrux_sha3::neon::x2;
#[cfg_attr(hax, hax_lib::opaque_type)]
pub(crate) type KeccakState = x2::incremental::KeccakState;

Expand Down Expand Up @@ -705,7 +697,7 @@ pub(crate) mod neon {
}

fn squeeze_first_block_x4(
x:&mut Shake256x4,
x: &mut Shake256x4,
) -> (
[u8; shake256::BLOCK_SIZE],
[u8; shake256::BLOCK_SIZE],
Expand Down
Loading

0 comments on commit 443ec96

Please sign in to comment.