Skip to content

Commit ba975dc

Browse files
kielbarryfjl
authored andcommitted
crypto: fix golint warnings (#16710)
1 parent eab6e5a commit ba975dc

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

crypto/crypto.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
)
3636

3737
var (
38-
secp256k1_N, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16)
39-
secp256k1_halfN = new(big.Int).Div(secp256k1_N, big.NewInt(2))
38+
secp256k1N, _ = new(big.Int).SetString("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141", 16)
39+
secp256k1halfN = new(big.Int).Div(secp256k1N, big.NewInt(2))
4040
)
4141

4242
// Keccak256 calculates and returns the Keccak256 hash of the input data.
@@ -68,7 +68,7 @@ func Keccak512(data ...[]byte) []byte {
6868
return d.Sum(nil)
6969
}
7070

71-
// Creates an ethereum address given the bytes and the nonce
71+
// CreateAddress creates an ethereum address given the bytes and the nonce
7272
func CreateAddress(b common.Address, nonce uint64) common.Address {
7373
data, _ := rlp.EncodeToBytes([]interface{}{b, nonce})
7474
return common.BytesToAddress(Keccak256(data)[12:])
@@ -99,7 +99,7 @@ func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) {
9999
priv.D = new(big.Int).SetBytes(d)
100100

101101
// The priv.D must < N
102-
if priv.D.Cmp(secp256k1_N) >= 0 {
102+
if priv.D.Cmp(secp256k1N) >= 0 {
103103
return nil, fmt.Errorf("invalid private key, >=N")
104104
}
105105
// The priv.D must not be zero or negative.
@@ -184,11 +184,11 @@ func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool {
184184
}
185185
// reject upper range of s values (ECDSA malleability)
186186
// see discussion in secp256k1/libsecp256k1/include/secp256k1.h
187-
if homestead && s.Cmp(secp256k1_halfN) > 0 {
187+
if homestead && s.Cmp(secp256k1halfN) > 0 {
188188
return false
189189
}
190190
// Frontier: allow s to be in full N range
191-
return r.Cmp(secp256k1_N) < 0 && s.Cmp(secp256k1_N) < 0 && (v == 0 || v == 1)
191+
return r.Cmp(secp256k1N) < 0 && s.Cmp(secp256k1N) < 0 && (v == 0 || v == 1)
192192
}
193193

194194
func PubkeyToAddress(p ecdsa.PublicKey) common.Address {

crypto/crypto_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func TestValidateSignatureValues(t *testing.T) {
154154
minusOne := big.NewInt(-1)
155155
one := common.Big1
156156
zero := common.Big0
157-
secp256k1nMinus1 := new(big.Int).Sub(secp256k1_N, common.Big1)
157+
secp256k1nMinus1 := new(big.Int).Sub(secp256k1N, common.Big1)
158158

159159
// correct v,r,s
160160
check(true, 0, one, one)
@@ -181,9 +181,9 @@ func TestValidateSignatureValues(t *testing.T) {
181181
// correct sig with max r,s
182182
check(true, 0, secp256k1nMinus1, secp256k1nMinus1)
183183
// correct v, combinations of incorrect r,s at upper limit
184-
check(false, 0, secp256k1_N, secp256k1nMinus1)
185-
check(false, 0, secp256k1nMinus1, secp256k1_N)
186-
check(false, 0, secp256k1_N, secp256k1_N)
184+
check(false, 0, secp256k1N, secp256k1nMinus1)
185+
check(false, 0, secp256k1nMinus1, secp256k1N)
186+
check(false, 0, secp256k1N, secp256k1N)
187187

188188
// current callers ensures r,s cannot be negative, but let's test for that too
189189
// as crypto package could be used stand-alone

crypto/secp256k1/curve.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (BitCurve *BitCurve) Params() *elliptic.CurveParams {
7777
}
7878
}
7979

80-
// IsOnBitCurve returns true if the given (x,y) lies on the BitCurve.
80+
// IsOnCurve returns true if the given (x,y) lies on the BitCurve.
8181
func (BitCurve *BitCurve) IsOnCurve(x, y *big.Int) bool {
8282
// y² = x³ + b
8383
y2 := new(big.Int).Mul(y, y) //y²

crypto/secp256k1/secp256_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func randSig() []byte {
4949
// tests for malleability
5050
// highest bit of signature ECDSA s value must be 0, in the 33th byte
5151
func compactSigCheck(t *testing.T, sig []byte) {
52-
var b int = int(sig[32])
52+
var b = int(sig[32])
5353
if b < 0 {
5454
t.Errorf("highest bit is negative: %d", b)
5555
}

crypto/signature_nocgo.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func VerifySignature(pubkey, hash, signature []byte) bool {
8888
return false
8989
}
9090
// Reject malleable signatures. libsecp256k1 does this check but btcec doesn't.
91-
if sig.S.Cmp(secp256k1_halfN) > 0 {
91+
if sig.S.Cmp(secp256k1halfN) > 0 {
9292
return false
9393
}
9494
return sig.Verify(hash, key)

0 commit comments

Comments
 (0)