-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/crypto/sha3: bytepad function is not safe #69169
Comments
Related Issues and Documentation (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
CC @golang/security |
@paocalvi's analysis seems right to me. Here's a reproducer for cSHAKE-128: s := []byte(strings.Repeat("x", 168-7))
fmt.Printf("S=%s\n", s)
cs := sha3.NewCShake128(nil, s)
h := cs.Sum(nil)
fmt.Printf("%x\n", h)
// Output: 430d3ebae1528304465f3b6f2ed34a7b931af804afe97d0e2a2796abf5725281
// Expected output: 2cf20c4b26c9ee7751eaa273368e616c868e7275178634e1ecdbac80d4cab5f4 https://go.dev/play/p/RQRAsLybuBg The 161-byte customization string ensures that the length of the bytepadded initial block will have a length equal to cSHAKE-128's rate (168 bytes). Expected output taken from this random js implementation. Someone should probably verify it against the reference implementation, though. |
Very unfortunate that neither our tests nor Wycheproof caught this. |
Change https://go.dev/cl/616576 mentions this issue: |
Go version
1.23 (all)
Output of
go env
in your module/workspace:What did you do?
Static analysis of the x/crypto/sha3/shake.go function
What did you see happen?
The code
and in particular
is not working properly when len(buf) % w == 0, causing an undesired padding.
The function appear to work only if the length of the input + length of the letfencoding is not a multiple of w already.
What did you expect to see?
leftEncode([]uint8("12345678"),10) // leftencode should be 2 bytelong that summed with 8 is 10
shoud return a 10 bytes result, not a 20 bytes result.
The text was updated successfully, but these errors were encountered: