Skip to content

Commit 503e180

Browse files
committed
sha3: fix cSHAKE initialization for extremely large N and or S
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
1 parent 7067223 commit 503e180

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: sha3/shake.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func newCShake(N, S []byte, rate, outputLen int, dsbyte byte) ShakeHash {
8585

8686
// leftEncode returns max 9 bytes
8787
c.initBlock = make([]byte, 0, 9*2+len(N)+len(S))
88-
c.initBlock = append(c.initBlock, leftEncode(uint64(len(N)*8))...)
88+
c.initBlock = append(c.initBlock, leftEncode(uint64(len(N))*8)...)
8989
c.initBlock = append(c.initBlock, N...)
90-
c.initBlock = append(c.initBlock, leftEncode(uint64(len(S)*8))...)
90+
c.initBlock = append(c.initBlock, leftEncode(uint64(len(S))*8)...)
9191
c.initBlock = append(c.initBlock, S...)
9292
c.Write(bytepad(c.initBlock, c.rate))
9393
return &c

0 commit comments

Comments
 (0)