Skip to content

Commit 3286475

Browse files
committed
apply feedback
1 parent b21b527 commit 3286475

File tree

6 files changed

+26
-29
lines changed

6 files changed

+26
-29
lines changed

libcrux-intrinsics/src/avx2.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![allow(unused_unsafe)]
2-
31
#[cfg(all(target_arch = "x86", not(hax)))]
42
pub use core::arch::x86::*;
53
#[cfg(all(target_arch = "x86_64", not(hax)))]

libcrux-sha3/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ harness = false
3232

3333
[dev-dependencies]
3434
criterion = "0.7.0"
35-
hax-lib.workspace = true
3635
hex = "0.4.3"
3736
rand = "0.9"
3837
cavp = { version = "0.0.2", path = "../cavp" }

libcrux-sha3/hax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def __call__(self, parser, args, values, option_string=None) -> None:
116116
"--interfaces",
117117
interface_include,
118118
]
119-
hax_env = {"RUSTFLAGS": "-C debug-assertions=off"}
119+
hax_env = {}
120120
shell(
121121
cargo_hax_into,
122122
cwd=".",

libcrux-sha3/src/generic_keccak/xof.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
generic_keccak::KeccakState,
3-
traits::{Absorb, KeccakItem, Squeeze1},
3+
traits::{Absorb, KeccakItem, Squeeze},
44
};
55

66
/// The internal keccak state that can also buffer inputs to absorb.
@@ -131,28 +131,24 @@ impl<const PARALLEL_LANES: usize, const RATE: usize, STATE: KeccakItem<PARALLEL_
131131
/// If `consumed > 0` is returned, `self.buf` contains a full block to be
132132
/// loaded.
133133
// Note: consciously not inlining this function to avoid using too much stack
134-
#[hax_lib::requires(PARALLEL_LANES > 0 && self.buf_len < RATE)]
135134
pub(crate) fn fill_buffer(&mut self, inputs: &[&[u8]; PARALLEL_LANES]) -> usize {
136135
let input_len = inputs[0].len();
137-
138-
// Nothing buffered, buffer full, or no input
139-
if self.buf_len == 0 || self.buf_len >= RATE || input_len == 0 {
140-
return 0;
141-
}
142-
143-
// Remaining space to complete a full block
144-
let need = RATE - self.buf_len;
145-
if input_len < need {
146-
return 0;
147-
}
148-
149-
let end = RATE; // buf_len + need == RATE
150-
#[allow(clippy::needless_range_loop)]
151-
for i in 0..PARALLEL_LANES {
152-
self.buf[i][self.buf_len..end].copy_from_slice(&inputs[i][..need]);
136+
let mut consumed = 0;
137+
if self.buf_len > 0 {
138+
// There's something buffered internally to consume.
139+
if self.buf_len + input_len >= RATE {
140+
// We have enough data when combining the internal buffer and
141+
// the input.
142+
consumed = RATE - self.buf_len;
143+
144+
#[allow(clippy::needless_range_loop)]
145+
for i in 0..PARALLEL_LANES {
146+
self.buf[i][self.buf_len..].copy_from_slice(&inputs[i][..consumed]);
147+
}
148+
self.buf_len += consumed;
149+
}
153150
}
154-
self.buf_len = end;
155-
need
151+
consumed
156152
}
157153

158154
/// Absorb a final block.
@@ -187,7 +183,7 @@ impl<const RATE: usize, STATE: KeccakItem<1>> KeccakXofState<1, RATE, STATE> {
187183
#[inline(always)]
188184
pub(crate) fn squeeze(&mut self, out: &mut [u8])
189185
where
190-
KeccakState<1, STATE>: Squeeze1<STATE>,
186+
KeccakState<1, STATE>: Squeeze<STATE>,
191187
{
192188
if self.sponge {
193189
// If we called `squeeze` before, call f1600 first.

libcrux-sha3/src/simd/portable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{generic_keccak::KeccakState, traits::*};
55
#[inline(always)]
66
fn rotate_left<const LEFT: i32, const RIGHT: i32>(x: u64) -> u64 {
77
debug_assert!(LEFT + RIGHT == 64);
8-
u64::rotate_left(x, LEFT as u32)
8+
x.rotate_left(LEFT as u32)
99
}
1010

1111
#[inline(always)]
@@ -142,7 +142,7 @@ impl Absorb<1> for KeccakState<1, u64> {
142142
}
143143
}
144144

145-
impl Squeeze1<u64> for KeccakState<1, u64> {
145+
impl Squeeze<u64> for KeccakState<1, u64> {
146146
fn squeeze<const RATE: usize>(&self, out: &mut [u8], start: usize, len: usize) {
147147
store_block::<RATE>(&self.st, out, start, len);
148148
}

libcrux-sha3/src/traits.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) trait Absorb<const N: usize> {
7474
#[hax_lib::fstar::replace(
7575
interface,
7676
"
77-
class t_Squeeze1 (v_Self: Type0) (v_T: Type0) = {
77+
class t_Squeeze (v_Self: Type0) (v_T: Type0) = {
7878
f_squeeze_pre:v_RATE: usize -> v_Self -> t_Slice u8 -> usize -> usize -> Type0;
7979
f_squeeze_post:v_RATE: usize -> v_Self -> t_Slice u8 -> usize -> usize -> t_Slice u8 -> Type0;
8080
f_squeeze:v_RATE: usize -> x0: v_Self -> x1: t_Slice u8 -> x2: usize -> x3: usize
@@ -84,10 +84,14 @@ class t_Squeeze1 (v_Self: Type0) (v_T: Type0) = {
8484
}
8585
"
8686
)]
87-
pub(crate) trait Squeeze1<T: KeccakItem<1>> {
87+
pub(crate) trait Squeeze<T: KeccakItem<1>> {
8888
fn squeeze<const RATE: usize>(&self, out: &mut [u8], start: usize, len: usize);
8989
}
9090

91+
// TODO: Renaming the squeeze functions of the Squeeze2 and Squeeze4 Trait is currently
92+
// necessary because F* will not find the correct pre conditions otherwise. This is
93+
// most likely fixed when doing full type checking.
94+
9195
/// Trait to squeeze bytes out of the state.
9296
///
9397
/// Note that this is implemented for each platform (1, 2, 4) because hax can't

0 commit comments

Comments
 (0)