sha3 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.md +8 -5
  4. data/certs/johanns.pem +23 -22
  5. data/ext/sha3/config.h +26 -0
  6. data/ext/sha3/digest.c +6 -6
  7. data/ext/sha3/extconf.rb +40 -10
  8. data/ext/sha3/lib/common/align.h +33 -0
  9. data/ext/sha3/{brg_endian.h → lib/common/brg_endian.h} +8 -7
  10. data/ext/sha3/{KeccakHash.c → lib/high/Keccak/FIPS202/KeccakHash.c} +26 -25
  11. data/ext/sha3/{KeccakHash.h → lib/high/Keccak/FIPS202/KeccakHash.h} +34 -19
  12. data/ext/sha3/lib/high/Keccak/KeccakSponge.c +111 -0
  13. data/ext/sha3/lib/high/Keccak/KeccakSponge.h +76 -0
  14. data/ext/sha3/lib/high/Keccak/KeccakSponge.inc +316 -0
  15. data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros +748 -0
  16. data/ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-unrolling.macros +305 -0
  17. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h +44 -0
  18. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference.h +23 -0
  19. data/ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c +625 -0
  20. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h +44 -0
  21. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c +444 -0
  22. data/ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.h +23 -0
  23. data/lib/sha3/version.rb +1 -1
  24. data/sha3.gemspec +6 -5
  25. data/tests.sh +8 -7
  26. data.tar.gz.sig +0 -0
  27. metadata +50 -66
  28. metadata.gz.sig +0 -0
  29. data/ext/sha3/KeccakF-1600-interface.h +0 -40
  30. data/ext/sha3/KeccakSponge.c +0 -192
  31. data/ext/sha3/KeccakSponge.h +0 -113
  32. data/ext/sha3/Optimized64/KeccakF-1600-64.macros +0 -2199
  33. data/ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h +0 -3
  34. data/ext/sha3/Optimized64/KeccakF-1600-opt64.c +0 -508
  35. data/ext/sha3/Optimized64/KeccakF-1600-unrolling.macros +0 -126
  36. data/ext/sha3/Optimized64/SnP-interface.h +0 -47
  37. data/ext/sha3/Reference/KeccakF-1600-reference.c +0 -311
  38. data/ext/sha3/Reference/KeccakF-reference.h +0 -26
  39. data/ext/sha3/Reference/SnP-FBWL-default.c +0 -96
  40. data/ext/sha3/Reference/SnP-FBWL-default.h +0 -26
  41. data/ext/sha3/Reference/SnP-interface.h +0 -42
  42. data/ext/sha3/Reference/displayIntermediateValues.c +0 -158
  43. data/ext/sha3/Reference/displayIntermediateValues.h +0 -34
  44. data/ext/sha3/SnP-Relaned.h +0 -249
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sha3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johanns Gregorian
@@ -10,45 +10,32 @@ bindir: exe
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIEFDCCAnygAwIBAgIBATANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDDA9pby9E
14
- Qz1qc2cvREM9aW8wHhcNMjIwMzA5MDcyODEwWhcNMjMwMzA5MDcyODEwWjAaMRgw
15
- FgYDVQQDDA9pby9EQz1qc2cvREM9aW8wggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAw
16
- ggGKAoIBgQCuPwkDs4uoBV6pQhKp3uA58LkDPRR7VoI4QryuH7PbIwuO3xbuyR6T
17
- xEqwcb9GgVnMxiFyXeVkWiriuGXqZ26Pp5zH/xxQNgPGCIyXuX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LmlvMBQGA1UdEgQNMAuBCWlvQGpzZy5pbzANBgkqhkiG9w0BAQsFAAOCAYEA
28
+ TexWHx3uLVObT+ylm3OE8Iue3cHdrDVE3zSjo8VlU3u1WBznH9MdoiPB7wux61Zx
29
+ jXUzBUaT7y7JnDaVGnECkpHXhfvPOYHBgkqEws6i79lAk/Va2U7EVPj0moM9d4Hv
30
+ 12V8YVM1Z9QnfwBVo7YGb5o7W8lr01jj1gT+Qcw+kln7M3Y9RB+jQ4DwySHVIEMc
31
+ Ow7//MF7bhCz6T5uAOXlGe88wTHKW+fO1AmW5MIQZUojR5Ioxm80v2YdW/JnQZ1l
32
+ 3VFpCutilnhDuzSw3DhgxReX7AK42aXFFclIzi11twW4KUPdt1KIvaoL/DgbZivl
33
+ PVG86dx4gfax2Mc2PiM+d1DiSllh+chh4dqRkIyhj0S4V7McQHkwW1ZBJ3kDf5rt
34
+ 1O/udKquzj7egb6uceqzBB40W/1/CsNkGNpNZ8Bk8lrTmKw+3bJpj+nKWxovmF2p
35
+ VhzZDQf2jkcjBXKNA9Z5ku7g0TCR1/Y1V3ODgkTLqhw+kQZmlbQEVzcwxGk9eL8z
35
36
  -----END CERTIFICATE-----
