summaryrefslogtreecommitdiff
path: root/src/libstrongswan/plugins/sha3/sha3_keccak.h
blob: eeea9d7fd13cb62323de9c6a891e90ecd6b9c00f (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * Copyright (C) 2016 Andreas Steffen
 * HSR Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
n */

/**
 * @defgroup sha3_keccak sha3_keccak
 * @{ @ingroup sha3_p
 */

#ifndef SHA3_KECCAK_H_
#define SHA3_KECCAK_H_

typedef struct sha3_keccak_t sha3_keccak_t;

#include <crypto/hashers/hasher.h>

/**
 * Implements the Keccak-f[1600] sponge function as defined by FIPS-202.
 */
struct sha3_keccak_t {

	/**
	 * Get the available rate in bytes
	 *
	 * @return			rate in bytes
	 */
	u_int (*get_rate)(sha3_keccak_t *this);

	/**
	 * Resets the internal Keccak state
	 */
	void (*reset)(sha3_keccak_t *this);

	/**
	 * Absorbs data into the Keccak state
	 *
	 * @param data		data to be absorbed
	 */
	void (*absorb)(sha3_keccak_t *this, chunk_t data);

	/**
	 * Finalize the absorption phase and switch to the squeeze phase
	 */
	void (*finalize)(sha3_keccak_t *this);

	/**
	 * Squeeze the Keccak state to get output data
	 * Can be called multiple times
	 *
	 * @param out_len	number of output bytes requested
	 * @param out		output buffer, must comprise at least out_len bytes
	 */
	void (*squeeze)(sha3_keccak_t *this, size_t out_len, uint8_t *out);

	/**
	 * Destroy the sha3_keccak_t object
	 */
	void (*destroy)(sha3_keccak_t *this);

};

/**
 * Creates a new sha3_keccak_t.
 *
 * @param	capacity		required capacity to achieve a given security level
 * @param delimited_suffix	bits delimiting the input message
 * @return					sha3_keccak_t object, NULL if capacity too big
 */
sha3_keccak_t *sha3_keccak_create(u_int capacity, uint8_t delimited_suffix);

#endif /** SHA3_KECCAK_H_ @}*/