Sfoglia il codice sorgente

Setting iterations limit in wiener attack.

According to "Twenty Years of attacks on the RSA cryptosystem", a valid fraction
resides in log N convergents.
Michele Orrù 11 anni fa
parent
commit
a13b5a1810
2 ha cambiato i file con 4 aggiunte e 10 eliminazioni
  1. 1 1
      src/questions/test/test_wiener.c
  2. 3 9
      src/questions/wiener.c

+ 1 - 1
src/questions/test/test_wiener.c

@@ -162,7 +162,7 @@ void test_BN_sqrtmod(void)
 void test_wiener(void)
 {
   X509 *crt;
-  FILE *fp = fopen("questions/test/wiener_test.crt", "r");
+  FILE *fp = fopen("test/wiener_test.crt", "r");
 
   if (!fp) exit(EXIT_FAILURE);
   crt = PEM_read_X509(fp, NULL, 0, NULL);

+ 3 - 9
src/questions/wiener.c

@@ -138,14 +138,6 @@ bigfraction_t* cf_next(cf_t *f)
   exit(EXIT_FAILURE);
 }
 
-static void BN_int2bn(BIGNUM** a, short int i)
-{
-  if (!*a) *a = BN_new();
-  /* trolololololol. */
-  BN_one(*a);
-  (*a)->d[0] = i;
-}
-
 
 /**
  * \brief Square Root for bignums.
@@ -216,6 +208,7 @@ int wiener_question_ask(X509* cert)
   /* equation coefficients */
   BIGNUM *b2, *delta;
   BN_CTX *ctx;
+  int bits;
 
   rsa = X509_get_pubkey(cert)->pkey.rsa;
   phi = BN_new();
@@ -229,11 +222,12 @@ int wiener_question_ask(X509* cert)
   /*
    * generate the continued fractions approximating e/N
    */
+  bits = BN_num_bits(n);
   cf = cf_init(NULL, e, n);
   ctx = cf->ctx;
   for (i=0, it = cf_next(cf);
        // XXX. how many keys shall I test?
-       i!=100 && it;
+       i!=bits && it;
        i++, it = cf_next(cf)) {
     t = it->h;
     d = it->k;