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
06e76422
Commit
06e76422
authored
Dec 12, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added length checkes
parent
1c7fd62e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
1 deletion
+18
-1
crypto.go
crypto/crypto.go
+18
-1
No files found.
crypto/crypto.go
View file @
06e76422
...
@@ -56,6 +56,10 @@ func Ecrecover(data []byte) []byte {
...
@@ -56,6 +56,10 @@ func Ecrecover(data []byte) []byte {
// New methods using proper ecdsa keys from the stdlib
// New methods using proper ecdsa keys from the stdlib
func
ToECDSA
(
prv
[]
byte
)
*
ecdsa
.
PrivateKey
{
func
ToECDSA
(
prv
[]
byte
)
*
ecdsa
.
PrivateKey
{
if
len
(
prv
)
==
0
{
return
nil
}
priv
:=
new
(
ecdsa
.
PrivateKey
)
priv
:=
new
(
ecdsa
.
PrivateKey
)
priv
.
PublicKey
.
Curve
=
S256
()
priv
.
PublicKey
.
Curve
=
S256
()
priv
.
D
=
ethutil
.
BigD
(
prv
)
priv
.
D
=
ethutil
.
BigD
(
prv
)
...
@@ -64,14 +68,27 @@ func ToECDSA(prv []byte) *ecdsa.PrivateKey {
...
@@ -64,14 +68,27 @@ func ToECDSA(prv []byte) *ecdsa.PrivateKey {
}
}
func
FromECDSA
(
prv
*
ecdsa
.
PrivateKey
)
[]
byte
{
func
FromECDSA
(
prv
*
ecdsa
.
PrivateKey
)
[]
byte
{
if
prv
==
nil
{
return
nil
}
return
prv
.
D
.
Bytes
()
return
prv
.
D
.
Bytes
()
}
}
func
PubToECDSA
(
pub
[]
byte
)
*
ecdsa
.
PublicKey
{
func
ToECDSAPub
(
pub
[]
byte
)
*
ecdsa
.
PublicKey
{
if
len
(
pub
)
==
0
{
return
nil
}
x
,
y
:=
elliptic
.
Unmarshal
(
S256
(),
pub
)
x
,
y
:=
elliptic
.
Unmarshal
(
S256
(),
pub
)
return
&
ecdsa
.
PublicKey
{
S256
(),
x
,
y
}
return
&
ecdsa
.
PublicKey
{
S256
(),
x
,
y
}
}
}
func
FromECDSAPub
(
pub
*
ecdsa
.
PublicKey
)
[]
byte
{
if
pub
==
nil
{
return
nil
}
return
elliptic
.
Marshal
(
S256
(),
pub
.
X
,
pub
.
Y
)
}
func
GenerateKey
()
(
*
ecdsa
.
PrivateKey
,
error
)
{
func
GenerateKey
()
(
*
ecdsa
.
PrivateKey
,
error
)
{
return
ecdsa
.
GenerateKey
(
S256
(),
rand
.
Reader
)
return
ecdsa
.
GenerateKey
(
S256
(),
rand
.
Reader
)
}
}
...
...
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