aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/types/transaction.go9
-rw-r--r--core/vm/address.go7
-rw-r--r--crypto/crypto.go16
-rw-r--r--whisper/message.go9
4 files changed, 28 insertions, 13 deletions
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 6f438ad9d..6646bdf29 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -9,6 +9,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
+ "github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rlp"
)
@@ -129,7 +131,12 @@ func (tx *Transaction) PublicKey() []byte {
//pubkey := crypto.Ecrecover(append(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(logger.Error).Infof("Could not get pubkey from signature: ", err)
+ return nil
+ }
+ pubkey := crypto.FromECDSAPub(p)
return pubkey
}
diff --git a/core/vm/address.go b/core/vm/address.go
index df801863f..742017dd2 100644
--- a/core/vm/address.go
+++ b/core/vm/address.go
@@ -5,6 +5,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
+ "github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/params"
)
@@ -80,9 +82,10 @@ func ecrecoverFunc(in []byte) []byte {
// v needs to be moved to the end
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
- if pubKey == nil || len(pubKey) != 65 {
+ if err != nil {
+ glog.V(logger.Error).Infof("EC RECOVER FAIL: ", err)
return nil
}
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 9a1559fbf..7d1d51fa6 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -68,10 +68,8 @@ func Ripemd160(data []byte) []byte {
return ripemd.Sum(nil)
}
-func Ecrecover(hash, sig []byte) []byte {
- r, _ := secp256k1.RecoverPubkey(hash, sig)
-
- return r
+func Ecrecover(hash, sig []byte) ([]byte, error) {
+ return secp256k1.RecoverPubkey(hash, sig)
}
// New methods using proper ecdsa keys from the stdlib
@@ -145,14 +143,14 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
return ecdsa.GenerateKey(S256(), rand.Reader)
}
-func SigToPub(hash, sig []byte) *ecdsa.PublicKey {
- s := Ecrecover(hash, sig)
- if s == nil || len(s) != 65 {
- return nil
+func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
+ s, err := Ecrecover(hash, sig)
+ if err != nil {
+ return nil, err
}
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) {
diff --git a/whisper/message.go b/whisper/message.go
index 5d9e5b5c1..ad6a1bcff 100644
--- a/whisper/message.go
+++ b/whisper/message.go
@@ -5,6 +5,8 @@ import (
"time"
"github.com/ethereum/go-ethereum/crypto"
+ "github.com/ethereum/go-ethereum/logger"
+ "github.com/ethereum/go-ethereum/logger/glog"
)
type Message struct {
@@ -32,7 +34,12 @@ func (self *Message) sign(key *ecdsa.PrivateKey) (err error) {
func (self *Message) Recover() *ecdsa.PublicKey {
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(logger.Error).Infof("Could not get pubkey from signature: ", err)
+ return nil
+ }
+ return pub
}
func (self *Message) Encrypt(to *ecdsa.PublicKey) (err error) {