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
3f306f63
Commit
3f306f63
authored
Apr 05, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Forward and log EC recover err and remove dup pubkey len check
parent
7c583f82
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
13 deletions
+25
-13
transaction.go
core/types/transaction.go
+7
-1
address.go
core/vm/address.go
+4
-2
crypto.go
crypto/crypto.go
+7
-9
message.go
whisper/message.go
+7
-1
No files found.
core/types/transaction.go
View file @
3f306f63
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
)
)
...
@@ -129,7 +130,12 @@ func (tx *Transaction) PublicKey() []byte {
...
@@ -129,7 +130,12 @@ func (tx *Transaction) PublicKey() []byte {
//pubkey := crypto.Ecrecover(append(hash[:], sig...))
//pubkey := crypto.Ecrecover(append(hash[:], sig...))
//pubkey, _ := secp256k1.RecoverPubkey(hash[:], sig)
//pubkey, _ := secp256k1.RecoverPubkey(hash[:], sig)
pubkey
:=
crypto
.
FromECDSAPub
(
crypto
.
SigToPub
(
hash
[
:
],
sig
))
p
,
err
:=
crypto
.
SigToPub
(
hash
[
:
],
sig
)
if
err
!=
nil
{
glog
.
V
(
0
)
.
Infof
(
"Could not get pubkey from signature: "
,
err
)
return
nil
}
pubkey
:=
crypto
.
FromECDSAPub
(
p
)
return
pubkey
return
pubkey
}
}
...
...
core/vm/address.go
View file @
3f306f63
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/params"
)
)
...
@@ -80,9 +81,10 @@ func ecrecoverFunc(in []byte) []byte {
...
@@ -80,9 +81,10 @@ func ecrecoverFunc(in []byte) []byte {
// v needs to be moved to the end
// v needs to be moved to the end
rsv
:=
append
(
in
[
64
:
128
],
byte
(
v
.
Uint64
()))
rsv
:=
append
(
in
[
64
:
128
],
byte
(
v
.
Uint64
()))
pubKey
:=
crypto
.
Ecrecover
(
in
[
:
32
],
rsv
)
pubKey
,
err
:=
crypto
.
Ecrecover
(
in
[
:
32
],
rsv
)
// make sure the public key is a valid one
// make sure the public key is a valid one
if
pubKey
==
nil
||
len
(
pubKey
)
!=
65
{
if
err
!=
nil
{
glog
.
V
(
0
)
.
Infof
(
"EC RECOVER FAIL: "
,
err
)
return
nil
return
nil
}
}
...
...
crypto/crypto.go
View file @
3f306f63
...
@@ -68,10 +68,8 @@ func Ripemd160(data []byte) []byte {
...
@@ -68,10 +68,8 @@ func Ripemd160(data []byte) []byte {
return
ripemd
.
Sum
(
nil
)
return
ripemd
.
Sum
(
nil
)
}
}
func
Ecrecover
(
hash
,
sig
[]
byte
)
[]
byte
{
func
Ecrecover
(
hash
,
sig
[]
byte
)
([]
byte
,
error
)
{
r
,
_
:=
secp256k1
.
RecoverPubkey
(
hash
,
sig
)
return
secp256k1
.
RecoverPubkey
(
hash
,
sig
)
return
r
}
}
// New methods using proper ecdsa keys from the stdlib
// New methods using proper ecdsa keys from the stdlib
...
@@ -145,14 +143,14 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
...
@@ -145,14 +143,14 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
return
ecdsa
.
GenerateKey
(
S256
(),
rand
.
Reader
)
return
ecdsa
.
GenerateKey
(
S256
(),
rand
.
Reader
)
}
}
func
SigToPub
(
hash
,
sig
[]
byte
)
*
ecdsa
.
PublicKey
{
func
SigToPub
(
hash
,
sig
[]
byte
)
(
*
ecdsa
.
PublicKey
,
error
)
{
s
:=
Ecrecover
(
hash
,
sig
)
s
,
err
:=
Ecrecover
(
hash
,
sig
)
if
s
==
nil
||
len
(
s
)
!=
65
{
if
err
!=
nil
{
return
nil
return
nil
,
err
}
}
x
,
y
:=
elliptic
.
Unmarshal
(
S256
(),
s
)
x
,
y
:=
elliptic
.
Unmarshal
(
S256
(),
s
)
return
&
ecdsa
.
PublicKey
{
S256
(),
x
,
y
}
return
&
ecdsa
.
PublicKey
{
S256
(),
x
,
y
}
,
nil
}
}
func
Sign
(
hash
[]
byte
,
prv
*
ecdsa
.
PrivateKey
)
(
sig
[]
byte
,
err
error
)
{
func
Sign
(
hash
[]
byte
,
prv
*
ecdsa
.
PrivateKey
)
(
sig
[]
byte
,
err
error
)
{
...
...
whisper/message.go
View file @
3f306f63
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"time"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger/glog"
)
)
type
Message
struct
{
type
Message
struct
{
...
@@ -32,7 +33,12 @@ func (self *Message) sign(key *ecdsa.PrivateKey) (err error) {
...
@@ -32,7 +33,12 @@ func (self *Message) sign(key *ecdsa.PrivateKey) (err error) {
func
(
self
*
Message
)
Recover
()
*
ecdsa
.
PublicKey
{
func
(
self
*
Message
)
Recover
()
*
ecdsa
.
PublicKey
{
defer
func
()
{
recover
()
}()
// in case of invalid sig
defer
func
()
{
recover
()
}()
// in case of invalid sig
return
crypto
.
SigToPub
(
self
.
hash
(),
self
.
Signature
)
pub
,
err
:=
crypto
.
SigToPub
(
self
.
hash
(),
self
.
Signature
)
if
err
!=
nil
{
glog
.
V
(
0
)
.
Infof
(
"Could not get pubkey from signature: "
,
err
)
return
nil
}
return
pub
}
}
func
(
self
*
Message
)
Encrypt
(
to
*
ecdsa
.
PublicKey
)
(
err
error
)
{
func
(
self
*
Message
)
Encrypt
(
to
*
ecdsa
.
PublicKey
)
(
err
error
)
{
...
...
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