Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5. #include <time.h>
  6. #include <assert.h>
  7. #include "u512.h"
  8. #include "fp.h"
  9. #include "mont.h"
  10. #include "csidh.h"
  11. void u512_print(u512 const *x)
  12. {
  13. for (size_t i = 63; i < 64; --i)
  14. printf("%02hhx", i[(unsigned char *) x->c]);
  15. }
  16. void fp_print(fp const *x)
  17. {
  18. u512 y;
  19. fp_dec(&y, x);
  20. u512_print(&y);
  21. }
  22. int main()
  23. {
  24. clock_t t0, t1;
  25. private_key priv_alice, priv_bob;
  26. public_key pub_alice, pub_bob;
  27. public_key shared_alice, shared_bob;
  28. printf("\n");
  29. t0 = clock();
  30. csidh_private(&priv_alice);
  31. t1 = clock();
  32. printf("Alice's private key (%7.3lf ms):\n ", 1000. * (t1 - t0) / CLOCKS_PER_SEC);
  33. for (size_t i = 0; i < sizeof(priv_alice); ++i)
  34. printf("%02hhx", i[(uint8_t *) &priv_alice]);
  35. printf("\n\n");
  36. t0 = clock();
  37. csidh_private(&priv_bob);
  38. t1 = clock();
  39. printf("Bob's private key (%7.3lf ms):\n ", 1000. * (t1 - t0) / CLOCKS_PER_SEC);
  40. for (size_t i = 0; i < sizeof(priv_bob); ++i)
  41. printf("%02hhx", i[(uint8_t *) &priv_bob]);
  42. printf("\n\n");
  43. t0 = clock();
  44. assert(csidh(&pub_alice, &base, &priv_alice));
  45. t1 = clock();
  46. printf("Alice's public key (%7.3lf ms):\n ", 1000. * (t1 - t0) / CLOCKS_PER_SEC);
  47. fp_print(&pub_alice.A);
  48. printf("\n\n");
  49. t0 = clock();
  50. assert(csidh(&pub_bob, &base, &priv_bob));
  51. t1 = clock();
  52. printf("Bob's public key (%7.3lf ms):\n ", 1000. * (t1 - t0) / CLOCKS_PER_SEC);
  53. fp_print(&pub_bob.A);
  54. printf("\n\n");
  55. t0 = clock();
  56. assert(csidh(&shared_alice, &pub_bob, &priv_alice));
  57. t1 = clock();
  58. printf("Alice's shared secret (%7.3lf ms):\n ", 1000. * (t1 - t0) / CLOCKS_PER_SEC);
  59. fp_print(&shared_alice.A);
  60. printf("\n\n");
  61. t0 = clock();
  62. assert(csidh(&shared_bob, &pub_alice, &priv_bob));
  63. t1 = clock();
  64. printf("Bob's shared secret (%7.3lf ms):\n ", 1000. * (t1 - t0) / CLOCKS_PER_SEC);
  65. fp_print(&shared_bob.A);
  66. printf("\n\n");
  67. printf(" ");
  68. if (memcmp(&shared_alice, &shared_bob, sizeof(public_key)))
  69. printf("\x1b[31mNOT EQUAL!\x1b[0m\n");
  70. else
  71. printf("\x1b[32mequal.\x1b[0m\n");
  72. printf("\n");
  73. printf("\n");
  74. }