aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_keccak_hasher2.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-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