aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-04-06 01:31:18 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-04-07 18:48:19 +0800
commit3f306f63d48f011a527e301e3bf9aec2d6efb7e1 (patch)
tree527dc3f1c6a0ededd135c4fe7236454a3a300308 /crypto
parent7c583f82228fb373dd6bbe15effb68cf5aac0ad9 (diff)
downloaddexon-3f306f63d48f011a527e301e3bf9aec2d6efb7e1.tar
dexon-3f306f63d48f011a527e301e3bf9aec2d6efb7e1.tar.gz
dexon-3f306f63d48f011a527e301e3bf9aec2d6efb7e1.tar.bz2
dexon-3f306f63d48f011a527e301e3bf9aec2d6efb7e1.tar.lz
dexon-3f306f63d48f011a527e301e3bf9aec2d6efb7e1.tar.xz
dexon-3f306f63d48f011a527e301e3bf9aec2d6efb7e1.tar.zst
dexon-3f306f63d48f011a527e301e3bf9aec2d6efb7e1.zip
Forward and log EC recover err and remove dup pubkey len check
Diffstat (limited to 'crypto')
-rw-r--r--crypto/crypto.go16
1 files changed, 7 insertions, 9 deletions
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) {