mirror of
https://github.com/emmansun/gmsm.git
synced 2025-06-28 00:13:26 +08:00
all: golint
This commit is contained in:
parent
fca59d1a92
commit
bb64af1a24
@ -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
|
||||||
)
|
)
|
||||||
|
@ -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))
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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())
|
||||||
})
|
})
|
||||||
|
@ -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 {
|
||||||
|
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user