Browse Source

Mixing chocolate with shit.

I am adding here what I believe is a wrong measure for the strength of a ssl
key.  Unfortunately I have no time to discuss this more with my teacher, so I am
leaving this note hoping to revert this commit after 14/03.
Michele Orrù 10 years ago
parent
commit
60e5dcabf2
2 changed files with 56 additions and 2 deletions
  1. 54 2
      src/questions/dixon.c
  2. 2 0
      src/questions/include/qdixon.h

+ 54 - 2
src/questions/dixon.c

@@ -20,6 +20,7 @@
 #include <assert.h>
 #include <string.h>
 #include <strings.h>
+#include <time.h>
 
 #include <openssl/bn.h>
 
@@ -156,8 +157,8 @@ discover_smooth(BIGNUM *y, BIGNUM *x, BIGNUM *n,
 }
 
 
-static RSA*
-dixon_question_ask_rsa(const RSA *rsa)
+RSA*
+dixon_factorize(const RSA *rsa)
 {
   /*
    * take exp(sqrt(ln N ln ln N))
@@ -308,6 +309,57 @@ dixon_question_ask_rsa(const RSA *rsa)
   return ret;
 }
 
+
+/**
+ * \brief Measuring the strength of a RSA key.
+ *
+ * Note that I assume this function to be shit. I did not have had enough time
+ * to discuss this with my professor, and furthermore I believe this to be an
+ * incorrect measure: inaffidable, defective, and misleading. It is being
+ * written anyway in order to make him happy.
+ */
+static RSA*
+dixon_question_ask_rsa(const RSA* rsa)
+{
+#ifdef HAVE_OPENMPI
+  return dixon_factorize(rsa);
+#else
+  time_t start, end;
+  /* see factorization function */
+  int primes = 3 * (BN_num_bits(rsa->n) * 10) / 2;
+  BIGNUM
+    *x = BN_new(),
+    *y = BN_new();
+  BN_CTX *ctx = BN_CTX_new();
+  char *v;
+  int count;
+  static const int wait = 60;
+
+
+  v = malloc(sizeof(char) * primes);
+  /* XXX. control error (return -1) here. */
+  time(&start);
+  end = start;
+  for (count = 0; end - wait < start; time(&end)) {
+    fprintf(stderr, "discovering: %dth..\r", count);
+    BN_pseudo_rand_range(x, rsa->n);
+    /* yᵢ = xᵢ² - N */
+    BN_sqr(y, x, ctx);
+    BN_sub(y, y, rsa->n);
+
+    if (dixon_smooth(y, ctx, v, primes)) count++;
+  }
+
+  fprintf(stderr,
+          "\nIn %.2f minutes %d smooth numbers"
+          "have been discovered\n", (float) end - start, count);
+
+  BN_CTX_free(ctx);
+  BN_free(x);
+  BN_free(y);
+  return NULL;
+#endif
+}
 qa_question_t DixonQuestion = {
   .name = "dixon",
   .pretty_name = "Dixon's Factorization",

+ 2 - 0
src/questions/include/qdixon.h

@@ -23,4 +23,6 @@ void discover_smooth(BIGNUM *y, BIGNUM *x, BIGNUM *n,
 
 int dixon_smooth(BIGNUM *x, BN_CTX *ctx, char *v, size_t len);
 
+
+RSA *dixon_factorize(const RSA *rsa);
 #endif /* _QA_DIXON_H_ */