keccak_sponge_shake
stdlib/keccak/keccak_sponge_shake.nbv
keccak_sponge_shake(static rate, input, static out_len)
SHAKE sponge over Keccak-f[1600] on bit vectors.
rate is the rate in bits (1344 for SHAKE128, 1088 for SHAKE256), input a vector of bits (least significant bit of each byte first) and out_len the number of output bits.
- Calls
calloc,keccak/keccak_f1600,slice,bits/xor_bits_vec- Precompiles
assert_eq!,clone!,concat!,div_ceil!,div_exact!,if_lt!,len!,loop!,loop_flat_map!,min!,modulo!- Used by
keccak/shake128,keccak/shake256
Source
# SHAKE sponge over Keccak-f[1600] on bit vectors.
#
# `rate` is the rate in bits (1344 for SHAKE128, 1088 for SHAKE256), `input` a
# vector of bits (least significant bit of each byte first) and `out_len` the
# number of output bits.
(static rate, input, static out_len)
static in_len = len! input
assert_eq! 0, (modulo! rate, 64)
# SHAKE domain suffix 1111 followed by pad10*1
static rem = modulo! in_len + 6, rate
static zeros = modulo! rate - rem, rate
let padded = concat! input, [1 1 1 1 1], calloc(zeros), [1]
static block_count = div_exact! (len! padded), rate
let mut state = calloc(1600)
loop! block_count, b {
let absorbed = xor_bits_vec(slice((clone! state), 0, rate), slice((clone! padded), b * rate, rate))
state = keccak_f1600(concat! absorbed, slice((clone! state), rate, 1600 - rate))
}
static squeeze_count = div_ceil! out_len, rate
loop_flat_map! squeeze_count, sb {
if_lt! 0, sb {
state = keccak_f1600(state)
}
static take = min! rate, out_len - sb * rate
slice((clone! state), 0, take)
}