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