aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-12-13 05:24:04 +0800
committerobscuren <geffobscura@gmail.com>2014-12-13 05:24:04 +0800
commit06e76422b5848283fac78b80ca7a392591bc58e4 (patch)
tree9dc21e6d7ebb028ddffc8ba393ab75552bbeeb4c
parent1c7fd62e5797be0a6fb79459137152e473f66191 (diff)
downloaddexon-06e76422b5848283fac78b80ca7a392591bc58e4.tar.gz
dexon-06e76422b5848283fac78b80ca7a392591bc58e4.tar.zst
dexon-06e76422b5848283fac78b80ca7a392591bc58e4.zip
Added length checkes
-rw-r--r--crypto/crypto.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go
index d70a5a4db..b8fd78fa2 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -56,6 +56,10 @@ func Ecrecover(data []byte) []byte {
// New methods using proper ecdsa keys from the stdlib
func ToECDSA(prv []byte) *ecdsa.PrivateKey {
+ if len(prv) == 0 {
+ return nil
+ }
+
priv := new(ecdsa.PrivateKey)
priv.PublicKey.Curve = S256()
priv.D = ethutil.BigD(prv)
@@ -64,14 +68,27 @@ func ToECDSA(prv []byte) *ecdsa.PrivateKey {
}
func FromECDSA(prv *ecdsa.PrivateKey) []byte {
+ if prv == nil {
+ return nil
+ }
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)
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) {
return ecdsa.GenerateKey(S256(), rand.Reader)
}