From d4f55f6d3b20201a19fbba31b6f98b57f80db3c5 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 1 Sep 2024 13:20:34 +0200 Subject: keccak: but squeeze code in common subroutine MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libhashsum_init_keccak__.c | 48 +++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'libhashsum_init_keccak__.c') 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 @@ -33,6 +33,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; } -- cgit v1.2.3-70-g09d2