aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2015-01-18 11:18:09 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2015-01-18 11:18:09 -0600
commit1f6765d9ba5df9ff2089a197a64e335e04206c37 (patch)
tree456d9ec10fe0c9c29c69030832961ade9f90a1a9 /src
parentaca05e6c7d7efff451c3f149d0e9e12d34a63a9f (diff)
downloadcryptography-1f6765d9ba5df9ff2089a197a64e335e04206c37.tar.gz
cryptography-1f6765d9ba5df9ff2089a197a64e335e04206c37.tar.bz2
cryptography-1f6765d9ba5df9ff2089a197a64e335e04206c37.zip
move attempts to a constant and add a comment about it
Diffstat (limited to 'src')
-rw-r--r--src/cryptography/hazmat/primitives/asymmetric/rsa.py8
1 files changed, 7 insertions, 1 deletions
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: