despicable.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * \file despicable.c
  3. * \brief Perform specific factorization attacks on the cluster.
  4. *
  5. *
  6. * Given a cvs file composed of public keys - pairs <n, e> - this file
  7. * iteratively runs a pre-selected attack (see global var *question), eventually
  8. * reporting broken keys to the standard output.
  9. */
  10. #include <openssl/rsa.h>
  11. #include <mpi.h>
  12. #include "qa/questions/questions.h"
  13. extern qa_question_t PollardQuestion;
  14. qa_question_t *question = &PollardQuestion;
  15. int next_pkey(RSA *pub, FILE *fp)
  16. {
  17. static char nbuf[2048];
  18. static char ebuf[10];
  19. if (fscanf(fp, "%s\t%s", nbuf, ebuf) != 2)
  20. return 0;
  21. BN_hex2bn(&pub->n, nbuf);
  22. BN_hex2bn(&pub->e, ebuf);
  23. return 1;
  24. }
  25. int main(int argc, char **argv)
  26. {
  27. FILE *fp;
  28. RSA *rsa;
  29. int proc, procs;
  30. int i;
  31. QA_library_init();
  32. MPI_Comm_rank(MPI_COMM_WORLD, &proc);
  33. MPI_Comm_size(MPI_COMM_WORLD, &procs);
  34. if (argc < 1) return EXIT_FAILURE;
  35. if (!(fp = fopen(argv[argc-1], "r"))) return EXIT_FAILURE;
  36. rsa = RSA_new();
  37. rsa->n = BN_new();
  38. rsa->e = BN_new();
  39. for (i=0; next_pkey(rsa, fp); i = (i+1) % procs) {
  40. if (i != proc) continue;
  41. if (run_question(question, NULL, rsa) == 1) {
  42. BN_print_fp(stdout, rsa->n);
  43. fprintf(stdout, "\t broken\n");
  44. }
  45. }
  46. MPI_Finalize();
  47. return EXIT_SUCCESS;
  48. }