aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2021-04-21 18:54:00 -0400
committerJack Lloyd <[email protected]>2021-04-21 18:54:00 -0400
commit5811aa1341fadc24de0ca0e91b4097be62d738b1 (patch)
tree7012e6b83fb75016e88be98b51a20af69293fef7 /src
parent2d7a3e2617406d98c5deb04fde36a27f49aac5fa (diff)
Don't loop forever if the RSA keygen rng is bad
Diffstat (limited to 'src')
-rw-r--r--src/lib/pubkey/rsa/rsa.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/lib/pubkey/rsa/rsa.cpp b/src/lib/pubkey/rsa/rsa.cpp
index cbea6becc..e1c3c4b0d 100644
--- a/src/lib/pubkey/rsa/rsa.cpp
+++ b/src/lib/pubkey/rsa/rsa.cpp
@@ -286,8 +286,11 @@ RSA_PrivateKey::RSA_PrivateKey(RandomNumberGenerator& rng,
const size_t p_bits = (bits + 1) / 2;
const size_t q_bits = bits - p_bits;
- for(;;)
+ for(size_t attempt = 0; ; ++attempt)
{
+ if(attempt > 10)
+ throw Internal_Error("RNG failure during RSA key generation");
+
// TODO could generate primes in thread pool
p = generate_rsa_prime(rng, rng, p_bits, e);
q = generate_rsa_prime(rng, rng, q_bits, e);