From 1a75fd65ca477d8bcf21b8f069b04e855eb3305d Mon Sep 17 00:00:00 2001 From: Sun Yimin Date: Fri, 15 Jul 2022 11:48:44 +0800 Subject: [PATCH] zuc: add comment and fix a bug --- sm3/sm3.go | 2 +- zuc/eia.go | 2 ++ zuc/eia256.go | 4 ++++ zuc/eia256_asm_arm64.s | 4 ++-- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/sm3/sm3.go b/sm3/sm3.go index c1bb8bb..dd1707e 100644 --- a/sm3/sm3.go +++ b/sm3/sm3.go @@ -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. diff --git a/zuc/eia.go b/zuc/eia.go index 8018776..73d1313 100644 --- a/zuc/eia.go +++ b/zuc/eia.go @@ -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 diff --git a/zuc/eia256.go b/zuc/eia256.go index 123af21..c45c301 100644 --- a/zuc/eia256.go +++ b/zuc/eia256.go @@ -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[:]...) } diff --git a/zuc/eia256_asm_arm64.s b/zuc/eia256_asm_arm64.s index a0b92a6..6acb36a 100644 --- a/zuc/eia256_asm_arm64.s +++ b/zuc/eia256_asm_arm64.s @@ -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]