36
- date: 2022-03-09 00:00:00.000000000 Z
37
+ date: 2022-10-24 00:00:00.000000000 Z
37
38
  dependencies:
38
- - !ruby/object:Gem::Dependency
39
- name: bundler
40
- requirement: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - "~>"
43
- - !ruby/object:Gem::Version
44
- version: '2.3'
45
- type: :development
46
- prerelease: false
47
- version_requirements: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - "~>"
50
- - !ruby/object:Gem::Version
51
- version: '2.3'
52
39
  - !ruby/object:Gem::Dependency
53
40
  name: rake
54
41
  requirement: !ruby/object:Gem::Requirement
@@ -69,14 +56,14 @@ dependencies:
69
56
  requirements:
70
57
  - - "~>"
71
58
  - !ruby/object:Gem::Version
72
- version: '1.1'
59
+ version: '1.2'
73
60
  type: :development
74
61
  prerelease: false
75
62
  version_requirements: !ruby/object:Gem::Requirement
76
63
  requirements:
77
64
  - - "~>"
78
65
  - !ruby/object:Gem::Version
79
- version: '1.1'
66
+ version: '1.2'
80
67
  - !ruby/object:Gem::Dependency
81
68
  name: rspec
82
69
  requirement: !ruby/object:Gem::Requirement
@@ -97,14 +84,14 @@ dependencies:
97
84
  requirements:
98
85
  - - "~>"
99
86
  - !ruby/object:Gem::Version
100
- version: '1.25'
87
+ version: '1.37'
101
88
  type: :development
102
89
  prerelease: false
103
90
  version_requirements: !ruby/object:Gem::Requirement
104
91
  requirements:
105
92
  - - "~>"
106
93
  - !ruby/object:Gem::Version
107
- version: '1.25'
94
+ version: '1.37'
108
95
  - !ruby/object:Gem::Dependency
109
96
  name: rubocop-rake
110
97
  requirement: !ruby/object:Gem::Requirement
@@ -125,16 +112,16 @@ dependencies:
125
112
  requirements:
126
113
  - - "~>"
127
114
  - !ruby/object:Gem::Version
128
- version: '2.9'
115
+ version: '2.14'
129
116
  type: :development
130
117
  prerelease: false
131
118
  version_requirements: !ruby/object:Gem::Requirement
132
119
  requirements:
133
120
  - - "~>"
134
121
  - !ruby/object:Gem::Version
135
- version: '2.9'
136
- description: SHA3 for Ruby is a native (C) FIPS 202 compliant implementation of SHA3
137
- (Keccak) cryptographic hashing algorithm.
122
+ version: '2.14'
123
+ description: A XKCP based native (C) binding to SHA3 (FIPS 202) cryptographic hashing
124
+ algorithm.
138
125
  email:
139
126
  - io+sha3@jsg.io
140
127
  executables: []
@@ -152,28 +139,25 @@ files:
152
139
  - README.md
153
140
  - Rakefile
154
141
  - certs/johanns.pem
