measure.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "crypto_auth.h"
  2. #include "randombytes.h"
  3. #include "cpucycles.h"
  4. extern void printentry(long long,const char *,long long *,long long);
  5. extern unsigned char *alignedcalloc(unsigned long long);
  6. extern const char *primitiveimplementation;
  7. extern const char *implementationversion;
  8. extern const char *sizenames[];
  9. extern const long long sizes[];
  10. extern void allocate(void);
  11. extern void measure(void);
  12. const char *primitiveimplementation = crypto_auth_IMPLEMENTATION;
  13. const char *implementationversion = crypto_auth_VERSION;
  14. const char *sizenames[] = { "outputbytes", "keybytes", 0 };
  15. const long long sizes[] = { crypto_auth_BYTES, crypto_auth_KEYBYTES };
  16. #define MAXTEST_BYTES 4096
  17. #ifdef SUPERCOP
  18. #define MGAP 8192
  19. #else
  20. #define MGAP 8
  21. #endif
  22. static unsigned char *k;
  23. static unsigned char *m;
  24. static unsigned char *h;
  25. void preallocate(void)
  26. {
  27. }
  28. void allocate(void)
  29. {
  30. k = alignedcalloc(crypto_auth_KEYBYTES);
  31. m = alignedcalloc(MAXTEST_BYTES);
  32. h = alignedcalloc(crypto_auth_BYTES);
  33. }
  34. #define TIMINGS 15
  35. static long long cycles[TIMINGS + 1];
  36. void measure(void)
  37. {
  38. int i;
  39. int loop;
  40. int mlen;
  41. for (loop = 0;loop < LOOPS;++loop) {
  42. for (mlen = 0;mlen <= MAXTEST_BYTES;mlen += 1 + mlen / MGAP) {
  43. randombytes(k,crypto_auth_KEYBYTES);
  44. randombytes(m,mlen);
  45. randombytes(h,crypto_auth_BYTES);
  46. for (i = 0;i <= TIMINGS;++i) {
  47. cycles[i] = cpucycles();
  48. crypto_auth(h,m,mlen,k);
  49. }
  50. for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
  51. printentry(mlen,"cycles",cycles,TIMINGS);
  52. for (i = 0;i <= TIMINGS;++i) {
  53. cycles[i] = cpucycles();
  54. crypto_auth_verify(h,m,mlen,k);
  55. }
  56. for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
  57. printentry(mlen,"verify_cycles",cycles,TIMINGS);
  58. }
  59. }
  60. }