sha3 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +8 -5
- data/certs/johanns.pem +23 -22
- data/ext/sha3/config.h +26 -0
- data/ext/sha3/digest.c +6 -6
- data/ext/sha3/extconf.rb +40 -10
- data/ext/sha3/lib/common/align.h +33 -0
- data/ext/sha3/{brg_endian.h → lib/common/brg_endian.h} +8 -7
- data/ext/sha3/{KeccakHash.c → lib/high/Keccak/FIPS202/KeccakHash.c} +26 -25
- data/ext/sha3/{KeccakHash.h → lib/high/Keccak/FIPS202/KeccakHash.h} +34 -19
- data/ext/sha3/lib/high/Keccak/KeccakSponge.c +111 -0
- data/ext/sha3/lib/high/Keccak/KeccakSponge.h +76 -0
- data/ext/sha3/lib/high/Keccak/KeccakSponge.inc +316 -0
- data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros +748 -0
- data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-unrolling.macros +305 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h +44 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference.h +23 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c +625 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h +44 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c +444 -0
- data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.h +23 -0
- data/lib/sha3/version.rb +1 -1
- data/sha3.gemspec +6 -5
- data/tests.sh +8 -7
- data.tar.gz.sig +0 -0
- metadata +50 -66
- metadata.gz.sig +0 -0
- data/ext/sha3/KeccakF-1600-interface.h +0 -40
- data/ext/sha3/KeccakSponge.c +0 -192
- data/ext/sha3/KeccakSponge.h +0 -113
- data/ext/sha3/Optimized64/KeccakF-1600-64.macros +0 -2199
- data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +0 -3
- data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +0 -508
- data/ext/sha3/Optimized64/KeccakF-1600-unrolling.macros +0 -126
- data/ext/sha3/Optimized64/SnP-interface.h +0 -47
- data/ext/sha3/Reference/KeccakF-1600-reference.c +0 -311
- data/ext/sha3/Reference/KeccakF-reference.h +0 -26
- data/ext/sha3/Reference/SnP-FBWL-default.c +0 -96
- data/ext/sha3/Reference/SnP-FBWL-default.h +0 -26
- data/ext/sha3/Reference/SnP-interface.h +0 -42
- data/ext/sha3/Reference/displayIntermediateValues.c +0 -158
- data/ext/sha3/Reference/displayIntermediateValues.h +0 -34
- data/ext/sha3/SnP-Relaned.h +0 -249
@@ -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/version.rb
CHANGED
data/sha3.gemspec
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'lib/sha3/version'
|
4
4
|
|
5
|
+
# rubocop:disable Metrics/BlockLength(Rubocop)
|
5
6
|
Gem::Specification.new do |spec|
|
6
7
|
spec.name = 'sha3'
|
7
8
|
spec.version = SHA3::VERSION
|
@@ -9,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
9
10
|
spec.authors = ['Johanns Gregorian']
|
10
11
|
spec.email = ['io+sha3@jsg.io']
|
11
12
|
|
12
|
-
spec.description = '
|
13
|
+
spec.description = 'A XKCP based native (C) binding to SHA3 (FIPS 202) cryptographic hashing algorithm.'
|
13
14
|
spec.summary = 'SHA3 (FIPS 202) cryptographic hashing algorithm'
|
14
15
|
|
15
16
|
spec.homepage = 'https://github.com/johanns/sha3'
|
@@ -40,14 +41,14 @@ Gem::Specification.new do |spec|
|
|
40
41
|
# guide at: https://bundler.io/guides/creating_gem.html
|
41
42
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
42
43
|
|
43
|
-
spec.add_development_dependency('bundler', '~> 2.3')
|
44
44
|
spec.add_development_dependency('rake', '~> 13.0')
|
45
|
-
spec.add_development_dependency('rake-compiler', '~> 1.
|
45
|
+
spec.add_development_dependency('rake-compiler', '~> 1.2')
|
46
46
|
spec.add_development_dependency('rspec', '~> 3.11')
|
47
|
-
spec.add_development_dependency('rubocop', '~> 1.
|
47
|
+
spec.add_development_dependency('rubocop', '~> 1.37')
|
48
48
|
spec.add_development_dependency('rubocop-rake', '~> 0.6')
|
49
|
-
spec.add_development_dependency('rubocop-rspec', '~> 2.
|
49
|
+
spec.add_development_dependency('rubocop-rspec', '~> 2.14')
|
50
50
|
|
51
51
|
spec.cert_chain = ['certs/johanns.pem']
|
52
52
|
spec.signing_key = File.expand_path('~/.ssh/gem-private_key.pem') if $PROGRAM_NAME =~ /gem\z/
|
53
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
CHANGED
Binary file
|