Changes to update Tomato RAF.
[tomato.git] / release / src / router / dnscrypt / src / libnacl / crypto_onetimeauth / measure.c
blob6d3ddfd52be0811539807ace63f04d71c9587df2
1 #include "crypto_onetimeauth.h"
2 #include "randombytes.h"
3 #include "cpucycles.h"
5 extern void printentry(long long,const char *,long long *,long long);
6 extern unsigned char *alignedcalloc(unsigned long long);
7 extern const char *primitiveimplementation;
8 extern const char *implementationversion;
9 extern const char *sizenames[];
10 extern const long long sizes[];
11 extern void allocate(void);
12 extern void measure(void);
14 const char *primitiveimplementation = crypto_onetimeauth_IMPLEMENTATION;
15 const char *implementationversion = crypto_onetimeauth_VERSION;
16 const char *sizenames[] = { "outputbytes", "keybytes", 0 };
17 const long long sizes[] = { crypto_onetimeauth_BYTES, crypto_onetimeauth_KEYBYTES };
19 #define MAXTEST_BYTES 4096
20 #ifdef SUPERCOP
21 #define MGAP 8192
22 #else
23 #define MGAP 8
24 #endif
26 static unsigned char *k;
27 static unsigned char *m;
28 static unsigned char *h;
30 void preallocate(void)
34 void allocate(void)
36 k = alignedcalloc(crypto_onetimeauth_KEYBYTES);
37 m = alignedcalloc(MAXTEST_BYTES);
38 h = alignedcalloc(crypto_onetimeauth_BYTES);
41 #define TIMINGS 15
42 static long long cycles[TIMINGS + 1];
44 void measure(void)
46 int i;
47 int loop;
48 int mlen;
50 for (loop = 0;loop < LOOPS;++loop) {
51 for (mlen = 0;mlen <= MAXTEST_BYTES;mlen += 1 + mlen / MGAP) {
52 randombytes(k,crypto_onetimeauth_KEYBYTES);
53 randombytes(m,mlen);
54 randombytes(h,crypto_onetimeauth_BYTES);
55 for (i = 0;i <= TIMINGS;++i) {
56 cycles[i] = cpucycles();
57 crypto_onetimeauth(h,m,mlen,k);
59 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
60 printentry(mlen,"cycles",cycles,TIMINGS);
61 for (i = 0;i <= TIMINGS;++i) {
62 cycles[i] = cpucycles();
63 crypto_onetimeauth_verify(h,m,mlen,k);
65 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
66 printentry(mlen,"verify_cycles",cycles,TIMINGS);