zuc: add comment and fix a bug

This commit is contained in:
Sun Yimin 2022-07-15 11:48:44 +08:00 committed by GitHub
parent 7e81d05ce9
commit 1a75fd65ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View File

@ -117,7 +117,7 @@ func New() hash.Hash {
return d return d
} }
// Sum appends the current hash to b and returns the resulting slice. // Sum appends the current hash to in and returns the resulting slice.
// It does not change the underlying hash state. // It does not change the underlying hash state.
func (d *digest) Sum(in []byte) []byte { func (d *digest) Sum(in []byte) []byte {
// Make a copy of d so that caller can keep writing and summing. // Make a copy of d so that caller can keep writing and summing.

View File

@ -206,6 +206,8 @@ func (m *ZUC128Mac) Finish(p []byte, nbits int) []byte {
return digest[:] return digest[:]
} }
// Sum appends the current hash to in and returns the resulting slice.
// It does not change the underlying hash state.
func (m *ZUC128Mac) Sum(in []byte) []byte { func (m *ZUC128Mac) Sum(in []byte) []byte {
// Make a copy of d so that caller can keep writing and summing. // Make a copy of d so that caller can keep writing and summing.
d0 := *m d0 := *m

View File

@ -231,9 +231,13 @@ func (m *ZUC256Mac) Finish(p []byte, nbits int) []byte {
return digest[:] return digest[:]
} }
// Sum appends the current hash to in and returns the resulting slice.
// It does not change the underlying hash state.
func (m *ZUC256Mac) Sum(in []byte) []byte { func (m *ZUC256Mac) Sum(in []byte) []byte {
// Make a copy of d so that caller can keep writing and summing. // Make a copy of d so that caller can keep writing and summing.
d0 := *m d0 := *m
d0.t = make([]uint32, len(m.t))
copy(d0.t, m.t)
hash := d0.checkSum(0, 0) hash := d0.checkSum(0, 0)
return append(in, hash[:]...) return append(in, hash[:]...)
} }