digest-kangarootwelve 0.0.1

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.
@@ -0,0 +1,56 @@
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 "KeccakSpongeWidth1600.h"
17
+
18
+ #ifdef KeccakReference
19
+ #include "displayIntermediateValues.h"
20
+ #endif
21
+
22
+ #ifndef KeccakP1600_excluded
23
+ #include "KeccakP-1600-SnP.h"
24
+
25
+ #define prefix KeccakWidth1600
26
+ #define SnP KeccakP1600
27
+ #define SnP_width 1600
28
+ #define SnP_Permute KeccakP1600_Permute_24rounds
29
+ #if defined(KeccakF1600_FastLoop_supported)
30
+ #define SnP_FastLoop_Absorb KeccakF1600_FastLoop_Absorb
31
+ #endif
32
+ #include "KeccakSponge.inc"
33
+ #undef prefix
34
+ #undef SnP
35
+ #undef SnP_width
36
+ #undef SnP_Permute
37
+ #undef SnP_FastLoop_Absorb
38
+ #endif
39
+
40
+ #ifndef KeccakP1600_excluded
41
+ #include "KeccakP-1600-SnP.h"
42
+
43
+ #define prefix KeccakWidth1600_12rounds
44
+ #define SnP KeccakP1600
45
+ #define SnP_width 1600
46
+ #define SnP_Permute KeccakP1600_Permute_12rounds
47
+ #if defined(KeccakP1600_12rounds_FastLoop_supported)
48
+ #define SnP_FastLoop_Absorb KeccakP1600_12rounds_FastLoop_Absorb
49
+ #endif
50
+ #include "KeccakSponge.inc"
51
+ #undef prefix
52
+ #undef SnP
53
+ #undef SnP_width
54
+ #undef SnP_Permute
55
+ #undef SnP_FastLoop_Absorb
56
+ #endif
@@ -0,0 +1,33 @@
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 _KeccakSpongeWidth1600_h_
17
+ #define _KeccakSpongeWidth1600_h_
18
+
19
+ #include "KeccakSponge-common.h"
20
+
21
+ #ifndef KeccakP1600_excluded
22
+ #include "KeccakP-1600-SnP.h"
23
+ KCP_DeclareSpongeStructure(KeccakWidth1600, KeccakP1600_stateSizeInBytes, KeccakP1600_stateAlignment)
24
+ KCP_DeclareSpongeFunctions(KeccakWidth1600)
25
+ #endif
26
+
27
+ #ifndef KeccakP1600_excluded
28
+ #include "KeccakP-1600-SnP.h"
29
+ KCP_DeclareSpongeStructure(KeccakWidth1600_12rounds, KeccakP1600_stateSizeInBytes, KeccakP1600_stateAlignment)
30
+ KCP_DeclareSpongeFunctions(KeccakWidth1600_12rounds)
31
+ #endif
32
+
33
+ #endif
@@ -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 _Phases_h_
17
+ #define _Phases_h_
18
+
19
+ typedef enum {
20
+ NOT_INITIALIZED,
21
+ ABSORBING,
22
+ FINAL,
23
+ SQUEEZING
24
+ } KCP_Phases;
25
+
26
+ #endif
@@ -0,0 +1,283 @@
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
+ /* expect PlSnP_baseParallelism, PlSnP_targetParallelism */
17
+ /* expect SnP_stateSizeInBytes, SnP_stateAlignment */
18
+ /* expect prefix */
19
+ /* expect SnP_* */
20
+
21
+ #define JOIN0(a, b) a ## b
22
+ #define JOIN(a, b) JOIN0(a, b)
23
+
24
+ #define PlSnP_StaticInitialize JOIN(prefix, _StaticInitialize)
25
+ #define PlSnP_InitializeAll JOIN(prefix, _InitializeAll)
26
+ #define PlSnP_AddByte JOIN(prefix, _AddByte)
27
+ #define PlSnP_AddBytes JOIN(prefix, _AddBytes)
28
+ #define PlSnP_AddLanesAll JOIN(prefix, _AddLanesAll)
29
+ #define PlSnP_OverwriteBytes JOIN(prefix, _OverwriteBytes)
30
+ #define PlSnP_OverwriteLanesAll JOIN(prefix, _OverwriteLanesAll)
31
+ #define PlSnP_OverwriteWithZeroes JOIN(prefix, _OverwriteWithZeroes)
32
+ #define PlSnP_ExtractBytes JOIN(prefix, _ExtractBytes)
33
+ #define PlSnP_ExtractLanesAll JOIN(prefix, _ExtractLanesAll)
34
+ #define PlSnP_ExtractAndAddBytes JOIN(prefix, _ExtractAndAddBytes)
35
+ #define PlSnP_ExtractAndAddLanesAll JOIN(prefix, _ExtractAndAddLanesAll)
36
+
37
+ #if (PlSnP_baseParallelism == 1)
38
+ #define SnP_stateSizeInBytes JOIN(SnP, _stateSizeInBytes)
39
+ #define SnP_stateAlignment JOIN(SnP, _stateAlignment)
40
+ #else
41
+ #define SnP_stateSizeInBytes JOIN(SnP, _statesSizeInBytes)
42
+ #define SnP_stateAlignment JOIN(SnP, _statesAlignment)
43
+ #endif
44
+ #define PlSnP_factor ((PlSnP_targetParallelism)/(PlSnP_baseParallelism))
45
+ #define SnP_stateOffset (((SnP_stateSizeInBytes+(SnP_stateAlignment-1))/SnP_stateAlignment)*SnP_stateAlignment)
46
+ #define stateWithIndex(i) ((unsigned char *)states+((i)*SnP_stateOffset))
47
+
48
+ #define SnP_StaticInitialize JOIN(SnP, _StaticInitialize)
49
+ #define SnP_Initialize JOIN(SnP, _Initialize)
50
+ #define SnP_InitializeAll JOIN(SnP, _InitializeAll)
51
+ #define SnP_AddByte JOIN(SnP, _AddByte)
52
+ #define SnP_AddBytes JOIN(SnP, _AddBytes)
53
+ #define SnP_AddLanesAll JOIN(SnP, _AddLanesAll)
54
+ #define SnP_OverwriteBytes JOIN(SnP, _OverwriteBytes)
55
+ #define SnP_OverwriteLanesAll JOIN(SnP, _OverwriteLanesAll)
56
+ #define SnP_OverwriteWithZeroes JOIN(SnP, _OverwriteWithZeroes)
57
+ #define SnP_ExtractBytes JOIN(SnP, _ExtractBytes)
58
+ #define SnP_ExtractLanesAll JOIN(SnP, _ExtractLanesAll)
59
+ #define SnP_ExtractAndAddBytes JOIN(SnP, _ExtractAndAddBytes)
60
+ #define SnP_ExtractAndAddLanesAll JOIN(SnP, _ExtractAndAddLanesAll)
61
+
62
+ void PlSnP_StaticInitialize( void )
63
+ {
64
+ SnP_StaticInitialize();
65
+ }
66
+
67
+ void PlSnP_InitializeAll(void *states)
68
+ {
69
+ unsigned int i;
70
+
71
+ for(i=0; i<PlSnP_factor; i++)
72
+ #if (PlSnP_baseParallelism == 1)
73
+ SnP_Initialize(stateWithIndex(i));
74
+ #else
75
+ SnP_InitializeAll(stateWithIndex(i));
76
+ #endif
77
+ }
78
+
79
+ void PlSnP_AddByte(void *states, unsigned int instanceIndex, unsigned char byte, unsigned int offset)
80
+ {
81
+ #if (PlSnP_baseParallelism == 1)
82
+ SnP_AddByte(stateWithIndex(instanceIndex), byte, offset);
83
+ #else
84
+ SnP_AddByte(stateWithIndex(instanceIndex/PlSnP_baseParallelism), instanceIndex%PlSnP_baseParallelism, byte, offset);
85
+ #endif
86
+ }
87
+
88
+ void PlSnP_AddBytes(void *states, unsigned int instanceIndex, const unsigned char *data, unsigned int offset, unsigned int length)
89
+ {
90
+ #if (PlSnP_baseParallelism == 1)
91
+ SnP_AddBytes(stateWithIndex(instanceIndex), data, offset, length);
92
+ #else
93
+ SnP_AddBytes(stateWithIndex(instanceIndex/PlSnP_baseParallelism), instanceIndex%PlSnP_baseParallelism, data, offset, length);
94
+ #endif
95
+ }
96
+
97
+ void PlSnP_AddLanesAll(void *states, const unsigned char *data, unsigned int laneCount, unsigned int laneOffset)
98
+ {
99
+ unsigned int i;
100
+
101
+ for(i=0; i<PlSnP_factor; i++) {
102
+ #if (PlSnP_baseParallelism == 1)
103
+ SnP_AddBytes(stateWithIndex(i), data, 0, laneCount*SnP_laneLengthInBytes);
104
+ #else
105
+ SnP_AddLanesAll(stateWithIndex(i), data, laneCount, laneOffset);
106
+ #endif
107
+ data += PlSnP_baseParallelism*laneOffset*SnP_laneLengthInBytes;
108
+ }
109
+ }
110
+
111
+ void PlSnP_OverwriteBytes(void *states, unsigned int instanceIndex, const unsigned char *data, unsigned int offset, unsigned int length)
112
+ {
113
+ #if (PlSnP_baseParallelism == 1)
114
+ SnP_OverwriteBytes(stateWithIndex(instanceIndex), data, offset, length);
115
+ #else
116
+ SnP_OverwriteBytes(stateWithIndex(instanceIndex/PlSnP_baseParallelism), instanceIndex%PlSnP_baseParallelism, data, offset, length);
117
+ #endif
118
+ }
119
+
120
+ void PlSnP_OverwriteLanesAll(void *states, const unsigned char *data, unsigned int laneCount, unsigned int laneOffset)
121
+ {
122
+ unsigned int i;
123
+
124
+ for(i=0; i<PlSnP_factor; i++) {
125
+ #if (PlSnP_baseParallelism == 1)
126
+ SnP_OverwriteBytes(stateWithIndex(i), data, 0, laneCount*SnP_laneLengthInBytes);
127
+ #else
128
+ SnP_OverwriteLanesAll(stateWithIndex(i), data, laneCount, laneOffset);
129
+ #endif
130
+ data += PlSnP_baseParallelism*laneOffset*SnP_laneLengthInBytes;
131
+ }
132
+ }
133
+
134
+ void PlSnP_OverwriteWithZeroes(void *states, unsigned int instanceIndex, unsigned int byteCount)
135
+ {
136
+ #if (PlSnP_baseParallelism == 1)
137
+ SnP_OverwriteWithZeroes(stateWithIndex(instanceIndex), byteCount);
138
+ #else
139
+ SnP_OverwriteWithZeroes(stateWithIndex(instanceIndex/PlSnP_baseParallelism), instanceIndex%PlSnP_baseParallelism, byteCount);
140
+ #endif
141
+ }
142
+
143
+ void PlSnP_PermuteAll(void *states)
144
+ {
145
+ unsigned int i;
146
+
147
+ for(i=0; i<PlSnP_factor; i++) {
148
+ #if (PlSnP_baseParallelism == 1)
149
+ SnP_Permute(stateWithIndex(i));
150
+ #else
151
+ SnP_PermuteAll(stateWithIndex(i));
152
+ #endif
153
+ }
154
+ }
155
+
156
+ #if (defined(SnP_Permute_12rounds) || defined(SnP_PermuteAll_12rounds))
157
+ void PlSnP_PermuteAll_12rounds(void *states)
158
+ {
159
+ unsigned int i;
160
+
161
+ for(i=0; i<PlSnP_factor; i++) {
162
+ #if (PlSnP_baseParallelism == 1)
163
+ SnP_Permute_12rounds(stateWithIndex(i));
164
+ #else
165
+ SnP_PermuteAll_12rounds(stateWithIndex(i));
166
+ #endif
167
+ }
168
+ }
169
+ #endif
170
+
171
+ #if (defined(SnP_Permute_Nrounds) || defined(SnP_PermuteAll_6rounds))
172
+ void PlSnP_PermuteAll_6rounds(void *states)
173
+ {
174
+ unsigned int i;
175
+
176
+ for(i=0; i<PlSnP_factor; i++) {
177
+ #if (PlSnP_baseParallelism == 1)
178
+ SnP_Permute_Nrounds(stateWithIndex(i), 6);
179
+ #else
180
+ SnP_PermuteAll_6rounds(stateWithIndex(i));
181
+ #endif
182
+ }
183
+ }
184
+ #endif
185
+
186
+ #if (defined(SnP_Permute_Nrounds) || defined(SnP_PermuteAll_4rounds))
187
+ void PlSnP_PermuteAll_4rounds(void *states)
188
+ {
189
+ unsigned int i;
190
+
191
+ for(i=0; i<PlSnP_factor; i++) {
192
+ #if (PlSnP_baseParallelism == 1)
193
+ SnP_Permute_Nrounds(stateWithIndex(i), 4);
194
+ #else
195
+ SnP_PermuteAll_4rounds(stateWithIndex(i));
196
+ #endif
197
+ }
198
+ }
199
+ #endif
200
+
201
+ void PlSnP_ExtractBytes(void *states, unsigned int instanceIndex, unsigned char *data, unsigned int offset, unsigned int length)
202
+ {
203
+ #if (PlSnP_baseParallelism == 1)
204
+ SnP_ExtractBytes(stateWithIndex(instanceIndex), data, offset, length);
205
+ #else
206
+ SnP_ExtractBytes(stateWithIndex(instanceIndex/PlSnP_baseParallelism), instanceIndex%PlSnP_baseParallelism, data, offset, length);
207
+ #endif
208
+ }
209
+
210
+ void PlSnP_ExtractLanesAll(const void *states, unsigned char *data, unsigned int laneCount, unsigned int laneOffset)
211
+ {
212
+ unsigned int i;
213
+
214
+ for(i=0; i<PlSnP_factor; i++) {
215
+ #if (PlSnP_baseParallelism == 1)
216
+ SnP_ExtractBytes(stateWithIndex(i), data, 0, laneCount*SnP_laneLengthInBytes);
217
+ #else
218
+ SnP_ExtractLanesAll(stateWithIndex(i), data, laneCount, laneOffset);
219
+ #endif
220
+ data += laneOffset*SnP_laneLengthInBytes*PlSnP_baseParallelism;
221
+ }
222
+ }
223
+
224
+ void PlSnP_ExtractAndAddBytes(void *states, unsigned int instanceIndex, const unsigned char *input, unsigned char *output, unsigned int offset, unsigned int length)
225
+ {
226
+ #if (PlSnP_baseParallelism == 1)
227
+ SnP_ExtractAndAddBytes(stateWithIndex(instanceIndex), input, output, offset, length);
228
+ #else
229
+ SnP_ExtractAndAddBytes(stateWithIndex(instanceIndex/PlSnP_baseParallelism), instanceIndex%PlSnP_baseParallelism, input, output, offset, length);
230
+ #endif
231
+ }
232
+
233
+ void PlSnP_ExtractAndAddLanesAll(const void *states, const unsigned char *input, unsigned char *output, unsigned int laneCount, unsigned int laneOffset)
234
+ {
235
+ unsigned int i;
236
+
237
+ for(i=0; i<PlSnP_factor; i++) {
238
+ #if (PlSnP_baseParallelism == 1)
239
+ SnP_ExtractAndAddBytes(stateWithIndex(i), input, output, 0, laneCount*SnP_laneLengthInBytes);
240
+ #else
241
+ SnP_ExtractAndAddLanesAll(stateWithIndex(i), input, output, laneCount, laneOffset);
242
+ #endif
243
+ input += laneOffset*SnP_laneLengthInBytes*PlSnP_baseParallelism;
244
+ output += laneOffset*SnP_laneLengthInBytes*PlSnP_baseParallelism;
245
+ }
246
+ }
247
+
248
+ #undef PlSnP_factor
249
+ #undef SnP_stateOffset
250
+ #undef stateWithIndex
251
+ #undef JOIN0
252
+ #undef JOIN
253
+ #undef PlSnP_StaticInitialize
254
+ #undef PlSnP_InitializeAll
255
+ #undef PlSnP_AddByte
256
+ #undef PlSnP_AddBytes
257
+ #undef PlSnP_AddLanesAll
258
+ #undef PlSnP_OverwriteBytes
259
+ #undef PlSnP_OverwriteLanesAll
260
+ #undef PlSnP_OverwriteWithZeroes
261
+ #undef PlSnP_PermuteAll
262
+ #undef PlSnP_ExtractBytes
263
+ #undef PlSnP_ExtractLanesAll
264
+ #undef PlSnP_ExtractAndAddBytes
265
+ #undef PlSnP_ExtractAndAddLanesAll
266
+ #undef SnP_stateAlignment
267
+ #undef SnP_stateSizeInBytes
268
+ #undef PlSnP_factor
269
+ #undef SnP_stateOffset
270
+ #undef stateWithIndex
271
+ #undef SnP_StaticInitialize
272
+ #undef SnP_Initialize
273
+ #undef SnP_InitializeAll
274
+ #undef SnP_AddByte
275
+ #undef SnP_AddBytes
276
+ #undef SnP_AddLanesAll
277
+ #undef SnP_OverwriteBytes
278
+ #undef SnP_OverwriteWithZeroes
279
+ #undef SnP_OverwriteLanesAll
280
+ #undef SnP_ExtractBytes
281
+ #undef SnP_ExtractLanesAll
282
+ #undef SnP_ExtractAndAddBytes
283
+ #undef SnP_ExtractAndAddLanesAll
@@ -0,0 +1,134 @@
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
+ #define SnP_AddBytes(state, data, offset, length, SnP_AddLanes, SnP_AddBytesInLane, SnP_laneLengthInBytes) \
20
+ { \
21
+ if ((offset) == 0) { \
22
+ SnP_AddLanes(state, data, (length)/SnP_laneLengthInBytes); \
23
+ SnP_AddBytesInLane(state, \
24
+ (length)/SnP_laneLengthInBytes, \
25
+ (data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
26
+ 0, \
27
+ (length)%SnP_laneLengthInBytes); \
28
+ } \
29
+ else { \
30
+ unsigned int _sizeLeft = (length); \
31
+ unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
32
+ unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
33
+ const unsigned char *_curData = (data); \
34
+ while(_sizeLeft > 0) { \
35
+ unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
36
+ if (_bytesInLane > _sizeLeft) \
37
+ _bytesInLane = _sizeLeft; \
38
+ SnP_AddBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
39
+ _sizeLeft -= _bytesInLane; \
40
+ _lanePosition++; \
41
+ _offsetInLane = 0; \
42
+ _curData += _bytesInLane; \
43
+ } \
44
+ } \
45
+ }
46
+
47
+ #define SnP_OverwriteBytes(state, data, offset, length, SnP_OverwriteLanes, SnP_OverwriteBytesInLane, SnP_laneLengthInBytes) \
48
+ { \
49
+ if ((offset) == 0) { \
50
+ SnP_OverwriteLanes(state, data, (length)/SnP_laneLengthInBytes); \
51
+ SnP_OverwriteBytesInLane(state, \
52
+ (length)/SnP_laneLengthInBytes, \
53
+ (data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
54
+ 0, \
55
+ (length)%SnP_laneLengthInBytes); \
56
+ } \
57
+ else { \
58
+ unsigned int _sizeLeft = (length); \
59
+ unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
60
+ unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
61
+ const unsigned char *_curData = (data); \
62
+ while(_sizeLeft > 0) { \
63
+ unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
64
+ if (_bytesInLane > _sizeLeft) \
65
+ _bytesInLane = _sizeLeft; \
66
+ SnP_OverwriteBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
67
+ _sizeLeft -= _bytesInLane; \
68
+ _lanePosition++; \
69
+ _offsetInLane = 0; \
70
+ _curData += _bytesInLane; \
71
+ } \
72
+ } \
73
+ }
74
+
75
+ #define SnP_ExtractBytes(state, data, offset, length, SnP_ExtractLanes, SnP_ExtractBytesInLane, SnP_laneLengthInBytes) \
76
+ { \
77
+ if ((offset) == 0) { \
78
+ SnP_ExtractLanes(state, data, (length)/SnP_laneLengthInBytes); \
79
+ SnP_ExtractBytesInLane(state, \
80
+ (length)/SnP_laneLengthInBytes, \
81
+ (data)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
82
+ 0, \
83
+ (length)%SnP_laneLengthInBytes); \
84
+ } \
85
+ else { \
86
+ unsigned int _sizeLeft = (length); \
87
+ unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
88
+ unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
89
+ unsigned char *_curData = (data); \
90
+ while(_sizeLeft > 0) { \
91
+ unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
92
+ if (_bytesInLane > _sizeLeft) \
93
+ _bytesInLane = _sizeLeft; \
94
+ SnP_ExtractBytesInLane(state, _lanePosition, _curData, _offsetInLane, _bytesInLane); \
95
+ _sizeLeft -= _bytesInLane; \
96
+ _lanePosition++; \
97
+ _offsetInLane = 0; \
98
+ _curData += _bytesInLane; \
99
+ } \
100
+ } \
101
+ }
102
+
103
+ #define SnP_ExtractAndAddBytes(state, input, output, offset, length, SnP_ExtractAndAddLanes, SnP_ExtractAndAddBytesInLane, SnP_laneLengthInBytes) \
104
+ { \
105
+ if ((offset) == 0) { \
106
+ SnP_ExtractAndAddLanes(state, input, output, (length)/SnP_laneLengthInBytes); \
107
+ SnP_ExtractAndAddBytesInLane(state, \
108
+ (length)/SnP_laneLengthInBytes, \
109
+ (input)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
110
+ (output)+((length)/SnP_laneLengthInBytes)*SnP_laneLengthInBytes, \
111
+ 0, \
112
+ (length)%SnP_laneLengthInBytes); \
113
+ } \
114
+ else { \
115
+ unsigned int _sizeLeft = (length); \
116
+ unsigned int _lanePosition = (offset)/SnP_laneLengthInBytes; \
117
+ unsigned int _offsetInLane = (offset)%SnP_laneLengthInBytes; \
118
+ const unsigned char *_curInput = (input); \
119
+ unsigned char *_curOutput = (output); \
120
+ while(_sizeLeft > 0) { \
121
+ unsigned int _bytesInLane = SnP_laneLengthInBytes - _offsetInLane; \
122
+ if (_bytesInLane > _sizeLeft) \
123
+ _bytesInLane = _sizeLeft; \
124
+ SnP_ExtractAndAddBytesInLane(state, _lanePosition, _curInput, _curOutput, _offsetInLane, _bytesInLane); \
125
+ _sizeLeft -= _bytesInLane; \
126
+ _lanePosition++; \
127
+ _offsetInLane = 0; \
128
+ _curInput += _bytesInLane; \
129
+ _curOutput += _bytesInLane; \
130
+ } \
131
+ } \
132
+ }
133
+
134
+ #endif