aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_keccak_hasher.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-08-28 16:41:28 +0200
committerMattias Andrée <maandree@kth.se>2024-08-28 16:41:28 +0200
commit9a0a1b696a47041985ce4d3969ba5d1261105ff0 (patch)
tree1f07a2cd0b101668d174329bad6f630c44261602 /libhashsum_init_keccak_hasher.c
parentm misc (diff)
downloadlibhashsum-9a0a1b696a47041985ce4d3969ba5d1261105ff0.tar.gz
libhashsum-9a0a1b696a47041985ce4d3969ba5d1261105ff0.tar.bz2
libhashsum-9a0a1b696a47041985ce4d3969ba5d1261105ff0.tar.xz
m + add support for z parameter for keccak
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum_init_keccak_hasher.c')
-rw-r--r--libhashsum_init_keccak_hasher.c20
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;