Przeglądaj źródła

Experimenting with OpenMPI.

Michele Orrù 11 lat temu
rodzic
commit
0d853f080f
4 zmienionych plików z 56 dodań i 14 usunięć
  1. 8 2
      configure.ac
  2. 34 11
      src/qa.c
  3. 8 1
      src/questions/allquestions.c
  4. 6 0
      src/questions/include/questions.h

+ 8 - 2
configure.ac

@@ -5,10 +5,10 @@ AC_PREREQ([2.65])
 AC_INIT([question_authority], [0.1], [maker@tumbolandia.net])
 AM_INIT_AUTOMAKE
 AC_CONFIG_SRCDIR([src/qa.c])
-AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_HEADERS([src/include/config.h])
 
 # Checks for programs.
-AC_PROG_CC([clang gcc cc])
+AC_PROG_CC([mpicc clang gcc cc])
 AC_PROG_CC_C99
 AC_PROG_RANLIB
 
@@ -20,6 +20,8 @@ AC_CHECK_HEADER(bsd/sys/queue.h, [:],
                 [AC_MSG_ERROR([Could not find or include bsd queues. Please install libbsd-dev.])])
 AC_CHECK_HEADERS([openssl/ssl.h openssl/bn.h openssl/x509.h openssl/rsa.h], [:],
                  AC_MSG_ERROR([Could not find or include openssl headers. Please install libssl-dev.]))
+AC_CHECK_HEADERS(mpi/mpi.h, [:],
+                 AC_MSG_WARN([OpenMPI shall be installed to enable MPI support.]))
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_TYPE_SIZE_T
@@ -37,6 +39,10 @@ AC_ARG_ENABLE(debug,
    AS_HELP_STRING([--enable-debug], [enable debugging, default: no]),
    CFLAGS+=" -DDEBUG -DBN_DEBUG -O0 -ggdb")
 
+AC_ARG_ENABLE(mpi,
+   AS_HELP_STRING([--enable-mpi], [enable mpi library, default:no]),
+   AC_DEFINE([HAVE_OPENMPI], [1], [OpenMPI support]))
+
 AC_OUTPUT([Makefile
            src/Makefile src/questions/Makefile
            src/apps/Makefile

+ 34 - 11
src/qa.c

@@ -5,6 +5,7 @@
  * After retrieving a valid configuration from the frontend, this file takes
  * care of running the actual mainloop.
  */
+#include "config.h"
 
 #include <assert.h>
 #include <error.h>
@@ -12,8 +13,12 @@
 #include <stdint.h>
 #include <string.h>
 #include <unistd.h>
-#include <bsd/sys/queue.h>
 
+#ifdef HAVE_OPENMPI
+#include <mpi.h>
+#endif
+
+#include <bsd/sys/queue.h>
 #include <openssl/err.h>
 #include <openssl/pem.h>
 #include <openssl/ssl.h>
@@ -124,7 +129,6 @@ qa_init(const struct qa_conf* conf)
   bio_out = BIO_new_fp(stdout, BIO_NOCLOSE);
   bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
 
-
   QA_library_init();
 
   if (!conf->attacks) select_all_questions();
@@ -150,15 +154,30 @@ qa_init(const struct qa_conf* conf)
 static int
 qa_dispose(X509 *crt, RSA *rsa)
 {
+  int exit_code = EXIT_SUCCESS;
   RSA *pub;
-  RSA *priv;
+  RSA *priv = NULL;
   qa_question_t *q;
+#ifdef HAVE_OPENMPI
+  int proc, procs, i;
+#endif
 
   if (!rsa && crt)  pub = X509_get_pubkey(crt)->pkey.rsa;
   else pub = rsa;
-
   printf("[+] Certificate acquired\n");
+
+#ifdef HAVE_OPENMPI
+  MPI_Comm_rank(MPI_COMM_WORLD, &proc);
+  MPI_Comm_size(MPI_COMM_WORLD, &procs);
+  i = 0;
+#endif
+
   LIST_FOREACH(q, &questions, qs) {
+
+#ifdef HAVE_OPENMPI
+    if (i++ %  procs != proc) continue;
+#endif
+
     printf( "[-] Running: %s\n", q->pretty_name);
 
     /*
@@ -179,6 +198,11 @@ qa_dispose(X509 *crt, RSA *rsa)
       continue;
     }
 
+    /*
+     * Attempt to attack the X509 certificate.
+     */
+    if (crt && q->ask_crt)  q->ask_crt(crt);
+
     /*
      * Attempt to attack RSA. If the attack went ok, there's no need to go
      * on. Print out a nice message and then quit.
@@ -187,14 +211,10 @@ qa_dispose(X509 *crt, RSA *rsa)
         (priv = q->ask_rsa(pub))) {
       fprintf(stderr, "[\\] Key Broken using %s.\n", q->pretty_name);
       print_rsa_private(priv);
-      return 1;
+      exit_code = EXIT_FAILURE;
+      break;
     }
 
-    /*
-     * Attempt to attack the X509 certificate.
-     */
-    if (crt && q->ask_crt)  q->ask_crt(crt);
-
     /*
      * Shut down the given question. If it fails, print an error messae and go
      * on.
@@ -205,8 +225,11 @@ qa_dispose(X509 *crt, RSA *rsa)
     }
   }
 
+  if (priv) RSA_free(priv);
+  MPI_Abort(MPI_COMM_WORLD, -1);
+  QA_library_del();
   /*
    *  Key seems resistent: exit successfully.
    */
-  return 0;
+  return EXIT_SUCCESS;
 }

+ 8 - 1
src/questions/allquestions.c

@@ -6,12 +6,15 @@
  * Implements procedures for addign and removing questions from the global \ref
  * questions variable.
  */
+#include "config.h"
 
 #include <assert.h>
 #include <string.h>
 #include <bsd/sys/queue.h>
 
 #include <openssl/ssl.h>
+#include <mpi.h>
+
 #include "qa/questions/questions.h"
 
 void QA_library_init(void)
@@ -19,8 +22,12 @@ void QA_library_init(void)
   /* Initialize SSL Library by registering algorithms. */
   SSL_library_init();
   SSL_load_error_strings();
-}
+#ifdef HAVE_OPENMPI
+  /* OpenMPI initialization */
+  MPI_Init(0 , NULL);
+#endif
 
+}
 
 /**
  * \brief Select a single question to be used.

+ 6 - 0
src/questions/include/questions.h

@@ -43,6 +43,12 @@ void select_all_questions(void);
 
 void QA_library_init(void);
 
+#ifdef HAVE_OPENMPI
+#define QA_library_del() MPI_Finalize()
+#else
+#define QA_library_del() ((void) 0)
+#endif
+
 #define REGISTER_QUESTION(q)                      \
   do {                                            \
       extern struct qa_question q;                \