sha3 1.0.3 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
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,444 @@
1
+ /*
2
+ The eXtended Keccak Code Package (XKCP)
3
+ https://github.com/XKCP/XKCP
4
+
5
+ The Keccak-p permutations, 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
+
18
+ This file implements Keccak-p[1600] in a SnP-compatible way.
19
+ Please refer to SnP-documentation.h for more details.
20
+
21
+ This implementation comes with KeccakP-1600-SnP.h in the same folder.
22
+ Please refer to LowLevel.build for the exact list of other files it must be combined with.
23
+ */
24
+
25
+ #if DEBUG
26
+ #include <assert.h>
27
+ #endif
28
+ #include <stdint.h>
29
+ #include <stdio.h>
30
+ #include <stdlib.h>
31
+ #include <string.h>
32
+ #include "brg_endian.h"
33
+ #ifdef KeccakReference
34
+ #include "displayIntermediateValues.h"
35
+ #endif
36
+
37
+ typedef uint64_t tKeccakLane;
38
+
39
+ #define maxNrRounds 24
40
+ #define nrLanes 25
41
+ #define index(x, y) (((x)%5)+5*((y)%5))
42
+
43
+ #ifdef KeccakReference
44
+
45
+ static tKeccakLane KeccakRoundConstants[maxNrRounds];
46
+ static unsigned int KeccakRhoOffsets[nrLanes];
47
+
48
+ /* ---------------------------------------------------------------- */
49
+
50
+ void KeccakP1600_InitializeRoundConstants(void);
51
+ void KeccakP1600_InitializeRhoOffsets(void);
52
+ static int LFSR86540(uint8_t *LFSR);
53
+
54
+ void KeccakP1600_StaticInitialize(void)
55
+ {
56
+ if (sizeof(tKeccakLane) != 8) {
57
+ printf("tKeccakLane should be 64-bit wide\n");
58
+ abort();
59
+ }
60
+ KeccakP1600_InitializeRoundConstants();
61
+ KeccakP1600_InitializeRhoOffsets();
62
+ }
63
+
64
+ void KeccakP1600_InitializeRoundConstants(void)
65
+ {
66
+ uint8_t LFSRstate = 0x01;
67
+ unsigned int i, j, bitPosition;
68
+
69
+ for(i=0; i<maxNrRounds; i++) {
70
+ KeccakRoundConstants[i] = 0;
71
+ for(j=0; j<7; j++) {
72
+ bitPosition = (1<<j)-1; /* 2^j-1 */
73
+ if (LFSR86540(&LFSRstate))
74
+ KeccakRoundConstants[i] ^= (tKeccakLane)1<<bitPosition;
75
+ }
76
+ }
77
+ }
78
+
79
+ void KeccakP1600_InitializeRhoOffsets(void)
80
+ {
81
+ unsigned int x, y, t, newX, newY;
82
+
83
+ KeccakRhoOffsets[index(0, 0)] = 0;
84
+ x = 1;
85
+ y = 0;
86
+ for(t=0; t<24; t++) {
87
+ KeccakRhoOffsets[index(x, y)] = ((t+1)*(t+2)/2) % 64;
88
+ newX = (0*x+1*y) % 5;
89
+ newY = (2*x+3*y) % 5;
90
+ x = newX;
91
+ y = newY;
92
+ }
93
+ }
94
+
95
+ static int LFSR86540(uint8_t *LFSR)
96
+ {
97
+ int result = ((*LFSR) & 0x01) != 0;
98
+ if (((*LFSR) & 0x80) != 0)
99
+ /* Primitive polynomial over GF(2): x^8+x^6+x^5+x^4+1 */
100
+ (*LFSR) = ((*LFSR) << 1) ^ 0x71;
101
+ else
102
+ (*LFSR) <<= 1;
103
+ return result;
104
+ }
105
+
106
+ #else
107
+
108
+ static const tKeccakLane KeccakRoundConstants[maxNrRounds] =
109
+ {
110
+ 0x0000000000000001,
111
+ 0x0000000000008082,
112
+ 0x800000000000808a,
113
+ 0x8000000080008000,
114
+ 0x000000000000808b,
115
+ 0x0000000080000001,
116
+ 0x8000000080008081,
117
+ 0x8000000000008009,
118
+ 0x000000000000008a,
119
+ 0x0000000000000088,
120
+ 0x0000000080008009,
121
+ 0x000000008000000a,
122
+ 0x000000008000808b,
123
+ 0x800000000000008b,
124
+ 0x8000000000008089,
125
+ 0x8000000000008003,
126
+ 0x8000000000008002,
127
+ 0x8000000000000080,
128
+ 0x000000000000800a,
129
+ 0x800000008000000a,
130
+ 0x8000000080008081,
131
+ 0x8000000000008080,
132
+ 0x0000000080000001,
133
+ 0x8000000080008008,
134
+ };
135
+
136
+ static const unsigned int KeccakRhoOffsets[nrLanes] =
137
+ {
138
+ 0, 1, 62, 28, 27, 36, 44, 6, 55, 20, 3, 10, 43, 25, 39, 41, 45, 15, 21, 8, 18, 2, 61, 56, 14
139
+ };
140
+
141
+ #endif
142
+
143
+ /* ---------------------------------------------------------------- */
144
+
145
+ void KeccakP1600_Initialize(void *state)
146
+ {
147
+ memset(state, 0, 1600/8);
148
+ }
149
+
150
+ /* ---------------------------------------------------------------- */
151
+
152
+ void KeccakP1600_AddByte(void *state, unsigned char byte, unsigned int offset)
153
+ {
154
+ #if DEBUG
155
+ assert(offset < 200);
156
+ #endif
157
+ ((unsigned char *)state)[offset] ^= byte;
158
+ }
159
+
160
+ /* ---------------------------------------------------------------- */
161
+
162
+ void KeccakP1600_AddBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
163
+ {
164
+ unsigned int i;
165
+
166
+ #if DEBUG
167
+ assert(offset < 200);
168
+ assert(offset+length <= 200);
169
+ #endif
170
+ for(i=0; i<length; i++)
171
+ ((unsigned char *)state)[offset+i] ^= data[i];
172
+ }
173
+
174
+ /* ---------------------------------------------------------------- */
175
+
176
+ void KeccakP1600_OverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
177
+ {
178
+ #if DEBUG
179
+ assert(offset < 200);
180
+ assert(offset+length <= 200);
181
+ #endif
182
+ memcpy((unsigned char*)state+offset, data, length);
183
+ }
184
+
185
+ /* ---------------------------------------------------------------- */
186
+
187
+ void KeccakP1600_OverwriteWithZeroes(void *state, unsigned int byteCount)
188
+ {
189
+ #if DEBUG
190
+ assert(byteCount <= 200);
191
+ #endif
192
+ memset(state, 0, byteCount);
193
+ }
194
+
195
+ /* ---------------------------------------------------------------- */
196
+
197
+ #if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
198
+ static void fromBytesToWords(tKeccakLane *stateAsWords, const unsigned char *state);
199
+ static void fromWordsToBytes(unsigned char *state, const tKeccakLane *stateAsWords);
200
+ #endif
201
+ void KeccakP1600OnWords(tKeccakLane *state, unsigned int nrRounds);
202
+ void KeccakP1600Round(tKeccakLane *state, unsigned int indexRound);
203
+ static void theta(tKeccakLane *A);
204
+ static void rho(tKeccakLane *A);
205
+ static void pi(tKeccakLane *A);
206
+ static void chi(tKeccakLane *A);
207
+ static void iota(tKeccakLane *A, unsigned int indexRound);
208
+
209
+ void KeccakP1600_Permute_Nrounds(void *state, unsigned int nrounds)
210
+ {
211
+ #if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
212
+ tKeccakLane stateAsWords[1600/64];
213
+ #endif
214
+
215
+ #ifdef KeccakReference
216
+ displayStateAsBytes(1, "Input of permutation", (const unsigned char *)state, 1600);
217
+ #endif
218
+ #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
219
+ KeccakP1600OnWords((tKeccakLane*)state, nrounds);
220
+ #else
221
+ fromBytesToWords(stateAsWords, (const unsigned char *)state);
222
+ KeccakP1600OnWords(stateAsWords, nrounds);
223
+ fromWordsToBytes((unsigned char *)state, stateAsWords);
224
+ #endif
225
+ #ifdef KeccakReference
226
+ displayStateAsBytes(1, "State after permutation", (const unsigned char *)state, 1600);
227
+ #endif
228
+ }
229
+
230
+ void KeccakP1600_Permute_12rounds(void *state)
231
+ {
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
249
+ }
250
+
251
+ void KeccakP1600_Permute_24rounds(void *state)
252
+ {
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
270
+ }
271
+
272
+ #if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
273
+ static void fromBytesToWords(tKeccakLane *stateAsWords, const unsigned char *state)
274
+ {
275
+ unsigned int i, j;
276
+
277
+ for(i=0; i<nrLanes; i++) {
278
+ stateAsWords[i] = 0;
279
+ for(j=0; j<(64/8); j++)
280
+ stateAsWords[i] |= (tKeccakLane)(state[i*(64/8)+j]) << (8*j);
281
+ }
282
+ }
283
+
284
+ static void fromWordsToBytes(unsigned char *state, const tKeccakLane *stateAsWords)
285
+ {
286
+ unsigned int i, j;
287
+
288
+ for(i=0; i<nrLanes; i++)
289
+ for(j=0; j<(64/8); j++)
290
+ state[i*(64/8)+j] = (unsigned char)((stateAsWords[i] >> (8*j)) & 0xFF);
291
+ }
292
+ #endif
293
+
294
+ void KeccakP1600OnWords(tKeccakLane *state, unsigned int nrRounds)
295
+ {
296
+ unsigned int i;
297
+
298
+ #ifdef KeccakReference
299
+ displayStateAsLanes(3, "Same, with lanes as 64-bit words", state, 1600);
300
+ #endif
301
+
302
+ for(i=(maxNrRounds-nrRounds); i<maxNrRounds; i++)
303
+ KeccakP1600Round(state, i);
304
+ }
305
+
306
+ void KeccakP1600Round(tKeccakLane *state, unsigned int indexRound)
307
+ {
308
+ #ifdef KeccakReference
309
+ displayRoundNumber(3, indexRound);
310
+ #endif
311
+
312
+ theta(state);
313
+ #ifdef KeccakReference
314
+ displayStateAsLanes(3, "After theta", state, 1600);
315
+ #endif
316
+
317
+ rho(state);
318
+ #ifdef KeccakReference
319
+ displayStateAsLanes(3, "After rho", state, 1600);
320
+ #endif
321
+
322
+ pi(state);
323
+ #ifdef KeccakReference
324
+ displayStateAsLanes(3, "After pi", state, 1600);
325
+ #endif
326
+
327
+ chi(state);
328
+ #ifdef KeccakReference
329
+ displayStateAsLanes(3, "After chi", state, 1600);
330
+ #endif
331
+
332
+ iota(state, indexRound);
333
+ #ifdef KeccakReference
334
+ displayStateAsLanes(3, "After iota", state, 1600);
335
+ #endif
336
+ }
337
+
338
+ #define ROL64(a, offset) ((offset != 0) ? ((((tKeccakLane)a) << offset) ^ (((tKeccakLane)a) >> (64-offset))) : a)
339
+
340
+ static void theta(tKeccakLane *A)
341
+ {
342
+ unsigned int x, y;
343
+ tKeccakLane C[5], D[5];
344
+
345
+ for(x=0; x<5; x++) {
346
+ C[x] = 0;
347
+ for(y=0; y<5; y++)
348
+ C[x] ^= A[index(x, y)];
349
+ }
350
+ for(x=0; x<5; x++)
351
+ D[x] = ROL64(C[(x+1)%5], 1) ^ C[(x+4)%5];
352
+ for(x=0; x<5; x++)
353
+ for(y=0; y<5; y++)
354
+ A[index(x, y)] ^= D[x];
355
+ }
356
+
357
+ static void rho(tKeccakLane *A)
358
+ {
359
+ unsigned int x, y;
360
+
361
+ for(x=0; x<5; x++) for(y=0; y<5; y++)
362
+ A[index(x, y)] = ROL64(A[index(x, y)], KeccakRhoOffsets[index(x, y)]);
363
+ }
364
+
365
+ static void pi(tKeccakLane *A)
366
+ {
367
+ unsigned int x, y;
368
+ tKeccakLane tempA[25];
369
+
370
+ for(x=0; x<5; x++) for(y=0; y<5; y++)
371
+ tempA[index(x, y)] = A[index(x, y)];
372
+ for(x=0; x<5; x++) for(y=0; y<5; y++)
373
+ A[index(0*x+1*y, 2*x+3*y)] = tempA[index(x, y)];
374
+ }
375
+
376
+ static void chi(tKeccakLane *A)
377
+ {
378
+ unsigned int x, y;
379
+ tKeccakLane C[5];
380
+
381
+ for(y=0; y<5; y++) {
382
+ for(x=0; x<5; x++)
383
+ C[x] = A[index(x, y)] ^ ((~A[index(x+1, y)]) & A[index(x+2, y)]);
384
+ for(x=0; x<5; x++)
385
+ A[index(x, y)] = C[x];
386
+ }
387
+ }
388
+
389
+ static void iota(tKeccakLane *A, unsigned int indexRound)
390
+ {
391
+ A[index(0, 0)] ^= KeccakRoundConstants[indexRound];
392
+ }
393
+
394
+ /* ---------------------------------------------------------------- */
395
+
396
+ void KeccakP1600_ExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length)
397
+ {
398
+ #if DEBUG
399
+ assert(offset < 200);
400
+ assert(offset+length <= 200);
401
+ #endif
402
+ memcpy(data, (unsigned char*)state+offset, length);
403
+ }
404
+
405
+ /* ---------------------------------------------------------------- */
406
+
407
+ void KeccakP1600_ExtractAndAddBytes(const void *state, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
408
+ {
409
+ unsigned int i;
410
+
411
+ #if DEBUG
412
+ assert(offset < 200);
413
+ assert(offset+length <= 200);
414
+ #endif
415
+ for(i=0; i<length; i++)
416
+ output[i] = input[i] ^ ((unsigned char *)state)[offset+i];
417
+ }
418
+
419
+ /* ---------------------------------------------------------------- */
420
+
421
+ void KeccakP1600_DisplayRoundConstants(FILE *f)
422
+ {
423
+ unsigned int i;
424
+
425
+ for(i=0; i<maxNrRounds; i++) {
426
+ fprintf(f, "RC[%02i][0][0] = ", i);
427
+ fprintf(f, "%08X", (unsigned int)(KeccakRoundConstants[i] >> 32));
428
+ fprintf(f, "%08X", (unsigned int)(KeccakRoundConstants[i] & 0xFFFFFFFFULL));
429
+ fprintf(f, "\n");
430
+ }
431
+ fprintf(f, "\n");
432
+ }
433
+
434
+ void KeccakP1600_DisplayRhoOffsets(FILE *f)
435
+ {
436
+ unsigned int x, y;
437
+
438
+ for(y=0; y<5; y++) for(x=0; x<5; x++) {
439
+ fprintf(f, "RhoOffset[%i][%i] = ", x, y);
440
+ fprintf(f, "%2i", KeccakRhoOffsets[index(x, y)]);
441
+ fprintf(f, "\n");
442
+ }
443
+ fprintf(f, "\n");
444
+ }
@@ -0,0 +1,23 @@
1
+ /*
2
+ The eXtended Keccak Code Package (XKCP)
3
+ https://github.com/XKCP/XKCP
4
+
5
+ The Keccak-p permutations, 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 _KeccakP_1600_reference_h_
18
+ #define _KeccakP_1600_reference_h_
19
+
20
+ void KeccakP1600_DisplayRoundConstants(FILE *f);
21
+ void KeccakP1600_DisplayRhoOffsets(FILE *f);
22
+
23
+ #endif
data/lib/sha3/doc.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest'
2
4
 
3
5
  module SHA3
@@ -99,8 +101,7 @@ module SHA3
99
101
  # @example
100
102
  # SHA3::Digest.hexdigest(256, 'compute me, please')
101
103
  # SHA3::Digest::SHA256.hexdigest('compute me, please') # => Alternate syntax
102
- def self.hexdigest(type, data)
103
- end
104
+ def self.hexdigest(type, data); end
104
105
 
105
106
  # Returns computed hash value for given hash type, and data in bytes.
106
107
  #
@@ -112,8 +113,7 @@ module SHA3
112
113
  # @example
113
114
  # SHA3::Digest.digest(256, 'compute me, please')
114
115
  # SHA3::Digest::SHA256.digest('compute me, please') # => Alternate syntax
115
- def self.digest(type, data)
116
- end
116
+ def self.digest(type, data); end
117
117
  end
118
118
 
119
119
  class DigestError < StandardError
data/lib/sha3/version.rb CHANGED
@@ -1,9 +1,9 @@
1
- module SHA3
2
- extend self
1
+ # frozen_string_literal: true
3
2
 
3
+ module SHA3
4
4
  # sha3 release version
5
- VERSION = '1.0.3'.freeze
5
+ VERSION = '1.0.5'
6
6
 
7
7
  # keccak version number
8
- KECCAK_VERSION = '4.0'.freeze
8
+ KECCAK_VERSION = '4.0'
9
9
  end
data/lib/sha3.rb CHANGED
@@ -1,35 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sha3_n'
2
4
  require 'sha3/version'
3
5
 
4
6
  module SHA3
5
7
  class Digest
6
-
7
8
  # Based on 'OpenSSL for Ruby 2' project
8
9
  # Copyright (C) 2002 Michal Rokos <m.rokos@sh.cvut.cz>
9
- alg = { :sha224 => "SHA224", :sha256 => "SHA256", :sha384 => "SHA384", :sha512 => "SHA512"}
10
+ alg = { sha224: 'SHA224', sha256: 'SHA256', sha384: 'SHA384', sha512: 'SHA512' }
10
11
 
11
12
  def self.digest(name, data)
12
13
  super(data, name)
13
14
  end
14
15
 
15
- alg.each { |key, name|
16
- klass = Class.new(Digest) {
17
- define_method(:initialize) { |*data|
16
+ alg.each do |key, name|
17
+ klass = Class.new(Digest) do
18
+ define_method(:initialize) do |*data|
18
19
  if data.length > 1
19
20
  raise ArgumentError,
20
- "wrong number of arguments (#{data.length} for 1)"
21
+ "wrong number of arguments (#{data.length} for 1)"
21
22
  end
22
23
 
23
24
  super(key, data.first)
24
- }
25
- }
25
+ end
26
+ end
27
+
26
28
  singleton = (class << klass; self; end)
27
- singleton.class_eval{
28
- define_method(:digest){ |data| Digest.digest(key, data) }
29
- define_method(:hexdigest){ |data| Digest.hexdigest(key, data) }
30
- }
29
+ singleton.class_eval do
30
+ define_method(:digest) { |data| Digest.digest(key, data) }
31
+ define_method(:hexdigest) { |data| Digest.hexdigest(key, data) }
32
+ end
31
33
 
32
34
  const_set(name, klass)
33
- }
35
+ end
34
36
  end
35
37
  end
data/sha3.gemspec CHANGED
@@ -1,23 +1,54 @@
1
- require File.expand_path('lib/sha3/version', __dir__)
2
-
3
- Gem::Specification.new do |gem|
4
- gem.name = 'sha3'
5
- gem.version = SHA3::VERSION
6
- gem.summary = 'SHA3 for Ruby'
7
- gem.description = 'SHA3 for Ruby is a native (C) FIPS 202 compliant implementation of SHA3 (Keccak) cryptographic hashing algorithm.'
8
- gem.license = 'MIT'
9
- gem.authors = ['Johanns Gregorian']
10
- gem.email = 'io+sha3@jsg.io'
11
- gem.homepage = 'https://github.com/johanns/sha3#readme'
12
-
13
- gem.files = `git ls-files`.split($/)
14
- gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
15
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
- gem.require_paths = ['lib']
17
- gem.extensions = ['ext/sha3/extconf.rb']
18
-
19
- gem.add_development_dependency 'rake-compiler', '~> 1.1'
20
- gem.add_development_dependency 'rspec', '~> 3.3'
21
- gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
22
- gem.add_development_dependency 'yard', '~> 0.9'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/sha3/version'
4
+
5
+ # rubocop:disable Metrics/BlockLength(Rubocop)
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'sha3'
8
+ spec.version = SHA3::VERSION
9
+
10
+ spec.authors = ['Johanns Gregorian']
11
+ spec.email = ['io+sha3@jsg.io']
12
+
13
+ spec.description = 'A XKCP based native (C) binding to SHA3 (FIPS 202) cryptographic hashing algorithm.'
14
+ spec.summary = 'SHA3 (FIPS 202) cryptographic hashing algorithm'
15
+
16
+ spec.homepage = 'https://github.com/johanns/sha3'
17
+ spec.license = 'MIT'
18
+ spec.required_ruby_version = '>= 2.6.0'
19
+
20
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = spec.homepage
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
29
+ end
30
+ end
31
+
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
+ spec.extensions = ['ext/sha3/extconf.rb']
35
+ spec.require_paths = ['lib']
36
+
37
+ # Uncomment to register a new dependency of your gem
38
+ # spec.add_dependency "example-gem", "~> 1.0"
39
+
40
+ # For more information and examples about making a new gem, check out our
41
+ # guide at: https://bundler.io/guides/creating_gem.html
42
+ spec.metadata['rubygems_mfa_required'] = 'true'
43
+
44
+ spec.add_development_dependency('rake', '~> 13.0')
45
+ spec.add_development_dependency('rake-compiler', '~> 1.2')
46
+ spec.add_development_dependency('rspec', '~> 3.11')
47
+ spec.add_development_dependency('rubocop', '~> 1.37')
48
+ spec.add_development_dependency('rubocop-rake', '~> 0.6')
49
+ spec.add_development_dependency('rubocop-rspec', '~> 2.14')
50
+
51
+ spec.cert_chain = ['certs/johanns.pem']
52
+ spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/
23
53
  end
54
+ # rubocop:enable Metrics/BlockLength(Rubocop)
data/tests.sh CHANGED
@@ -11,18 +11,19 @@ else
11
11
  fi
12
12
 
13
13
  pushd "spec/data"
14
-
15
14
  if [ -f "*.txt" ]
16
15
  then
17
16
  rm -v *.txt
18
17
  fi
19
18
 
20
- wget "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-224.txt"
21
- wget "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-256.txt"
22
- wget "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-384.txt"
23
- wget "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-512.txt"
24
-
25
- cd ".."
19
+ curl "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-224.txt" > ShortMsgKAT_SHA3-224.txt
20
+ curl "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-256.txt" > ShortMsgKAT_SHA3-256.txt
21
+ curl "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-384.txt" > ShortMsgKAT_SHA3-384.txt
22
+ curl "https://raw.githubusercontent.com/XKCP/XKCP/master/tests/TestVectors/ShortMsgKAT_SHA3-512.txt" > ShortMsgKAT_SHA3-512.txt
23
+ popd
26
24
 
25
+ pushd spec
27
26
  ruby generate_tests.rb
27
+ popd
28
+
28
29
  rake
data.tar.gz.sig ADDED
Binary file