From: Robert Griesemer Date: Tue, 5 Apr 2016 16:44:00 +0000 (-0700) Subject: crypto/dsa: eliminate invalid PublicKey early X-Git-Tag: go1.7beta1~893 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=eb876dd83cb8413335d64e50aae5d38337d1ebb4;p=gostls13.git crypto/dsa: eliminate invalid PublicKey early For PublicKey.P == 0, Verify will fail. Don't even try. Change-Id: I1009f2b3dead8d0041626c946633acb10086d8c8 Reviewed-on: https://go-review.googlesource.com/21533 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/crypto/dsa/dsa.go b/src/crypto/dsa/dsa.go index 96768ce2a0..e9b6a0c253 100644 --- a/src/crypto/dsa/dsa.go +++ b/src/crypto/dsa/dsa.go @@ -247,6 +247,10 @@ func Sign(rand io.Reader, priv *PrivateKey, hash []byte) (r, s *big.Int, err err func Verify(pub *PublicKey, hash []byte, r, s *big.Int) bool { // FIPS 186-3, section 4.7 + if pub.P.Sign() == 0 { + return false + } + if r.Sign() < 1 || r.Cmp(pub.Q) >= 0 { return false }