Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
ba975dc0
Commit
ba975dc0
authored
May 08, 2018
by
kiel barry
Committed by
Felix Lange
May 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto: fix golint warnings (#16710)
parent
eab6e5a3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
13 deletions
+13
-13
crypto.go
crypto/crypto.go
+6
-6
crypto_test.go
crypto/crypto_test.go
+4
-4
curve.go
crypto/secp256k1/curve.go
+1
-1
secp256_test.go
crypto/secp256k1/secp256_test.go
+1
-1
signature_nocgo.go
crypto/signature_nocgo.go
+1
-1
No files found.
crypto/crypto.go
View file @
ba975dc0
...
...
@@ -35,8 +35,8 @@ import (
)
var
(
secp256k1
_
N
,
_
=
new
(
big
.
Int
)
.
SetString
(
"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"
,
16
)
secp256k1
_halfN
=
new
(
big
.
Int
)
.
Div
(
secp256k1_
N
,
big
.
NewInt
(
2
))
secp256k1N
,
_
=
new
(
big
.
Int
)
.
SetString
(
"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"
,
16
)
secp256k1
halfN
=
new
(
big
.
Int
)
.
Div
(
secp256k1
N
,
big
.
NewInt
(
2
))
)
// Keccak256 calculates and returns the Keccak256 hash of the input data.
...
...
@@ -68,7 +68,7 @@ func Keccak512(data ...[]byte) []byte {
return
d
.
Sum
(
nil
)
}
// Creates an ethereum address given the bytes and the nonce
// Create
Address create
s an ethereum address given the bytes and the nonce
func
CreateAddress
(
b
common
.
Address
,
nonce
uint64
)
common
.
Address
{
data
,
_
:=
rlp
.
EncodeToBytes
([]
interface
{}{
b
,
nonce
})
return
common
.
BytesToAddress
(
Keccak256
(
data
)[
12
:
])
...
...
@@ -99,7 +99,7 @@ func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) {
priv
.
D
=
new
(
big
.
Int
)
.
SetBytes
(
d
)
// The priv.D must < N
if
priv
.
D
.
Cmp
(
secp256k1
_
N
)
>=
0
{
if
priv
.
D
.
Cmp
(
secp256k1N
)
>=
0
{
return
nil
,
fmt
.
Errorf
(
"invalid private key, >=N"
)
}
// The priv.D must not be zero or negative.
...
...
@@ -184,11 +184,11 @@ func ValidateSignatureValues(v byte, r, s *big.Int, homestead bool) bool {
}
// reject upper range of s values (ECDSA malleability)
// see discussion in secp256k1/libsecp256k1/include/secp256k1.h
if
homestead
&&
s
.
Cmp
(
secp256k1
_
halfN
)
>
0
{
if
homestead
&&
s
.
Cmp
(
secp256k1halfN
)
>
0
{
return
false
}
// Frontier: allow s to be in full N range
return
r
.
Cmp
(
secp256k1
_N
)
<
0
&&
s
.
Cmp
(
secp256k1_
N
)
<
0
&&
(
v
==
0
||
v
==
1
)
return
r
.
Cmp
(
secp256k1
N
)
<
0
&&
s
.
Cmp
(
secp256k1
N
)
<
0
&&
(
v
==
0
||
v
==
1
)
}
func
PubkeyToAddress
(
p
ecdsa
.
PublicKey
)
common
.
Address
{
...
...
crypto/crypto_test.go
View file @
ba975dc0
...
...
@@ -154,7 +154,7 @@ func TestValidateSignatureValues(t *testing.T) {
minusOne
:=
big
.
NewInt
(
-
1
)
one
:=
common
.
Big1
zero
:=
common
.
Big0
secp256k1nMinus1
:=
new
(
big
.
Int
)
.
Sub
(
secp256k1
_
N
,
common
.
Big1
)
secp256k1nMinus1
:=
new
(
big
.
Int
)
.
Sub
(
secp256k1N
,
common
.
Big1
)
// correct v,r,s
check
(
true
,
0
,
one
,
one
)
...
...
@@ -181,9 +181,9 @@ func TestValidateSignatureValues(t *testing.T) {
// correct sig with max r,s
check
(
true
,
0
,
secp256k1nMinus1
,
secp256k1nMinus1
)
// correct v, combinations of incorrect r,s at upper limit
check
(
false
,
0
,
secp256k1
_
N
,
secp256k1nMinus1
)
check
(
false
,
0
,
secp256k1nMinus1
,
secp256k1
_
N
)
check
(
false
,
0
,
secp256k1
_N
,
secp256k1_
N
)
check
(
false
,
0
,
secp256k1N
,
secp256k1nMinus1
)
check
(
false
,
0
,
secp256k1nMinus1
,
secp256k1N
)
check
(
false
,
0
,
secp256k1
N
,
secp256k1
N
)
// current callers ensures r,s cannot be negative, but let's test for that too
// as crypto package could be used stand-alone
...
...
crypto/secp256k1/curve.go
View file @
ba975dc0
...
...
@@ -77,7 +77,7 @@ func (BitCurve *BitCurve) Params() *elliptic.CurveParams {
}
}
// IsOn
Bit
Curve returns true if the given (x,y) lies on the BitCurve.
// IsOnCurve returns true if the given (x,y) lies on the BitCurve.
func
(
BitCurve
*
BitCurve
)
IsOnCurve
(
x
,
y
*
big
.
Int
)
bool
{
// y² = x³ + b
y2
:=
new
(
big
.
Int
)
.
Mul
(
y
,
y
)
//y²
...
...
crypto/secp256k1/secp256_test.go
View file @
ba975dc0
...
...
@@ -49,7 +49,7 @@ func randSig() []byte {
// tests for malleability
// highest bit of signature ECDSA s value must be 0, in the 33th byte
func
compactSigCheck
(
t
*
testing
.
T
,
sig
[]
byte
)
{
var
b
int
=
int
(
sig
[
32
])
var
b
=
int
(
sig
[
32
])
if
b
<
0
{
t
.
Errorf
(
"highest bit is negative: %d"
,
b
)
}
...
...
crypto/signature_nocgo.go
View file @
ba975dc0
...
...
@@ -88,7 +88,7 @@ func VerifySignature(pubkey, hash, signature []byte) bool {
return
false
}
// Reject malleable signatures. libsecp256k1 does this check but btcec doesn't.
if
sig
.
S
.
Cmp
(
secp256k1
_
halfN
)
>
0
{
if
sig
.
S
.
Cmp
(
secp256k1halfN
)
>
0
{
return
false
}
return
sig
.
Verify
(
hash
,
key
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment