From 1a32bdf92cceb7a42e5636e12d95609e17b8f786 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 11 Dec 2017 22:49:09 +0100 Subject: crypto: fix error check in toECDSA (#15632) With this change, key, err := crypto.HexToECDSA("000000...") returns nil key and an error instead of a non-nil key with nil X and Y inside. Issue found by @guidovranken. --- crypto/crypto.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'crypto/crypto.go') diff --git a/crypto/crypto.go b/crypto/crypto.go index 8161769d3..3a98bfb50 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -98,6 +98,9 @@ func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) { } priv.D = new(big.Int).SetBytes(d) priv.PublicKey.X, priv.PublicKey.Y = priv.PublicKey.Curve.ScalarBaseMult(d) + if priv.PublicKey.X == nil { + return nil, errors.New("invalid private key") + } return priv, nil } -- cgit