blob: f90e3b706643dcaa3592b6193bc0035ffefd86b4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
|