sha3 0.2.5 → 1.0.3

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.

Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +232 -20
  3. data/.travis.yml +18 -12
  4. data/Gemfile +1 -1
  5. data/Gemfile.ci +5 -5
  6. data/LICENSE.txt +1 -1
  7. data/README.md +120 -0
  8. data/Rakefile +15 -18
  9. data/ext/sha3/KeccakF-1600-interface.h +28 -34
  10. data/ext/sha3/KeccakHash.c +80 -0
  11. data/ext/sha3/KeccakHash.h +110 -0
  12. data/ext/sha3/KeccakSponge.c +127 -201
  13. data/ext/sha3/KeccakSponge.h +74 -37
  14. data/ext/sha3/Optimized64/KeccakF-1600-64.macros +2199 -0
  15. data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +3 -0
  16. data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +508 -0
  17. data/ext/sha3/{KeccakF-1600-unrolling.macros → Optimized64/KeccakF-1600-unrolling.macros} +16 -14
  18. data/ext/sha3/Optimized64/SnP-interface.h +47 -0
  19. data/ext/sha3/Reference/KeccakF-1600-reference.c +311 -0
  20. data/ext/sha3/Reference/KeccakF-reference.h +26 -0
  21. data/ext/sha3/Reference/SnP-FBWL-default.c +96 -0
  22. data/ext/sha3/Reference/SnP-FBWL-default.h +26 -0
  23. data/ext/sha3/Reference/SnP-interface.h +42 -0
  24. data/ext/sha3/{displayIntermediateValues.c → Reference/displayIntermediateValues.c} +52 -11
  25. data/ext/sha3/{displayIntermediateValues.h → Reference/displayIntermediateValues.h} +11 -6
  26. data/ext/sha3/SnP-Relaned.h +249 -0
  27. data/ext/sha3/brg_endian.h +0 -0
  28. data/ext/sha3/digest.c +182 -167
  29. data/ext/sha3/digest.h +37 -29
  30. data/ext/sha3/extconf.rb +13 -13
  31. data/ext/sha3/sha3.c +46 -30
  32. data/ext/sha3/sha3.h +10 -9
  33. data/lib/sha3/doc.rb +26 -39
  34. data/lib/sha3/version.rb +2 -3
  35. data/sha3.gemspec +13 -15
  36. data/spec/generate_tests.rb +22 -57
  37. data/spec/sha3_core_spec.rb +111 -133
  38. data/spec/spec_helper.rb +2 -2
  39. data/tests.sh +11 -9
  40. metadata +46 -51
  41. data/README.rdoc +0 -132
  42. data/ext/sha3/KeccakF-1600-32-rvk.macros +0 -555
  43. data/ext/sha3/KeccakF-1600-32-s1.macros +0 -1187
  44. data/ext/sha3/KeccakF-1600-32-s2.macros +0 -1187
  45. data/ext/sha3/KeccakF-1600-32.macros +0 -26
  46. data/ext/sha3/KeccakF-1600-64.macros +0 -728
  47. data/ext/sha3/KeccakF-1600-int-set.h +0 -6
  48. data/ext/sha3/KeccakF-1600-opt.c +0 -504
  49. data/ext/sha3/KeccakF-1600-opt32-settings.h +0 -4
  50. data/ext/sha3/KeccakF-1600-opt32.c-arch +0 -524
  51. data/ext/sha3/KeccakF-1600-opt64-settings.h +0 -7
  52. data/ext/sha3/KeccakF-1600-opt64.c-arch +0 -504
  53. data/ext/sha3/KeccakF-1600-reference.c-arch +0 -300
  54. data/ext/sha3/KeccakF-1600-x86-64-gas.s +0 -766
  55. data/ext/sha3/KeccakF-1600-x86-64-shld-gas.s +0 -766
  56. data/ext/sha3/KeccakNISTInterface.c +0 -81
  57. data/ext/sha3/KeccakNISTInterface.h +0 -70
@@ -0,0 +1,3 @@
1
+ #define FullUnrolling
2
+ #define UseLaneComplementing
3
+ #define UseSHLD
@@ -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
+ }
@@ -1,17 +1,19 @@
1
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/
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
5
 
6
- Implementation by the designers,
7
- hereby denoted as "the implementer".
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/
8
10
 
9
11
  To the extent possible under law, the implementer has waived all copyright
10
12
  and related or neighboring rights to the source code in this file.
11
13
  http://creativecommons.org/publicdomain/zero/1.0/
12
14
  */
13
15
 
14
- #if (Unrolling == 24)
16
+ #if (defined(FullUnrolling))
15
17
  #define rounds \
16
18
  prepareTheta \
17
19
  thetaRhoPiChiIotaPrepareTheta( 0, A, E) \
@@ -38,7 +40,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
38
40
  thetaRhoPiChiIotaPrepareTheta(21, E, A) \
39
41
  thetaRhoPiChiIotaPrepareTheta(22, A, E) \
