Skip to content

Commit

Permalink
crypto/rsa: return error if keygen random source is broken
Browse files Browse the repository at this point in the history
Fixes golang#70643

Change-Id: I47c76500bb2e79b0d1dc096651eb45885f6888b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/632896
Reviewed-by: Russ Cox <[email protected]>
Reviewed-by: Roland Shoemaker <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Auto-Submit: Filippo Valsorda <[email protected]>
  • Loading branch information
FiloSottile authored and gopherbot committed Dec 3, 2024
1 parent 106c804 commit 485ed2f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/crypto/internal/fips140/rsa/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func GenerateKey(rand io.Reader, bits int) (*PrivateKey, error) {
return nil, err
}

if Q.Nat().ExpandFor(P).Equal(P.Nat()) == 1 {
return nil, errors.New("rsa: generated p == q, random source is broken")
}

N, err := bigmod.NewModulusProduct(p, q)
if err != nil {
return nil, err
Expand Down

0 comments on commit 485ed2f

Please sign in to comment.