aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_keccak_hasher2.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-12 20:18:55 +0200
committerMattias Andrée <maandree@kth.se>2024-09-12 20:18:55 +0200
commita17e0d582aaf91c6be55a5adbd5d8d38a09db222 (patch)
tree202a201357907ffd9dc72f586e19a99ac661365c /libhashsum_init_keccak_hasher2.c
parentm (diff)
downloadlibhashsum-a17e0d582aaf91c6be55a5adbd5d8d38a09db222.tar.gz
libhashsum-a17e0d582aaf91c6be55a5adbd5d8d38a09db222.tar.bz2
libhashsum-a17e0d582aaf91c6be55a5adbd5d8d38a09db222.tar.xz
Add libhashsum_init_keccak_hasher2
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum_init_keccak_hasher2.c')
-rw-r--r--libhashsum_init_keccak_hasher2.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/libhashsum_init_keccak_hasher2.c b/libhashsum_init_keccak_hasher2.c
new file mode 100644
index 0000000..71631f6
--- /dev/null
+++ b/libhashsum_init_keccak_hasher2.c
@@ -0,0 +1,47 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifdef SUPPORT_KECCAK
+
+
+int
+libhashsum_init_keccak_hasher2(struct libhashsum_hasher *this, const struct libhashsum_keccak_params *params)
+{
+ struct libkeccak_generalised_spec gspec;
+ struct libkeccak_spec spec;
+
+ libkeccak_generalised_spec_initialise(&gspec);
+ if ((params->ratebits | params->capbits |
+ params->hashbits | params->statebits |
+ params->wordbits) > (size_t)LONG_MAX)
+ goto einval;
+ if (params->ratebits)
+ gspec.bitrate = (long int)params->ratebits;
+ if (params->capbits)
+ gspec.capacity = (long int)params->capbits;
+ if (params->hashbits)
+ gspec.output = (long int)params->hashbits;
+ if (params->statebits)
+ gspec.state_size = (long int)params->statebits;
+ if (params->wordbits)
+ gspec.word_size = (long int)params->wordbits;
+ if (libkeccak_degeneralise_spec(&gspec, &spec) || libkeccak_spec_check(&spec)) {
+ einval:
+ errno = EINVAL;
+ return -1;
+ }
+
+ return libhashsum_init_keccak_hasher(this, (size_t)spec.bitrate, (size_t)spec.capacity,
+ (size_t)gspec.output, params->squeezes);
+}
+
+
+#else
+int
+libhashsum_init_keccak_hasher2(struct libhashsum_hasher *this, const struct libhashsum_keccak_params *params)
+{
+ (void) this;
+ (void) params;
+ errno = ENOSYS;
+ return -1;
+}
+#endif