Read squeezes an arbitrary number of bytes from the sponge.
(out []byte)
| 161 | |
| 162 | // Read squeezes an arbitrary number of bytes from the sponge. |
| 163 | func (d *state) Read(out []byte) (n int, err error) { |
| 164 | // If we're still absorbing, pad and apply the permutation. |
| 165 | if d.state == spongeAbsorbing { |
| 166 | d.padAndPermute(d.dsbyte) |
| 167 | } |
| 168 | |
| 169 | n = len(out) |
| 170 | |
| 171 | // Now, do the squeezing. |
| 172 | for len(out) > 0 { |
| 173 | n := copy(out, d.buf) |
| 174 | d.buf = d.buf[n:] |
| 175 | out = out[n:] |
| 176 | |
| 177 | // Apply the permutation if we've squeezed the sponge dry. |
| 178 | if len(d.buf) == 0 { |
| 179 | d.permute() |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | return |
| 184 | } |
| 185 | |
| 186 | // Sum applies padding to the hash state and then squeezes out the desired |
| 187 | // number of output bytes. |
no test coverage detected