sha3 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.rspec +3 -1
  4. data/.rubocop.yml +6 -0
  5. data/Gemfile +3 -1
  6. data/README.md +10 -7
  7. data/Rakefile +10 -37
  8. data/certs/johanns.pem +25 -0
  9. data/ext/sha3/config.h +26 -0
  10. data/ext/sha3/digest.c +6 -6
  11. data/ext/sha3/extconf.rb +40 -16
  12. data/ext/sha3/lib/common/align.h +33 -0
  13. data/ext/sha3/{brg_endian.h → lib/common/brg_endian.h} +8 -7
  14. data/ext/sha3/{KeccakHash.c → lib/high/Keccak/FIPS202/KeccakHash.c} +26 -25
  15. data/ext/sha3/{KeccakHash.h → lib/high/Keccak/FIPS202/KeccakHash.h} +34 -19
  16. data/ext/sha3/lib/high/Keccak/KeccakSponge.c +111 -0
  17. data/ext/sha3/lib/high/Keccak/KeccakSponge.h +76 -0
  18. data/ext/sha3/lib/high/Keccak/KeccakSponge.inc +316 -0
  19. data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros +748 -0
  20. data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-unrolling.macros +305 -0
  21. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h +44 -0
  22. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference.h +23 -0
  23. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c +625 -0
  24. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h +44 -0
  25. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c +444 -0
  26. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.h +23 -0
  27. data/lib/sha3/doc.rb +4 -4
  28. data/lib/sha3/version.rb +4 -4
  29. data/lib/sha3.rb +15 -13
  30. data/sha3.gemspec +53 -22
  31. data/tests.sh +8 -7
  32. data.tar.gz.sig +0 -0
  33. metadata +100 -51
  34. metadata.gz.sig +0 -0
  35. data/.gitignore +0 -234
  36. data/.travis.yml +0 -21
  37. data/Gemfile.ci +0 -8
  38. data/ext/sha3/KeccakF-1600-interface.h +0 -40
  39. data/ext/sha3/KeccakSponge.c +0 -192
  40. data/ext/sha3/KeccakSponge.h +0 -113
  41. data/ext/sha3/Optimized64/KeccakF-1600-64.macros +0 -2199
  42. data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +0 -3
  43. data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +0 -508
  44. data/ext/sha3/Optimized64/KeccakF-1600-unrolling.macros +0 -126
  45. data/ext/sha3/Optimized64/SnP-interface.h +0 -47
  46. data/ext/sha3/Reference/KeccakF-1600-reference.c +0 -311
  47. data/ext/sha3/Reference/KeccakF-reference.h +0 -26
  48. data/ext/sha3/Reference/SnP-FBWL-default.c +0 -96
  49. data/ext/sha3/Reference/SnP-FBWL-default.h +0 -26
  50. data/ext/sha3/Reference/SnP-interface.h +0 -42
  51. data/ext/sha3/Reference/displayIntermediateValues.c +0 -158
  52. data/ext/sha3/Reference/displayIntermediateValues.h +0 -34
  53. data/ext/sha3/SnP-Relaned.h +0 -249
  54. data/spec/generate_tests.rb +0 -49
  55. data/spec/sha3_core_spec.rb +0 -148
  56. data/spec/spec_helper.rb +0 -4
