summaryrefslogtreecommitdiff
path: root/nacl/crypto_onetimeauth/measure.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/crypto_onetimeauth/measure.c')
-rw-r--r--nacl/crypto_onetimeauth/measure.c69
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
5extern void printentry(long long,const char *,long long *,long long);
6extern unsigned char *alignedcalloc(unsigned long long);
7extern const char *primitiveimplementation;
8extern const char *implementationversion;
9extern const char *sizenames[];
10extern const long long sizes[];
11extern void allocate(void);
12extern void measure(void);
13
14const char *primitiveimplementation = crypto_onetimeauth_IMPLEMENTATION;
15const char *implementationversion = crypto_onetimeauth_VERSION;
16const char *sizenames[] = { "outputbytes", "keybytes", 0 };
17const 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
26static unsigned char *k;
27static unsigned char *m;
28static unsigned char *h;
29
30void preallocate(void)
31{
32}
33
34void 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
42static long long cycles[TIMINGS + 1];
43
44void 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}