diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-02 09:53:34 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-02 09:53:34 -0400 |
commit | e2967396ac73cb7410787886cdaf072a184ffc49 (patch) | |
tree | 527a74d25a4a0705fc641994fd35bfab22662034 /nacl/crypto_auth/measure.c | |
parent | 8928c817df345f29aa0b194743595aa11bd6a8ba (diff) |
Added NaCl crypto library.
Diffstat (limited to 'nacl/crypto_auth/measure.c')
-rw-r--r-- | nacl/crypto_auth/measure.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/nacl/crypto_auth/measure.c b/nacl/crypto_auth/measure.c new file mode 100644 index 00000000..e5209903 --- /dev/null +++ b/nacl/crypto_auth/measure.c | |||
@@ -0,0 +1,69 @@ | |||
1 | #include "crypto_auth.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_auth_IMPLEMENTATION; | ||
15 | const char *implementationversion = crypto_auth_VERSION; | ||
16 | const char *sizenames[] = { "outputbytes", "keybytes", 0 }; | ||
17 | const long long sizes[] = { crypto_auth_BYTES, crypto_auth_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_auth_KEYBYTES); | ||
37 | m = alignedcalloc(MAXTEST_BYTES); | ||
38 | h = alignedcalloc(crypto_auth_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_auth_KEYBYTES); | ||
53 | randombytes(m,mlen); | ||
54 | randombytes(h,crypto_auth_BYTES); | ||
55 | for (i = 0;i <= TIMINGS;++i) { | ||
56 | cycles[i] = cpucycles(); | ||
57 | crypto_auth(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_auth_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 | } | ||