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
}
// 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.
func (d *digest) Sum(in []byte) []byte {
// 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[:]
}
// 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 {
// Make a copy of d so that caller can keep writing and summing.
d0 := *m

View File

@ -231,9 +231,13 @@ func (m *ZUC256Mac) Finish(p []byte, nbits int) []byte {
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 {
// Make a copy of d so that caller can keep writing and summing.
d0 := *m
d0.t = make([]uint32, len(m.t))
copy(d0.t, m.t)
hash := d0.checkSum(0, 0)
return append(in, hash[:]...)
}

View File

@ -69,7 +69,7 @@ TEXT ·eia256RoundTag8(SB),NOSPLIT,$0
MOVD ks+8(FP), BX
MOVD p+16(FP), CX
LOAD_GLOBAL_DATA()
LOAD_GLOBAL_DATA()
// Reverse data bytes
VLD1 (CX), [XDATA.B16]
@ -148,7 +148,7 @@ TEXT ·eia256RoundTag16(SB),NOSPLIT,$0
MOVD ks+8(FP), BX
MOVD p+16(FP), CX
LOAD_GLOBAL_DATA()
LOAD_GLOBAL_DATA()
// Reverse data bytes
VLD1 (CX), [XDATA.B16]