@@ -143,6 +143,12 @@ func (s *asmState) Write(b []byte) (int, error) {
143
143
144
144
// Read squeezes an arbitrary number of bytes from the sponge.
145
145
func (s * asmState ) Read (out []byte ) (n int , err error ) {
146
+ // The 'compute last message digest' instruction only stores the digest
147
+ // at the first operand (dst) for SHAKE functions.
148
+ if s .function != shake_128 && s .function != shake_256 {
149
+ panic ("sha3: can only call Read for SHAKE functions" )
150
+ }
151
+
146
152
n = len (out )
147
153
148
154
// need to pad if we were absorbing
@@ -202,8 +208,17 @@ func (s *asmState) Sum(b []byte) []byte {
202
208
203
209
// Hash the buffer. Note that we don't clear it because we
204
210
// aren't updating the state.
205
- klmd (s .function , & a , nil , s .buf )
206
- return append (b , a [:s .outputLen ]... )
211
+ switch s .function {
212
+ case sha3_224 , sha3_256 , sha3_384 , sha3_512 :
213
+ klmd (s .function , & a , nil , s .buf )
214
+ return append (b , a [:s .outputLen ]... )
215
+ case shake_128 , shake_256 :
216
+ d := make ([]byte , s .outputLen , 64 )
217
+ klmd (s .function , & a , d , s .buf )
218
+ return append (b , d [:s .outputLen ]... )
219
+ default :
220
+ panic ("sha3: unknown function" )
221
+ }
207
222
}
208
223
209
224
// Reset resets the Hash to its initial state.
0 commit comments