Skip to content

Commit

Permalink
Remove unused and flawed keccak_absorb
Browse files Browse the repository at this point in the history
  • Loading branch information
bwesterb committed Apr 11, 2023
1 parent 1b1637c commit 5acfd2d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 108 deletions.
54 changes: 0 additions & 54 deletions src/avx2/fips202.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,41 +323,6 @@ pub(crate) fn keccakf1600_statepermute(state: &mut[u64])
state[24] = asu;
}

// Name: keccak_absorb
//
// Description: Absorb step of Keccak;
// non-incremental, starts by zeroing the state.
//
// Arguments: - u64 s: Keccak state
// usize pos: position in current block to be absorbed
// - usize r: rate in bytes (e.g., 168 for SHAKE128)
// - const [u8] input: pointer to input to be absorbed into s
// - u64 inlen: length of input in bytes
pub(crate) fn keccak_absorb(
s: &mut[u64],
mut pos: usize,
r: usize,
input: &[u8],
mut inlen: usize
) -> usize
{
let mut idx = 0usize;
while pos+inlen >= r {
for i in pos..r {
s[i/8] ^= (input[idx] as u64) << 8 * (i%8);
idx += 1;
}
inlen -= r-pos;
keccakf1600_statepermute(s);
pos = 0;
}
let new_pos = pos+inlen;
for i in pos..new_pos {
s[i/8] ^= (input[idx] as u64) << 8 * (i%8);
}
new_pos
}

// Name: keccak_squeezeblocks
//
// Description: Squeeze step of Keccak. Squeezes full blocks of r bytes each.
Expand All @@ -381,20 +346,6 @@ pub(crate) fn keccak_squeezeblocks(h: &mut[u8], mut nblocks: usize, s: &mut [u64
}
}

// Name: shake128_absorb
//
// Description: Absorb step of the SHAKE128 XOF.
// non-incremental, starts by zeroing the state.
//
// Arguments: - u64 *s: (uninitialized) output Keccak state
// - const [u8] input: input to be absorbed into s
// - u64 inputByteLen: length of input in bytes
pub(crate) fn shake128_absorb(state: &mut KeccakState, input: &[u8], inlen: usize)
{
let pos = state.pos;
state.pos =keccak_absorb(&mut state.s, pos, SHAKE128_RATE, input, inlen);
}

// Name: shake128_squeezeblocks
//
// Description: Squeeze step of SHAKE128 XOF. Squeezes full blocks of
Expand Down Expand Up @@ -610,11 +561,6 @@ fn shake256_init(state: &mut KeccakState) {
state.reset();
}

fn shake256_absorb(state: &mut KeccakState, input: &[u8], inlen: usize)
{
state.pos = keccak_absorb(&mut state.s, state.pos, SHAKE256_RATE, input, inlen);
}

fn shake256_finalize(state: &mut KeccakState)
{
keccak_finalize(&mut state.s, state.pos, SHAKE256_RATE, 0x1F);
Expand Down
54 changes: 0 additions & 54 deletions src/reference/fips202.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,41 +324,6 @@ pub fn keccakf1600_statepermute(state: &mut[u64])
state[24] = asu;
}

// Name: keccak_absorb
//
// Description: Absorb step of Keccak;
// non-incremental, starts by zeroeing the state.
//
// Arguments: - u64 s: Keccak state
// usize pos: position in current block to be absorbed
// - usize r: rate in bytes (e.g., 168 for SHAKE128)
// - const [u8] input: pointer to input to be absorbed into s
// - u64 inlen: length of input in bytes
pub(crate) fn keccak_absorb(
s: &mut[u64],
mut pos: usize,
r: usize,
input: &[u8],
mut inlen: usize
) -> usize
{
let mut idx = 0usize;
while pos+inlen >= r {
for i in pos..r {
s[i/8] ^= (input[idx] as u64) << 8 * (i%8);
idx += 1;
}
inlen -= r-pos;
keccakf1600_statepermute(s);
pos = 0;
}
let new_pos = pos+inlen;
for i in pos..new_pos {
s[i/8] ^= (input[idx] as u64) << 8 * (i%8);
}
new_pos
}

// Name: keccak_squeezeblocks
//
// Description: Squeeze step of Keccak. Squeezes full blocks of r bytes each.
Expand All @@ -382,20 +347,6 @@ pub(crate) fn keccak_squeezeblocks(h: &mut[u8], mut nblocks: usize, s: &mut [u64
}
}

// Name: shake128_absorb
//
// Description: Absorb step of the SHAKE128 XOF.
// non-incremental, starts by zeroeing the state.
//
// Arguments: - u64 *s: (uninitialized) output Keccak state
// - const [u8] input: input to be absorbed into s
// - u64 inputByteLen: length of input in bytes
pub(crate) fn shake128_absorb(state: &mut KeccakState, input: &[u8], inlen: usize)
{
let pos = state.pos;
state.pos =keccak_absorb(&mut state.s, pos, SHAKE128_RATE, input, inlen);
}

// Name: shake128_squeezeblocks
//
// Description: Squeeze step of SHAKE128 XOF. Squeezes full blocks of
Expand Down Expand Up @@ -611,11 +562,6 @@ fn shake256_init(state: &mut KeccakState) {
state.reset();
}

fn shake256_absorb(state: &mut KeccakState, input: &[u8], inlen: usize)
{
state.pos = keccak_absorb(&mut state.s, state.pos, SHAKE256_RATE, input, inlen);
}

fn shake256_finalize(state: &mut KeccakState)
{
keccak_finalize(&mut state.s, state.pos, SHAKE256_RATE, 0x1F);
Expand Down

0 comments on commit 5acfd2d

Please sign in to comment.