sha3 0.2.6 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of sha3 might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +9 -1
- data/Gemfile.ci +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +145 -0
- data/Rakefile +4 -5
- data/ext/sha3/KeccakF-1600-interface.h +28 -34
- data/ext/sha3/KeccakHash.c +80 -0
- data/ext/sha3/KeccakHash.h +110 -0
- data/ext/sha3/KeccakSponge.c +127 -201
- data/ext/sha3/KeccakSponge.h +74 -37
- data/ext/sha3/Optimized64/KeccakF-1600-64.macros +2199 -0
- data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +3 -0
- data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +508 -0
- data/ext/sha3/{KeccakF-1600-unrolling.macros → Optimized64/KeccakF-1600-unrolling.macros} +16 -14
- data/ext/sha3/Optimized64/SnP-interface.h +47 -0
- data/ext/sha3/Reference/KeccakF-1600-reference.c +311 -0
- data/ext/sha3/Reference/KeccakF-reference.h +26 -0
- data/ext/sha3/Reference/SnP-FBWL-default.c +96 -0
- data/ext/sha3/Reference/SnP-FBWL-default.h +26 -0
- data/ext/sha3/Reference/SnP-interface.h +42 -0
- data/ext/sha3/{displayIntermediateValues.c → Reference/displayIntermediateValues.c} +52 -11
- data/ext/sha3/{displayIntermediateValues.h → Reference/displayIntermediateValues.h} +11 -6
- data/ext/sha3/SnP-Relaned.h +249 -0
- data/ext/sha3/brg_endian.h +0 -0
- data/ext/sha3/digest.c +67 -70
- data/ext/sha3/digest.h +2 -2
- data/ext/sha3/extconf.rb +7 -12
- data/ext/sha3/sha3.h +2 -2
- data/lib/sha3/doc.rb +26 -39
- data/lib/sha3/version.rb +2 -2
- data/sha3.gemspec +6 -6
- data/spec/generate_tests.rb +6 -41
- data/spec/sha3_core_spec.rb +111 -133
- data/spec/spec_helper.rb +2 -2
- data/tests.sh +9 -7
- metadata +33 -36
- data/README.rdoc +0 -131
- data/ext/sha3/KeccakF-1600-32-rvk.macros +0 -555
- data/ext/sha3/KeccakF-1600-32-s1.macros +0 -1187
- data/ext/sha3/KeccakF-1600-32-s2.macros +0 -1187
- data/ext/sha3/KeccakF-1600-32.macros +0 -26
- data/ext/sha3/KeccakF-1600-64.macros +0 -728
- data/ext/sha3/KeccakF-1600-int-set.h +0 -6
- data/ext/sha3/KeccakF-1600-opt.c +0 -504
- data/ext/sha3/KeccakF-1600-opt32-settings.h +0 -4
- data/ext/sha3/KeccakF-1600-opt32.c-arch +0 -524
- data/ext/sha3/KeccakF-1600-opt64-settings.h +0 -7
- data/ext/sha3/KeccakF-1600-opt64.c-arch +0 -504
- data/ext/sha3/KeccakF-1600-reference.c-arch +0 -300
- data/ext/sha3/KeccakF-1600-x86-64-gas.s +0 -766
- data/ext/sha3/KeccakF-1600-x86-64-shld-gas.s +0 -766
- data/ext/sha3/KeccakNISTInterface.c +0 -81
- data/ext/sha3/KeccakNISTInterface.h +0 -70
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,96 @@
|
|
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
|
+
}
|
@@ -0,0 +1,26 @@
|
|
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
|
@@ -0,0 +1,42 @@
|
|
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,10 +1,12 @@
|
|
1
1
|
/*
|
2
|
-
|
3
|
-
Michaël Peeters
|
4
|
-
|
2
|
+
Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
|
3
|
+
Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby
|
4
|
+
denoted as "the implementer".
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
For more information, feedback or questions, please refer to our websites:
|
7
|
+
http://keccak.noekeon.org/
|
8
|
+
http://keyak.noekeon.org/
|
9
|
+
http://ketje.noekeon.org/
|
8
10
|
|
9
11
|
To the extent possible under law, the implementer has waived all copyright
|
10
12
|
and related or neighboring rights to the source code in this file.
|
@@ -13,7 +15,7 @@ http://creativecommons.org/publicdomain/zero/1.0/
|
|
13
15
|
|
14
16
|
#include <stdio.h>
|
15
17
|
#include "displayIntermediateValues.h"
|
16
|
-
#include "
|
18
|
+
#include "SnP-interface.h"
|
17
19
|
|
18
20
|
FILE *intermediateValueFile = 0;
|
19
21
|
int displayLevel = 0;
|
@@ -62,16 +64,17 @@ void displayBits(int level, const char *text, const unsigned char *data, unsigne
|
|
62
64
|
|
63
65
|
void displayStateAsBytes(int level, const char *text, const unsigned char *state)
|
64
66
|
{
|
65
|
-
displayBytes(level, text, state,
|
67
|
+
displayBytes(level, text, state, SnP_width/8);
|
66
68
|
}
|
67
69
|
|
70
|
+
#if (SnP_laneLengthInBytes == 8)
|
68
71
|
void displayStateAs32bitWords(int level, const char *text, const unsigned int *state)
|
69
72
|
{
|
70
73
|
unsigned int i;
|
71
74
|
|
72
75
|
if ((intermediateValueFile) && (level <= displayLevel)) {
|
73
76
|
fprintf(intermediateValueFile, "%s:\n", text);
|
74
|
-
for(i=0; i<
|
77
|
+
for(i=0; i<SnP_width/64; i++) {
|
75
78
|
fprintf(intermediateValueFile, "%08X:%08X", (unsigned int)state[2*i+0], (unsigned int)state[2*i+1]);
|
76
79
|
if ((i%5) == 4)
|
77
80
|
fprintf(intermediateValueFile, "\n");
|
@@ -80,14 +83,28 @@ void displayStateAs32bitWords(int level, const char *text, const unsigned int *s
|
|
80
83
|
}
|
81
84
|
}
|
82
85
|
}
|
86
|
+
#endif
|
83
87
|
|
84
|
-
void
|
88
|
+
void displayStateAsLanes(int level, const char *text, void *statePointer)
|
85
89
|
{
|
86
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
|
87
103
|
|
88
104
|
if ((intermediateValueFile) && (level <= displayLevel)) {
|
89
105
|
fprintf(intermediateValueFile, "%s:\n", text);
|
90
|
-
|
106
|
+
#if (SnP_laneLengthInBytes == 8)
|
107
|
+
for(i=0; i<25; i++) {
|
91
108
|
fprintf(intermediateValueFile, "%08X", (unsigned int)(state[i] >> 32));
|
92
109
|
fprintf(intermediateValueFile, "%08X", (unsigned int)(state[i] & 0xFFFFFFFFULL));
|
93
110
|
if ((i%5) == 4)
|
@@ -95,6 +112,30 @@ void displayStateAs64bitWords(int level, const char *text, const unsigned long l
|
|
95
112
|
else
|
96
113
|
fprintf(intermediateValueFile, " ");
|
97
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
|
98
139
|
}
|
99
140
|
}
|
100
141
|
|
@@ -110,7 +151,7 @@ void displayRoundNumber(int level, unsigned int i)
|
|
110
151
|
void displayText(int level, const char *text)
|
111
152
|
{
|
112
153
|
if ((intermediateValueFile) && (level <= displayLevel)) {
|
113
|
-
fprintf(intermediateValueFile, text);
|
154
|
+
fprintf(intermediateValueFile, "%s", text);
|
114
155
|
fprintf(intermediateValueFile, "\n");
|
115
156
|
fprintf(intermediateValueFile, "\n");
|
116
157
|
}
|
@@ -1,10 +1,12 @@
|
|
1
1
|
/*
|
2
|
-
|
3
|
-
Michaël Peeters
|
4
|
-
|
2
|
+
Implementation by the Keccak, Keyak and Ketje Teams, namely, Guido Bertoni,
|
3
|
+
Joan Daemen, Michaël Peeters, Gilles Van Assche and Ronny Van Keer, hereby
|
4
|
+
denoted as "the implementer".
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
For more information, feedback or questions, please refer to our websites:
|
7
|
+
http://keccak.noekeon.org/
|
8
|
+
http://keyak.noekeon.org/
|
9
|
+
http://ketje.noekeon.org/
|
8
10
|
|
9
11
|
To the extent possible under law, the implementer has waived all copyright
|
10
12
|
and related or neighboring rights to the source code in this file.
|
@@ -15,14 +17,17 @@ http://creativecommons.org/publicdomain/zero/1.0/
|
|
15
17
|
#define _displayIntermediateValues_h_
|
16
18
|
|
17
19
|
#include <stdio.h>
|
20
|
+
#include "SnP-interface.h"
|
18
21
|
|
19
22
|
void displaySetIntermediateValueFile(FILE *f);
|
20
23
|
void displaySetLevel(int level);
|
21
24
|
void displayBytes(int level, const char *text, const unsigned char *bytes, unsigned int size);
|
22
25
|
void displayBits(int level, const char *text, const unsigned char *data, unsigned int size, int MSBfirst);
|
23
26
|
void displayStateAsBytes(int level, const char *text, const unsigned char *state);
|
27
|
+
#if (SnP_laneLengthInBytes == 8)
|
24
28
|
void displayStateAs32bitWords(int level, const char *text, const unsigned int *state);
|
25
|
-
|
29
|
+
#endif
|
30
|
+
void displayStateAsLanes(int level, const char *text, void *statePointer);
|
26
31
|
void displayRoundNumber(int level, unsigned int i);
|
27
32
|
void displayText(int level, const char *text);
|
28
33
|
|
@@ -0,0 +1,249 @@
|
|
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_Relaned_h_
|
17
|
+
#define _SnP_Relaned_h_
|
18
|
+
|
19
|
+
/** Function to XOR data given as bytes into the state.
|
20
|
+
* The bits to modify are restricted to be consecutive and to be in the same lane.
|
21
|
+
* The bit positions that are affected by this function are
|
22
|
+
* from @a lanePosition*(lane size in bits) + @a offset*8
|
23
|
+
* to @a lanePosition*(lane size in bits) + @a offset*8 + @a length*8.
|
24
|
+
* (The bit positions, the x,y,z coordinates and their link are defined in the "Keccak reference".)
|
25
|
+
* @param state Pointer to the state.
|
26
|
+
* @param lanePosition Index of the lane to be modified (x+5*y,
|
27
|
+
* or bit position divided by the lane size).
|
28
|
+
* @param data Pointer to the input data.
|
29
|
+
* @param offset Offset in bytes within the lane.
|
30
|
+
* @param length Number of bytes.
|
31
|
+
* @pre 0 ≤ @a lanePosition < 25
|
32
|
+
* @pre 0 ≤ @a offset < (lane size in bytes)
|
33
|
+
* @pre 0 ≤ @a offset + @a length ≤ (lane size in bytes)
|
34
|
+
*/
|
35
|
+
void SnP_XORBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length);
|
36
|
+
|
37
|
+
/** Function to XOR data given as bytes into the state.
|
38
|
+
* The bits to modify are restricted to start from the bit position 0 and
|
39
|
+
* to span a whole number of lanes.
|
40
|
+
* @param state Pointer to the state.
|
41
|
+
* @param data Pointer to the input data.
|
42
|
+
* @param laneCount The number of lanes, i.e., the length of the data
|
43
|
+
* divided by the lane size.
|
44
|
+
* @pre 0 ≤ @a laneCount ≤ 25
|
45
|
+
*/
|
46
|
+
void SnP_XORLanes(void *state, const unsigned char *data, unsigned int laneCount);
|
47
|
+
|
48
|
+
/** Function to overwrite data given as bytes into the state.
|
49
|
+
* The bits to modify are restricted to be consecutive and to be in the same lane.
|
50
|
+
* The bit positions that are affected by this function are
|
51
|
+
* from @a lanePosition*(lane size in bits) + @a offset*8
|
52
|
+
* to @a lanePosition*(lane size in bits) + @a offset*8 + @a length*8.
|
53
|
+
* (The bit positions, the x,y,z coordinates and their link are defined in the "Keccak reference".)
|
54
|
+
* @param state Pointer to the state.
|
55
|
+
* @param lanePosition Index of the lane to be modified (x+5*y,
|
56
|
+
* or bit position divided by the lane size).
|
57
|
+
* @param data Pointer to the input data.
|
58
|
+
* @param offset Offset in bytes within the lane.
|
59
|
+
* @param length Number of bytes.
|
60
|
+
* @pre 0 ≤ @a lanePosition < 25
|
61
|
+
* @pre 0 ≤ @a offset < (lane size in bytes)
|
62
|
+
* @pre 0 ≤ @a offset + @a length ≤ (lane size in bytes)
|
63
|
+
*/
|
64
|
+
void SnP_OverwriteBytesInLane(void *state, unsigned int lanePosition, const unsigned char *data, unsigned int offset, unsigned int length);
|
65
|
+
|
66
|
+
/** Function to overwrite data given as bytes into the state.
|
67
|
+
* The bits to modify are restricted to start from the bit position 0 and
|
68
|
+
* to span a whole number of lanes.
|
69
|
+
* @param state Pointer to the state.
|
70
|
+
* @param data Pointer to the input data.
|
71
|
+
* @param laneCount The number of lanes, i.e., the length of the data
|
72
|
+
* divided by the lane size.
|
73
|
+
* @pre 0 ≤ @a laneCount ≤ 25
|
74
|
+
*/
|
75
|
+
void SnP_OverwriteLanes(void *state, const unsigned char *data, unsigned int laneCount);
|
76
|
+
|
77
|
+
/** Function to retrieve data from the state into bytes.
|
78
|
+
* The bits to output are restricted to be consecutive and to be in the same lane.
|
79
|
+
* The bit positions that are retrieved by this function are
|
80
|
+
* from @a lanePosition*(lane size in bits) + @a offset*8
|
81
|
+
* to @a lanePosition*(lane size in bits) + @a offset*8 + @a length*8.
|
82
|
+
* (The bit positions, the x,y,z coordinates and their link are defined in the "Keccak reference".)
|
83
|
+
* @param state Pointer to the state.
|
84
|
+
* @param lanePosition Index of the lane to be read (x+5*y,
|
85
|
+
* or bit position divided by the lane size).
|
86
|
+
* @param data Pointer to the area where to store output data.
|
87
|
+
* @param offset Offset in byte within the lane.
|
88
|
+
* @param length Number of bytes.
|
89
|
+
* @pre 0 ≤ @a lanePosition < 25
|
90
|
+
* @pre 0 ≤ @a offset < (lane size in bytes)
|
91
|
+
* @pre 0 ≤ @a offset + @a length ≤ (lane size in bytes)
|
92
|
+
*/
|
93
|
+
void SnP_ExtractBytesInLane(const void *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length);
|
94
|
+
|
95
|
+
/** Function to retrieve data from the state into bytes.
|
96
|
+
* The bits to output are restricted to start from the bit position 0 and
|
97
|
+
* to span a whole number of lanes.
|
98
|
+
* @param state Pointer to the state.
|
99
|
+
* @param data Pointer to the area where to store output data.
|
100
|
+
* @param laneCount The number of lanes, i.e., the length of the data
|
101
|
+
* divided by the lane size.
|
102
|
+
* @pre 0 ≤ @a laneCount ≤ 25
|
103
|
+
*/
|
104
|
+
void SnP_ExtractLanes(const void *state, unsigned char *data, unsigned int laneCount);
|
105
|
+
|
106
|
+
/** Function to retrieve data from the state into bytes and
|
107
|
+
* to XOR them into the output buffer.
|
108
|
+
* The bits to output are restricted to be consecutive and to be in the same lane.
|
109
|
+
* The bit positions that are retrieved by this function are
|
110
|
+
* from @a lanePosition*(lane size in bits) + @a offset*8
|
111
|
+
* to @a lanePosition*(lane size in bits) + @a offset*8 + @a length*8.
|
112
|
+
* (The bit positions, the x,y,z coordinates and their link are defined in the "Keccak reference".)
|
113
|
+
* @param state Pointer to the state.
|
114
|
+
* @param lanePosition Index of the lane to be read (x+5*y,
|
115
|
+
* or bit position divided by the lane size).
|
116
|
+
* @param data Pointer to the area where to XOR output data.
|
117
|
+
* @param offset Offset in byte within the lane.
|
118
|
+
* @param length Number of bytes.
|
119
|
+
* @pre 0 ≤ @a lanePosition < 25
|
120
|
+
* @pre 0 ≤ @a offset < (lane size in bytes)
|
121
|
+
* @pre 0 ≤ @a offset + @a length ≤ (lane size in bytes)
|
122
|
+
*/
|
123
|
+
void SnP_ExtractAndXORBytesInLane(const void *state, unsigned int lanePosition, unsigned char *data, unsigned int offset, unsigned int length);
|
124
|
+
|
125
|
+
/** Function to retrieve data from the state into bytes and
|
126
|
+
* to XOR them into the output buffer.
|
127
|
+
* The bits to output are restricted to start from the bit position 0 and
|
128
|
+
* to span a whole number of lanes.
|
129
|
+
* @param state Pointer to the state.
|
130
|
+
* @param data Pointer to the area where to XOR output data.
|
131
|
+
* @param laneCount The number of lanes, i.e., the length of the data
|
132
|
+
* divided by the lane size.
|
133
|
+
* @pre 0 ≤ @a laneCount ≤ 25
|
134
|
+
*/
|
135
|
+
void SnP_ExtractAndXORLanes(const void *state, unsigned char *data, unsigned int laneCount);
|
136
|
+
|
137
|
+
#define SnP_XORBytes(state, data, offset, length) \
|
138
|
+
{ \
|
139
|
+
if ((offset) == 0) { \
|
140
|
+
SnP_XORLanes(state, data, (length)/SnP_laneLengthInBytes); \
|
141
|
+
SnP_XORBytesInLane(state, \
|
142
|
+
(length)/SnP_laneLengthInBytes, \
|
143
|
+
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
|
144
|
+
0, \
|
145
|
+
(length)%SnP_laneLengthInBytes); \
|
146
|
+
} \
|
147
|
+
else { \
|
148
|
+
unsigned int _sizeLeft = (length); \
|
149
|
+
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
|
150
|
+
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
|
151
|
+
const unsigned char *_curData = (data); \
|
152
|
+
while(_sizeLeft > 0) { \
|
153
|
+
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
|
154
|
+
if (_bytesInLane > _sizeLeft) \
|
155
|
+
_bytesInLane = _sizeLeft; \
|
156
|
+
SnP_XORBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
|
157
|
+
_sizeLeft -= _bytesInLane; \
|
158
|
+
_lanePosition++; \
|
159
|
+
_offsetInLane = 0; \
|
160
|
+
_curData += _bytesInLane; \
|
161
|
+
} \
|
162
|
+
} \
|
163
|
+
}
|
164
|
+
|
165
|
+
#define SnP_OverwriteBytes(state, data, offset, length) \
|
166
|
+
{ \
|
167
|
+
if ((offset) == 0) { \
|
168
|
+
SnP_OverwriteLanes(state, data, (length)/SnP_laneLengthInBytes); \
|
169
|
+
SnP_OverwriteBytesInLane(state, \
|
170
|
+
(length)/SnP_laneLengthInBytes, \
|
171
|
+
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
|
172
|
+
0, \
|
173
|
+
(length)%SnP_laneLengthInBytes); \
|
174
|
+
} \
|
175
|
+
else { \
|
176
|
+
unsigned int _sizeLeft = (length); \
|
177
|
+
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
|
178
|
+
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
|
179
|
+
const unsigned char *_curData = (data); \
|
180
|
+
while(_sizeLeft > 0) { \
|
181
|
+
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
|
182
|
+
if (_bytesInLane > _sizeLeft) \
|
183
|
+
_bytesInLane = _sizeLeft; \
|
184
|
+
SnP_OverwriteBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
|
185
|
+
_sizeLeft -= _bytesInLane; \
|
186
|
+
_lanePosition++; \
|
187
|
+
_offsetInLane = 0; \
|
188
|
+
_curData += _bytesInLane; \
|
189
|
+
} \
|
190
|
+
} \
|
191
|
+
}
|
192
|
+
|
193
|
+
#define SnP_ExtractBytes(state, data, offset, length) \
|
194
|
+
{ \
|
195
|
+
if ((offset) == 0) { \
|
196
|
+
SnP_ExtractLanes(state, data, (length)/SnP_laneLengthInBytes); \
|
197
|
+
SnP_ExtractBytesInLane(state, \
|
198
|
+
(length)/SnP_laneLengthInBytes, \
|
199
|
+
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
|
200
|
+
0, \
|
201
|
+
(length)%SnP_laneLengthInBytes); \
|
202
|
+
} \
|
203
|
+
else { \
|
204
|
+
unsigned int _sizeLeft = (length); \
|
205
|
+
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
|
206
|
+
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
|
207
|
+
unsigned char *_curData = (data); \
|
208
|
+
while(_sizeLeft > 0) { \
|
209
|
+
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
|
210
|
+
if (_bytesInLane > _sizeLeft) \
|
211
|
+
_bytesInLane = _sizeLeft; \
|
212
|
+
SnP_ExtractBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
|
213
|
+
_sizeLeft -= _bytesInLane; \
|
214
|
+
_lanePosition++; \
|
215
|
+
_offsetInLane = 0; \
|
216
|
+
_curData += _bytesInLane; \
|
217
|
+
} \
|
218
|
+
} \
|
219
|
+
}
|
220
|
+
|
221
|
+
#define SnP_ExtractAndXORBytes(state, data, offset, length) \
|
222
|
+
{ \
|
223
|
+
if ((offset) == 0) { \
|
224
|
+
SnP_ExtractAndXORLanes(state, data, (length)/SnP_laneLengthInBytes); \
|
225
|
+
SnP_ExtractAndXORBytesInLane(state, \
|
226
|
+
(length)/SnP_laneLengthInBytes, \
|
227
|
+
(data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
|
228
|
+
0, \
|
229
|
+
(length)%SnP_laneLengthInBytes); \
|
230
|
+
} \
|
231
|
+
else { \
|
232
|
+
unsigned int _sizeLeft = (length); \
|
233
|
+
unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
|
234
|
+
unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
|
235
|
+
unsigned char *_curData = (data); \
|
236
|
+
while(_sizeLeft > 0) { \
|
237
|
+
unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
|
238
|
+
if (_bytesInLane > _sizeLeft) \
|
239
|
+
_bytesInLane = _sizeLeft; \
|
240
|
+
SnP_ExtractAndXORBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
|
241
|
+
_sizeLeft -= _bytesInLane; \
|
242
|
+
_lanePosition++; \
|
243
|
+
_offsetInLane = 0; \
|
244
|
+
_curData += _bytesInLane; \
|
245
|
+
} \
|
246
|
+
} \
|
247
|
+
}
|
248
|
+
|
249
|
+
#endif
|