Skip to content

Commit

Permalink
fixed bug in padding for shake, addes testcases for full code coverage (
Browse files Browse the repository at this point in the history
  • Loading branch information
immoschuett authored Nov 20, 2023
1 parent 88e1c83 commit 8ef91b6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/shake.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ function digest!(context::T,d::UInt,p::Ptr{UInt8}) where {T<:SHAKE}
context.buffer[end] = 0x80
else
# Otherwise, we have to add on a whole new buffer
context.buffer[end] = 0x1f
transform!(context)
context.buffer[1:end-1] .= 0x0
context.buffer[end] = 0x80
context.buffer[end] = 0x9f
end
# Final transform:
transform!(context)
Expand Down
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ end
@test SHA.shake128(hex2bytes(k[1]),k[2]) == hex2bytes(v)
end
@test SHA.shake128(b"",UInt(16)) == hex2bytes("7f9c2ba4e88f827d616045507605853e")
@test SHA.shake128(codeunits("0" ^ 167), UInt(32)) == hex2bytes("ff60b0516fb8a3d4032900976e98b5595f57e9d4a88a0e37f7cc5adfa3c47da2")
end

@testset "shake256" begin
for (k,v) in SHA256test
@test SHA.shake256(hex2bytes(k[1]),k[2]) == hex2bytes(v)
end
@test SHA.shake256(b"",UInt(32)) == hex2bytes("46b9dd2b0ba88d13233b3feb743eeb243fcd52ea62b81b82b50c27646ed5762f")
@test SHA.shake256(codeunits("0"^135),UInt(32)) == hex2bytes("ab11f61b5085a108a58670a66738ea7a8d8ce23b7c57d64de83eaafb10923cf8")
end
@time SHA.shake256(b"abc",UInt(100000))
@time SHA.shake128(b"abc",UInt(100000))
Expand Down

0 comments on commit 8ef91b6

Please sign in to comment.