diff options
Diffstat (limited to 'libhashsum_init_keccak_hasher.c')
-rw-r--r-- | libhashsum_init_keccak_hasher.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/libhashsum_init_keccak_hasher.c b/libhashsum_init_keccak_hasher.c index 93622f6..45e8627 100644 --- a/libhashsum_init_keccak_hasher.c +++ b/libhashsum_init_keccak_hasher.c @@ -4,11 +4,14 @@ int -libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t ratebits, size_t capbits, size_t hashbits) +libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t ratebits, size_t capbits, size_t hashbits, size_t squeezes) { struct libkeccak_generalised_spec gspec; struct libkeccak_spec spec; + if (!squeezes) + squeezes = 1U; + if ((ratebits | capbits | hashbits) > (size_t)LONG_MAX) { errno = EINVAL; return -1; @@ -38,7 +41,7 @@ libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t ratebits, s } this->algorithm = LIBHASHSUM_KECCAK; - if ((capbits >> 1) == hashbits && !(capbits & 1U) && + if ((capbits >> 1) == hashbits && !(capbits & 1U) && squeezes == 1U && 1600U >= capbits && ratebits == 1600U - capbits) { if (hashbits == 224U) { this->algorithm = LIBHASHSUM_KECCAK_224; @@ -55,19 +58,26 @@ libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t ratebits, s } } if (this->algorithm == LIBHASHSUM_KECCAK) { - sprintf(this->state.keccak.algostr, "Keccak[r=%zu,c=%zu,n=%zu]", ratebits, capbits, hashbits); + if (squeezes > 1U) { + sprintf(this->state.keccak.algostr, "Keccak[r=%zu,c=%zu,n=%zu,z=%zu]", + ratebits, capbits, hashbits, squeezes); + } else { + sprintf(this->state.keccak.algostr, "Keccak[r=%zu,c=%zu,n=%zu]", ratebits, capbits, hashbits); + } this->algorithm_string = this->state.keccak.algostr; } - return libhashsum_init_keccak__(this, hashbits, &spec, ""); + return libhashsum_init_keccak__(this, hashbits, &spec, squeezes, ""); } #else int -libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t hashbits) +libhashsum_init_keccak_hasher(struct libhashsum_hasher *this, size_t ratebits, size_t capbits, size_t hashbits, size_t squeezes) { (void) this; + (void) ratebits; + (void) capbits; (void) hashbits; errno = ENOSYS; return -1; |