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
6cd6b921
Commit
6cd6b921
authored
Jan 02, 2018
by
Alex Wu
Committed by
Felix Lange
Jan 02, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto: ensure private keys are < N (#15745)
Fixes #15744
parent
908faf8c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
0 deletions
+10
-0
crypto.go
crypto/crypto.go
+10
-0
No files found.
crypto/crypto.go
View file @
6cd6b921
...
@@ -97,6 +97,16 @@ func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) {
...
@@ -97,6 +97,16 @@ func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) {
return
nil
,
fmt
.
Errorf
(
"invalid length, need %d bits"
,
priv
.
Params
()
.
BitSize
)
return
nil
,
fmt
.
Errorf
(
"invalid length, need %d bits"
,
priv
.
Params
()
.
BitSize
)
}
}
priv
.
D
=
new
(
big
.
Int
)
.
SetBytes
(
d
)
priv
.
D
=
new
(
big
.
Int
)
.
SetBytes
(
d
)
// The priv.D must < N
if
priv
.
D
.
Cmp
(
secp256k1_N
)
>=
0
{
return
nil
,
fmt
.
Errorf
(
"invalid private key, >=N"
)
}
// The priv.D must not be zero or negative.
if
priv
.
D
.
Sign
()
<=
0
{
return
nil
,
fmt
.
Errorf
(
"invalid private key, zero or negative"
)
}
priv
.
PublicKey
.
X
,
priv
.
PublicKey
.
Y
=
priv
.
PublicKey
.
Curve
.
ScalarBaseMult
(
d
)
priv
.
PublicKey
.
X
,
priv
.
PublicKey
.
Y
=
priv
.
PublicKey
.
Curve
.
ScalarBaseMult
(
d
)
if
priv
.
PublicKey
.
X
==
nil
{
if
priv
.
PublicKey
.
X
==
nil
{
return
nil
,
errors
.
New
(
"invalid private key"
)
return
nil
,
errors
.
New
(
"invalid private 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