2The Keccak sponge function, designed by Guido Bertoni, Joan Daemen,
3Michaƫl Peeters and Gilles Van Assche. For more information, feedback or
4questions, please refer to our website: http://keccak.noekeon.org/
6Implementation by the designers,
7hereby denoted as "the implementer".
9To the extent possible under law, the implementer has waived all copyright
10and related or neighboring rights to the source code in this file.
14#ifndef _KeccakSponge_h_
15#define _KeccakSponge_h_
17#define KeccakPermutationSize 1600
18#define KeccakPermutationSizeInBytes (KeccakPermutationSize/8)
19#define KeccakMaximumRate 1536
20#define KeccakMaximumRateInBytes (KeccakMaximumRate/8)
22#if defined(UseSSE) || defined(UseXOP)
23#if defined(__GNUC__)
24#define ALIGN __attribute__ ((aligned(32)))
25#elif defined(_MSC_VER)
26#define ALIGN __declspec(align(32))
30#ifndef ALIGN
31# define ALIGN
34ALIGN typedef struct spongeStateStruct {
35 ALIGN unsigned char state[KeccakPermutationSizeInBytes];
36 ALIGN unsigned char dataQueue[KeccakMaximumRateInBytes];
37 unsigned int rate;
38 unsigned int capacity;
39 unsigned int bitsInQueue;
40 unsigned int fixedOutputLength;
41 int squeezing;
42 unsigned int bitsAvailableForSqueezing;
43} spongeState;
46 * Function to initialize the state of the Keccak[r, c] sponge function.
47 * The sponge function is set to the absorbing phase.
48 * @param state Pointer to the state of the sponge function to be initialized.
49 * @param rate The value of the rate r.
50 * @param capacity The value of the capacity c.
51 * @pre One must have r+c=1600 and the rate a multiple of 64 bits in this implementation.
52 * @return Zero if successful, 1 otherwise.
53 */
54static int InitSponge(spongeState *state, unsigned int rate, unsigned int capacity);
56 * Function to give input data for the sponge function to absorb.
57 * @param state Pointer to the state of the sponge function initialized by InitSponge().
58 * @param data Pointer to the input data.
59 * When @a databitLen is not a multiple of 8, the last bits of data must be
60 * in the least significant bits of the last byte.
61 * @param databitLen The number of input bits provided in the input data.
62 * @pre In the previous call to Absorb(), databitLen was a multiple of 8.
63 * @pre The sponge function must be in the absorbing phase,
64 * i.e., Squeeze() must not have been called before.
65 * @return Zero if successful, 1 otherwise.
66 */
67static int Absorb(spongeState *state, const unsigned char *data, unsigned long long databitlen);
69 * Function to squeeze output data from the sponge function.
70 * If the sponge function was in the absorbing phase, this function
71 * switches it to the squeezing phase.
72 * @param state Pointer to the state of the sponge function initialized by InitSponge().
73 * @param output Pointer to the buffer where to store the output data.
74 * @param outputLength The number of output bits desired.
75 * It must be a multiple of 8.
76 * @return Zero if successful, 1 otherwise.
77 */
78static int Squeeze(spongeState *state, unsigned char *output, unsigned long long outputLength);