diff options
Diffstat (limited to 'nacl/crypto_onetimeauth/measure.c')
-rw-r--r-- | nacl/crypto_onetimeauth/measure.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/nacl/crypto_onetimeauth/measure.c b/nacl/crypto_onetimeauth/measure.c new file mode 100644 index 00000000..6d3ddfd5 --- /dev/null +++ b/nacl/crypto_onetimeauth/measure.c | |||
@@ -0,0 +1,69 @@ | |||
1 | #include "crypto_onetimeauth.h" | ||
2 | #include "randombytes.h" | ||
3 | #include "cpucycles.h" | ||
4 | |||
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); | ||
13 | |||
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 }; | ||
18 | |||
19 | #define MAXTEST_BYTES 4096 | ||
20 | #ifdef SUPERCOP | ||
21 | #define MGAP 8192 | ||
22 | #else | ||
23 | #define MGAP 8 | ||
24 | #endif | ||
25 | |||
26 | static unsigned char *k; | ||
27 | static unsigned char *m; | ||
28 | static unsigned char *h; | ||
29 | |||
30 | void preallocate(void) | ||
31 | { | ||
32 | } | ||
33 | |||
34 | void allocate(void) | ||
35 | { | ||
36 | k = alignedcalloc(crypto_onetimeauth_KEYBYTES); | ||
37 | m = alignedcalloc(MAXTEST_BYTES); | ||
38 | h = alignedcalloc(crypto_onetimeauth_BYTES); | ||
39 | } | ||
40 | |||
41 | #define TIMINGS 15 | ||
42 | static long long cycles[TIMINGS + 1]; | ||
43 | |||
44 | void measure(void) | ||
45 | { | ||
46 | int i; | ||
47 | int loop; | ||
48 | int mlen; | ||
49 | |||
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); | ||
58 | } | ||
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); | ||
64 | } | ||
65 | for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i]; | ||
66 | printentry(mlen,"verify_cycles",cycles,TIMINGS); | ||
67 | } | ||
68 | } | ||
69 | } | ||