diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-24 18:02:00 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-24 18:02:00 +0200 |
commit | 72111e7a53eaad7bea841ab8b09e70642bde00ae (patch) | |
tree | 016e0326b794f8a5b9cc03139b8a5ab094ed7411 /libhashsum_init_rawshake_hasher.c | |
parent | Make it possible for libhashsum_state to grow in future versions (diff) | |
download | libhashsum-72111e7a53eaad7bea841ab8b09e70642bde00ae.tar.gz libhashsum-72111e7a53eaad7bea841ab8b09e70642bde00ae.tar.bz2 libhashsum-72111e7a53eaad7bea841ab8b09e70642bde00ae.tar.xz |
Add support for Keccak, SHA3, SHAKE, and RawSHAKE via libkeccak>=1.3 (this version introduced zerocopy)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libhashsum_init_rawshake_hasher.c')
-rw-r--r-- | libhashsum_init_rawshake_hasher.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/libhashsum_init_rawshake_hasher.c b/libhashsum_init_rawshake_hasher.c new file mode 100644 index 0000000..f90e3b7 --- /dev/null +++ b/libhashsum_init_rawshake_hasher.c @@ -0,0 +1,52 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" +#ifdef SUPPORT_RAWSHAKE + + +int +libhashsum_init_rawshake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits) +{ + struct libkeccak_spec spec; + + if (hcapbits == 128U) { + this->algorithm = LIBHASHSUM_RAWSHAKE128; + this->algorithm_string = "RawSHAKE128"; + } else if (hcapbits == 256U) { + this->algorithm = LIBHASHSUM_RAWSHAKE256; + this->algorithm_string = "RawSHAKE256"; + } else if (hcapbits == 512U) { + this->algorithm = LIBHASHSUM_RAWSHAKE512; + this->algorithm_string = "RawSHAKE512"; + } else { + errno = EINVAL; + return -1; + } + + if (hashbits == 0U) { + hashbits = hcapbits; + } else if (hashbits > (size_t)LONG_MAX) { + errno = EINVAL; + return -1; + } + + if (hashbits != hcapbits) { + sprintf(this->state.keccak.algostr, "%s[n=%zu]", this->algorithm_string, hashbits); + this->algorithm_string = this->state.keccak.algostr; + } + + libkeccak_spec_rawshake(&spec, (long int)hcapbits, (long int)hashbits); + return libhashsum_init_keccak__(this, hashbits, &spec, LIBKECCAK_RAWSHAKE_SUFFIX); +} + + +#else +int +libhashsum_init_rawshake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits) +{ + (void) this; + (void) hcapbits; + (void) hashbits; + errno = ENOSYS; + return -1; +} +#endif |