aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-29 21:02:49 +0800
committerobscuren <geffobscura@gmail.com>2015-03-29 21:02:49 +0800
commit61c5edcb57a200764bfa37e3a7da909727a7852b (patch)
treed9bbd2d19cea7a1bcfbe53d2a02252976709c58f /crypto
parentaf153e78849871cff7cef494533fb7f028957083 (diff)
downloaddexon-61c5edcb57a200764bfa37e3a7da909727a7852b.tar
dexon-61c5edcb57a200764bfa37e3a7da909727a7852b.tar.gz
dexon-61c5edcb57a200764bfa37e3a7da909727a7852b.tar.bz2
dexon-61c5edcb57a200764bfa37e3a7da909727a7852b.tar.lz
dexon-61c5edcb57a200764bfa37e3a7da909727a7852b.tar.xz
dexon-61c5edcb57a200764bfa37e3a7da909727a7852b.tar.zst
dexon-61c5edcb57a200764bfa37e3a7da909727a7852b.zip
Cleanup.
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 442942c6c..9a1559fbf 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -68,13 +68,8 @@ func Ripemd160(data []byte) []byte {
return ripemd.Sum(nil)
}
-func Ecrecover(data []byte) []byte {
- var in = struct {
- hash []byte
- sig []byte
- }{data[:32], data[32:]}
-
- r, _ := secp256k1.RecoverPubkey(in.hash, in.sig)
+func Ecrecover(hash, sig []byte) []byte {
+ r, _ := secp256k1.RecoverPubkey(hash, sig)
return r
}
@@ -151,9 +146,12 @@ func GenerateKey() (*ecdsa.PrivateKey, error) {
}
func SigToPub(hash, sig []byte) *ecdsa.PublicKey {
- s := Ecrecover(append(hash, sig...))
- x, y := elliptic.Unmarshal(S256(), s)
+ s := Ecrecover(hash, sig)
+ if s == nil || len(s) != 65 {
+ return nil
+ }
+ x, y := elliptic.Unmarshal(S256(), s)
return &ecdsa.PublicKey{S256(), x, y}
}