155
- - ext/sha3/KeccakF-1600-interface.h
156
- - ext/sha3/KeccakHash.c
157
- - ext/sha3/KeccakHash.h
158
- - ext/sha3/KeccakSponge.c
159
- - ext/sha3/KeccakSponge.h
160
- - ext/sha3/Optimized64/KeccakF-1600-64.macros
161
- - ext/sha3/Optimized64/KeccakF-1600-opt64-settings.h
162
- - ext/sha3/Optimized64/KeccakF-1600-opt64.c
163
- - ext/sha3/Optimized64/KeccakF-1600-unrolling.macros
164
- - ext/sha3/Optimized64/SnP-interface.h
165
- - ext/sha3/Reference/KeccakF-1600-reference.c
166
- - ext/sha3/Reference/KeccakF-reference.h
167
- - ext/sha3/Reference/SnP-FBWL-default.c
168
- - ext/sha3/Reference/SnP-FBWL-default.h
169
- - ext/sha3/Reference/SnP-interface.h
170
- - ext/sha3/Reference/displayIntermediateValues.c
171
- - ext/sha3/Reference/displayIntermediateValues.h
172
- - ext/sha3/SnP-Relaned.h
173
- - ext/sha3/brg_endian.h
142
+ - ext/sha3/config.h
174
143
  - ext/sha3/digest.c
175
144
  - ext/sha3/digest.h
176
145
  - ext/sha3/extconf.rb
146
+ - ext/sha3/lib/common/align.h
147
+ - ext/sha3/lib/common/brg_endian.h
148
+ - ext/sha3/lib/high/Keccak/FIPS202/KeccakHash.c
149
+ - ext/sha3/lib/high/Keccak/FIPS202/KeccakHash.h
150
+ - ext/sha3/lib/high/Keccak/KeccakSponge.c
151
+ - ext/sha3/lib/high/Keccak/KeccakSponge.h
152
+ - ext/sha3/lib/high/Keccak/KeccakSponge.inc
153
+ - ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-64.macros
154
+ - ext/sha3/lib/low/KeccakP-1600/common/KeccakP-1600-unrolling.macros
155
+ - ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-SnP.h
156
+ - ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference.h
157
+ - ext/sha3/lib/low/KeccakP-1600/ref-32bits/KeccakP-1600-reference32BI.c
158
+ - ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-SnP.h
159
+ - ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.c
160
+ - ext/sha3/lib/low/KeccakP-1600/ref-64bits/KeccakP-1600-reference.h
177
161
  - ext/sha3/sha3.c
178
162
  - ext/sha3/sha3.h
179
163
  - lib/sha3.rb
@@ -204,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
188
  - !ruby/object:Gem::Version
205
189
  version: '0'
206
190
  requirements: []
207
- rubygems_version: 3.2.32
191
+ rubygems_version: 3.3.7
208
192
  signing_key:
209
193
  specification_version: 4
210
194
  summary: SHA3 (FIPS 202) cryptographic hashing algorithm
metadata.gz.sig CHANGED
Binary file
@@ -1,40 +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 _KeccakF1600Interface_h_
17
- #define _KeccakF1600Interface_h_
18
-
19
- #include <string.h>
20
-
21
- #define KeccakF_width 1600
22
- #define KeccakF_laneInBytes 8
23
- #define KeccakF_stateSizeInBytes (KeccakF_width/8)
24
- #define KeccakF_1600
25
-
26
- void KeccakF1600_Initialize( void );
27
- void KeccakF1600_StateInitialize(void *state);
28
- void KeccakF1600_StateXORBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length);
29
- void KeccakF1600_StateOverwriteBytes(void *state, const unsigned char *data, unsigned int offset, unsigned int length);
30
- void KeccakF1600_StateOverwriteWithZeroes(void *state, unsigned int byteCount);
31
- void KeccakF1600_StateComplementBit(void *state, unsigned int position);
32
- void KeccakF1600_StatePermute(void *state);
33
- void KeccakF1600_StateExtractBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length);
34
- void KeccakF1600_StateExtractAndXORBytes(const void *state, unsigned char *data, unsigned int offset, unsigned int length);
35
- size_t KeccakF1600_FBWL_Absorb(void *state, unsigned int laneCount, const unsigned char *data, size_t dataByteLen, unsigned char trailingBits);
36
- size_t KeccakF1600_FBWL_Squeeze(void *state, unsigned int laneCount, unsigned char *data, size_t dataByteLen);
37
- size_t KeccakF1600_FBWL_Wrap(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits);
38
- size_t KeccakF1600_FBWL_Unwrap(void *state, unsigned int laneCount, const unsigned char *dataIn, unsigned char *dataOut, size_t dataByteLen, unsigned char trailingBits);
39
-
40
- #endif
@@ -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