Skip to content

Commit 36b1725

Browse files
FiloSottilegopherbot
authored andcommitted
sha3: avoid trailing permutation
If you read a multiple of the rate, and then stop, there is no point in running the final permutation. Change-Id: Ic95e70f78b6e139aca1d3e3c11e09d2bbcf54f6c Reviewed-on: https://go-review.googlesource.com/c/crypto/+/620555 Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> Reviewed-by: Roland Shoemaker <roland@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Auto-Submit: Filippo Valsorda <filippo@golang.org>
1 parent 80ea76e commit 36b1725

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

sha3/sha3.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ func (d *state) Read(out []byte) (n int, err error) {
143143

144144
// Now, do the squeezing.
145145
for len(out) > 0 {
146-
x := copy(out, d.a[d.n:d.rate])
147-
d.n += x
148-
out = out[x:]
149-
150146
// Apply the permutation if we've squeezed the sponge dry.
151147
if d.n == d.rate {
152148
d.permute()
153149
}
150+
151+
x := copy(out, d.a[d.n:d.rate])
152+
d.n += x
153+
out = out[x:]
154154
}
155155

156156
return

0 commit comments

Comments
 (0)