sha3 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -1,192 +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 "KeccakSponge.h"
18
- #include "SnP-interface.h"
19
- #ifdef KeccakReference
20
- #include "displayIntermediateValues.h"
21
- #endif
22
-
23
- /* ---------------------------------------------------------------- */
24
-
25
- int Keccak_SpongeInitialize(Keccak_SpongeInstance *instance, unsigned int rate, unsigned int capacity)
26
- {
27
- if (rate+capacity != SnP_width)
28
- return 1;
29
- if ((rate <= 0) || (rate > SnP_width) || ((rate % 8) != 0))
30
- return 1;
31
- SnP_StaticInitialize();
32
- SnP_Initialize(instance->state);
33
- instance->rate = rate;
34
- instance->byteIOIndex = 0;
35
- instance->squeezing = 0;
36
-
37
- return 0;
38
- }
39
-
40
- /* ---------------------------------------------------------------- */
41
-
42
- int Keccak_SpongeAbsorb(Keccak_SpongeInstance *instance, const unsigned char *data, size_t dataByteLen)
43
- {
44
- size_t i, j;
45
- unsigned int partialBlock;
46
- const unsigned char *curData;
47
- unsigned int rateInBytes = instance->rate/8;
48
-
49
- if (instance->squeezing)
50
- return 1; // Too late for additional input
51
-
52
- i = 0;
53
- curData = data;
54
- while(i < dataByteLen) {
55
- if ((instance->byteIOIndex == 0) && (dataByteLen >= (i + rateInBytes))) {
56
- // processing full blocks first
57
- if ((rateInBytes % SnP_laneLengthInBytes) == 0) {
58
- // fast lane: whole lane rate
59
- j = SnP_FBWL_Absorb(instance->state, rateInBytes/SnP_laneLengthInBytes, curData, dataByteLen - i, 0);
60
- i += j;
61
- curData += j;
62
- }
63
- else {
64
- for(j=dataByteLen-i; j>=rateInBytes; j-=rateInBytes) {
65
- #ifdef KeccakReference
66
- displayBytes(1, "Block to be absorbed", curData, rateInBytes);
67
- #endif
68
- SnP_XORBytes(instance->state, curData, 0, rateInBytes);
69
- SnP_Permute(instance->state);
70
- curData+=rateInBytes;
71
- }
72
- i = dataByteLen - j;
73
- }
74
- }
75
- else {
76
- // normal lane: using the message queue
77
- partialBlock = (unsigned int)(dataByteLen - i);
78
- if (partialBlock+instance->byteIOIndex > rateInBytes)
79
- partialBlock = rateInBytes-instance->byteIOIndex;
80
- #ifdef KeccakReference
81
- displayBytes(1, "Block to be absorbed (part)", curData, partialBlock);
82
- #endif
83
- i += partialBlock;
84
-
85
- SnP_XORBytes(instance->state, curData, instance->byteIOIndex, partialBlock);
86
- curData += partialBlock;
87
- instance->byteIOIndex += partialBlock;
88
- if (instance->byteIOIndex == rateInBytes) {
89
- SnP_Permute(instance->state);
90
- instance->byteIOIndex = 0;
91
- }
92
- }
93
- }
94
- return 0;
95
- }
96
-
97
- /* ---------------------------------------------------------------- */
98
-
99
- int Keccak_SpongeAbsorbLastFewBits(Keccak_SpongeInstance *instance, unsigned char delimitedData)
100
- {
101
- unsigned char delimitedData1[1];
102
- unsigned int rateInBytes = instance->rate/8;
103
-
104
- if (delimitedData == 0)
105
- return 1;
106
- if (instance->squeezing)
107
- return 1; // Too late for additional input
108
-
109
- delimitedData1[0] = delimitedData;
110
- #ifdef KeccakReference
111
- displayBytes(1, "Block to be absorbed (last few bits + first bit of padding)", delimitedData1, 1);
112
- #endif
113
- // Last few bits, whose delimiter coincides with first bit of padding
114
- SnP_XORBytes(instance->state, delimitedData1, instance->byteIOIndex, 1);
115
- // If the first bit of padding is at position rate-1, we need a whole new block for the second bit of padding
116
- if ((delimitedData >= 0x80) && (instance->byteIOIndex == (rateInBytes-1)))
117
- SnP_Permute(instance->state);
118
- // Second bit of padding
119
- SnP_ComplementBit(instance->state, rateInBytes*8-1);
120
- #ifdef KeccakReference
121
- {
122
- unsigned char block[SnP_width/8];
123
- memset(block, 0, SnP_width/8);
124
- block[rateInBytes-1] = 0x80;
125
- displayBytes(1, "Second bit of padding", block, rateInBytes);
126
- }
127
- #endif
128
- SnP_Permute(instance->state);
129
- instance->byteIOIndex = 0;
130
- instance->squeezing = 1;
131
- #ifdef KeccakReference
132
- displayText(1, "--- Switching to squeezing phase ---");
133
- #endif
134
- return 0;
135
- }
136
-
137
- /* ---------------------------------------------------------------- */
138
-
139
- int Keccak_SpongeSqueeze(Keccak_SpongeInstance *instance, unsigned char *data, size_t dataByteLen)
140
- {
141
- size_t i, j;
142
- unsigned int partialBlock;
143
- unsigned int rateInBytes = instance->rate/8;
144
- unsigned char *curData;
145
-
146
- if (!instance->squeezing)
147
- Keccak_SpongeAbsorbLastFewBits(instance, 0x01);
148
-
149
- i = 0;
150
- curData = data;
151
- while(i < dataByteLen) {
152
- if ((instance->byteIOIndex == rateInBytes) && (dataByteLen >= (i + rateInBytes))) {
153
- // processing full blocks first
154
- if ((rateInBytes % SnP_laneLengthInBytes) == 0) {
155
- // fast lane: whole lane rate
156
- j = SnP_FBWL_Squeeze(instance->state, rateInBytes/SnP_laneLengthInBytes, curData, dataByteLen - i);
157
- i += j;
158
- curData += j;
159
- }
160
- else {
161
- for(j=dataByteLen-i; j>=rateInBytes; j-=rateInBytes) {
162
- SnP_Permute(instance->state);
163
- SnP_ExtractBytes(instance->state, curData, 0, rateInBytes);
164
- #ifdef KeccakReference
165
- displayBytes(1, "Squeezed block", curData, rateInBytes);
166
- #endif
167
- curData+=rateInBytes;
168
- }
169
- i = dataByteLen - j;
170
- }
171
- }
172
- else {
173
- // normal lane: using the message queue
174
- if (instance->byteIOIndex == rateInBytes) {
175
- SnP_Permute(instance->state);
176
- instance->byteIOIndex = 0;
177
- }
178
- partialBlock = (unsigned int)(dataByteLen - i);
179
- if (partialBlock+instance->byteIOIndex > rateInBytes)
180
- partialBlock = rateInBytes-instance->byteIOIndex;
181
- i += partialBlock;
182
-
183
- SnP_ExtractBytes(instance->state, curData, instance->byteIOIndex, partialBlock);
184
- #ifdef KeccakReference
185
- displayBytes(1, "Squeezed block (part)", curData, partialBlock);
186
- #endif
187
- curData += partialBlock;
188
- instance->byteIOIndex += partialBlock;
189
- }
190
- }
191
- return 0;
192
- }
@@ -1,113 +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 _KeccakSponge_h_
17
- #define _KeccakSponge_h_
18
-
19
- #include "SnP-interface.h"
20
- #include <string.h>
21
-
22
- // on Mac OS-X and possibly others, ALIGN(x) is defined in param.h, and -Werror chokes on the redef.
23
- #ifdef ALIGN
24
- #undef ALIGN
25
- #endif
26
-
27
- #if defined(__GNUC__)
28
- #define ALIGN __attribute__ ((aligned(32)))
29
- #elif defined(_MSC_VER)
30
- #define ALIGN __declspec(align(32))
31
- #else
32
- #define ALIGN
33
- #endif
34
-
35
- /**
36
- * Structure that contains the sponge instance attributes for use with the
37
- * Keccak_Sponge* functions.
38
- * It gathers the state processed by the permutation as well as the rate,
39
- * the position of input/output bytes in the state and the phase
40
- * (absorbing or squeezing).
41
- */
42
- ALIGN typedef struct Keccak_SpongeInstanceStruct {
43
- /** The state processed by the permutation. */
44
- ALIGN unsigned char state[SnP_stateSizeInBytes];
45
- /** The value of the rate in bits.*/
46
- unsigned int rate;
47
- /** The position in the state of the next byte to be input (when absorbing) or output (when squeezing). */
48
- unsigned int byteIOIndex;
49
- /** If set to 0, in the absorbing phase; otherwise, in the squeezing phase. */
50
- int squeezing;
51
- } Keccak_SpongeInstance;
52
-
53
- /**
54
- * Function to initialize the state of the Keccak[r, c] sponge function.
55
- * The phase of the sponge function is set to absorbing.
56
- * @param spongeInstance Pointer to the sponge instance to be initialized.
57
- * @param rate The value of the rate r.
58
- * @param capacity The value of the capacity c.
59
- * @pre One must have r+c equal to the supported width of this implementation
60
- * and the rate a multiple of 8 bits (one byte) in this implementation.
61
- * @return Zero if successful, 1 otherwise.
62
- */
63
- int Keccak_SpongeInitialize(Keccak_SpongeInstance *spongeInstance, unsigned int rate, unsigned int capacity);
64
-
65
- /**
66
- * Function to give input data bytes for the sponge function to absorb.
67
- * @param spongeInstance Pointer to the sponge instance initialized by Keccak_SpongeInitialize().
68
- * @param data Pointer to the input data.
69
- * @param dataByteLen The number of input bytes provided in the input data.
70
- * @pre The sponge function must be in the absorbing phase,
71
- * i.e., Keccak_SpongeSqueeze() or Keccak_SpongeAbsorbLastFewBits()
72
- * must not have been called before.
73
- * @return Zero if successful, 1 otherwise.
74
- */
75
- int Keccak_SpongeAbsorb(Keccak_SpongeInstance *spongeInstance, const unsigned char *data, size_t dataByteLen);
76
-
77
- /**
78
- * Function to give input data bits for the sponge function to absorb
79
- * and then to switch to the squeezing phase.
80
- * @param spongeInstance Pointer to the sponge instance initialized by Keccak_SpongeInitialize().
81
- * @param delimitedData Byte containing from 0 to 7 trailing bits
82
- * that must be absorbed.
83
- * These <i>n</i> bits must be in the least significant bit positions.
84
- * These bits must be delimited with a bit 1 at position <i>n</i>
85
- * (counting from 0=LSB to 7=MSB) and followed by bits 0
86
- * from position <i>n</i>+1 to position 7.
87
- * Some examples:
88
- * - If no bits are to be absorbed, then @a delimitedData must be 0x01.
89
- * - If the 2-bit sequence 0,0 is to be absorbed, @a delimitedData must be 0x04.
90
- * - If the 5-bit sequence 0,1,0,0,1 is to be absorbed, @a delimitedData must be 0x32.
91
- * - If the 7-bit sequence 1,1,0,1,0,0,0 is to be absorbed, @a delimitedData must be 0x8B.
92
- * .
93
- * @pre The sponge function must be in the absorbing phase,
94
- * i.e., Keccak_SpongeSqueeze() or Keccak_SpongeAbsorbLastFewBits()
95
- * must not have been called before.
96
- * @pre @a delimitedData ≠ 0x00
97
- * @return Zero if successful, 1 otherwise.
98
- */
99
- int Keccak_SpongeAbsorbLastFewBits(Keccak_SpongeInstance *spongeInstance, unsigned char delimitedData);
100
-
101
- /**
102
- * Function to squeeze output data from the sponge function.
103
- * If the sponge function was in the absorbing phase, this function
104
- * switches it to the squeezing phase
105
- * as if Keccak_SpongeAbsorbLastFewBits(spongeInstance, 0x01) was called.
106
- * @param spongeInstance Pointer to the sponge instance initialized by Keccak_SpongeInitialize().
107
- * @param data Pointer to the buffer where to store the output data.
108
- * @param dataByteLen The number of output bytes desired.
109
- * @return Zero if successful, 1 otherwise.
110
- */
111
- int Keccak_SpongeSqueeze(Keccak_SpongeInstance *spongeInstance, unsigned char *data, size_t dataByteLen);
112
-
113
- #endif