Browse Source

Adopting qa_RSA_recover() in old algorithms.

Michele Orrù 11 years ago
parent
commit
ac55106982

+ 3 - 8
src/questions/dixon.c

@@ -184,7 +184,7 @@ dixon_question_ask_rsa(const RSA *rsa)
   h = kernel(m);
   BN_one(x);
   BN_one(sqy);
-  for (i=0; i!=f; i++)
+  for (i=0; i!=f && !ret; i++)
     /* if we found an even power */
     if (is_vzero(m->M[i], f)) {
       /* compute x, y² */
@@ -197,13 +197,8 @@ dixon_question_ask_rsa(const RSA *rsa)
       assert(!BN_is_zero(rem));
       BN_gcd(gcd, x, y, ctx);
       if (BN_cmp(gcd, rsa->n) < 0 &&
-          BN_cmp(gcd, BN_value_one()) > 0) {
-        ret = RSA_new();
-        ret->p = BN_dup(gcd);
-        ret->q = BN_new();
-        BN_div(ret->q, NULL, ret->p, rsa->n, ctx);
-        ret->n = BN_dup(rsa->n);
-      }
+          BN_cmp(gcd, BN_value_one()) > 0)
+        ret = qa_RSA_recover(rsa, gcd, ctx);
     }
 
   /* free all the shit */

+ 1 - 0
src/questions/include/qarith.h

@@ -37,4 +37,5 @@ bigfraction_t* cf_next(cf_t *f);
 int BN_sqrtmod(BIGNUM* dv, BIGNUM* rem, BIGNUM* a, BN_CTX* ctx);
 
 RSA* qa_RSA_recover(const RSA *rsapub, const BIGNUM *p, BN_CTX *ctx);
+
 #endif /* _QA_ARITH_H_ */

+ 2 - 9
src/questions/pollard.c

@@ -69,7 +69,6 @@ pollard1_question_ask_rsa(const RSA *rsa)
   BIGNUM *a, *B, *a1;
   BIGNUM *gcd, *rem;
   BIGNUM *n;
-  BIGNUM *p, *q;
   BN_CTX *ctx;
 
   n = rsa->n;
@@ -95,14 +94,8 @@ pollard1_question_ask_rsa(const RSA *rsa)
   }
 
   /* Either p or q found :) */
-  if (!BN_is_zero(B)) {
-    ret = RSA_new();
-    ret->n = rsa->n;
-    ret->e = rsa->e;
-    ret->q = q = BN_new();
-    ret->p = p = BN_dup(gcd);
-    BN_div(q, NULL, n, gcd, ctx);
-  }
+  if (!BN_is_zero(B))
+    ret = qa_RSA_recover(rsa, gcd, ctx);
 
   BN_free(a);
   BN_free(B);

+ 2 - 8
src/questions/pollardrho.c

@@ -56,14 +56,8 @@ pollardrho_question_ask_rsa(const RSA *rsa)
     BN_gcd(gcd, tmp, n, ctx);
   }
 
-  if (BN_ucmp(gcd, n) != 0) {
-    ret = RSA_new();
-    ret->n = rsa->n;
-    ret->e = rsa->e;
-    ret->p = BN_dup(gcd);
-    ret->q = BN_new();
-    BN_div(ret->q, NULL, n, gcd, ctx);
-  }
+  if (BN_ucmp(gcd, n) != 0)
+    ret = qa_RSA_recover(rsa, gcd, ctx);
 
   BN_free(tmp);
   BN_free(x);

+ 3 - 8
src/questions/williams+1.c

@@ -111,14 +111,9 @@ williams_question_ask_rsa(const RSA* rsa)
   BN_free(p);
   prime_iterator_free(pit);
 
-  if (BN_ucmp(gcd, n) != 0) {
-    ret = RSA_new();
-    ret->n = rsa->n;
-    ret->e = rsa->e;
-    ret->p = BN_dup(gcd);
-    ret->q = BN_new();
-    BN_div(ret->q, NULL, n, gcd, ctx);
-  }
+  if (BN_ucmp(gcd, n) != 0)
+    ret = qa_RSA_recover(rsa, gcd, ctx);
+
   return ret;
 }