-
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: cSHAKE initialization misbehaves for extremely (unrealistically) large N
or S
#66232
Comments
This can only happen if |
following “cSHAKE implementations is based on NIST SP 800-185 [2]” 3.3 Definition, I think we should check the length validity, len(N) and len(S) should less than 2040bit(255 byte). I make a pr for this~ |
Because the value is "length of N or S" in bits, 64 bit int can also overflow (though not on any current production silicon) with unfathomably large N or S, due to
Unfortunately that's not correct. The upper limit for all N and S is "2^2040-1 bits". |
I misunderstood. You were right. |
The max length of a Go slice is 2^48, so Lines 213 to 218 in 3a41bfa
Also, I think we can safely assume no machine has more than 2 exabyte of memory. If we agree it would fix the 32-bit platforms and that 64-bit platforms are unaffected, I would appreciate a CL to switch to |
Ah ok. I didn't know about the limit on slice sizes. TIL.
The fix sounds good to me. |
While both impractical and unlikely, the multiplication could overflow on 32-bit architectures. The 64-bit architecture case is unaffected by both the maximum length of Go slices being too small to trigger the overflow (everything except s390), and it being safe to assume no machine has more than 2 EiB of memory. Fixes golang/go#66232
While both impractical and unlikely, the multiplication could overflow on 32-bit architectures. The 64-bit architecture case is unaffected by both the maximum length of Go slices being too small to trigger the overflow (everything except s390), and it being safe to assume no machine has more than 2 EiB of memory. Fixes golang/go#66232
Change https://go.dev/cl/570876 mentions this issue: |
Change https://go.dev/cl/616576 mentions this issue: |
We used to compute the incorrect value if len(initBlock) % rate == 0. Also, add a test vector for golang/go#66232, confirmed to fail on GOARCH=386 without CL 570876. Fixes golang/go#69169 Change-Id: I3f2400926fca111dd0ca1327d6b5975e51b28f96 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/616576 Reviewed-by: Andrew Ekstedt <[email protected]> Reviewed-by: Daniel McCarney <[email protected]> Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
Go version
go version go1.22.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
Manual code review.
https://github.com/golang/crypto/blob/7067223927c4e3f3bb91a5c6e0d2aae83df74e7a/sha3/shake.go#L83
What did you see happen?
newCShake
will silently misbehave if passed an extremely (unrealistically) largeN
orS
, due to the multiply overflowing.What did you expect to see?
There should be overflow checks for the multiplications in the following calls:
c.initBlock = append(c.initBlock, leftEncode(uint64(len(N)*8))...)
c.initBlock = append(c.initBlock, leftEncode(uint64(len(S)*8))...)
Alternatively
leftEncode
could be modified to support the full range of possible slice lengths.The text was updated successfully, but these errors were encountered: