diff --git a/internal/cpuid/cpuid_amd64.go b/internal/cpuid/cpuid_amd64.go index b7afad1..4244205 100644 --- a/internal/cpuid/cpuid_amd64.go +++ b/internal/cpuid/cpuid_amd64.go @@ -3,7 +3,7 @@ package cpuid import "github.com/emmansun/gmsm/internal/deps/cpu" var ( - HasAES = cpu.X86.HasAES - HasGFMUL = cpu.X86.HasPCLMULQDQ + HasAES = cpu.X86.HasAES + HasGFMUL = cpu.X86.HasPCLMULQDQ HasVPMSUMD = false ) diff --git a/mldsa/encoder.go b/mldsa/encoder.go index ce8cf82..e2283e3 100644 --- a/mldsa/encoder.go +++ b/mldsa/encoder.go @@ -371,7 +371,7 @@ func bitPackSignedTwoPower19(s []byte, f ringElement) []byte { b[5] = uint8(x1 >> 40) b[6] = uint8(x1 >> 48) b[7] = uint8(x1 >> 56) - + b = b[10:] } return s @@ -387,7 +387,7 @@ func bitUnpackSignedTwoPower19(b []byte, f *ringElement) { for i := 0; i < n; i += 4 { x2 := (uint64(b[9]) << 8) | uint64(b[8]) x1 := uint64(b[0]) | (uint64(b[1]) << 8) | (uint64(b[2]) << 16) | (uint64(b[3]) << 24) | (uint64(b[4]) << 32) | (uint64(b[5]) << 40) | (uint64(b[6]) << 48) | (uint64(b[7]) << 56) - + b = b[10:] f[i] = fieldSub(r, fieldElement(x1&bitsMask)) f[i+1] = fieldSub(r, fieldElement((x1>>20)&bitsMask)) diff --git a/mldsa/field.go b/mldsa/field.go index 77fcb2c..3a9e70f 100644 --- a/mldsa/field.go +++ b/mldsa/field.go @@ -46,8 +46,8 @@ const ( r = 4193792 // 2^32 mod q ) -// See FIPS 204, Algorithm 49, MontgomeryReduce() func fieldReduce(a uint64) fieldElement { + // See FIPS 204, Algorithm 49, MontgomeryReduce() t := uint32(a) * qNegInv return fieldReduceOnce(uint32((a + uint64(t)*q) >> 32)) } @@ -243,4 +243,3 @@ func vectorCountOnes(a []ringElement) int { } return oneCount } - diff --git a/sm2/sm2_dsa.go b/sm2/sm2_dsa.go index a400b06..9271008 100644 --- a/sm2/sm2_dsa.go +++ b/sm2/sm2_dsa.go @@ -845,7 +845,7 @@ var _p256 *sm2Curve func p256() *sm2Curve { p256Once.Do(func() { _p256 = &sm2Curve{ - newPoint: func() *_sm2ec.SM2P256Point { return _sm2ec.NewSM2P256Point() }, + newPoint: _sm2ec.NewSM2P256Point, } precomputeParams(_p256, P256()) }) diff --git a/smx509/cfca_csr.go b/smx509/cfca_csr.go index 07b4559..791273d 100644 --- a/smx509/cfca_csr.go +++ b/smx509/cfca_csr.go @@ -159,7 +159,7 @@ func buildTmpPublicKeyAttr(key crypto.Signer, rawAttributes []asn1.RawValue, tmp } publicKeyBytes = make([]byte, 136) // Prefix{8} || X{32} || zero{32} || Y{32} || zero{32} - copy(publicKeyBytes[:], tmpPublicKeyPrefix) + copy(publicKeyBytes, tmpPublicKeyPrefix) ecPub, _ := tmpPub.(*ecdsa.PublicKey) ecPub.X.FillBytes(publicKeyBytes[8:40]) ecPub.Y.FillBytes(publicKeyBytes[72:104]) @@ -175,7 +175,7 @@ func buildTmpPublicKeyAttr(key crypto.Signer, rawAttributes []asn1.RawValue, tmp } var tmpPublicKey = tmpPublicKeyInfo{ Version: 1, - PublicKey: publicKeyBytes[:], + PublicKey: publicKeyBytes, } b, err := asn1.Marshal(tmpPublicKey) if err != nil { diff --git a/smx509/x509_additional_test.go b/smx509/x509_additional_test.go index 483596b..468cf85 100644 --- a/smx509/x509_additional_test.go +++ b/smx509/x509_additional_test.go @@ -393,11 +393,11 @@ func TestCheckSignatureWithDigest(t *testing.T) { algo: SM2WithSM3, digest: func() []byte { hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil) - return hash[:] + return hash }(), signature: func() []byte { hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil) - return mustSignSM2(t, sm2PrivateKey, hash[:]) + return mustSignSM2(t, sm2PrivateKey, hash) }(), expectedError: nil, }, @@ -409,7 +409,7 @@ func TestCheckSignatureWithDigest(t *testing.T) { algo: SM2WithSM3, digest: func() []byte { hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil) - return hash[:] + return hash }(), signature: func() []byte { hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey2.PublicKey, rawMessage, nil)