blob: 460e4c052e00cef7cc947df0c791c05f8fde5c28 (
plain) (
tree)
|
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifdef SUPPORT_SHAKE
int
libhashsum_init_shake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits)
{
struct libkeccak_spec spec;
if (hcapbits == 128U) {
this->algorithm = LIBHASHSUM_SHAKE128;
this->algorithm_string = "SHAKE128";
} else if (hcapbits == 256U) {
this->algorithm = LIBHASHSUM_SHAKE256;
this->algorithm_string = "SHAKE256";
} else if (hcapbits == 512U) {
this->algorithm = LIBHASHSUM_SHAKE512;
this->algorithm_string = "SHAKE512";
} 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_shake(&spec, (long int)hcapbits, (long int)hashbits);
return libhashsum_init_keccak__(this, hashbits, &spec, 1U, LIBKECCAK_SHAKE_SUFFIX);
}
#else
int
libhashsum_init_shake_hasher(struct libhashsum_hasher *this, size_t hcapbits, size_t hashbits)
{
(void) this;
(void) hcapbits;
(void) hashbits;
errno = ENOSYS;
return -1;
}
#endif
|