1
0
mirror of https://github.com/henrydcase/nobs.git synced 2024-11-22 23:28:57 +00:00

sha3: simplifies Read function

This commit is contained in:
Henry Case 2020-10-03 22:08:28 +01:00
parent cccb9890e1
commit bd23898fdb

View File

@ -179,22 +179,17 @@ func (c *state) Read(out []byte) (nread int, err error) {
// copy out full blocks and squeeze. at this point // copy out full blocks and squeeze. at this point
// there is no more data in the buffer. // there is no more data in the buffer.
nblocks := l / rate nblocks := l / rate
for i := 0; i < nblocks; i++ { for nblocks > 0 {
keccakF1600(&c.a) keccakF1600(&c.a)
copyOut(c, out[:rate]) copyOut(c, out[:rate])
out = out[rate:] out = out[rate:]
} nblocks--
// produce more if needed
l = len(out)
if l == 0 {
return nread, nil
} }
keccakF1600(&c.a) keccakF1600(&c.a)
copyOut(c, buf) copyOut(c, buf)
copy(out, buf[:l]) copy(out, buf[:len(out)])
c.idx = rate - l c.idx = rate - len(out)
return nread, nil return nread, nil
} }