Skip to content

Commit 8ef91b6

Browse files
authored
fixed bug in padding for shake, addes testcases for full code coverage (#95)
1 parent 88e1c83 commit 8ef91b6

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

src/shake.jl

+1-4
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ function digest!(context::T,d::UInt,p::Ptr{UInt8}) where {T<:SHAKE}
8282
context.buffer[end] = 0x80
8383
else
8484
# Otherwise, we have to add on a whole new buffer
85-
context.buffer[end] = 0x1f
86-
transform!(context)
87-
context.buffer[1:end-1] .= 0x0
88-
context.buffer[end] = 0x80
85+
context.buffer[end] = 0x9f
8986
end
9087
# Final transform:
9188
transform!(context)

test/runtests.jl

+2
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,15 @@ end
164164
@test SHA.shake128(hex2bytes(k[1]),k[2]) == hex2bytes(v)
165165
end
166166
@test SHA.shake128(b"",UInt(16)) == hex2bytes("7f9c2ba4e88f827d616045507605853e")
167+
@test SHA.shake128(codeunits("0" ^ 167), UInt(32)) == hex2bytes("ff60b0516fb8a3d4032900976e98b5595f57e9d4a88a0e37f7cc5adfa3c47da2")
167168
end
168169

169170
@testset "shake256" begin
170171
for (k,v) in SHA256test
171172
@test SHA.shake256(hex2bytes(k[1]),k[2]) == hex2bytes(v)
172173
end
173174
@test SHA.shake256(b"",UInt(32)) == hex2bytes("46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f")
175+
@test SHA.shake256(codeunits("0"^135),UInt(32)) == hex2bytes("ab11f61b5085a108a58670a66738ea7a8d8ce23b7c57d64de83eaafb10923cf8")
174176
end
175177
@time SHA.shake256(b"abc",UInt(100000))
176178
@time SHA.shake128(b"abc",UInt(100000))

0 commit comments

Comments
 (0)