From 1f6765d9ba5df9ff2089a197a64e335e04206c37 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Sun, 18 Jan 2015 11:18:09 -0600 Subject: move attempts to a constant and add a comment about it --- src/cryptography/hazmat/primitives/asymmetric/rsa.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cryptography/hazmat/primitives/asymmetric/rsa.py b/src/cryptography/hazmat/primitives/asymmetric/rsa.py index d267c387..47bdf5cb 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/rsa.py +++ b/src/cryptography/hazmat/primitives/asymmetric/rsa.py @@ -121,6 +121,12 @@ def rsa_crt_dmq1(private_exponent, q): return private_exponent % (q - 1) +# Controls the number of iterations rsa_recover_prime_factors will perform +# to obtain the prime factors. Each iteration increments by 2 so the actual +# maximum attempts is half this number. +_MAX_RECOVERY_ATTEMPTS = 1000 + + def rsa_recover_prime_factors(n, e, d): """ Compute factors p and q from the private exponent d. We assume that n has @@ -140,7 +146,7 @@ def rsa_recover_prime_factors(n, e, d): # as Factorization", M. Rabin, 1979 spotted = False a = 2 - while not spotted and a < 1000: + while not spotted and a < _MAX_RECOVERY_ATTEMPTS: k = t # Cycle through all values a^{t*2^i}=a^k while k < ktot: -- cgit v1.2.3