all: golint

This commit is contained in:
Sun Yimin 2025-06-20 10:24:08 +08:00 committed by GitHub
parent fca59d1a92
commit bb64af1a24
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 11 additions and 12 deletions

View File

@ -3,7 +3,7 @@ package cpuid
import "github.com/emmansun/gmsm/internal/deps/cpu" import "github.com/emmansun/gmsm/internal/deps/cpu"
var ( var (
HasAES = cpu.X86.HasAES HasAES = cpu.X86.HasAES
HasGFMUL = cpu.X86.HasPCLMULQDQ HasGFMUL = cpu.X86.HasPCLMULQDQ
HasVPMSUMD = false HasVPMSUMD = false
) )

View File

@ -371,7 +371,7 @@ func bitPackSignedTwoPower19(s []byte, f ringElement) []byte {
b[5] = uint8(x1 >> 40) b[5] = uint8(x1 >> 40)
b[6] = uint8(x1 >> 48) b[6] = uint8(x1 >> 48)
b[7] = uint8(x1 >> 56) b[7] = uint8(x1 >> 56)
b = b[10:] b = b[10:]
} }
return s return s
@ -387,7 +387,7 @@ func bitUnpackSignedTwoPower19(b []byte, f *ringElement) {
for i := 0; i < n; i += 4 { for i := 0; i < n; i += 4 {
x2 := (uint64(b[9]) << 8) | uint64(b[8]) 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) 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:] b = b[10:]
f[i] = fieldSub(r, fieldElement(x1&bitsMask)) f[i] = fieldSub(r, fieldElement(x1&bitsMask))
f[i+1] = fieldSub(r, fieldElement((x1>>20)&bitsMask)) f[i+1] = fieldSub(r, fieldElement((x1>>20)&bitsMask))

View File

@ -46,8 +46,8 @@ const (
r = 4193792 // 2^32 mod q r = 4193792 // 2^32 mod q
) )
// See FIPS 204, Algorithm 49, MontgomeryReduce()
func fieldReduce(a uint64) fieldElement { func fieldReduce(a uint64) fieldElement {
// See FIPS 204, Algorithm 49, MontgomeryReduce()
t := uint32(a) * qNegInv t := uint32(a) * qNegInv
return fieldReduceOnce(uint32((a + uint64(t)*q) >> 32)) return fieldReduceOnce(uint32((a + uint64(t)*q) >> 32))
} }
@ -243,4 +243,3 @@ func vectorCountOnes(a []ringElement) int {
} }
return oneCount return oneCount
} }

View File

@ -845,7 +845,7 @@ var _p256 *sm2Curve
func p256() *sm2Curve { func p256() *sm2Curve {
p256Once.Do(func() { p256Once.Do(func() {
_p256 = &sm2Curve{ _p256 = &sm2Curve{
newPoint: func() *_sm2ec.SM2P256Point { return _sm2ec.NewSM2P256Point() }, newPoint: _sm2ec.NewSM2P256Point,
} }
precomputeParams(_p256, P256()) precomputeParams(_p256, P256())
}) })

View File

@ -159,7 +159,7 @@ func buildTmpPublicKeyAttr(key crypto.Signer, rawAttributes []asn1.RawValue, tmp
} }
publicKeyBytes = make([]byte, 136) publicKeyBytes = make([]byte, 136)
// Prefix{8} || X{32} || zero{32} || Y{32} || zero{32} // Prefix{8} || X{32} || zero{32} || Y{32} || zero{32}
copy(publicKeyBytes[:], tmpPublicKeyPrefix) copy(publicKeyBytes, tmpPublicKeyPrefix)
ecPub, _ := tmpPub.(*ecdsa.PublicKey) ecPub, _ := tmpPub.(*ecdsa.PublicKey)
ecPub.X.FillBytes(publicKeyBytes[8:40]) ecPub.X.FillBytes(publicKeyBytes[8:40])
ecPub.Y.FillBytes(publicKeyBytes[72:104]) ecPub.Y.FillBytes(publicKeyBytes[72:104])
@ -175,7 +175,7 @@ func buildTmpPublicKeyAttr(key crypto.Signer, rawAttributes []asn1.RawValue, tmp
} }
var tmpPublicKey = tmpPublicKeyInfo{ var tmpPublicKey = tmpPublicKeyInfo{
Version: 1, Version: 1,
PublicKey: publicKeyBytes[:], PublicKey: publicKeyBytes,
} }
b, err := asn1.Marshal(tmpPublicKey) b, err := asn1.Marshal(tmpPublicKey)
if err != nil { if err != nil {

View File

@ -393,11 +393,11 @@ func TestCheckSignatureWithDigest(t *testing.T) {
algo: SM2WithSM3, algo: SM2WithSM3,
digest: func() []byte { digest: func() []byte {
hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil) hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil)
return hash[:] return hash
}(), }(),
signature: func() []byte { signature: func() []byte {
hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil) hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil)
return mustSignSM2(t, sm2PrivateKey, hash[:]) return mustSignSM2(t, sm2PrivateKey, hash)
}(), }(),
expectedError: nil, expectedError: nil,
}, },
@ -409,7 +409,7 @@ func TestCheckSignatureWithDigest(t *testing.T) {
algo: SM2WithSM3, algo: SM2WithSM3,
digest: func() []byte { digest: func() []byte {
hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil) hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey.PublicKey, rawMessage, nil)
return hash[:] return hash
}(), }(),
signature: func() []byte { signature: func() []byte {
hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey2.PublicKey, rawMessage, nil) hash, _ := sm2.CalculateSM2Hash(&sm2PrivateKey2.PublicKey, rawMessage, nil)