aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-01 13:20:34 +0200
committerMattias Andrée <maandree@kth.se>2024-09-01 13:20:34 +0200
commitd4f55f6d3b20201a19fbba31b6f98b57f80db3c5 (patch)
treeacb561397aeae8421d4774324ff71bd9b710ea92
parentAdd tests for Keccak and fix squeeze support in finalise_const for Keccak (diff)
downloadlibhashsum-d4f55f6d3b20201a19fbba31b6f98b57f80db3c5.tar.gz
libhashsum-d4f55f6d3b20201a19fbba31b6f98b57f80db3c5.tar.bz2
libhashsum-d4f55f6d3b20201a19fbba31b6f98b57f80db3c5.tar.xz
keccak: but squeeze code in common subroutine
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--libhashsum_init_keccak__.c48
1 files changed, 22 insertions, 26 deletions
diff --git a/libhashsum_init_keccak__.c b/libhashsum_init_keccak__.c
index 9a9fa06..9d58958 100644
--- a/libhashsum_init_keccak__.c
+++ b/libhashsum_init_keccak__.c
@@ -34,6 +34,26 @@ process(struct libhashsum_hasher *this, const void *data, size_t bytes)
LIBHASHSUM_1_NONNULL_
+static void
+finalise_common(struct libhashsum_hasher *this)
+{
+ 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;
+}
+
+
+LIBHASHSUM_1_NONNULL_
static int
finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, unsigned extra_bits)
{
@@ -57,19 +77,7 @@ finalise_const(struct libhashsum_hasher *this, const void *data, size_t bytes, u
}
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;
+ finalise_common(this);
return 0;
}
@@ -112,19 +120,7 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr
else
libkeccak_zerocopy_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;
+ finalise_common(this);
return 0;
}