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
@@ -1,311 +0,0 @@
|
|
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 <stdio.h>
|
17
|
-
#include <stdlib.h>
|
18
|
-
#include <string.h>
|
19
|
-
#include "brg_endian.h"
|
20
|
-
#include "displayIntermediateValues.h"
|
21
|
-
|
22
|
-
typedef unsigned char UINT8;
|
23
|
-
typedef unsigned long long UINT64;
|
24
|
-
typedef UINT64 tKeccakLane;
|
25
|
-
|
26
|
-
#define nrRounds 24
|
27
|
-
tKeccakLane KeccakRoundConstants[nrRounds];
|
28
|
-
#define nrLanes 25
|
29
|
-
unsigned int KeccakRhoOffsets[nrLanes];
|
30
|
-
|
31
|
-
/* ---------------------------------------------------------------- */
|
32
|
-
|
33
|
-
void KeccakF1600_InitializeRoundConstants();
|
34
|
-
void KeccakF1600_InitializeRhoOffsets();
|
35
|
-
int LFSR86540(UINT8 *LFSR);
|
36
|
-
|
37
|
-
void KeccakF1600_Initialize()
|
38
|
-
{
|
39
|
-
if (sizeof(tKeccakLane) != 8) {
|
40
|
-
printf("tKeccakLane should be 64-bit wide\n");
|
41
|
-
abort();
|
42
|
-
}
|
43
|
-
KeccakF1600_InitializeRoundConstants();
|
44
|
-
KeccakF1600_InitializeRhoOffsets();
|
45
|
-
}
|
46
|
-
|
47
|
-
void KeccakF1600_InitializeRoundConstants()
|
48
|
-
{
|
49
|
-
UINT8 LFSRstate = 0x01;
|
50
|
-
unsigned int i, j, bitPosition;
|
51
|
-
|
52
|
-
for(i=0; i<nrRounds; i++) {
|
53
|
-
KeccakRoundConstants[i] = 0;
|
54
|
-
for(j=0; j<7; j++) {
|
55
|
-
bitPosition = (1<<j)-1; //2^j-1
|
56
|
-
if (LFSR86540(&LFSRstate))
|
57
|
-
KeccakRoundConstants[i] ^= (tKeccakLane)1<<bitPosition;
|
58
|
-
}
|
59
|
-
}
|
60
|
-
}
|
61
|
-
|
62
|
-
#define index(x, y) (((x)%5)+5*((y)%5))
|
63
|
-
|
64
|
-
void KeccakF1600_InitializeRhoOffsets()
|
65
|
-
{
|
66
|
-
unsigned int x, y, t, newX, newY;
|
67
|
-
|
68
|
-
KeccakRhoOffsets[index(0, 0)] = 0;
|
69
|
-
x = 1;
|
70
|
-
y = 0;
|
71
|
-
for(t=0; t<24; t++) {
|
72
|
-
KeccakRhoOffsets[index(x, y)] = ((t+1)*(t+2)/2) % 64;
|
73
|
-
newX = (0*x+1*y) % 5;
|
74
|
-
newY = (2*x+3*y) % 5;
|
75
|
-
x = newX;
|
76
|
-
y = newY;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
int LFSR86540(UINT8 *LFSR)
|
81
|
-
{
|
82
|
-
int result = ((*LFSR) & 0x01) != 0;
|
83
|
-
if (((*LFSR) & 0x80) != 0)
|
84
|
-
// Primitive polynomial over GF(2): x^8+x^6+x^5+x^4+1
|
85
|
-
(*LFSR) = ((*LFSR) << 1) ^ 0x71;
|
86
|
-
else
|
87
|
-
(*LFSR) <<= 1;
|
88
|
-
return result;
|
89
|
-
}
|
90
|
-
|
91
|
-
/* ---------------------------------------------------------------- */
|
92
|
-
|
93
|
-
void KeccakF1600_StateInitialize(void *state)
|
94
|
-
{
|
95
|
-
memset(state, 0, KeccakF_width/8);
|
96
|
-
}
|
97
|
-
|
98
|
-
/* ---------------------------------------------------------------- */
|
99
|
-
|
100
|
-
void KeccakF1600_StateXORBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
|
101
|
-
{
|
102
|
-
unsigned int i;
|
103
|
-
|
104
|
-
for(i=0; i<length; i++)
|
105
|
-
((unsigned char *)state)[offset+i] ^= data[i];
|
106
|
-
}
|
107
|
-
|
108
|
-
/* ---------------------------------------------------------------- */
|
109
|
-
|
110
|
-
void KeccakF1600_StateOverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length)
|
111
|
-
{
|
112
|
-
memcpy((unsigned char*)state+offset, data, length);
|
113
|
-
}
|
114
|
-
|
115
|
-
/* ---------------------------------------------------------------- */
|
116
|
-
|
117
|
-
void KeccakF1600_StateOverwriteWithZeroes(void *state, unsigned int byteCount)
|
118
|
-
{
|
119
|
-
memset(state, 0, byteCount);
|
120
|
-
}
|
121
|
-
|
122
|
-
/* ---------------------------------------------------------------- */
|
123
|
-
|
124
|
-
void KeccakF1600_StateComplementBit(void *state, unsigned int position)
|
125
|
-
{
|
126
|
-
if (position < 1600) {
|
127
|
-
unsigned int bytePosition = position/8;
|
128
|
-
unsigned int bitPosition = position%8;
|
129
|
-
|
130
|
-
((unsigned char *)state)[bytePosition] ^= (UINT8)1 << bitPosition;
|
131
|
-
}
|
132
|
-
}
|
133
|
-
|
134
|
-
/* ---------------------------------------------------------------- */
|
135
|
-
|
136
|
-
void fromBytesToWords(tKeccakLane *stateAsWords, const unsigned char *state);
|
137
|
-
void fromWordsToBytes(unsigned char *state, const tKeccakLane *stateAsWords);
|
138
|
-
void KeccakF1600OnWords(tKeccakLane *state);
|
139
|
-
void KeccakF1600Round(tKeccakLane *state, unsigned int indexRound);
|
140
|
-
void theta(tKeccakLane *A);
|
141
|
-
void rho(tKeccakLane *A);
|
142
|
-
void pi(tKeccakLane *A);
|
143
|
-
void chi(tKeccakLane *A);
|
144
|
-
void iota(tKeccakLane *A, unsigned int indexRound);
|
145
|
-
|
146
|
-
void KeccakF1600_StatePermute(void *state)
|
147
|
-
{
|
148
|
-
#if (PLATFORM_BYTE_ORDER != IS_LITTLE_ENDIAN)
|
149
|
-
tKeccakLane stateAsWords[KeccakF_width/64];
|
150
|
-
#endif
|
151
|
-
|
152
|
-
displayStateAsBytes(1, "Input of permutation", (const unsigned char *)state);
|
153
|
-
#if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN)
|
154
|
-
KeccakF1600OnWords((tKeccakLane*)state);
|
155
|
-
#else
|
156
|
-
fromBytesToWords(stateAsWords, (const unsigned char *)state);
|
157
|
-
KeccakF1600OnWords(stateAsWords);
|
158
|
-
fromWordsToBytes((unsigned char *)state, stateAsWords);
|
159
|
-
#endif
|
160
|
-
displayStateAsBytes(1, "State after permutation", (const unsigned char *)state);
|
161
|
-
}
|
162
|
-
|
163
|
-
void fromBytesToWords(tKeccakLane *stateAsWords, const unsigned char *state)
|
164
|
-
{
|
165
|
-
unsigned int i, j;
|
166
|
-
|
167
|
-
for(i=0; i<nrLanes; i++) {
|
168
|
-
stateAsWords[i] = 0;
|
169
|
-
for(j=0; j<(64/8); j++)
|
170
|
-
stateAsWords[i] |= (tKeccakLane)(state[i*(64/8)+j]) << (8*j);
|
171
|
-
}
|
172
|
-
}
|
173
|
-
|
174
|
-
void fromWordsToBytes(unsigned char *state, const tKeccakLane *stateAsWords)
|
175
|
-
{
|
176
|
-
unsigned int i, j;
|
177
|
-
|
178
|
-
for(i=0; i<nrLanes; i++)
|
179
|
-
for(j=0; j<(64/8); j++)
|
180
|
-
state[i*(64/8)+j] = (stateAsWords[i] >> (8*j)) & 0xFF;
|
181
|
-
}
|
182
|
-
|
183
|
-
void KeccakF1600OnWords(tKeccakLane *state)
|
184
|
-
{
|
185
|
-
unsigned int i;
|
186
|
-
|
187
|
-
displayStateAsLanes(3, "Same, with lanes as 64-bit words", state);
|
188
|
-
|
189
|
-
for(i=0; i<nrRounds; i++)
|
190
|
-
KeccakF1600Round(state, i);
|
191
|
-
}
|
192
|
-
|
193
|
-
void KeccakF1600Round(tKeccakLane *state, unsigned int indexRound)
|
194
|
-
{
|
195
|
-
displayRoundNumber(3, indexRound);
|
196
|
-
|
197
|
-
theta(state);
|
198
|
-
displayStateAsLanes(3, "After theta", state);
|
199
|
-
|
200
|
-
rho(state);
|
201
|
-
displayStateAsLanes(3, "After rho", state);
|
202
|
-
|
203
|
-
pi(state);
|
204
|
-
displayStateAsLanes(3, "After pi", state);
|
205
|
-
|
206
|
-
chi(state);
|
207
|
-
displayStateAsLanes(3, "After chi", state);
|
208
|
-
|
209
|
-
iota(state, indexRound);
|
210
|
-
displayStateAsLanes(3, "After iota", state);
|
211
|
-
}
|
212
|
-
|
213
|
-
#define ROL64(a, offset) ((offset != 0) ? ((((tKeccakLane)a) << offset) ^ (((tKeccakLane)a) >> (64-offset))) : a)
|
214
|
-
|
215
|
-
void theta(tKeccakLane *A)
|
216
|
-
{
|
217
|
-
unsigned int x, y;
|
218
|
-
tKeccakLane C[5], D[5];
|
219
|
-
|
220
|
-
for(x=0; x<5; x++) {
|
221
|
-
C[x] = 0;
|
222
|
-
for(y=0; y<5; y++)
|
223
|
-
C[x] ^= A[index(x, y)];
|
224
|
-
}
|
225
|
-
for(x=0; x<5; x++)
|
226
|
-
D[x] = ROL64(C[(x+1)%5], 1) ^ C[(x+4)%5];
|
227
|
-
for(x=0; x<5; x++)
|
228
|
-
for(y=0; y<5; y++)
|
229
|
-
A[index(x, y)] ^= D[x];
|
230
|
-
}
|
231
|
-
|
232
|
-
void rho(tKeccakLane *A)
|
233
|
-
{
|
234
|
-
unsigned int x, y;
|
235
|
-
|
236
|
-
for(x=0; x<5; x++) for(y=0; y<5; y++)
|
237
|
-
A[index(x, y)] = ROL64(A[index(x, y)], KeccakRhoOffsets[index(x, y)]);
|
238
|
-
}
|
239
|
-
|
240
|
-
void pi(tKeccakLane *A)
|
241
|
-
{
|
242
|
-
unsigned int x, y;
|
243
|
-
tKeccakLane tempA[25];
|
244
|
-
|
245
|
-
for(x=0; x<5; x++) for(y=0; y<5; y++)
|
246
|
-
tempA[index(x, y)] = A[index(x, y)];
|
247
|
-
for(x=0; x<5; x++) for(y=0; y<5; y++)
|
248
|
-
A[index(0*x+1*y, 2*x+3*y)] = tempA[index(x, y)];
|
249
|
-
}
|
250
|
-
|
251
|
-
void chi(tKeccakLane *A)
|
252
|
-
{
|
253
|
-
unsigned int x, y;
|
254
|
-
tKeccakLane C[5];
|
255
|
-
|
256
|
-
for(y=0; y<5; y++) {
|
257
|
-
for(x=0; x<5; x++)
|
258
|
-
C[x] = A[index(x, y)] ^ ((~A[index(x+1, y)]) & A[index(x+2, y)]);
|
259
|
-
for(x=0; x<5; x++)
|
260
|
-
A[index(x, y)] = C[x];
|
261
|
-
}
|
262
|
-
}
|
263
|
-
|
264
|
-
void iota(tKeccakLane *A, unsigned int indexRound)
|
265
|
-
{
|
266
|
-
A[index(0, 0)] ^= KeccakRoundConstants[indexRound];
|
267
|
-
}
|
268
|
-
|
269
|
-
/* ---------------------------------------------------------------- */
|
270
|
-
|
271
|
-
void KeccakF1600_StateExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length)
|
272
|
-
{
|
273
|
-
memcpy(data, (unsigned char*)state+offset, length);
|
274
|
-
}
|
275
|
-
|
276
|
-
/* ---------------------------------------------------------------- */
|
277
|
-
|
278
|
-
void KeccakF1600_StateExtractAndXORBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length)
|
279
|
-
{
|
280
|
-
unsigned int i;
|
281
|
-
|
282
|
-
for(i=0; i<length; i++)
|
283
|
-
data[i] ^= ((unsigned char *)state)[offset+i];
|
284
|
-
}
|
285
|
-
|
286
|
-
/* ---------------------------------------------------------------- */
|
287
|
-
|
288
|
-
void displayRoundConstants(FILE *f)
|
289
|
-
{
|
290
|
-
unsigned int i;
|
291
|
-
|
292
|
-
for(i=0; i<nrRounds; i++) {
|
293
|
-
fprintf(f, "RC[%02i][0][0] = ", i);
|
294
|
-
fprintf(f, "%08X", (unsigned int)(KeccakRoundConstants[i] >> 32));
|
295
|
-
fprintf(f, "%08X", (unsigned int)(KeccakRoundConstants[i] & 0xFFFFFFFFULL));
|
296
|
-
fprintf(f, "\n");
|
297
|
-
}
|
298
|
-
fprintf(f, "\n");
|
299
|
-
}
|
300
|
-
|
301
|
-
void displayRhoOffsets(FILE *f)
|
302
|
-
{
|
303
|
-
unsigned int x, y;
|
304
|
-
|
305
|
-
for(y=0; y<5; y++) for(x=0; x<5; x++) {
|
306
|
-
fprintf(f, "RhoOffset[%i][%i] = ", x, y);
|
307
|
-
fprintf(f, "%2i", KeccakRhoOffsets[index(x, y)]);
|
308
|
-
fprintf(f, "\n");
|
309
|
-
}
|
310
|
-
fprintf(f, "\n");
|
311
|
-
}
|
@@ -1,26 +0,0 @@
|
|
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 _KeccakFReference_h_
|
17
|
-
#define _KeccakFReference_h_
|
18
|
-
#include "KeccakF-1600-interface.h"
|
19
|
-
|
20
|
-
void displayRoundConstants(FILE *f);
|
21
|
-
void displayRhoOffsets(FILE *f);
|
22
|
-
|
23
|
-
#define KeccakF_Initialize KeccakF1600_Initialize
|
24
|
-
#define KeccakF_StatePermute KeccakF1600_StatePermute
|
25
|
-
|
26
|
-
#endif
|
@@ -1,96 +0,0 @@
|
|
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 "SnP-interface.h"
|
18
|
-
#ifdef KeccakReference
|
19
|
-
#include "displayIntermediateValues.h"
|
20
|
-
#endif
|
21
|
-
|
22
|
-
size_t SnP_FBWL_Absorb_Default(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen, unsigned char trailingBits)
|
23
|
-
{
|
24
|
-
size_t processed = 0;
|
25
|
-
|
26
|
-
while(dataByteLen >= laneCount*SnP_laneLengthInBytes) {
|
27
|
-
#ifdef KeccakReference
|
28
|
-
if (trailingBits == 0)
|
29
|
-
displayBytes(1, "Block to be absorbed", data, laneCount*SnP_laneLengthInBytes);
|
30
|
-
else {
|
31
|
-
displayBytes(1, "Block to be absorbed (part)", data, laneCount*SnP_laneLengthInBytes);
|
32
|
-
displayBytes(1, "Block to be absorbed (trailing bits)", &trailingBits, 1);
|
33
|
-
}
|
34
|
-
#endif
|
35
|
-
SnP_XORBytes(state, data, 0, laneCount*SnP_laneLengthInBytes);
|
36
|
-
SnP_XORBytes(state, &trailingBits, laneCount*SnP_laneLengthInBytes, 1);
|
37
|
-
SnP_Permute(state);
|
38
|
-
data += laneCount*SnP_laneLengthInBytes;
|
39
|
-
dataByteLen -= laneCount*SnP_laneLengthInBytes;
|
40
|
-
processed += laneCount*SnP_laneLengthInBytes;
|
41
|
-
}
|
42
|
-
return processed;
|
43
|
-
}
|
44
|
-
|
45
|
-
size_t SnP_FBWL_Squeeze_Default(void *state, unsigned int laneCount, unsigned char *data, size_t dataByteLen)
|
46
|
-
{
|
47
|
-
size_t processed = 0;
|
48
|
-
|
49
|
-
while(dataByteLen >= laneCount*SnP_laneLengthInBytes) {
|
50
|
-
SnP_Permute(state);
|
51
|
-
SnP_ExtractBytes(state, data, 0, laneCount*SnP_laneLengthInBytes);
|
52
|
-
#ifdef KeccakReference
|
53
|
-
displayBytes(1, "Squeezed block", data, laneCount*SnP_laneLengthInBytes);
|
54
|
-
#endif
|
55
|
-
data += laneCount*SnP_laneLengthInBytes;
|
56
|
-
dataByteLen -= laneCount*SnP_laneLengthInBytes;
|
57
|
-
processed += laneCount*SnP_laneLengthInBytes;
|
58
|
-
}
|
59
|
-
return processed;
|
60
|
-
}
|
61
|
-
|
62
|
-
size_t SnP_FBWL_Wrap_Default(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits)
|
63
|
-
{
|
64
|
-
size_t processed = 0;
|
65
|
-
|
66
|
-
while(dataByteLen >= laneCount*SnP_laneLengthInBytes) {
|
67
|
-
SnP_XORBytes(state, dataIn, 0, laneCount*SnP_laneLengthInBytes);
|
68
|
-
SnP_ExtractBytes(state, dataOut, 0, laneCount*SnP_laneLengthInBytes);
|
69
|
-
SnP_XORBytes(state, &trailingBits, laneCount*SnP_laneLengthInBytes, 1);
|
70
|
-
SnP_Permute(state);
|
71
|
-
dataIn += laneCount*SnP_laneLengthInBytes;
|
72
|
-
dataOut += laneCount*SnP_laneLengthInBytes;
|
73
|
-
dataByteLen -= laneCount*SnP_laneLengthInBytes;
|
74
|
-
processed += laneCount*SnP_laneLengthInBytes;
|
75
|
-
}
|
76
|
-
return processed;
|
77
|
-
}
|
78
|
-
|
79
|
-
size_t SnP_FBWL_Unwrap_Default(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits)
|
80
|
-
{
|
81
|
-
size_t processed = 0;
|
82
|
-
|
83
|
-
if (dataIn != dataOut)
|
84
|
-
memcpy(dataOut, dataIn, dataByteLen);
|
85
|
-
while(dataByteLen >= laneCount*SnP_laneLengthInBytes) {
|
86
|
-
SnP_ExtractAndXORBytes(state, dataOut, 0, laneCount*SnP_laneLengthInBytes);
|
87
|
-
SnP_XORBytes(state, dataOut, 0, laneCount*SnP_laneLengthInBytes);
|
88
|
-
SnP_XORBytes(state, &trailingBits, laneCount*SnP_laneLengthInBytes, 1);
|
89
|
-
SnP_Permute(state);
|
90
|
-
dataIn += laneCount*SnP_laneLengthInBytes;
|
91
|
-
dataOut += laneCount*SnP_laneLengthInBytes;
|
92
|
-
dataByteLen -= laneCount*SnP_laneLengthInBytes;
|
93
|
-
processed += laneCount*SnP_laneLengthInBytes;
|
94
|
-
}
|
95
|
-
return processed;
|
96
|
-
}
|
@@ -1,26 +0,0 @@
|
|
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_FBWL_Default_h_
|
17
|
-
#define _SnP_FBWL_Default_h_
|
18
|
-
|
19
|
-
#include <string.h>
|
20
|
-
|
21
|
-
size_t SnP_FBWL_Absorb_Default(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen, unsigned char trailingBits);
|
22
|
-
size_t SnP_FBWL_Squeeze_Default(void *state, unsigned int laneCount, unsigned char *data, size_t dataByteLen);
|
23
|
-
size_t SnP_FBWL_Wrap_Default(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits);
|
24
|
-
size_t SnP_FBWL_Unwrap_Default(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits);
|
25
|
-
|
26
|
-
#endif
|
@@ -1,42 +0,0 @@
|
|
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
|
-
#include "SnP-FBWL-default.h"
|
21
|
-
|
22
|
-
#define SnP_width KeccakF_width
|
23
|
-
#define SnP_stateSizeInBytes KeccakF_stateSizeInBytes
|
24
|
-
#define SnP_laneLengthInBytes KeccakF_laneInBytes
|
25
|
-
#define SnP_laneCount 25
|
26
|
-
|
27
|
-
#define SnP_StaticInitialize KeccakF1600_Initialize
|
28
|
-
#define SnP_Initialize KeccakF1600_StateInitialize
|
29
|
-
#define SnP_XORBytes KeccakF1600_StateXORBytes
|
30
|
-
#define SnP_OverwriteBytes KeccakF1600_StateOverwriteBytes
|
31
|
-
#define SnP_OverwriteWithZeroes KeccakF1600_StateOverwriteWithZeroes
|
32
|
-
#define SnP_ComplementBit KeccakF1600_StateComplementBit
|
33
|
-
#define SnP_Permute KeccakF1600_StatePermute
|
34
|
-
#define SnP_ExtractBytes KeccakF1600_StateExtractBytes
|
35
|
-
#define SnP_ExtractAndXORBytes KeccakF1600_StateExtractAndXORBytes
|
36
|
-
|
37
|
-
#define SnP_FBWL_Absorb SnP_FBWL_Absorb_Default
|
38
|
-
#define SnP_FBWL_Squeeze SnP_FBWL_Squeeze_Default
|
39
|
-
#define SnP_FBWL_Wrap SnP_FBWL_Wrap_Default
|
40
|
-
#define SnP_FBWL_Unwrap SnP_FBWL_Unwrap_Default
|
41
|
-
|
42
|
-
#endif
|
@@ -1,158 +0,0 @@
|
|
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 <stdio.h>
|
17
|
-
#include "displayIntermediateValues.h"
|
18
|
-
#include "SnP-interface.h"
|
19
|
-
|
20
|
-
FILE *intermediateValueFile = 0;
|
21
|
-
int displayLevel = 0;
|
22
|
-
|
23
|
-
void displaySetIntermediateValueFile(FILE *f)
|
24
|
-
{
|
25
|
-
intermediateValueFile = f;
|
26
|
-
}
|
27
|
-
|
28
|
-
void displaySetLevel(int level)
|
29
|
-
{
|
30
|
-
displayLevel = level;
|
31
|
-
}
|
32
|
-
|
33
|
-
void displayBytes(int level, const char *text, const unsigned char *bytes, unsigned int size)
|
34
|
-
{
|
35
|
-
unsigned int i;
|
36
|
-
|
37
|
-
if ((intermediateValueFile) && (level <= displayLevel)) {
|
38
|
-
fprintf(intermediateValueFile, "%s:\n", text);
|
39
|
-
for(i=0; i<size; i++)
|
40
|
-
fprintf(intermediateValueFile, "%02X ", bytes[i]);
|
41
|
-
fprintf(intermediateValueFile, "\n");
|
42
|
-
fprintf(intermediateValueFile, "\n");
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
void displayBits(int level, const char *text, const unsigned char *data, unsigned int size, int MSBfirst)
|
47
|
-
{
|
48
|
-
unsigned int i, iByte, iBit;
|
49
|
-
|
50
|
-
if ((intermediateValueFile) && (level <= displayLevel)) {
|
51
|
-
fprintf(intermediateValueFile, "%s:\n", text);
|
52
|
-
for(i=0; i<size; i++) {
|
53
|
-
iByte = i/8;
|
54
|
-
iBit = i%8;
|
55
|
-
if (MSBfirst)
|
56
|
-
fprintf(intermediateValueFile, "%d ", ((data[iByte] << iBit) & 0x80) != 0);
|
57
|
-
else
|
58
|
-
fprintf(intermediateValueFile, "%d ", ((data[iByte] >> iBit) & 0x01) != 0);
|
59
|
-
}
|
60
|
-
fprintf(intermediateValueFile, "\n");
|
61
|
-
fprintf(intermediateValueFile, "\n");
|
62
|
-
}
|
63
|
-
}
|
64
|
-
|
65
|
-
void displayStateAsBytes(int level, const char *text, const unsigned char *state)
|
66
|
-
{
|
67
|
-
displayBytes(level, text, state, SnP_width/8);
|
68
|
-
}
|
69
|
-
|
70
|
-
#if (SnP_laneLengthInBytes == 8)
|
71
|
-
void displayStateAs32bitWords(int level, const char *text, const unsigned int *state)
|
72
|
-
{
|
73
|
-
unsigned int i;
|
74
|
-
|
75
|
-
if ((intermediateValueFile) && (level <= displayLevel)) {
|
76
|
-
fprintf(intermediateValueFile, "%s:\n", text);
|
77
|
-
for(i=0; i<SnP_width/64; i++) {
|
78
|
-
fprintf(intermediateValueFile, "%08X:%08X", (unsigned int)state[2*i+0], (unsigned int)state[2*i+1]);
|
79
|
-
if ((i%5) == 4)
|
80
|
-
fprintf(intermediateValueFile, "\n");
|
81
|
-
else
|
82
|
-
fprintf(intermediateValueFile, " ");
|
83
|
-
}
|
84
|
-
}
|
85
|
-
}
|
86
|
-
#endif
|
87
|
-
|
88
|
-
void displayStateAsLanes(int level, const char *text, void *statePointer)
|
89
|
-
{
|
90
|
-
unsigned int i;
|
91
|
-
#if (SnP_laneLengthInBytes == 8)
|
92
|
-
unsigned long long int *state = statePointer;
|
93
|
-
#endif
|
94
|
-
#if (SnP_laneLengthInBytes == 4)
|
95
|
-
unsigned int *state = statePointer;
|
96
|
-
#endif
|
97
|
-
#if (SnP_laneLengthInBytes == 2)
|
98
|
-
unsigned short *state = statePointer;
|
99
|
-
#endif
|
100
|
-
#if (SnP_laneLengthInBytes == 1)
|
101
|
-
unsigned char *state = statePointer;
|
102
|
-
#endif
|
103
|
-
|
104
|
-
if ((intermediateValueFile) && (level <= displayLevel)) {
|
105
|
-
fprintf(intermediateValueFile, "%s:\n", text);
|
106
|
-
#if (SnP_laneLengthInBytes == 8)
|
107
|
-
for(i=0; i<25; i++) {
|
108
|
-
fprintf(intermediateValueFile, "%08X", (unsigned int)(state[i] >> 32));
|
109
|
-
fprintf(intermediateValueFile, "%08X", (unsigned int)(state[i] & 0xFFFFFFFFULL));
|
110
|
-
if ((i%5) == 4)
|
111
|
-
fprintf(intermediateValueFile, "\n");
|
112
|
-
else
|
113
|
-
fprintf(intermediateValueFile, " ");
|
114
|
-
}
|
115
|
-
#endif
|
116
|
-
#if (SnP_laneLengthInBytes == 4)
|
117
|
-
for(i=0; i<25; i++) {
|
118
|
-
fprintf(intermediateValueFile, "%08X", state[i]);
|
119
|
-
if ((i%5) == 4)
|
120
|
-
fprintf(intermediateValueFile, "\n");
|
121
|
-
else
|
122
|
-
fprintf(intermediateValueFile, " ");
|
123
|
-
}
|
124
|
-
#endif
|
125
|
-
#if (SnP_laneLengthInBytes == 2)
|
126
|
-
for(i=0; i<25; i++) {
|
127
|
-
fprintf(intermediateValueFile, "%04X ", state[i]);
|
128
|
-
if ((i%5) == 4)
|
129
|
-
fprintf(intermediateValueFile, "\n");
|
130
|
-
}
|
131
|
-
#endif
|
132
|
-
#if (SnP_laneLengthInBytes == 1)
|
133
|
-
for(i=0; i<25; i++) {
|
134
|
-
fprintf(intermediateValueFile, "%02X ", state[i]);
|
135
|
-
if ((i%5) == 4)
|
136
|
-
fprintf(intermediateValueFile, "\n");
|
137
|
-
}
|
138
|
-
#endif
|
139
|
-
}
|
140
|
-
}
|
141
|
-
|
142
|
-
void displayRoundNumber(int level, unsigned int i)
|
143
|
-
{
|
144
|
-
if ((intermediateValueFile) && (level <= displayLevel)) {
|
145
|
-
fprintf(intermediateValueFile, "\n");
|
146
|
-
fprintf(intermediateValueFile, "--- Round %d ---\n", i);
|
147
|
-
fprintf(intermediateValueFile, "\n");
|
148
|
-
}
|
149
|
-
}
|
150
|
-
|
151
|
-
void displayText(int level, const char *text)
|
152
|
-
{
|
153
|
-
if ((intermediateValueFile) && (level <= displayLevel)) {
|
154
|
-
fprintf(intermediateValueFile, "%s", text);
|
155
|
-
fprintf(intermediateValueFile, "\n");
|
156
|
-
fprintf(intermediateValueFile, "\n");
|
157
|
-
}
|
158
|
-
}
|
@@ -1,34 +0,0 @@
|
|
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 _displayIntermediateValues_h_
|
17
|
-
#define _displayIntermediateValues_h_
|
18
|
-
|
19
|
-
#include <stdio.h>
|
20
|
-
#include "SnP-interface.h"
|
21
|
-
|
22
|
-
void displaySetIntermediateValueFile(FILE *f);
|
23
|
-
void displaySetLevel(int level);
|
24
|
-
void displayBytes(int level, const char *text, const unsigned char *bytes, unsigned int size);
|
25
|
-
void displayBits(int level, const char *text, const unsigned char *data, unsigned int size, int MSBfirst);
|
26
|
-
void displayStateAsBytes(int level, const char *text, const unsigned char *state);
|
27
|
-
#if (SnP_laneLengthInBytes == 8)
|
28
|
-
void displayStateAs32bitWords(int level, const char *text, const unsigned int *state);
|
29
|
-
#endif
|
30
|
-
void displayStateAsLanes(int level, const char *text, void *statePointer);
|
31
|
-
void displayRoundNumber(int level, unsigned int i);
|
32
|
-
void displayText(int level, const char *text);
|
33
|
-
|
34
|
-
#endif
|