aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_keccak__.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-01 13:15:50 +0200
committerMattias Andrée <maandree@kth.se>2024-09-01 13:15:50 +0200
commitb9d4bfaea3209fdcebdba148cb99242c44371c4a (patch)
tree94c15e93ed1bf712064f225da3db7e33e550869c /libhashsum_init_keccak__.c
parentAdd tests for SHAKE and RawSHAKE (diff)
downloadlibhashsum-b9d4bfaea3209fdcebdba148cb99242c44371c4a.tar.gz
libhashsum-b9d4bfaea3209fdcebdba148cb99242c44371c4a.tar.bz2
libhashsum-b9d4bfaea3209fdcebdba148cb99242c44371c4a.tar.xz
Add tests for Keccak and fix squeeze support in finalise_const for Keccak
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libhashsum_init_keccak__.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/libhashsum_init_keccak__.c b/libhashsum_init_keccak__.c
index ee146bc..9a9fa06 100644
--- a/libhashsum_init_keccak__.c
+++ b/libhashsum_init_keccak__.c
@@ -55,7 +55,19 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u
else
this->hash_output = this->state.keccak.sum.buf;
}
- libkeccak_digest(&this->state.keccak.s, m, bytes, extra_bits, this->state.keccak.suffix, this->hash_output);
+ libkeccak_digest(&this->state.keccak.s, m, bytes, extra_bits, this->state.keccak.suffix,
+ this->state.keccak.squeezes > 1U ? NULL : this->hash_output);
+ if (this->state.keccak.squeezes > 2U) {
+ size_t squeezes = this->state.keccak.squeezes - 2U;
+ while (squeezes > (size_t)LONG_MAX) {
+ libkeccak_fast_squeeze(&this->state.keccak.s, LONG_MAX);
+ squeezes -= (size_t)LONG_MAX;
+ }
+ libkeccak_fast_squeeze(&this->state.keccak.s, (long int)squeezes);
+ }
+ if (this->state.keccak.squeezes > 1U)
+ libkeccak_squeeze(&this->state.keccak.s, this->hash_output);
+
libkeccak_state_wipe_message(&this->state.keccak.s);
this->stretch = &stretch;
return 0;