aboutsummaryrefslogtreecommitdiffstats
path: root/libhashsum_init_keccak_hasher2.c
blob: 71631f6c7d4f2610dce1985292112fa05593d24a (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
/* 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