diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-04-05 20:40:40 +0000 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-04-05 21:03:20 +0000 |
commit | d7c699d9935ce2f99419faf81909b36409171705 (patch) | |
tree | 6517ad09be7e1bedf1d465b3880cf4e5cc51afe8 /src/crypto/rsa/rsa.go | |
parent | 7e0d66020c49ef56158346ce18dc3f538393829e (diff) | |
download | go-d7c699d9935ce2f99419faf81909b36409171705.tar.gz go-d7c699d9935ce2f99419faf81909b36409171705.zip |
crypto/rsa, crypto/ecdsa: fail earlier on zero parameters
Change-Id: Ia6ed49d5ef3a256a55e6d4eaa1b4d9f0fc447013
Reviewed-on: https://go-review.googlesource.com/21560
Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/crypto/rsa/rsa.go')
-rw-r--r-- | src/crypto/rsa/rsa.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go index 3f353f891f..594305631b 100644 --- a/src/crypto/rsa/rsa.go +++ b/src/crypto/rsa/rsa.go @@ -465,6 +465,9 @@ func decrypt(random io.Reader, priv *PrivateKey, c *big.Int) (m *big.Int, err er err = ErrDecryption return } + if priv.N.Sign() == 0 { + return nil, ErrDecryption + } var ir *big.Int if random != nil { @@ -490,7 +493,7 @@ func decrypt(random io.Reader, priv *PrivateKey, c *big.Int) (m *big.Int, err er } } bigE := big.NewInt(int64(priv.E)) - rpowe := new(big.Int).Exp(r, bigE, priv.N) + rpowe := new(big.Int).Exp(r, bigE, priv.N) // N != 0 cCopy := new(big.Int).Set(c) cCopy.Mul(cCopy, rpowe) cCopy.Mod(cCopy, priv.N) |