From 36b172546bd03a74c79e109ec84c599b672ea9e4 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Wed, 2 Oct 2024 12:44:13 +0200 Subject: [PATCH] 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 Reviewed-by: Roland Shoemaker LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Pratt Auto-Submit: Filippo Valsorda --- sha3/sha3.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sha3/sha3.go b/sha3/sha3.go index bda574e..4f5cadd 100644 --- a/sha3/sha3.go +++ b/sha3/sha3.go @@ -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