aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/rsa/rsa.go
diff options
context:
space:
mode:
authorAdam Langley <agl@golang.org>2015-06-27 14:50:39 -0700
committerRuss Cox <rsc@golang.org>2015-06-29 19:32:48 +0000
commit2814906df029aea2130c7065d12be85634229861 (patch)
tree893716a831dc1fcd94317e2cfda81ee0ee9ad1aa /src/crypto/rsa/rsa.go
parent9b2d84efc896b50b5d143fed4fe128237a864a72 (diff)
downloadgo-2814906df029aea2130c7065d12be85634229861.tar.gz
go-2814906df029aea2130c7065d12be85634229861.zip
crypto/rsa: check for primes ≤ 1 in Validate
Change 7c7126cfeb82894229b9c3d5109e4b04e6cfde0c removed the primality checking in Validate to save CPU time. That check happened to be filtering out private keys with primes that were zero or one. Without that filtering, such primes cause a panic when trying to use such a private key. This change specifically checks for and rejects primes ≤ 1 in Validate. Fixes #11233. Change-Id: Ie6537edb8250c07a45aaf50dab43227002ee7386 Reviewed-on: https://go-review.googlesource.com/11611 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/crypto/rsa/rsa.go')
-rw-r--r--src/crypto/rsa/rsa.go4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go
index 8a6014a5dc..1293b78367 100644
--- a/src/crypto/rsa/rsa.go
+++ b/src/crypto/rsa/rsa.go
@@ -146,6 +146,10 @@ func (priv *PrivateKey) Validate() error {
// Check that Πprimes == n.
modulus := new(big.Int).Set(bigOne)
for _, prime := range priv.Primes {
+ // Any primes ≤ 1 will cause divide-by-zero panics later.
+ if prime.Cmp(bigOne) <= 0 {
+ return errors.New("crypto/rsa: invalid prime value")
+ }
modulus.Mul(modulus, prime)
}
if modulus.Cmp(priv.N) != 0 {