Belle II Software  release-08-01-10
KeccakSponge.h
1 /*
2 Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
3 Joan Daemen, MichaĆ«l Peeters, Gilles Van Assche and Ronny Van Keer, hereby
4 denoted as "the implementer".
5 
6 For more information, feedback or questions, please refer to our websites:
7 http://keccak.noekeon.org/
8 http://keyak.noekeon.org/
9 http://ketje.noekeon.org/
10 
11 To the extent possible under law, the implementer has waived all copyright
12 and related or neighboring rights to the source code in this file.
13 http://creativecommons.org/publicdomain/zero/1.0/
14 */
15 
16 #ifndef _KeccakSponge_h_
17 #define _KeccakSponge_h_
18 
42 #ifdef DontReallyInclude_DocumentationOnly
67 int Prefix_Sponge(unsigned int rate, unsigned int capacity, const unsigned char* input, size_t inputByteLen, unsigned char suffix,
68  unsigned char* output, size_t outputByteLen);
69 
80 int Prefix_SpongeInitialize(Prefix_SpongeInstance* spongeInstance, unsigned int rate, unsigned int capacity);
81 
92 int Prefix_SpongeAbsorb(Prefix_SpongeInstance* spongeInstance, const unsigned char* data, size_t dataByteLen);
93 
116 int Prefix_SpongeAbsorbLastFewBits(Prefix_SpongeInstance* spongeInstance, unsigned char delimitedData);
117 
128 int Prefix_SpongeSqueeze(Prefix_SpongeInstance* spongeInstance, unsigned char* data, size_t dataByteLen);
129 #endif
130 
131 #include <string.h>
132 #include "align.h"
133 
134 #define KCP_DeclareSpongeStructure(prefix, size, alignment) \
135  ALIGN(alignment) typedef struct prefix##_SpongeInstanceStruct { \
136  unsigned char state[size]; \
137  unsigned int rate; \
138  unsigned int byteIOIndex; \
139  int squeezing; \
140  } prefix##_SpongeInstance;
141 
142 #define KCP_DeclareSpongeFunctions(prefix) \
143  int prefix##_Sponge(unsigned int rate, unsigned int capacity, const unsigned char *input, size_t inputByteLen, unsigned char suffix, unsigned char *output, size_t outputByteLen); \
144  int prefix##_SpongeInitialize(prefix##_SpongeInstance *spongeInstance, unsigned int rate, unsigned int capacity); \
145  int prefix##_SpongeAbsorb(prefix##_SpongeInstance *spongeInstance, const unsigned char *data, size_t dataByteLen); \
146  int prefix##_SpongeAbsorbLastFewBits(prefix##_SpongeInstance *spongeInstance, unsigned char delimitedData); \
147  int prefix##_SpongeSqueeze(prefix##_SpongeInstance *spongeInstance, unsigned char *data, size_t dataByteLen);
148 
149 #ifndef KeccakP200_excluded
150 #include "KeccakP-200-SnP.h"
151 KCP_DeclareSpongeStructure(KeccakWidth200, KeccakP200_stateSizeInBytes, KeccakP200_stateAlignment)
152 KCP_DeclareSpongeFunctions(KeccakWidth200)
153 #endif
154 
155 #ifndef KeccakP400_excluded
156 #include "KeccakP-400-SnP.h"
157 KCP_DeclareSpongeStructure(KeccakWidth400, KeccakP400_stateSizeInBytes, KeccakP400_stateAlignment)
158 KCP_DeclareSpongeFunctions(KeccakWidth400)
159 #endif
160 
161 #ifndef KeccakP800_excluded
162 #include "KeccakP-800-SnP.h"
163 KCP_DeclareSpongeStructure(KeccakWidth800, KeccakP800_stateSizeInBytes, KeccakP800_stateAlignment)
164 KCP_DeclareSpongeFunctions(KeccakWidth800)
165 #endif
166 
167 #ifndef KeccakP1600_excluded
168 #include "KeccakP-1600-SnP.h"
169 KCP_DeclareSpongeStructure(KeccakWidth1600, KeccakP1600_stateSizeInBytes, KeccakP1600_stateAlignment)
170 KCP_DeclareSpongeFunctions(KeccakWidth1600)
171 #endif
172 
173 #ifndef KeccakP1600_excluded
174 #include "KeccakP-1600-SnP.h"
175 KCP_DeclareSpongeStructure(KeccakWidth1600_12rounds, KeccakP1600_stateSizeInBytes, KeccakP1600_stateAlignment)
176 KCP_DeclareSpongeFunctions(KeccakWidth1600_12rounds)
177 #endif
178 
179 #endif