sha3 1.0.5 → 2.1.0

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 (54) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/.clang-format +54 -0
  4. data/.document +3 -3
  5. data/.rdoc_options +11 -0
  6. data/.rspec +2 -2
  7. data/.rubocop.yml +8 -1
  8. data/CHANGELOG.md +23 -0
  9. data/Gemfile +12 -0
  10. data/LICENSE.txt +1 -1
  11. data/README.md +185 -65
  12. data/Rakefile +12 -4
  13. data/certs/io+sha3@jsg.io.pem +26 -0
  14. data/doc/sha3.rb +83 -0
  15. data/ext/sha3/config.h +2 -2
  16. data/ext/sha3/digest.c +726 -169
  17. data/ext/sha3/digest.h +6 -35
  18. data/ext/sha3/extconf.rb +42 -38
  19. data/ext/sha3/kmac.c +504 -0
  20. data/ext/sha3/kmac.h +14 -0
  21. data/ext/sha3/lib/high/Keccak/KeccakDuplex.c +81 -0
  22. data/ext/sha3/lib/high/Keccak/KeccakDuplex.h +73 -0
  23. data/ext/sha3/lib/high/Keccak/KeccakDuplex.inc +201 -0
  24. data/ext/sha3/lib/high/Keccak/KeccakSponge.c +2 -18
  25. data/ext/sha3/lib/high/Keccak/KeccakSponge.h +4 -10
  26. data/ext/sha3/lib/high/Keccak/KeccakSponge.inc +27 -31
  27. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.c +61 -0
  28. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.h +67 -0
  29. data/ext/sha3/lib/high/Keccak/PRG/KeccakPRG.inc +128 -0
  30. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.c +93 -0
  31. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.h +599 -0
  32. data/ext/sha3/lib/high/Keccak/SP800-185/SP800-185.inc +573 -0
  33. data/ext/sha3/lib/high/common/Phases.h +25 -0
  34. data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros +19 -9
  35. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h +18 -12
  36. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c +28 -36
  37. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h +18 -12
  38. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c +28 -59
  39. data/ext/sha3/lib/low/common/PlSnP-Fallback.inc +291 -0
  40. data/ext/sha3/lib/low/common/SnP-Relaned.h +145 -0
  41. data/ext/sha3/sha3.c +28 -59
  42. data/ext/sha3/sha3.h +4 -13
  43. data/lib/constants.rb +5 -0
  44. data/lib/sha3.rb +25 -24
  45. data.tar.gz.sig +0 -0
  46. metadata +61 -127
  47. metadata.gz.sig +0 -0
  48. data/.yardopts +0 -1
  49. data/ChangeLog.rdoc +0 -27
  50. data/certs/johanns.pem +0 -25
  51. data/lib/sha3/doc.rb +0 -121
  52. data/lib/sha3/version.rb +0 -9
  53. data/sha3.gemspec +0 -54
  54. data/tests.sh +0 -29
@@ -32,6 +32,7 @@ Please refer to LowLevel.build for the exact list of other files it must be comb
32
32
  #ifdef KeccakReference
33
33
  #include "displayIntermediateValues.h"
34
34
  #endif
35
+ #include "KeccakP-1600-SnP.h"
35
36
 
36
37
  #define maxNrRounds 24
37
38
  #define nrLanes 25
@@ -187,16 +188,16 @@ static const unsigned int KeccakRhoOffsets[nrLanes] =
187
188
 
188
189
  /* ---------------------------------------------------------------- */
189
190
 
190
- void KeccakP1600_Initialize(void *state)
191
+ void KeccakP1600_Initialize(KeccakP1600_plain32_state *state)
191
192
  {
192
193
  memset(state, 0, 1600/8);
193
194
  }
194
195
 
195
196
  /* ---------------------------------------------------------------- */
196
197
 
197
- void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length);
198
+ void KeccakP1600_AddBytes(KeccakP1600_plain32_state *state, const unsigned char *data, unsigned int offset, unsigned int length);
198
199
 
