@@ -170,16 +170,70 @@ end
170
170
@testset " shake128" begin
171
171
for (k,v) in SHA128test
172
172
@test SHA. shake128 (hex2bytes (k[1 ]),k[2 ]) == hex2bytes (v)
173
+ ctx = SHAKE_128_CTX ()
174
+ in = hex2bytes (k[1 ])
175
+ idx = 1
176
+ while idx <= length (in)
177
+ l = min (rand (1 : length (in)), length (in) - idx + 1 )
178
+ update! (ctx, in[idx: idx+ l- 1 ])
179
+ idx += l
180
+ end
181
+ out = Vector {UInt8} (undef, k[2 ])
182
+ idx = 0
183
+ while idx < k[2 ]
184
+ l = min (rand (1 : k[2 ]), k[2 ] - idx)
185
+ digest! (ctx, l, pointer (out) + idx)
186
+ idx += l
187
+ end
188
+ @test out == hex2bytes (v)
173
189
end
174
190
@test SHA. shake128 (b "" ,UInt (16 )) == hex2bytes (" 7f9c2ba4e88f827d616045507605853e" )
175
191
@test SHA. shake128 (codeunits (" 0" ^ 167 ), UInt (32 )) == hex2bytes (" ff60b0516fb8a3d4032900976e98b5595f57e9d4a88a0e37f7cc5adfa3c47da2" )
192
+
193
+ for chunksize in UInt[1 , 2 , 3 , 200 ]
194
+ ctx = SHAKE_128_CTX ()
195
+ out = Vector {UInt8} (undef, 10000 )
196
+ idx = 0
197
+ while idx < length (out)
198
+ digest! (ctx, chunksize, pointer (out) + idx)
199
+ idx += chunksize
200
+ end
201
+ @test out == SHA. shake128 (UInt8[], UInt (length (out)))
202
+ end
176
203
end
177
204
178
205
@testset " shake256" begin
179
206
for (k,v) in SHA256test
180
207
@test SHA. shake256 (hex2bytes (k[1 ]),k[2 ]) == hex2bytes (v)
208
+ ctx = SHAKE_256_CTX ()
209
+ in = hex2bytes (k[1 ])
210
+ idx = 1
211
+ while idx <= length (in)
212
+ l = min (rand (1 : length (in)), length (in) - idx + 1 )
213
+ update! (ctx, in[idx: idx+ l- 1 ])
214
+ idx += l
215
+ end
216
+ out = Vector {UInt8} (undef, k[2 ])
217
+ idx = 0
218
+ while idx < k[2 ]
219
+ l = min (rand (1 : k[2 ]), k[2 ] - idx)
220
+ digest! (ctx, l, pointer (out) + idx)
221
+ idx += l
222
+ end
223
+ @test out == hex2bytes (v)
181
224
end
182
225
@test SHA. shake256 (b "" ,UInt (32 )) == hex2bytes (" 46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f" )
183
226
@test SHA. shake256 (codeunits (" 0" ^ 135 ),UInt (32 )) == hex2bytes (" ab11f61b5085a108a58670a66738ea7a8d8ce23b7c57d64de83eaafb10923cf8" )
227
+
228
+ for chunksize in UInt[1 , 2 , 3 , 200 ]
229
+ ctx = SHAKE_256_CTX ()
230
+ out = Vector {UInt8} (undef, 10000 )
231
+ idx = 0
232
+ while idx < length (out)
233
+ digest! (ctx, chunksize, pointer (out) + idx)
234
+ idx += chunksize
235
+ end
236
+ @test out == SHA. shake256 (UInt8[], UInt (length (out)))
237
+ end
184
238
end
185
239
end
0 commit comments