Skip to content
This repository was archived by the owner on Jan 27, 2022. It is now read-only.

Commit 7acba5f

Browse files
wbolsterdlitz
authored andcommitted
Increase attempts for recovering RSA (p,q) from (n,e,d)
Bump the maximum number of iterations to recover (p,q) given (n,e,d) to increase the chance that the algorithm succeeds. The algorithm used is a probabilistic one with a 1/2 chance of finding the right value in each iteration, so it's likely that only a few iterations are needed. However, in some extreme cases this may still fail. Bumping the maximum number allow the algorithm to correctly find the right values for these cases. This changes bumps the number of iterations from 50 to 500 (the value 'a' is increased by 2 in each step), and hence reduces the chance of failure from 2**-50 to 2**-500. Note that this change does *not* result in a performance degradation.
1 parent 13fcb9e commit 7acba5f

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/Crypto/PublicKey/_slowmath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def rsa_construct(n, e, d=None, p=None, q=None, u=None):
113113
# as Factorization", M. Rabin, 1979
114114
spotted = 0
115115
a = 2
116-
while not spotted and a<100:
116+
while not spotted and a<1000:
117117
k = t
118118
# Cycle through all values a^{t*2^i}=a^k
119119
while k<ktot:

src/_fastmath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ static int factorize_N_from_D(rsaKey *key)
616616
cnt = mpz_scan1(t, 0);
617617
mpz_fdiv_q_2exp(t,t,cnt);
618618
mpz_set_ui(a, 2);
619-
for (spotted=0; (!spotted) && (mpz_cmp_ui(a,100)<0); mpz_add_ui(a,a,2)) {
619+
for (spotted=0; (!spotted) && (mpz_cmp_ui(a,1000)<0); mpz_add_ui(a,a,2)) {
620620
mpz_set(k, t);
621621
for (; (mpz_cmp(k,ktot)<0); mpz_mul_ui(k,k,2)) {
622622
mpz_powm(cand,a,k,key->n);

0 commit comments

Comments
 (0)