You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

9 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "../crypto_sign.h"
  4. #include "../cpucycles.h"
  5. #include "../randombytes.h"
  6. #include "../horst.h"
  7. #include "../wots.h"
  8. #include "../hash.h"
  9. #define MLEN 59
  10. #define REP 1
  11. #define NRUNS 100
  12. static int ull_cmp(const void *a, const void *b)
  13. {
  14. const unsigned long long *ia = (const unsigned long long *)a;
  15. const unsigned long long *ib = (const unsigned long long *)b;
  16. if (*ia > *ib) return 1;
  17. if (*ia < *ib) return -1;
  18. return 0;
  19. }
  20. static const unsigned char seed[32] = {
  21. 0x22, 0x26, 0xb5, 0x64, 0xbb, 0x78, 0xcc, 0xab, 0x4a, 0x4c, 0x0a, 0x64, 0xc2, 0x0b, 0x5d, 0x68,
  22. 0x38, 0x74, 0x1a, 0xc0, 0x03, 0x17, 0xff, 0xd8, 0xe3, 0x53, 0xc8, 0x59, 0xc6, 0x23, 0x5b, 0xaa};
  23. int main()
  24. {
  25. unsigned long long t[NRUNS];
  26. int i,j;
  27. printf("\n=== Benchmarks of signatures ===\n\n");
  28. unsigned char sk[CRYPTO_SECRETKEYBYTES];
  29. unsigned char pk[CRYPTO_PUBLICKEYBYTES];
  30. unsigned char m[MLEN+CRYPTO_BYTES];
  31. unsigned char sm[MLEN+CRYPTO_BYTES];
  32. unsigned long long mlen;
  33. unsigned long long smlen;
  34. unsigned char masks[2*HORST_LOGT*HASH_BYTES];
  35. randombytes(masks,N_MASKS*HASH_BYTES);
  36. unsigned char msg_seed[MSGHASH_BYTES];
  37. randombytes(msg_seed, MSGHASH_BYTES);
  38. //Benchmarking signature key generation
  39. for(i=0;i<NRUNS;i++)
  40. {
  41. t[i] = cpucycles();
  42. for(j=0;j<REP;j++)
  43. crypto_sign_keypair(pk, sk);
  44. }
  45. for(i=0;i<NRUNS-1;i++)
  46. t[i] = (t[i+1] - t[i]);
  47. qsort(t, NRUNS-1, sizeof(unsigned long long), ull_cmp);
  48. printf("keypair: %13.3lf\n", (double)t[NRUNS/2-1]/REP);
  49. //Benchmarking signature generation
  50. for(i=0;i<NRUNS;i++)
  51. {
  52. t[i] = cpucycles();
  53. for(j=0;j<REP;j++)
  54. crypto_sign(sm, &smlen, m, MLEN, sk);
  55. }
  56. for(i=0;i<NRUNS-1;i++)
  57. t[i] = (t[i+1] - t[i]);
  58. qsort(t, NRUNS-1, sizeof(unsigned long long), ull_cmp);
  59. printf("sign: %13.3lf\n", (double)t[NRUNS/2-1]/REP);
  60. //Benchmarking signature verification
  61. for(i=0;i<NRUNS;i++)
  62. {
  63. t[i] = cpucycles();
  64. for(j=0;j<REP;j++)
  65. crypto_sign_open(m, &mlen, sm, smlen, pk);
  66. }
  67. for(i=0;i<NRUNS-1;i++)
  68. t[i] = (t[i+1] - t[i]);
  69. qsort(t, NRUNS-1, sizeof(unsigned long long), ull_cmp);
  70. printf("sign_open: %13.3lf\n", (double)t[NRUNS/2-1]/REP);
  71. //Benchmarking WOTS pkgen
  72. for(i=0;i<NRUNS;i++)
  73. {
  74. t[i] = cpucycles();
  75. for(j=0;j<REP;j++)
  76. wots_pkgen(sm, seed, masks);
  77. }
  78. for(i=0;i<NRUNS-1;i++)
  79. t[i] = (t[i+1] - t[i]);
  80. qsort(t, NRUNS-1, sizeof(unsigned long long), ull_cmp);
  81. printf("wots_pkgen: %13.3lf\n", (double)t[NRUNS/2-1]/REP);
  82. printf("416*wots_pkgen: %13.3lf\n", 416*(double)t[NRUNS/2-1]/REP);
  83. //Benchmarking HORSt signing
  84. for(i=0;i<NRUNS;i++)
  85. {
  86. t[i] = cpucycles();
  87. for(j=0;j<REP;j++)
  88. horst_sign(sm, pk, &smlen, m, MLEN, seed, masks, msg_seed);
  89. }
  90. for(i=0;i<NRUNS-1;i++)
  91. t[i] = (t[i+1] - t[i]);
  92. qsort(t, NRUNS-1, sizeof(unsigned long long), ull_cmp);
  93. printf("horst_sign: %13.3lf\n", (double)t[NRUNS/2-1]/REP);
  94. //Benchmarking hash_2n_n
  95. for(i=0;i<NRUNS;i++)
  96. {
  97. t[i] = cpucycles();
  98. for(j=0;j<REP;j++)
  99. hash_2n_n(sm, sm);
  100. }
  101. for(i=0;i<NRUNS-1;i++)
  102. t[i] = (t[i+1] - t[i]);
  103. qsort(t, NRUNS-1, sizeof(unsigned long long), ull_cmp);
  104. printf("hash_2n_n: %13.3lf\n", (double)t[NRUNS/2-1]/REP);
  105. return 0;
  106. }