sha3 0.2.6 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sha3 might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +9 -1
- data/Gemfile.ci +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +145 -0
- data/Rakefile +4 -5
- data/ext/sha3/KeccakF-1600-interface.h +28 -34
- data/ext/sha3/KeccakHash.c +80 -0
- data/ext/sha3/KeccakHash.h +110 -0
- data/ext/sha3/KeccakSponge.c +127 -201
- data/ext/sha3/KeccakSponge.h +74 -37
- data/ext/sha3/Optimized64/KeccakF-1600-64.macros +2199 -0
- data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +3 -0
- data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +508 -0
- data/ext/sha3/{KeccakF-1600-unrolling.macros → Optimized64/KeccakF-1600-unrolling.macros} +16 -14
- data/ext/sha3/Optimized64/SnP-interface.h +47 -0
- data/ext/sha3/Reference/KeccakF-1600-reference.c +311 -0
- data/ext/sha3/Reference/KeccakF-reference.h +26 -0
- data/ext/sha3/Reference/SnP-FBWL-default.c +96 -0
- data/ext/sha3/Reference/SnP-FBWL-default.h +26 -0
- data/ext/sha3/Reference/SnP-interface.h +42 -0
- data/ext/sha3/{displayIntermediateValues.c → Reference/displayIntermediateValues.c} +52 -11
- data/ext/sha3/{displayIntermediateValues.h → Reference/displayIntermediateValues.h} +11 -6
- data/ext/sha3/SnP-Relaned.h +249 -0
- data/ext/sha3/brg_endian.h +0 -0
- data/ext/sha3/digest.c +67 -70
- data/ext/sha3/digest.h +2 -2
- data/ext/sha3/extconf.rb +7 -12
- data/ext/sha3/sha3.h +2 -2
- data/lib/sha3/doc.rb +26 -39
- data/lib/sha3/version.rb +2 -2
- data/sha3.gemspec +6 -6
- data/spec/generate_tests.rb +6 -41
- data/spec/sha3_core_spec.rb +111 -133
- data/spec/spec_helper.rb +2 -2
- data/tests.sh +9 -7
- metadata +33 -36
- data/README.rdoc +0 -131
- data/ext/sha3/KeccakF-1600-32-rvk.macros +0 -555
- data/ext/sha3/KeccakF-1600-32-s1.macros +0 -1187
- data/ext/sha3/KeccakF-1600-32-s2.macros +0 -1187
- data/ext/sha3/KeccakF-1600-32.macros +0 -26
- data/ext/sha3/KeccakF-1600-64.macros +0 -728
- data/ext/sha3/KeccakF-1600-int-set.h +0 -6
- data/ext/sha3/KeccakF-1600-opt.c +0 -504
- data/ext/sha3/KeccakF-1600-opt32-settings.h +0 -4
- data/ext/sha3/KeccakF-1600-opt32.c-arch +0 -524
- data/ext/sha3/KeccakF-1600-opt64-settings.h +0 -7
- data/ext/sha3/KeccakF-1600-opt64.c-arch +0 -504
- data/ext/sha3/KeccakF-1600-reference.c-arch +0 -300
- data/ext/sha3/KeccakF-1600-x86-64-gas.s +0 -766
- data/ext/sha3/KeccakF-1600-x86-64-shld-gas.s +0 -766
- data/ext/sha3/KeccakNISTInterface.c +0 -81
- data/ext/sha3/KeccakNISTInterface.h +0 -70
@@ -0,0 +1,508 @@
|
|
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
|
+
#include <string.h>
|
17
|
+
#include <stdlib.h>
|
18
|
+
#include "brg_endian.h"
|
19
|
+
#include "KeccakF-1600-opt64-settings.h"
|
20
|
+
#include "KeccakF-1600-interface.h"
|
21
|
+
|
22
|
+
typedef unsigned char UINT8;
|
23
|
+
typedef unsigned long long int UINT64;
|
24
|
+
|
25
|
+
#if defined(__GNUC__)
|
26
|
+
#define ALIGN __attribute__ ((aligned(32)))
|
27
|
+
#elif defined(_MSC_VER)
|
28
|
+
#define ALIGN __declspec(align(32))
|
29
|
+
#else
|
30
|
+
#define ALIGN
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#if defined(UseLaneComplementing)
|
34
|
+
#define UseBebigokimisa
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#if defined(_MSC_VER)
|
38
|
+
#define ROL64(a, offset) _rotl64(a, offset)
|
39
|
+
#elif defined(UseSHLD)
|
40
|
+
#define ROL64(x,N) ({ \
|
41
|
+
register UINT64 __out; \
|
42
|
+
register UINT64 __in = x; \
|
43
|
+
__asm__ ("shld %2,%0,%0" : "=r"(__out) : "0"(__in), "i"(N)); \
|
44
|
+
__out; \
|
45
|
+
})
|
46
|
+
#else
|
47
|
+
#define ROL64(a, offset) ((((UINT64)a) << offset) ^ (((UINT64)a) >> (64-offset)))
|
48
|
+
#endif
|
49
|
+
|
50
|
+
#include "KeccakF-1600-64.macros"
|
51
|
+
#include "KeccakF-1600-unrolling.macros"
|
52
|
+
|
53
|
+
const UINT64 KeccakF1600RoundConstants[24] = {
|
54
|
+
0x0000000000000001ULL,
|
55
|
+
0x0000000000008082ULL,
|
56
|
+
0x800000000000808aULL,
|
57
|
+
0x8000000080008000ULL,
|
58
|
+
0x000000000000808bULL,
|
59
|
+
0x0000000080000001ULL,
|
60
|
+
0x8000000080008081ULL,
|
61
|
+
0x8000000000008009ULL,
|
62
|
+
0x000000000000008aULL,
|
63
|
+
0x0000000000000088ULL,
|
64
|
+
0x0000000080008009ULL,
|
65
|
+
0x000000008000000aULL,
|
66
|
+
0x000000008000808bULL,
|
67
|
+
0x800000000000008bULL,
|
68
|
+
0x8000000000008089ULL,
|
69
|
+
0x8000000000008003ULL,
|
70
|
+
0x8000000000008002ULL,
|
71
|
+
0x8000000000000080ULL,
|
72
|
+
0x000000000000800aULL,
|
73
|
+
0x800000008000000aULL,
|
74
|
+
0x8000000080008081ULL,
|
75
|
+
0x8000000000008080ULL,
|
76
|
+
0x0000000080000001ULL,
|
77
|
+
0x8000000080008008ULL };
|
78
|
+
|
79
|
+
void KeccakF1600_StateXORPermuteExtract(void *state, const unsigned char *inData, unsigned int inLaneCount, unsigned char *outData, unsigned int outLaneCount);
|
80
|
+
|
81
|
+
/* ---------------------------------------------------------------- */
|
82
|
+
|
83
|
+
void KeccakF1600_Initialize( void )
|
84
|
+
{
|
85
|
+
}
|
86
|
+
|
87
|
+
/* ---------------------------------------------------------------- */
|
88
|
+
|
89
|
+
void KeccakF1600_StateInitialize(void *state)
|
90
|
+
{
|
91
|
+
memset(state, 0, 200);
|
92
|
+
#ifdef UseLaneComplementing
|
93
|
+
((UINT64*)state)[ 1] = ~(UINT64)0;
|
94
|
+
((UINT64*)state)[ 2] = ~(UINT64)0;
|
95
|
+
((UINT64*)state)[ 8] = ~(UINT64)0;
|
96
|
+
((UINT64*)state)[12] = ~(UINT64)0;
|
97
|
+
((UINT64*)state)[17] = ~(UINT64)0;
|
98
|
+
((UINT64*)state)[20] = ~(UINT64)0;
|
99
|
+
#endif
|
100
|
+
}
|
101
|
+
|
102
|
+
/* ---------------------------------------------------------------- */
|
103
|
+
|
104
|
+
void KeccakF1600_StateXORBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length)
|
105
|
+
{
|
106
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
107
|
+
if (length == 0)
|
108
|
+
return;
|
109
|
+
UINT64 lane;
|
110
|
+
if (length == 1)
|
111
|
+
lane = data[0];
|
112
|
+
else {
|
113
|
+
lane = 0;
|
114
|
+
memcpy(&lane, data, length);
|
115
|
+
}
|
116
|
+
lane <<= offset*8;
|
117
|
+
#else
|
118
|
+
UINT64 lane = 0;
|
119
|
+
unsigned int i;
|
120
|
+
for(i=0; i<length; i++)
|
121
|
+
lane |= ((UINT64)data[i]) << ((i+offset)*8);
|
122
|
+
#endif
|
123
|
+
((UINT64*)state)[lanePosition] ^= lane;
|
124
|
+
}
|
125
|
+
|
126
|
+
/* ---------------------------------------------------------------- */
|
127
|
+
|
128
|
+
void KeccakF1600_StateXORLanes(void *state, const unsigned char *data, unsigned int laneCount)
|
129
|
+
{
|
130
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
131
|
+
unsigned int i = 0;
|
132
|
+
#ifdef NO_MISALIGNED_ACCESSES
|
133
|
+
// If either pointer is misaligned, fall back to byte-wise xor.
|
134
|
+
if (((((uintptr_t)state) & 7) != 0) || ((((uintptr_t)data) & 7) != 0)) {
|
135
|
+
for (i = 0; i < laneCount * 8; i++) {
|
136
|
+
((unsigned char*)state)[i] ^= data[i];
|
137
|
+
}
|
138
|
+
}
|
139
|
+
else
|
140
|
+
#endif
|
141
|
+
{
|
142
|
+
// Otherwise...
|
143
|
+
for( ; (i+8)<=laneCount; i+=8) {
|
144
|
+
((UINT64*)state)[i+0] ^= ((UINT64*)data)[i+0];
|
145
|
+
((UINT64*)state)[i+1] ^= ((UINT64*)data)[i+1];
|
146
|
+
((UINT64*)state)[i+2] ^= ((UINT64*)data)[i+2];
|
147
|
+
((UINT64*)state)[i+3] ^= ((UINT64*)data)[i+3];
|
148
|
+
((UINT64*)state)[i+4] ^= ((UINT64*)data)[i+4];
|
149
|
+
((UINT64*)state)[i+5] ^= ((UINT64*)data)[i+5];
|
150
|
+
((UINT64*)state)[i+6] ^= ((UINT64*)data)[i+6];
|
151
|
+
((UINT64*)state)[i+7] ^= ((UINT64*)data)[i+7];
|
152
|
+
}
|
153
|
+
for( ; (i+4)<=laneCount; i+=4) {
|
154
|
+
((UINT64*)state)[i+0] ^= ((UINT64*)data)[i+0];
|
155
|
+
((UINT64*)state)[i+1] ^= ((UINT64*)data)[i+1];
|
156
|
+
((UINT64*)state)[i+2] ^= ((UINT64*)data)[i+2];
|
157
|
+
((UINT64*)state)[i+3] ^= ((UINT64*)data)[i+3];
|
158
|
+
}
|
159
|
+
for( ; (i+2)<=laneCount; i+=2) {
|
160
|
+
((UINT64*)state)[i+0] ^= ((UINT64*)data)[i+0];
|
161
|
+
((UINT64*)state)[i+1] ^= ((UINT64*)data)[i+1];
|
162
|
+
}
|
163
|
+
if (i<laneCount) {
|
164
|
+
((UINT64*)state)[i+0] ^= ((UINT64*)data)[i+0];
|
165
|
+
}
|
166
|
+
}
|
167
|
+
#else
|
168
|
+
unsigned int i;
|
169
|
+
UINT8 *curData = data;
|
170
|
+
for(i=0; i<laneCount; i++, curData+=8) {
|
171
|
+
UINT64 lane = (UINT64)curData[0]
|
172
|
+
| ((UINT64)curData[1] << 8)
|
173
|
+
| ((UINT64)curData[2] << 16)
|
174
|
+
| ((UINT64)curData[3] << 24)
|
175
|
+
| ((UINT64)curData[4] <<32)
|
176
|
+
| ((UINT64)curData[5] << 40)
|
177
|
+
| ((UINT64)curData[6] << 48)
|
178
|
+
| ((UINT64)curData[7] << 56);
|
179
|
+
((UINT64*)state)[i] ^= lane;
|
180
|
+
}
|
181
|
+
#endif
|
182
|
+
}
|
183
|
+
|
184
|
+
/* ---------------------------------------------------------------- */
|
185
|
+
|
186
|
+
void KeccakF1600_StateOverwriteBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length)
|
187
|
+
{
|
188
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
189
|
+
#ifdef UseLaneComplementing
|
190
|
+
if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20)) {
|
191
|
+
unsigned int i;
|
192
|
+
for(i=0; i<length; i++)
|
193
|
+
((unsigned char*)state)[lanePosition*8+offset+i] = ~data[i];
|
194
|
+
}
|
195
|
+
else
|
196
|
+
#endif
|
197
|
+
{
|
198
|
+
memcpy((unsigned char*)state+lanePosition*8+offset, data, length);
|
199
|
+
}
|
200
|
+
#else
|
201
|
+
#error "Not yet implemented"
|
202
|
+
#endif
|
203
|
+
}
|
204
|
+
|
205
|
+
/* ---------------------------------------------------------------- */
|
206
|
+
|
207
|
+
void KeccakF1600_StateOverwriteLanes(void *state, const unsigned char *data, unsigned int laneCount)
|
208
|
+
{
|
209
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
210
|
+
#ifdef UseLaneComplementing
|
211
|
+
unsigned int lanePosition;
|
212
|
+
|
213
|
+
for(lanePosition=0; lanePosition<laneCount; lanePosition++)
|
214
|
+
if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20))
|
215
|
+
((UINT64*)state)[lanePosition] = ~((const UINT64*)data)[lanePosition];
|
216
|
+
else
|
217
|
+
((UINT64*)state)[lanePosition] = ((const UINT64*)data)[lanePosition];
|
218
|
+
#else
|
219
|
+
memcpy(state, data, laneCount*8);
|
220
|
+
#endif
|
221
|
+
#else
|
222
|
+
#error "Not yet implemented"
|
223
|
+
#endif
|
224
|
+
}
|
225
|
+
|
226
|
+
/* ---------------------------------------------------------------- */
|
227
|
+
|
228
|
+
void KeccakF1600_StateOverwriteWithZeroes(void *state, unsigned int byteCount)
|
229
|
+
{
|
230
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
231
|
+
#ifdef UseLaneComplementing
|
232
|
+
unsigned int lanePosition;
|
233
|
+
|
234
|
+
for(lanePosition=0; lanePosition<byteCount/8; lanePosition++)
|
235
|
+
if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20))
|
236
|
+
((UINT64*)state)[lanePosition] = ~0;
|
237
|
+
else
|
238
|
+
((UINT64*)state)[lanePosition] = 0;
|
239
|
+
if (byteCount%8 != 0) {
|
240
|
+
lanePosition = byteCount/8;
|
241
|
+
if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20))
|
242
|
+
memset(state+lanePosition*8, 0xFF, byteCount%8);
|
243
|
+
else
|
244
|
+
memset(state+lanePosition*8, 0, byteCount%8);
|
245
|
+
}
|
246
|
+
#else
|
247
|
+
memset(state, 0, byteCount);
|
248
|
+
#endif
|
249
|
+
#else
|
250
|
+
#error "Not yet implemented"
|
251
|
+
#endif
|
252
|
+
}
|
253
|
+
|
254
|
+
/* ---------------------------------------------------------------- */
|
255
|
+
|
256
|
+
void KeccakF1600_StateComplementBit(void *state, unsigned int position)
|
257
|
+
{
|
258
|
+
UINT64 lane = (UINT64)1 << (position%64);
|
259
|
+
((UINT64*)state)[position/64] ^= lane;
|
260
|
+
}
|
261
|
+
|
262
|
+
/* ---------------------------------------------------------------- */
|
263
|
+
|
264
|
+
void KeccakF1600_StatePermute(void *state)
|
265
|
+
{
|
266
|
+
declareABCDE
|
267
|
+
#ifndef FullUnrolling
|
268
|
+
unsigned int i;
|
269
|
+
#endif
|
270
|
+
UINT64 *stateAsLanes = (UINT64*)state;
|
271
|
+
|
272
|
+
copyFromState(A, stateAsLanes)
|
273
|
+
rounds
|
274
|
+
copyToState(stateAsLanes, A)
|
275
|
+
}
|
276
|
+
|
277
|
+
/* ---------------------------------------------------------------- */
|
278
|
+
|
279
|
+
void KeccakF1600_StateExtractBytesInLane(const void *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length)
|
280
|
+
{
|
281
|
+
UINT64 lane = ((UINT64*)state)[lanePosition];
|
282
|
+
#ifdef UseLaneComplementing
|
283
|
+
if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20))
|
284
|
+
lane = ~lane;
|
285
|
+
#endif
|
286
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
287
|
+
{
|
288
|
+
UINT64 lane1[1];
|
289
|
+
lane1[0] = lane;
|
290
|
+
memcpy(data, (UINT8*)lane1+offset, length);
|
291
|
+
}
|
292
|
+
#else
|
293
|
+
unsigned int i;
|
294
|
+
lane >>= offset*8;
|
295
|
+
for(i=0; i<length; i++) {
|
296
|
+
data[i] = lane & 0xFF;
|
297
|
+
lane >>= 8;
|
298
|
+
}
|
299
|
+
#endif
|
300
|
+
}
|
301
|
+
|
302
|
+
/* ---------------------------------------------------------------- */
|
303
|
+
|
304
|
+
#if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
|
305
|
+
void fromWordToBytes(UINT8 *bytes, const UINT64 word)
|
306
|
+
{
|
307
|
+
unsigned int i;
|
308
|
+
|
309
|
+
for(i=0; i<(64/8); i++)
|
310
|
+
bytes[i] = (word >> (8*i)) & 0xFF;
|
311
|
+
}
|
312
|
+
#endif
|
313
|
+
|
314
|
+
void KeccakF1600_StateExtractLanes(const void *state, unsigned char *data, unsigned int laneCount)
|
315
|
+
{
|
316
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
317
|
+
memcpy(data, state, laneCount*8);
|
318
|
+
#else
|
319
|
+
unsigned int i;
|
320
|
+
|
321
|
+
for(i=0; i<laneCount; i++)
|
322
|
+
fromWordToBytes(data+(i*8), ((const UINT64*)state)[i]);
|
323
|
+
#endif
|
324
|
+
#ifdef UseLaneComplementing
|
325
|
+
if (laneCount > 1) {
|
326
|
+
((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1];
|
327
|
+
if (laneCount > 2) {
|
328
|
+
((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2];
|
329
|
+
if (laneCount > 8) {
|
330
|
+
((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8];
|
331
|
+
if (laneCount > 12) {
|
332
|
+
((UINT64*)data)[12] = ~((UINT64*)data)[12];
|
333
|
+
if (laneCount > 17) {
|
334
|
+
((UINT64*)data)[17] = ~((UINT64*)data)[17];
|
335
|
+
if (laneCount > 20) {
|
336
|
+
((UINT64*)data)[20] = ~((UINT64*)data)[20];
|
337
|
+
}
|
338
|
+
}
|
339
|
+
}
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}
|
343
|
+
#endif
|
344
|
+
}
|
345
|
+
|
346
|
+
/* ---------------------------------------------------------------- */
|
347
|
+
|
348
|
+
void KeccakF1600_StateExtractAndXORBytesInLane(const void *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length)
|
349
|
+
{
|
350
|
+
UINT64 lane = ((UINT64*)state)[lanePosition];
|
351
|
+
#ifdef UseLaneComplementing
|
352
|
+
if ((lanePosition == 1) || (lanePosition == 2) || (lanePosition == 8) || (lanePosition == 12) || (lanePosition == 17) || (lanePosition == 20))
|
353
|
+
lane = ~lane;
|
354
|
+
#endif
|
355
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
356
|
+
{
|
357
|
+
unsigned int i;
|
358
|
+
UINT64 lane1[1];
|
359
|
+
lane1[0] = lane;
|
360
|
+
for(i=0; i<length; i++)
|
361
|
+
data[i] ^= ((UINT8*)lane1)[offset+i];
|
362
|
+
}
|
363
|
+
#else
|
364
|
+
unsigned int i;
|
365
|
+
lane >>= offset*8;
|
366
|
+
for(i=0; i<length; i++) {
|
367
|
+
data[i] ^= lane & 0xFF;
|
368
|
+
lane >>= 8;
|
369
|
+
}
|
370
|
+
#endif
|
371
|
+
}
|
372
|
+
|
373
|
+
/* ---------------------------------------------------------------- */
|
374
|
+
|
375
|
+
void KeccakF1600_StateExtractAndXORLanes(const void *state, unsigned char *data, unsigned int laneCount)
|
376
|
+
{
|
377
|
+
unsigned int i;
|
378
|
+
#if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
|
379
|
+
unsigned char temp[8];
|
380
|
+
unsigned int j;
|
381
|
+
#endif
|
382
|
+
|
383
|
+
for(i=0; i<laneCount; i++) {
|
384
|
+
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
385
|
+
((UINT64*)data)[i] ^= ((const UINT64*)state)[i];
|
386
|
+
#else
|
387
|
+
fromWordToBytes(temp, ((const UINT64*)state)[i]);
|
388
|
+
for(j=0; j<8; j++)
|
389
|
+
data[i*8+j] ^= temp[j];
|
390
|
+
#endif
|
391
|
+
}
|
392
|
+
#ifdef UseLaneComplementing
|
393
|
+
if (laneCount > 1) {
|
394
|
+
((UINT64*)data)[ 1] = ~((UINT64*)data)[ 1];
|
395
|
+
if (laneCount > 2) {
|
396
|
+
((UINT64*)data)[ 2] = ~((UINT64*)data)[ 2];
|
397
|
+
if (laneCount > 8) {
|
398
|
+
((UINT64*)data)[ 8] = ~((UINT64*)data)[ 8];
|
399
|
+
if (laneCount > 12) {
|
400
|
+
((UINT64*)data)[12] = ~((UINT64*)data)[12];
|
401
|
+
if (laneCount > 17) {
|
402
|
+
((UINT64*)data)[17] = ~((UINT64*)data)[17];
|
403
|
+
if (laneCount > 20) {
|
404
|
+
((UINT64*)data)[20] = ~((UINT64*)data)[20];
|
405
|
+
}
|
406
|
+
}
|
407
|
+
}
|
408
|
+
}
|
409
|
+
}
|
410
|
+
}
|
411
|
+
#endif
|
412
|
+
}
|
413
|
+
|
414
|
+
/* ---------------------------------------------------------------- */
|
415
|
+
|
416
|
+
size_t KeccakF1600_FBWL_Absorb(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen, unsigned char trailingBits)
|
417
|
+
{
|
418
|
+
size_t originalDataByteLen = dataByteLen;
|
419
|
+
declareABCDE
|
420
|
+
#ifndef FullUnrolling
|
421
|
+
unsigned int i;
|
422
|
+
#endif
|
423
|
+
UINT64 *stateAsLanes = (UINT64*)state;
|
424
|
+
UINT64 *inDataAsLanes = (UINT64*)data;
|
425
|
+
|
426
|
+
copyFromState(A, stateAsLanes)
|
427
|
+
while(dataByteLen >= laneCount*8) {
|
428
|
+
XORinputAndTrailingBits(A, inDataAsLanes, laneCount, ((UINT64)trailingBits))
|
429
|
+
rounds
|
430
|
+
inDataAsLanes += laneCount;
|
431
|
+
dataByteLen -= laneCount*8;
|
432
|
+
}
|
433
|
+
copyToState(stateAsLanes, A)
|
434
|
+
return originalDataByteLen - dataByteLen;
|
435
|
+
}
|
436
|
+
|
437
|
+
/* ---------------------------------------------------------------- */
|
438
|
+
|
439
|
+
size_t KeccakF1600_FBWL_Squeeze(void *state, unsigned int laneCount, unsigned char *data, size_t dataByteLen)
|
440
|
+
{
|
441
|
+
size_t originalDataByteLen = dataByteLen;
|
442
|
+
declareABCDE
|
443
|
+
#ifndef FullUnrolling
|
444
|
+
unsigned int i;
|
445
|
+
#endif
|
446
|
+
UINT64 *stateAsLanes = (UINT64*)state;
|
447
|
+
UINT64 *outDataAsLanes = (UINT64*)data;
|
448
|
+
|
449
|
+
copyFromState(A, stateAsLanes)
|
450
|
+
while(dataByteLen >= laneCount*8) {
|
451
|
+
rounds
|
452
|
+
output(A, outDataAsLanes, laneCount)
|
453
|
+
outDataAsLanes += laneCount;
|
454
|
+
dataByteLen -= laneCount*8;
|
455
|
+
}
|
456
|
+
copyToState(stateAsLanes, A)
|
457
|
+
return originalDataByteLen - dataByteLen;
|
458
|
+
}
|
459
|
+
|
460
|
+
/* ---------------------------------------------------------------- */
|
461
|
+
|
462
|
+
size_t KeccakF1600_FBWL_Wrap(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits)
|
463
|
+
{
|
464
|
+
size_t originalDataByteLen = dataByteLen;
|
465
|
+
declareABCDE
|
466
|
+
#ifndef FullUnrolling
|
467
|
+
unsigned int i;
|
468
|
+
#endif
|
469
|
+
UINT64 *stateAsLanes = (UINT64*)state;
|
470
|
+
UINT64 *inDataAsLanes = (UINT64*)dataIn;
|
471
|
+
UINT64 *outDataAsLanes = (UINT64*)dataOut;
|
472
|
+
|
473
|
+
copyFromState(A, stateAsLanes)
|
474
|
+
while(dataByteLen >= laneCount*8) {
|
475
|
+
wrap(A, inDataAsLanes, outDataAsLanes, laneCount, ((UINT64)trailingBits))
|
476
|
+
rounds
|
477
|
+
inDataAsLanes += laneCount;
|
478
|
+
outDataAsLanes += laneCount;
|
479
|
+
dataByteLen -= laneCount*8;
|
480
|
+
}
|
481
|
+
copyToState(stateAsLanes, A)
|
482
|
+
return originalDataByteLen - dataByteLen;
|
483
|
+
}
|
484
|
+
|
485
|
+
/* ---------------------------------------------------------------- */
|
486
|
+
|
487
|
+
size_t KeccakF1600_FBWL_Unwrap(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits)
|
488
|
+
{
|
489
|
+
size_t originalDataByteLen = dataByteLen;
|
490
|
+
declareABCDE
|
491
|
+
#ifndef FullUnrolling
|
492
|
+
unsigned int i;
|
493
|
+
#endif
|
494
|
+
UINT64 *stateAsLanes = (UINT64*)state;
|
495
|
+
UINT64 *inDataAsLanes = (UINT64*)dataIn;
|
496
|
+
UINT64 *outDataAsLanes = (UINT64*)dataOut;
|
497
|
+
|
498
|
+
copyFromState(A, stateAsLanes)
|
499
|
+
while(dataByteLen >= laneCount*8) {
|
500
|
+
unwrap(A, inDataAsLanes, outDataAsLanes, laneCount, ((UINT64)trailingBits))
|
501
|
+
rounds
|
502
|
+
inDataAsLanes += laneCount;
|
503
|
+
outDataAsLanes += laneCount;
|
504
|
+
dataByteLen -= laneCount*8;
|
505
|
+
}
|
506
|
+
copyToState(stateAsLanes, A)
|
507
|
+
return originalDataByteLen - dataByteLen;
|
508
|
+
}
|