aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
}