Skip to content

Commit

Permalink
cfg gate more items in tiny-keccak
Browse files Browse the repository at this point in the history
  • Loading branch information
habnabit committed Jul 5, 2024
1 parent 27f1340 commit 53fbc8e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tiny-keccak-1536/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,35 @@ pub trait Xof {
fn squeeze(&mut self, output: &mut [u8]);
}

#[cfg(any(
feature = "cshake",
feature = "kmac",
feature = "tuple_hash",
feature = "parallel_hash"
))]
struct EncodedLen {
offset: usize,
buffer: [u8; 9],
}

#[cfg(any(
feature = "cshake",
feature = "kmac",
feature = "tuple_hash",
feature = "parallel_hash"
))]
impl EncodedLen {
fn value(&self) -> &[u8] {
&self.buffer[self.offset..]
}
}

#[cfg(any(
feature = "cshake",
feature = "kmac",
feature = "tuple_hash",
feature = "parallel_hash"
))]
fn left_encode(len: usize) -> EncodedLen {
let mut buffer = [0u8; 9];
buffer[1..].copy_from_slice(&(len as u64).to_be_bytes());
Expand All @@ -289,6 +307,12 @@ fn left_encode(len: usize) -> EncodedLen {
}
}

#[cfg(any(
feature = "cshake",
feature = "kmac",
feature = "tuple_hash",
feature = "parallel_hash"
))]
fn right_encode(len: usize) -> EncodedLen {
let mut buffer = [0u8; 9];
buffer[..8].copy_from_slice(&(len as u64).to_be_bytes());
Expand Down Expand Up @@ -466,6 +490,7 @@ impl<P: Permutation> KeccakState<P> {
self.offset = 0;
}

#[cfg(feature = "k12")]
fn reset(&mut self) {
self.buffer = Buffer::default();
self.offset = 0;
Expand Down

0 comments on commit 53fbc8e

Please sign in to comment.