Write absorbs more data into the hash's state. It produces an error if more data is written to the ShakeHash after writing
(p []byte)
| 126 | // Write absorbs more data into the hash's state. It produces an error |
| 127 | // if more data is written to the ShakeHash after writing |
| 128 | func (d *state) Write(p []byte) (written int, err error) { |
| 129 | if d.state != spongeAbsorbing { |
| 130 | panic("sha3: write to sponge after read") |
| 131 | } |
| 132 | if d.buf == nil { |
| 133 | d.buf = d.storage[:0] |
| 134 | } |
| 135 | written = len(p) |
| 136 | |
| 137 | for len(p) > 0 { |
| 138 | if len(d.buf) == 0 && len(p) >= d.rate { |
| 139 | // The fast path; absorb a full "rate" bytes of input and apply the permutation. |
| 140 | xorIn(d, p[:d.rate]) |
| 141 | p = p[d.rate:] |
| 142 | keccakF1600(&d.a) |
| 143 | } else { |
| 144 | // The slow path; buffer the input until we can fill the sponge, and then xor it in. |
| 145 | todo := d.rate - len(d.buf) |
| 146 | if todo > len(p) { |
| 147 | todo = len(p) |
| 148 | } |
| 149 | d.buf = append(d.buf, p[:todo]...) |
| 150 | p = p[todo:] |
| 151 | |
| 152 | // If the sponge is full, apply the permutation. |
| 153 | if len(d.buf) == d.rate { |
| 154 | d.permute() |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return |
| 160 | } |
| 161 | |
| 162 | // Read squeezes an arbitrary number of bytes from the sponge. |
| 163 | func (d *state) Read(out []byte) (n int, err error) { |
no test coverage detected