40
42
  thetaRhoPiChiIota(23, E, A) \
41
- copyToState(state, A)
43
+
42
44
  #elif (Unrolling == 12)
43
45
  #define rounds \
44
46
  prepareTheta \
@@ -56,7 +58,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
56
58
  thetaRhoPiChiIotaPrepareTheta(i+10, A, E) \
57
59
  thetaRhoPiChiIotaPrepareTheta(i+11, E, A) \
58
60
  } \
59
- copyToState(state, A)
61
+
60
62
  #elif (Unrolling == 8)
61
63
  #define rounds \
62
64
  prepareTheta \
@@ -70,7 +72,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
70
72
  thetaRhoPiChiIotaPrepareTheta(i+6, A, E) \
71
73
  thetaRhoPiChiIotaPrepareTheta(i+7, E, A) \
72
74
  } \
73
- copyToState(state, A)
75
+
74
76
  #elif (Unrolling == 6)
75
77
  #define rounds \
76
78
  prepareTheta \
@@ -82,7 +84,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
82
84
  thetaRhoPiChiIotaPrepareTheta(i+4, A, E) \
83
85
  thetaRhoPiChiIotaPrepareTheta(i+5, E, A) \
84
86
  } \
85
- copyToState(state, A)
87
+
86
88
  #elif (Unrolling == 4)
87
89
  #define rounds \
88
90
  prepareTheta \
@@ -92,7 +94,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
92
94
  thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
93
95
  thetaRhoPiChiIotaPrepareTheta(i+3, E, A) \
94
96
  } \
95
- copyToState(state, A)
97
+
96
98
  #elif (Unrolling == 3)
97
99
  #define rounds \
98
100
  prepareTheta \
@@ -102,7 +104,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
102
104
  thetaRhoPiChiIotaPrepareTheta(i+2, A, E) \
103
105
  copyStateVariables(A, E) \
104
106
  } \
105
- copyToState(state, A)
107
+
106
108
  #elif (Unrolling == 2)
107
109
  #define rounds \
108
110
  prepareTheta \
@@ -110,7 +112,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
110
112
  thetaRhoPiChiIotaPrepareTheta(i , A, E) \
111
113
  thetaRhoPiChiIotaPrepareTheta(i+1, E, A) \
112
114
  } \
113
- copyToState(state, A)
115
+
114
116
  #elif (Unrolling == 1)
115
117
  #define rounds \
116
118
  prepareTheta \
@@ -118,7 +120,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
118
120
  thetaRhoPiChiIotaPrepareTheta(i , A, E) \
119
121
  copyStateVariables(A, E) \
120
122
  } \
121
- copyToState(state, A)
123
+
122
124
  #else
123
125
  #error "Unrolling is not correctly specified!"
124
126
  #endif
@@ -0,0 +1,47 @@
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 _SnP_Interface_h_
17
+ #define _SnP_Interface_h_
18
+
19
+ #include "KeccakF-1600-interface.h"
20
+
21
+ #define SnP_width KeccakF_width
22
+ #define SnP_stateSizeInBytes KeccakF_stateSizeInBytes
23
+ #define SnP_laneLengthInBytes KeccakF_laneInBytes
24
+ #define SnP_laneCount 25
25
+
26
+ #define SnP_StaticInitialize KeccakF1600_Initialize
27
+ #define SnP_Initialize KeccakF1600_StateInitialize
28
+ #define SnP_XORBytesInLane KeccakF1600_StateXORBytesInLane
29
+ #define SnP_XORLanes KeccakF1600_StateXORLanes
30
+ #define SnP_OverwriteBytesInLane KeccakF1600_StateOverwriteBytesInLane
31
+ #define SnP_OverwriteLanes KeccakF1600_StateOverwriteLanes
32
+ #define SnP_OverwriteWithZeroes KeccakF1600_StateOverwriteWithZeroes
33
+ #define SnP_ComplementBit KeccakF1600_StateComplementBit
34
+ #define SnP_Permute KeccakF1600_StatePermute
35
+ #define SnP_ExtractBytesInLane KeccakF1600_StateExtractBytesInLane
36
+ #define SnP_ExtractLanes KeccakF1600_StateExtractLanes
37
+ #define SnP_ExtractAndXORBytesInLane KeccakF1600_StateExtractAndXORBytesInLane
38
+ #define SnP_ExtractAndXORLanes KeccakF1600_StateExtractAndXORLanes
39
+
40
+ #include "SnP-Relaned.h"
41
+
42
+ #define SnP_FBWL_Absorb KeccakF1600_FBWL_Absorb
43
+ #define SnP_FBWL_Squeeze KeccakF1600_FBWL_Squeeze
44
+ #define SnP_FBWL_Wrap KeccakF1600_FBWL_Wrap
45
+ #define SnP_FBWL_Unwrap KeccakF1600_FBWL_Unwrap
46
+
47
+ #endif