@@ -0,0 +1,111 @@
1
+ /*
2
+ The eXtended Keccak Code Package (XKCP)
3
+ https://github.com/XKCP/XKCP
4
+
5
+ Keccak, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche.
6
+
7
+ Implementation by the designers, hereby denoted as "the implementer".
8
+
9
+ For more information, feedback or questions, please refer to the Keccak Team website:
10
+ https://keccak.team/
11
+
12
+ To the extent possible under law, the implementer has waived all copyright
13
+ and related or neighboring rights to the source code in this file.
14
+ http://creativecommons.org/publicdomain/zero/1.0/
15
+ */
16
+
17
+ #include "KeccakSponge.h"
18
+
19
+ #ifdef KeccakReference
20
+ #include "displayIntermediateValues.h"
21
+ #endif
22
+
23
+ #ifdef XKCP_has_KeccakP200
24
+ #include "KeccakP-200-SnP.h"
25
+
26
+ #define prefix KeccakWidth200
27
+ #define SnP KeccakP200
28
+ #define SnP_width 200
29
+ #define SnP_Permute KeccakP200_Permute_18rounds
30
+ #if defined(KeccakF200_FastLoop_supported)
31
+ #define SnP_FastLoop_Absorb KeccakF200_FastLoop_Absorb
32
+ #endif
33
+ #include "KeccakSponge.inc"
34
+ #undef prefix
35
+ #undef SnP
36
+ #undef SnP_width
37
+ #undef SnP_Permute
38
+ #undef SnP_FastLoop_Absorb
39
+ #endif
40
+
41
+ #ifdef XKCP_has_KeccakP400
42
+ #include "KeccakP-400-SnP.h"
43
+
44
+ #define prefix KeccakWidth400
45
+ #define SnP KeccakP400
46
+ #define SnP_width 400
47
+ #define SnP_Permute KeccakP400_Permute_20rounds
48
+ #if defined(KeccakF400_FastLoop_supported)
49
+ #define SnP_FastLoop_Absorb KeccakF400_FastLoop_Absorb
50
+ #endif
51
+ #include "KeccakSponge.inc"
52
+ #undef prefix
53
+ #undef SnP
54
+ #undef SnP_width
55
+ #undef SnP_Permute
56
+ #undef SnP_FastLoop_Absorb
57
+ #endif
58
+
59
+ #ifdef XKCP_has_KeccakP800
60
+ #include "KeccakP-800-SnP.h"
61
+
62
+ #define prefix KeccakWidth800
63
+ #define SnP KeccakP800
64
+ #define SnP_width 800
65
+ #define SnP_Permute KeccakP800_Permute_22rounds
66
+ #if defined(KeccakF800_FastLoop_supported)
67
+ #define SnP_FastLoop_Absorb KeccakF800_FastLoop_Absorb
68
+ #endif
69
+ #include "KeccakSponge.inc"
70
+ #undef prefix
71
+ #undef SnP
72
+ #undef SnP_width
73
+ #undef SnP_Permute
74
+ #undef SnP_FastLoop_Absorb
75
+ #endif
76
+
77
+ #ifdef XKCP_has_KeccakP1600
78
+ #include "KeccakP-1600-SnP.h"
79
+
80
+ #define prefix KeccakWidth1600
81
+ #define SnP KeccakP1600
82
+ #define SnP_width 1600
83
+ #define SnP_Permute KeccakP1600_Permute_24rounds
84
+ #if defined(KeccakF1600_FastLoop_supported)
85
+ #define SnP_FastLoop_Absorb KeccakF1600_FastLoop_Absorb
86
+ #endif
87
+ #include "KeccakSponge.inc"
88
+ #undef prefix
89
+ #undef SnP
90
+ #undef SnP_width
91
+ #undef SnP_Permute
92
+ #undef SnP_FastLoop_Absorb
93
+ #endif
94
+
95
+ #ifdef XKCP_has_KeccakP1600
96
+ #include "KeccakP-1600-SnP.h"
97
+
98
+ #define prefix KeccakWidth1600_12rounds
99
+ #define SnP KeccakP1600
100
+ #define SnP_width 1600
101
+ #define SnP_Permute KeccakP1600_Permute_12rounds
102
+ #if defined(KeccakP1600_12rounds_FastLoop_supported)
103
+ #define SnP_FastLoop_Absorb KeccakP1600_12rounds_FastLoop_Absorb
104
+ #endif
105
+ #include "KeccakSponge.inc"
106
+ #undef prefix
107
+ #undef SnP
108
+ #undef SnP_width
109
+ #undef SnP_Permute
110
+ #undef SnP_FastLoop_Absorb
111
+ #endif
@@ -0,0 +1,76 @@
1
+ /*
2
+ The eXtended Keccak Code Package (XKCP)
3
+ https://github.com/XKCP/XKCP
4
+
5
+ Keccak, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche.
6
+
7
+ Implementation by the designers, hereby denoted as "the implementer".
8
+
9
+ For more information, feedback or questions, please refer to the Keccak Team website:
10
+ https://keccak.team/
11
+
12
+ To the extent possible under law, the implementer has waived all copyright
13
+ and related or neighboring rights to the source code in this file.
14
+ http://creativecommons.org/publicdomain/zero/1.0/
15
+ */
16
+
17
+ #ifndef _KeccakSponge_h_
18
+ #define _KeccakSponge_h_
19
+
20
+ /* For the documentation, please follow the link: */
21
+ /* #include "KeccakSponge-documentation.h" */
22
+
23
+ #include <string.h>
24
+ #include "align.h"
25
+ #include "config.h"
26
+
27
+ #define XKCP_DeclareSpongeStructure(prefix, size, alignment) \
28
+ ALIGN(alignment) typedef struct prefix##_SpongeInstanceStruct { \
29
+ unsigned char state[size]; \
30
+ unsigned int rate; \
31
+ unsigned int byteIOIndex; \
32
+ int squeezing; \
33
+ } prefix##_SpongeInstance;
34
+
35
+ #define XKCP_DeclareSpongeFunctions(prefix) \
36
+ 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); \
37
+ int prefix##_SpongeInitialize(prefix##_SpongeInstance *spongeInstance, unsigned int rate, unsigned int capacity); \
38
+ int prefix##_SpongeAbsorb(prefix##_SpongeInstance *spongeInstance, const unsigned char *data, size_t dataByteLen); \
39
+ int prefix##_SpongeAbsorbLastFewBits(prefix##_SpongeInstance *spongeInstance, unsigned char delimitedData); \
40
+ int prefix##_SpongeSqueeze(prefix##_SpongeInstance *spongeInstance, unsigned char *data, size_t dataByteLen);
41
+
42
+ #ifdef XKCP_has_KeccakP200
43
+ #include "KeccakP-200-SnP.h"
44
+ XKCP_DeclareSpongeStructure(KeccakWidth200, KeccakP200_stateSizeInBytes, KeccakP200_stateAlignment)
45
+ XKCP_DeclareSpongeFunctions(KeccakWidth200)
46
+ #define XKCP_has_Sponge_Keccak_width200
47
+ #endif
48
+
49
+ #ifdef XKCP_has_KeccakP400
50
+ #include "KeccakP-400-SnP.h"
51
+ XKCP_DeclareSpongeStructure(KeccakWidth400, KeccakP400_stateSizeInBytes, KeccakP400_stateAlignment)
52
+ XKCP_DeclareSpongeFunctions(KeccakWidth400)
53
+ #define XKCP_has_Sponge_Keccak_width400
54
+ #endif
55
+
56
+ #ifdef XKCP_has_KeccakP800
57
+ #include "KeccakP-800-SnP.h"
58
+ XKCP_DeclareSpongeStructure(KeccakWidth800, KeccakP800_stateSizeInBytes, KeccakP800_stateAlignment)
59
+ XKCP_DeclareSpongeFunctions(KeccakWidth800)
60
+ #define XKCP_has_Sponge_Keccak_width800
61
+ #endif
62
+
63
+ #ifdef XKCP_has_KeccakP1600
64
+ #include "KeccakP-1600-SnP.h"
65
+ XKCP_DeclareSpongeStructure(KeccakWidth1600, KeccakP1600_stateSizeInBytes, KeccakP1600_stateAlignment)
66
+ XKCP_DeclareSpongeFunctions(KeccakWidth1600)
67
+ #define XKCP_has_Sponge_Keccak_width1600
68
+ #endif
69
+
70
+ #ifdef XKCP_has_KeccakP1600
71
+ #include "KeccakP-1600-SnP.h"
72
+ XKCP_DeclareSpongeStructure(KeccakWidth1600_12rounds, KeccakP1600_stateSizeInBytes, KeccakP1600_stateAlignment)
73
+ XKCP_DeclareSpongeFunctions(KeccakWidth1600_12rounds)
74
+ #endif
75
+
76
+ #endif
@@ -0,0 +1,316 @@
1
+ /*
2
+ The eXtended Keccak Code Package (XKCP)
3
+ https://github.com/XKCP/XKCP
4
+
5
+ Keccak, designed by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche.
6
+
7
+ Implementation by the designers, hereby denoted as "the implementer".
8
+
9
+ For more information, feedback or questions, please refer to the Keccak Team website:
10
+ https://keccak.team/
11
+
12
+ To the extent possible under law, the implementer has waived all copyright
13
+ and related or neighboring rights to the source code in this file.
14
+ http://creativecommons.org/publicdomain/zero/1.0/
15
+ */
16
+
17
+ #define JOIN0(a, b) a ## b
18
+ #define JOIN(a, b) JOIN0(a, b)
19
+
20
+ #define Sponge JOIN(prefix, _Sponge)
21
+ #define SpongeInstance JOIN(prefix, _SpongeInstance)
22
+ #define SpongeInitialize JOIN(prefix, _SpongeInitialize)
23
+ #define SpongeAbsorb JOIN(prefix, _SpongeAbsorb)
24
+ #define SpongeAbsorbLastFewBits JOIN(prefix, _SpongeAbsorbLastFewBits)
25
+ #define SpongeSqueeze JOIN(prefix, _SpongeSqueeze)
26
+
27
+ #define SnP_stateSizeInBytes JOIN(SnP, _stateSizeInBytes)
28
+ #define SnP_stateAlignment JOIN(SnP, _stateAlignment)
29
+ #define SnP_StaticInitialize JOIN(SnP, _StaticInitialize)
30
+ #define SnP_Initialize JOIN(SnP, _Initialize)
31
+ #define SnP_AddByte JOIN(SnP, _AddByte)
32
+ #define SnP_AddBytes JOIN(SnP, _AddBytes)
33
+ #define SnP_ExtractBytes JOIN(SnP, _ExtractBytes)
34
+
35
+ int Sponge(unsigned int rate, unsigned int capacity, const unsigned char *input, size_t inputByteLen, unsigned char suffix, unsigned char *output, size_t outputByteLen)
36
+ {
37
+ ALIGN(SnP_stateAlignment) unsigned char state[SnP_stateSizeInBytes];
38
+ unsigned int partialBlock;
39
+ const unsigned char *curInput = input;
40
+ unsigned char *curOutput = output;
41
+ unsigned int rateInBytes = rate/8;
42
+
43
+ if (rate+capacity != SnP_width)
44
+ return 1;
45
+ if ((rate <= 0) || (rate > SnP_width) || ((rate % 8) != 0))
46
+ return 1;
47
+ if (suffix == 0)
48
+ return 1;
49
+
50
+ /* Initialize the state */
51
+ SnP_StaticInitialize();
52
+ SnP_Initialize(state);
53
+
54
+ /* First, absorb whole blocks */
55
+ #ifdef SnP_FastLoop_Absorb
56
+ if (((rateInBytes % (SnP_width/200)) == 0) && (inputByteLen >= rateInBytes)) {
57
+ /* fast lane: whole lane rate */
58
+ size_t j;
59
+ j = SnP_FastLoop_Absorb(state, rateInBytes/(SnP_width/200), curInput, inputByteLen);
60
+ curInput += j;
61
+ inputByteLen -= j;
62
+ }
63
+ #endif
64
+ while(inputByteLen >= (size_t)rateInBytes) {
65
+ #ifdef KeccakReference
66
+ displayBytes(1, "Block to be absorbed", curInput, rateInBytes);
67
+ #endif
68
+ SnP_AddBytes(state, curInput, 0, rateInBytes);
69
+ SnP_Permute(state);
70
+ curInput += rateInBytes;
71
+ inputByteLen -= rateInBytes;
72
+ }
73
+
74
+ /* Then, absorb what remains */
75
+ partialBlock = (unsigned int)inputByteLen;
76
+ #ifdef KeccakReference
77
+ displayBytes(1, "Block to be absorbed (part)", curInput, partialBlock);
78
+ #endif
79
+ SnP_AddBytes(state, curInput, 0, partialBlock);
80
+
81
+ /* Finally, absorb the suffix */
82
+ #ifdef KeccakReference
83
+ {
84
+ unsigned char delimitedData1[1];
85
+ delimitedData1[0] = suffix;
86
+ displayBytes(1, "Block to be absorbed (last few bits + first bit of padding)", delimitedData1, 1);
87
+ }
88
+ #endif
89
+ /* Last few bits, whose delimiter coincides with first bit of padding */
90
+ SnP_AddByte(state, suffix, partialBlock);
91
+ /* If the first bit of padding is at position rate-1, we need a whole new block for the second bit of padding */
92
+ if ((suffix >= 0x80) && (partialBlock == (rateInBytes-1)))
93
+ SnP_Permute(state);
94
+ /* Second bit of padding */
95
+ SnP_AddByte(state, 0x80, rateInBytes-1);
96
+ #ifdef KeccakReference
97
+ {
98
+ unsigned char block[SnP_width/8];
99
+ memset(block, 0, SnP_width/8);
100
+ block[rateInBytes-1] = 0x80;
101
+ displayBytes(1, "Second bit of padding", block, rateInBytes);
102
+ }
103
+ #endif
104
+ SnP_Permute(state);
105
+ #ifdef KeccakReference
106
+ displayText(1, "--- Switching to squeezing phase ---");
107
+ #endif
108
+
109
+ /* First, output whole blocks */
110
+ while(outputByteLen > (size_t)rateInBytes) {
111
+ SnP_ExtractBytes(state, curOutput, 0, rateInBytes);
112
+ SnP_Permute(state);
113
+ #ifdef KeccakReference
114
+ displayBytes(1, "Squeezed block", curOutput, rateInBytes);
115
+ #endif
116
+ curOutput += rateInBytes;
117
+ outputByteLen -= rateInBytes;
118
+ }
119
+
120
+ /* Finally, output what remains */
121
+ partialBlock = (unsigned int)outputByteLen;
122
+ SnP_ExtractBytes(state, curOutput, 0, partialBlock);
123
+ #ifdef KeccakReference
124
+ displayBytes(1, "Squeezed block (part)", curOutput, partialBlock);
125
+ #endif
126
+
127
+ return 0;
128
+ }
129
+
130
+ /* ---------------------------------------------------------------- */
131
+ /* ---------------------------------------------------------------- */
132
+ /* ---------------------------------------------------------------- */
133
+
134
+ int SpongeInitialize(SpongeInstance *instance, unsigned int rate, unsigned int capacity)
135
+ {
136
+ if (rate+capacity != SnP_width)
137
+ return 1;
138
+ if ((rate <= 0) || (rate > SnP_width) || ((rate % 8) != 0))
139
+ return 1;
140
+ SnP_StaticInitialize();
141
+ SnP_Initialize(instance->state);
142
+ instance->rate = rate;
143
+ instance->byteIOIndex = 0;
144
+ instance->squeezing = 0;
145
+
146
+ return 0;
147
+ }
148
+
149
+ /* ---------------------------------------------------------------- */
150
+
151
+ int SpongeAbsorb(SpongeInstance *instance, const unsigned char *data, size_t dataByteLen)
152
+ {
153
+ size_t i, j;
154
+ unsigned int partialBlock;
155
+ const unsigned char *curData;
156
+ unsigned int rateInBytes = instance->rate/8;
157
+
158
+ if (instance->squeezing)
159
+ return 1; /* Too late for additional input */
160
+
161
+ i = 0;
162
+ curData = data;
163
+ while(i < dataByteLen) {
164
+ if ((instance->byteIOIndex == 0) && (dataByteLen-i >= rateInBytes)) {
165
+ #ifdef SnP_FastLoop_Absorb
166
+ /* processing full blocks first */
167
+ if ((rateInBytes % (SnP_width/200)) == 0) {
168
+ /* fast lane: whole lane rate */
169
+ j = SnP_FastLoop_Absorb(instance->state, rateInBytes/(SnP_width/200), curData, dataByteLen - i);
170
+ i += j;
171
+ curData += j;
172
+ }
173
+ else {
174
+ #endif
175
+ for(j=dataByteLen-i; j>=rateInBytes; j-=rateInBytes) {
176
+ #ifdef KeccakReference
177
+ displayBytes(1, "Block to be absorbed", curData, rateInBytes);
178
+ #endif
179
+ SnP_AddBytes(instance->state, curData, 0, rateInBytes);
180
+ SnP_Permute(instance->state);
181
+ curData+=rateInBytes;
182
+ }
183
+ i = dataByteLen - j;
184
+ #ifdef SnP_FastLoop_Absorb
185
+ }
186
+ #endif
187
+ }
188
+ else {
189
+ /* normal lane: using the message queue */
190
+ if (dataByteLen-i > rateInBytes-instance->byteIOIndex)
191
+ partialBlock = rateInBytes-instance->byteIOIndex;
192
+ else
193
+ partialBlock = (unsigned int)(dataByteLen - i);
194
+ #ifdef KeccakReference
195
+ displayBytes(1, "Block to be absorbed (part)", curData, partialBlock);
196
+ #endif
197
+ i += partialBlock;
198
+
199
+ SnP_AddBytes(instance->state, curData, instance->byteIOIndex, partialBlock);
200
+ curData += partialBlock;
201
+ instance->byteIOIndex += partialBlock;
202
+ if (instance->byteIOIndex == rateInBytes) {
203
+ SnP_Permute(instance->state);
204
+ instance->byteIOIndex = 0;
205
+ }
206
+ }
207
+ }
208
+ return 0;
209
+ }
210
+
211
+ /* ---------------------------------------------------------------- */
212
+
213
+ int SpongeAbsorbLastFewBits(SpongeInstance *instance, unsigned char delimitedData)
214
+ {
215
+ unsigned int rateInBytes = instance->rate/8;
216
+
217
+ if (delimitedData == 0)
218
+ return 1;
219
+ if (instance->squeezing)
220
+ return 1; /* Too late for additional input */
221
+
222
+ #ifdef KeccakReference
223
+ {
224
+ unsigned char delimitedData1[1];
225
+ delimitedData1[0] = delimitedData;
226
+ displayBytes(1, "Block to be absorbed (last few bits + first bit of padding)", delimitedData1, 1);
227
+ }
228
+ #endif
229
+ /* Last few bits, whose delimiter coincides with first bit of padding */
230
+ SnP_AddByte(instance->state, delimitedData, instance->byteIOIndex);
231
+ /* If the first bit of padding is at position rate-1, we need a whole new block for the second bit of padding */
232
+ if ((delimitedData >= 0x80) && (instance->byteIOIndex == (rateInBytes-1)))
233
+ SnP_Permute(instance->state);
234
+ /* Second bit of padding */
235
+ SnP_AddByte(instance->state, 0x80, rateInBytes-1);
236
+ #ifdef KeccakReference
237
+ {
238
+ unsigned char block[SnP_width/8];
239
+ memset(block, 0, SnP_width/8);
240
+ block[rateInBytes-1] = 0x80;
241
+ displayBytes(1, "Second bit of padding", block, rateInBytes);
242
+ }
243
+ #endif
244
+ SnP_Permute(instance->state);
245
+ instance->byteIOIndex = 0;
246
+ instance->squeezing = 1;
247
+ #ifdef KeccakReference
248
+ displayText(1, "--- Switching to squeezing phase ---");
249
+ #endif
250
+ return 0;
251
+ }
252
+
253
+ /* ---------------------------------------------------------------- */
254
+
255
+ int SpongeSqueeze(SpongeInstance *instance, unsigned char *data, size_t dataByteLen)
256
+ {
257
+ size_t i, j;
258
+ unsigned int partialBlock;
259
+ unsigned int rateInBytes = instance->rate/8;
260
+ unsigned char *curData;
261
+
262
+ if (!instance->squeezing)
263
+ SpongeAbsorbLastFewBits(instance, 0x01);
264
+
265
+ i = 0;
266
+ curData = data;
267
+ while(i < dataByteLen) {
268
+ if ((instance->byteIOIndex == rateInBytes) && (dataByteLen-i >= rateInBytes)) {
269
+ for(j=dataByteLen-i; j>=rateInBytes; j-=rateInBytes) {
270
+ SnP_Permute(instance->state);
271
+ SnP_ExtractBytes(instance->state, curData, 0, rateInBytes);
272
+ #ifdef KeccakReference
273
+ displayBytes(1, "Squeezed block", curData, rateInBytes);
274
+ #endif
275
+ curData+=rateInBytes;
276
+ }
277
+ i = dataByteLen - j;
278
+ }
279
+ else {
280
+ /* normal lane: using the message queue */
281
+ if (instance->byteIOIndex == rateInBytes) {
282
+ SnP_Permute(instance->state);
283
+ instance->byteIOIndex = 0;
284
+ }
285
+ if (dataByteLen-i > rateInBytes-instance->byteIOIndex)
286
+ partialBlock = rateInBytes-instance->byteIOIndex;
287
+ else
288
+ partialBlock = (unsigned int)(dataByteLen - i);
289
+ i += partialBlock;
290
+
291
+ SnP_ExtractBytes(instance->state, curData, instance->byteIOIndex, partialBlock);
292
+ #ifdef KeccakReference
293
+ displayBytes(1, "Squeezed block (part)", curData, partialBlock);
294
+ #endif
295
+ curData += partialBlock;
296
+ instance->byteIOIndex += partialBlock;
297
+ }
298
+ }
299
+ return 0;
300
+ }
301
+
302
+ /* ---------------------------------------------------------------- */
303
+
304
+ #undef Sponge
305
+ #undef SpongeInstance
306
+ #undef SpongeInitialize
307
+ #undef SpongeAbsorb
308
+ #undef SpongeAbsorbLastFewBits
309
+ #undef SpongeSqueeze
310
+ #undef SnP_stateSizeInBytes
311
+ #undef SnP_stateAlignment
312
+ #undef SnP_StaticInitialize
313
+ #undef SnP_Initialize
314
+ #undef SnP_AddByte
315
+ #undef SnP_AddBytes
316
+ #undef SnP_ExtractBytes