199
- void KeccakP1600_AddByte(void *state, unsigned char byte, unsigned int offset)
200
+ void KeccakP1600_AddByte(KeccakP1600_plain32_state *state, unsigned char byte, unsigned int offset)
200
201
  {
201
202
  unsigned char data[1];
202
203
 
@@ -209,13 +210,12 @@ void KeccakP1600_AddByte(void *state, unsigned char byte, unsigned int offset)
209
210
 
210
211
  /* ---------------------------------------------------------------- */
211
212
 
212
- void KeccakP1600_AddBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length)
213
+ void KeccakP1600_AddBytesInLane(KeccakP1600_plain32_state *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length)
213
214
  {
214
215
  if ((lanePosition < 25) && (offset < 8) && (offset+length <= 8)) {
215
216
  uint8_t laneAsBytes[8];
216
217
  uint32_t low, high;
217
218
  uint32_t lane[2];
218
- uint32_t *stateAsHalfLanes;
219
219
 
220
220
  memset(laneAsBytes, 0, 8);
221
221
  memcpy(laneAsBytes+offset, data, length);
@@ -228,13 +228,12 @@ void KeccakP1600_AddBytesInLane(void *state, unsigned int lanePosition, const un
228
228
  | ((uint32_t)(laneAsBytes[6]) << 16)
229
229
  | ((uint32_t)(laneAsBytes[7]) << 24);
230
230
  toBitInterleaving(low, high, lane, lane+1);
231
- stateAsHalfLanes = (uint32_t*)state;
232
- stateAsHalfLanes[lanePosition*2+0] ^= lane[0];
233
- stateAsHalfLanes[lanePosition*2+1] ^= lane[1];
231
+ state->A[lanePosition*2+0] ^= lane[0];
232
+ state->A[lanePosition*2+1] ^= lane[1];
234
233
  }
235
234
  }
236
235
 
237
- void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
236
+ void KeccakP1600_AddBytes(KeccakP1600_plain32_state *state, const unsigned char *data, unsigned int offset, unsigned int length)
238
237
  {
239
238
  unsigned int lanePosition = offset/8;
240
239
  unsigned int offsetInLane = offset%8;
@@ -257,15 +256,14 @@ void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int o
257
256
 
258
257
  /* ---------------------------------------------------------------- */
259
258
 
260
- void KeccakP1600_ExtractBytesInLane(const void *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length);
259
+ void KeccakP1600_ExtractBytesInLane(const KeccakP1600_plain32_state *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length);
261
260
 
262
- void KeccakP1600_OverwriteBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length)
261
+ void KeccakP1600_OverwriteBytesInLane(KeccakP1600_plain32_state *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length)
263
262
  {
264
263
  if ((lanePosition < 25) && (offset < 8) && (offset+length <= 8)) {
265
264
  uint8_t laneAsBytes[8];
266
265
  uint32_t low, high;
267
266
  uint32_t lane[2];
268
- uint32_t *stateAsHalfLanes;
269
267
 
270
268
  KeccakP1600_ExtractBytesInLane(state, lanePosition, laneAsBytes, 0, 8);
271
269
  memcpy(laneAsBytes+offset, data, length);
@@ -278,13 +276,12 @@ void KeccakP1600_OverwriteBytesInLane(void *state, unsigned int lanePosition, co
278
276
  | ((uint32_t)(laneAsBytes[6]) << 16)
279
277
  | ((uint32_t)(laneAsBytes[7]) << 24);
280
278
  toBitInterleaving(low, high, lane, lane+1);
281
- stateAsHalfLanes = (uint32_t*)state;
282
- stateAsHalfLanes[lanePosition*2+0] = lane[0];
283
- stateAsHalfLanes[lanePosition*2+1] = lane[1];
279
+ state->A[lanePosition*2+0] = lane[0];
280
+ state->A[lanePosition*2+1] = lane[1];
284
281
  }
285
282
  }
286
283
 
287
- void KeccakP1600_OverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
284
+ void KeccakP1600_OverwriteBytes(KeccakP1600_plain32_state *state, const unsigned char *data, unsigned int offset, unsigned int length)
288
285
  {
289
286
  unsigned int lanePosition = offset/8;
290
287
  unsigned int offsetInLane = offset%8;
@@ -307,7 +304,7 @@ void KeccakP1600_OverwriteBytes(void *state, const unsigned char *data, unsigned
307
304
 
308
305
  /* ---------------------------------------------------------------- */
309
306
 
310
- void KeccakP1600_OverwriteWithZeroes(void *state, unsigned int byteCount)
307
+ void KeccakP1600_OverwriteWithZeroes(KeccakP1600_plain32_state *state, unsigned int byteCount)
311
308
  {
312
309
  uint8_t laneAsBytes[8];
313
310
  unsigned int lanePosition = 0;
@@ -322,9 +319,8 @@ void KeccakP1600_OverwriteWithZeroes(void *state, unsigned int byteCount)
322
319
  byteCount = 0;
323
320
  }
324
321
  else {
325
- uint32_t *stateAsHalfLanes = (uint32_t*)state;
326
- stateAsHalfLanes[lanePosition*2+0] = 0;
327
- stateAsHalfLanes[lanePosition*2+1] = 0;
322
+ state->A[lanePosition*2+0] = 0;
323
+ state->A[lanePosition*2+1] = 0;
328
324
  byteCount -= 8;
329
325
  lanePosition++;
330
326
  }
@@ -339,11 +335,10 @@ static void rho(uint32_t *A);
339
335
  static void pi(uint32_t *A);
340
336
  static void chi(uint32_t *A);
341
337
  static void iota(uint32_t *A, unsigned int indexRound);
342
- void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length);
338
+ void KeccakP1600_ExtractBytes(const KeccakP1600_plain32_state *state, unsigned char *data, unsigned int offset, unsigned int length);
343
339
 
344
- void KeccakP1600_Permute_Nrounds(void *state, unsigned int nrounds)
340
+ void KeccakP1600_Permute_Nrounds(KeccakP1600_plain32_state *state, unsigned int nrounds)
345
341
  {
346
- uint32_t *stateAsHalfLanes = (uint32_t*)state;
347
342
  {
348
343
  uint8_t stateAsBytes[1600/8];
349
344
  KeccakP1600_ExtractBytes(state, stateAsBytes, 0, 1600/8);
@@ -351,7 +346,7 @@ void KeccakP1600_Permute_Nrounds(void *state, unsigned int nrounds)
351
346
  displayStateAsBytes(1, "Input of permutation", stateAsBytes, 1600);
352
347
  #endif
353
348
  }
354
- KeccakP1600_PermutationOnWords(stateAsHalfLanes, nrounds);
349
+ KeccakP1600_PermutationOnWords(state->A, nrounds);
355
350
  {
356
351
  uint8_t stateAsBytes[1600/8];
357
352
  KeccakP1600_ExtractBytes(state, stateAsBytes, 0, 1600/8);
@@ -362,9 +357,8 @@ void KeccakP1600_Permute_Nrounds(void *state, unsigned int nrounds)
362
357
  }
363
358
 
364
359
 
365
- void KeccakP1600_Permute_12rounds(void *state)
360
+ void KeccakP1600_Permute_12rounds(KeccakP1600_plain32_state *state)
366
361
  {
367
- uint32_t *stateAsHalfLanes = (uint32_t*)state;
368
362
  {
369
363
  uint8_t stateAsBytes[1600/8];
370
364
  KeccakP1600_ExtractBytes(state, stateAsBytes, 0, 1600/8);
@@ -372,7 +366,7 @@ void KeccakP1600_Permute_12rounds(void *state)
372
366
  displayStateAsBytes(1, "Input of permutation", stateAsBytes, 1600);
373
367
  #endif
374
368
  }
375
- KeccakP1600_PermutationOnWords(stateAsHalfLanes, 12);
369
+ KeccakP1600_PermutationOnWords(state->A, 12);
376
370
  {
377
371
  uint8_t stateAsBytes[1600/8];
378
372
  KeccakP1600_ExtractBytes(state, stateAsBytes, 0, 1600/8);
@@ -382,9 +376,8 @@ void KeccakP1600_Permute_12rounds(void *state)
382
376
  }
383
377
  }
384
378
 
385
- void KeccakP1600_Permute_24rounds(void *state)
379
+ void KeccakP1600_Permute_24rounds(KeccakP1600_plain32_state *state)
386
380
  {
387
- uint32_t *stateAsHalfLanes = (uint32_t*)state;
388
381
  {
389
382
  uint8_t stateAsBytes[1600/8];
390
383
  KeccakP1600_ExtractBytes(state, stateAsBytes, 0, 1600/8);
@@ -392,7 +385,7 @@ void KeccakP1600_Permute_24rounds(void *state)
392
385
  displayStateAsBytes(1, "Input of permutation", stateAsBytes, 1600);
393
386
  #endif
394
387
  }
395
- KeccakP1600_PermutationOnWords(stateAsHalfLanes, 24);
388
+ KeccakP1600_PermutationOnWords(state->A, 24);
396
389
  {
397
390
  uint8_t stateAsBytes[1600/8];
398
391
  KeccakP1600_ExtractBytes(state, stateAsBytes, 0, 1600/8);
@@ -522,13 +515,12 @@ static void iota(uint32_t *A, unsigned int indexRound)
522
515
 
523
516
  /* ---------------------------------------------------------------- */
524
517
 
525
- void KeccakP1600_ExtractBytesInLane(const void *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length)
518
+ void KeccakP1600_ExtractBytesInLane(const KeccakP1600_plain32_state *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length)
526
519
  {
527
520
  if ((lanePosition < 25) && (offset < 8) && (offset+length <= 8)) {
528
- uint32_t *stateAsHalfLanes = (uint32_t*)state;
529
521
  uint32_t lane[2];
530
522
  uint8_t laneAsBytes[8];
531
- fromBitInterleaving(stateAsHalfLanes[lanePosition*2], stateAsHalfLanes[lanePosition*2+1], lane, lane+1);
523
+ fromBitInterleaving(state->A[lanePosition*2], state->A[lanePosition*2+1], lane, lane+1);
532
524
  laneAsBytes[0] = lane[0] & 0xFF;
533
525
  laneAsBytes[1] = (lane[0] >> 8) & 0xFF;
534
526
  laneAsBytes[2] = (lane[0] >> 16) & 0xFF;
@@ -541,7 +533,7 @@ void KeccakP1600_ExtractBytesInLane(const void *state, unsigned int lanePosition
541
533
  }
542
534
  }
543
535
 
544
- void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length)
536
+ void KeccakP1600_ExtractBytes(const KeccakP1600_plain32_state *state, unsigned char *data, unsigned int offset, unsigned int length)
545
537
  {
546
538
  unsigned int lanePosition = offset/8;
547
539
  unsigned int offsetInLane = offset%8;
@@ -564,7 +556,7 @@ void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned i
564
556
 
565
557
  /* ---------------------------------------------------------------- */
566
558
 
567
- void KeccakP1600_ExtractAndAddBytesInLane(const void *state, unsigned int lanePosition, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
559
+ void KeccakP1600_ExtractAndAddBytesInLane(const KeccakP1600_plain32_state *state, unsigned int lanePosition, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
568
560
  {
569
561
  if ((lanePosition < 25) && (offset < 8) && (offset+length <= 8)) {
570
562
  uint8_t laneAsBytes[8];
@@ -576,7 +568,7 @@ void KeccakP1600_ExtractAndAddBytesInLane(const void *state, unsigned int lanePo
576
568
  }
577
569
  }
578
570
 
579
- void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
571
+ void KeccakP1600_ExtractAndAddBytes(const KeccakP1600_plain32_state *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
580
572
  {
581
573
  unsigned int lanePosition = offset/8;
582
574
  unsigned int offsetInLane = offset%8;
@@ -21,24 +21,30 @@ Please refer to SnP-documentation.h for more details.
21
21
  #ifndef _KeccakP_1600_SnP_h_
22
22
  #define _KeccakP_1600_SnP_h_
23
23
 
24
+ #include <stdint.h>
25
+
26
+ typedef struct {
27
+ uint8_t A[200];
28
+ } KeccakP1600_plain8_state;
29
+
30
+ typedef KeccakP1600_plain8_state KeccakP1600_state;
31
+
24
32
  #define KeccakP1600_implementation "64-bit reference implementation"
25
- #define KeccakP1600_stateSizeInBytes 200
26
- #define KeccakP1600_stateAlignment 8
27
33
 
28
34
  #ifdef KeccakReference
29
35
  void KeccakP1600_StaticInitialize( void );
30
36
  #else
31
37
  #define KeccakP1600_StaticInitialize()
32
38
  #endif
33
- void KeccakP1600_Initialize(void *state);
34
- void KeccakP1600_AddByte(void *state, unsigned char data, unsigned int offset);
35
- void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length);
36
- void KeccakP1600_OverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length);
37
- void KeccakP1600_OverwriteWithZeroes(void *state, unsigned int byteCount);
38
- void KeccakP1600_Permute_Nrounds(void *state, unsigned int nrounds);
39
- void KeccakP1600_Permute_12rounds(void *state);
40
- void KeccakP1600_Permute_24rounds(void *state);
41
- void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length);
42
- void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length);
39
+ void KeccakP1600_Initialize(KeccakP1600_plain8_state *state);
40
+ void KeccakP1600_AddByte(KeccakP1600_plain8_state *state, unsigned char data, unsigned int offset);
41
+ void KeccakP1600_AddBytes(KeccakP1600_plain8_state *state, const unsigned char *data, unsigned int offset, unsigned int length);
42
+ void KeccakP1600_OverwriteBytes(KeccakP1600_plain8_state *state, const unsigned char *data, unsigned int offset, unsigned int length);
43
+ void KeccakP1600_OverwriteWithZeroes(KeccakP1600_plain8_state *state, unsigned int byteCount);
44
+ void KeccakP1600_Permute_Nrounds(KeccakP1600_plain8_state *state, unsigned int nrounds);
45
+ void KeccakP1600_Permute_12rounds(KeccakP1600_plain8_state *state);
46
+ void KeccakP1600_Permute_24rounds(KeccakP1600_plain8_state *state);
47
+ void KeccakP1600_ExtractBytes(const KeccakP1600_plain8_state *state, unsigned char *data, unsigned int offset, unsigned int length);
48
+ void KeccakP1600_ExtractAndAddBytes(const KeccakP1600_plain8_state *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length);
43
49
 
44
50
  #endif
@@ -33,6 +33,7 @@ Please refer to LowLevel.build for the exact list of other files it must be comb
33
33
  #ifdef KeccakReference
34
34
  #include "displayIntermediateValues.h"
35
35
  #endif
36
+ #include "KeccakP-1600-SnP.h"
36
37
 
37
38
  typedef uint64_t tKeccakLane;
38
39
 
@@ -142,24 +143,24 @@ static const unsigned int KeccakRhoOffsets[nrLanes] =
142
143
 
143
144
  /* ---------------------------------------------------------------- */
144
145
 
145
- void KeccakP1600_Initialize(void *state)
146
+ void KeccakP1600_Initialize(KeccakP1600_plain8_state *state)
146
147
  {
147
- memset(state, 0, 1600/8);
148
+ memset(state->A, 0, sizeof(state->A));
148
149
  }
149
150
 
150
151
  /* ---------------------------------------------------------------- */
151
152
 
152
- void KeccakP1600_AddByte(void *state, unsigned char byte, unsigned int offset)
153
+ void KeccakP1600_AddByte(KeccakP1600_plain8_state *state, unsigned char byte, unsigned int offset)
153
154
  {
154
155
  #if DEBUG
155
156
  assert(offset < 200);
156
157
  #endif
157
- ((unsigned char *)state)[offset] ^= byte;
158
+ state->A[offset] ^= byte;
158
159
  }
159
160
 
160
161
  /* ---------------------------------------------------------------- */
161
162
 
162
- void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
163
+ void KeccakP1600_AddBytes(KeccakP1600_plain8_state *state, const unsigned char *data, unsigned int offset, unsigned int length)
163
164
  {
164
165
  unsigned int i;
165
166
 
@@ -168,28 +169,28 @@ void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int o
168
169
  assert(offset+length <= 200);
169
170
  #endif
170
171
  for(i=0; i<length; i++)
171
- ((unsigned char *)state)[offset+i] ^= data[i];
172
+ state->A[offset+i] ^= data[i];
172
173
  }
173
174
 
174
175
  /* ---------------------------------------------------------------- */
175
176
 
176
- void KeccakP1600_OverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
177
+ void KeccakP1600_OverwriteBytes(KeccakP1600_plain8_state *state, const unsigned char *data, unsigned int offset, unsigned int length)
177
178
  {
178
179
  #if DEBUG
179
180
  assert(offset < 200);
180
181
  assert(offset+length <= 200);
181
182
  #endif
182
- memcpy((unsigned char*)state+offset, data, length);
183
+ memcpy(state->A+offset, data, length);
183
184
  }
184
185
 
185
186
  /* ---------------------------------------------------------------- */
186
187
 
187
- void KeccakP1600_OverwriteWithZeroes(void *state, unsigned int byteCount)
188
+ void KeccakP1600_OverwriteWithZeroes(KeccakP1600_plain8_state *state, unsigned int byteCount)
188
189
  {
189
190
  #if DEBUG
190
191
  assert(byteCount <= 200);
191
192
  #endif
192
- memset(state, 0, byteCount);
193
+ memset(state->A, 0, byteCount);
193
194
  }
194
195
 
195
196
  /* ---------------------------------------------------------------- */
@@ -206,71 +207,39 @@ static void pi(tKeccakLane *A);
206
207
  static void chi(tKeccakLane *A);
207
208
  static void iota(tKeccakLane *A, unsigned int indexRound);
208
209
 
209
- void KeccakP1600_Permute_Nrounds(void *state, unsigned int nrounds)
210
+ void KeccakP1600_Permute_Nrounds(KeccakP1600_plain8_state *state, unsigned int nrounds)
210
211
  {
211
212
  #if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
212
213
  tKeccakLane stateAsWords[1600/64];
213
214
  #endif
214
215
 
215
216
  #ifdef KeccakReference
216
- displayStateAsBytes(1, "Input of permutation", (const unsigned char *)state, 1600);
217
+ displayStateAsBytes(1, "Input of permutation", (const unsigned char *)state->A, 1600);
217
218
  #endif
218
219
  #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
219
- KeccakP1600OnWords((tKeccakLane*)state, nrounds);
220
+ KeccakP1600OnWords((tKeccakLane*)state->A, nrounds);
220
221
  #else
221
- fromBytesToWords(stateAsWords, (const unsigned char *)state);
222
+ fromBytesToWords(stateAsWords, state->A);
222
223
  KeccakP1600OnWords(stateAsWords, nrounds);
223
- fromWordsToBytes((unsigned char *)state, stateAsWords);
224
+ fromWordsToBytes(state->A, stateAsWords);
224
225
  #endif
225
226
  #ifdef KeccakReference
226
- displayStateAsBytes(1, "State after permutation", (const unsigned char *)state, 1600);
227
+ displayStateAsBytes(1, "State after permutation", (const unsigned char *)state->A, 1600);
227
228
  #endif
228
229
  }
229
230
 
230
- void KeccakP1600_Permute_12rounds(void *state)
231
+ void KeccakP1600_Permute_12rounds(KeccakP1600_plain8_state *state)
231
232
  {
232
- #if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
233
- tKeccakLane stateAsWords[1600/64];
234
- #endif
235
-
236
- #ifdef KeccakReference
237
- displayStateAsBytes(1, "Input of permutation", (const unsigned char *)state, 1600);
238
- #endif
239
- #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
240
- KeccakP1600OnWords((tKeccakLane*)state, 12);
241
- #else
242
- fromBytesToWords(stateAsWords, (const unsigned char *)state);
243
- KeccakP1600OnWords(stateAsWords, 12);
244
- fromWordsToBytes((unsigned char *)state, stateAsWords);
245
- #endif
246
- #ifdef KeccakReference
247
- displayStateAsBytes(1, "State after permutation", (const unsigned char *)state, 1600);
248
- #endif
233
+ KeccakP1600_Permute_Nrounds(state, 12);
249
234
  }
250
235
 
251
- void KeccakP1600_Permute_24rounds(void *state)
236
+ void KeccakP1600_Permute_24rounds(KeccakP1600_plain8_state *state)
252
237
  {
253
- #if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
254
- tKeccakLane stateAsWords[1600/64];
255
- #endif
256
-
257
- #ifdef KeccakReference
258
- displayStateAsBytes(1, "Input of permutation", (const unsigned char *)state, 1600);
259
- #endif
260
- #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
261
- KeccakP1600OnWords((tKeccakLane*)state, 24);
262
- #else
263
- fromBytesToWords(stateAsWords, (const unsigned char *)state);
264
- KeccakP1600OnWords(stateAsWords, 24);
265
- fromWordsToBytes((unsigned char *)state, stateAsWords);
266
- #endif
267
- #ifdef KeccakReference
268
- displayStateAsBytes(1, "State after permutation", (const unsigned char *)state, 1600);
269
- #endif
238
+ KeccakP1600_Permute_Nrounds(state, 24);
270
239
  }
271
240
 
272
241
  #if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
273
- static void fromBytesToWords(tKeccakLane *stateAsWords, const unsigned char *state)
242
+ static void fromBytesToWords(tKeccakLane *stateAsWords, const uint8_t *state)
274
243
  {
275
244
  unsigned int i, j;
276
245
 
@@ -281,13 +250,13 @@ static void fromBytesToWords(tKeccakLane *stateAsWords, const unsigned char *sta
281
250
  }
282
251
  }
283
252
 
284
- static void fromWordsToBytes(unsigned char *state, const tKeccakLane *stateAsWords)
253
+ static void fromWordsToBytes(uint8_t *state, const tKeccakLane *stateAsWords)
285
254
  {
286
255
  unsigned int i, j;
287
256
 
288
257
  for(i=0; i<nrLanes; i++)
289
258
  for(j=0; j<(64/8); j++)
290
- state[i*(64/8)+j] = (unsigned char)((stateAsWords[i] >> (8*j)) & 0xFF);
259
+ state[i*(64/8)+j] = (uint8_t)((stateAsWords[i] >> (8*j)) & 0xFF);
291
260
  }
292
261
  #endif
293
262
 
@@ -393,18 +362,18 @@ static void iota(tKeccakLane *A, unsigned int indexRound)
393
362
 
394
363
  /* ---------------------------------------------------------------- */
395
364
 
396
- void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length)
365
+ void KeccakP1600_ExtractBytes(const KeccakP1600_plain8_state *state, unsigned char *data, unsigned int offset, unsigned int length)
397
366
  {
398
367
  #if DEBUG
399
368
  assert(offset < 200);
400
369
  assert(offset+length <= 200);
401
370
  #endif
402
- memcpy(data, (unsigned char*)state+offset, length);
371
+ memcpy(data, state->A+offset, length);
403
372
  }
404
373
 
405
374
  /* ---------------------------------------------------------------- */
406
375
 
407
- void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
376
+ void KeccakP1600_ExtractAndAddBytes(const KeccakP1600_plain8_state *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
408
377
  {
409
378
  unsigned int i;
410
379
 
@@ -413,7 +382,7 @@ void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *inpu
413
382
  assert(offset+length <= 200);
414
383
  #endif
415
384
  for(i=0; i<length; i++)
416
- output[i] = input[i] ^ ((unsigned char *)state)[offset+i];
385
+ output[i] = input[i] ^ state->A[offset+i];
417
386
  }
418
387
 
419
388
  /* ---------------------------------------------------------------- */