diff options
Diffstat (limited to '')
-rw-r--r-- | libhashsum_init_keccak__.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/libhashsum_init_keccak__.c b/libhashsum_init_keccak__.c index b0023a5..03dd466 100644 --- a/libhashsum_init_keccak__.c +++ b/libhashsum_init_keccak__.c @@ -73,11 +73,22 @@ finalise(struct libhashsum_hasher *this, void *data, size_t bytes, unsigned extr else this->hash_output = this->state.keccak.sum.buf; if (size < need) - 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); else - libkeccak_zerocopy_digest(&this->state.keccak.s, m, bytes, extra_bits, - this->state.keccak.suffix, this->hash_output); + 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); libkeccak_state_fast_destroy(&this->state.keccak.s); memset(&this->state.keccak.s, 0, sizeof(this->state.keccak.s)); @@ -102,7 +113,7 @@ destroy(struct libhashsum_hasher *this) int -libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void *spec_, const char *suffix) +libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void *spec_, size_t squeezes, const char *suffix) { struct libkeccak_spec *spec = spec_; @@ -110,6 +121,7 @@ libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void * this->hash_size += (size_t)!!(hashbits & 7U); this->hash_output = NULL; this->supports_non_whole_bytes = 1; + this->state.keccak.squeezes = squeezes; this->state.keccak.suffix = suffix; if (this->hash_size > sizeof(this->state.keccak.sum.buf)) { @@ -137,10 +149,11 @@ libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void * #else int -libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void *spec, const char *suffix); +libhashsum_init_keccak__(struct libhashsum_hasher *this, size_t hashbits, void *spec, size_t squeezes, const char *suffix); { (void) this; (void) spec; + (void) squeezes; (void) suffix; errno = ENOSYS; return -1; |