Skip to content

Commit

Permalink
sha3: avoid trailing permutation
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Roland Shoemaker <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
Auto-Submit: Filippo Valsorda <[email protected]>
  • Loading branch information
FiloSottile authored and gopherbot committed Oct 22, 2024
1 parent 80ea76e commit 36b1725
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sha3/sha3.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ func (d *state) Read(out []byte) (n int, err error) {

// Now, do the squeezing.
for len(out) > 0 {
x := copy(out, d.a[d.n:d.rate])
d.n += x
out = out[x:]

// Apply the permutation if we've squeezed the sponge dry.
if d.n == d.rate {
d.permute()
}

x := copy(out, d.a[d.n:d.rate])
d.n += x
out = out[x:]
}

return
Expand Down

0 comments on commit 36b1725

Please sign in to comment.