From 72111e7a53eaad7bea841ab8b09e70642bde00ae Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 24 Aug 2024 18:02:00 +0200 Subject: Add support for Keccak, SHA3, SHAKE, and RawSHAKE via libkeccak>=1.3 (this version introduced zerocopy) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libhashsum_init_sha3_hasher.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libhashsum_init_sha3_hasher.c (limited to 'libhashsum_init_sha3_hasher.c') diff --git a/libhashsum_init_sha3_hasher.c b/libhashsum_init_sha3_hasher.c new file mode 100644 index 0000000..c9d6ac7 --- /dev/null +++ b/libhashsum_init_sha3_hasher.c @@ -0,0 +1,42 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_SHA3 + + +int +libhashsum_init_sha3_hasher(struct libhashsum_hasher *this, size_t hashbits) +{ + struct libkeccak_spec spec; + + if (hashbits == 224U) { + this->algorithm = LIBHASHSUM_SHA3_224; + this->algorithm_string = "SHA3-224"; + } else if (hashbits == 256U) { + this->algorithm = LIBHASHSUM_SHA3_256; + this->algorithm_string = "SHA3-256"; + } else if (hashbits == 384U) { + this->algorithm = LIBHASHSUM_SHA3_384; + this->algorithm_string = "SHA3-384"; + } else if (hashbits == 512U) { + this->algorithm = LIBHASHSUM_SHA3_512; + this->algorithm_string = "SHA3-512"; + } else { + errno = EINVAL; + return -1; + } + + libkeccak_spec_sha3(&spec, (long int)hashbits); + return libhashsum_init_keccak__(this, hashbits, &spec, LIBKECCAK_SHA3_SUFFIX); +} + + +#else +int +libhashsum_init_sha3_hasher(struct libhashsum_hasher *this, size_t hashbits) +{ + (void) this; + (void) hashbits; + errno = ENOSYS; + return -1; +} +#endif -- cgit v1.2.3-70-g09d2