diff options
Diffstat (limited to 'nacl/crypto_stream/measure.c')
-rw-r--r-- | nacl/crypto_stream/measure.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/nacl/crypto_stream/measure.c b/nacl/crypto_stream/measure.c new file mode 100644 index 00000000..ff3ab610 --- /dev/null +++ b/nacl/crypto_stream/measure.c | |||
@@ -0,0 +1,73 @@ | |||
1 | #include <stdlib.h> | ||
2 | #include "randombytes.h" | ||
3 | #include "cpucycles.h" | ||
4 | #include "crypto_stream.h" | ||
5 | |||
6 | extern void printentry(long long,const char *,long long *,long long); | ||
7 | extern unsigned char *alignedcalloc(unsigned long long); | ||
8 | extern const char *primitiveimplementation; | ||
9 | extern const char *implementationversion; | ||
10 | extern const char *sizenames[]; | ||
11 | extern const long long sizes[]; | ||
12 | extern void allocate(void); | ||
13 | extern void measure(void); | ||
14 | |||
15 | const char *primitiveimplementation = crypto_stream_IMPLEMENTATION; | ||
16 | const char *implementationversion = crypto_stream_VERSION; | ||
17 | const char *sizenames[] = { "keybytes", "noncebytes", 0 }; | ||
18 | const long long sizes[] = { crypto_stream_KEYBYTES, crypto_stream_NONCEBYTES }; | ||
19 | |||
20 | #define MAXTEST_BYTES 4096 | ||
21 | #ifdef SUPERCOP | ||
22 | #define MGAP 8192 | ||
23 | #else | ||
24 | #define MGAP 8 | ||
25 | #endif | ||
26 | |||
27 | static unsigned char *k; | ||
28 | static unsigned char *n; | ||
29 | static unsigned char *m; | ||
30 | static unsigned char *c; | ||
31 | |||
32 | void preallocate(void) | ||
33 | { | ||
34 | } | ||
35 | |||
36 | void allocate(void) | ||
37 | { | ||
38 | k = alignedcalloc(crypto_stream_KEYBYTES); | ||
39 | n = alignedcalloc(crypto_stream_NONCEBYTES); | ||
40 | m = alignedcalloc(MAXTEST_BYTES); | ||
41 | c = alignedcalloc(MAXTEST_BYTES); | ||
42 | } | ||
43 | |||
44 | #define TIMINGS 15 | ||
45 | static long long cycles[TIMINGS + 1]; | ||
46 | |||
47 | void measure(void) | ||
48 | { | ||
49 | int i; | ||
50 | int loop; | ||
51 | int mlen; | ||
52 | |||
53 | for (loop = 0;loop < LOOPS;++loop) { | ||
54 | for (mlen = 0;mlen <= MAXTEST_BYTES;mlen += 1 + mlen / MGAP) { | ||
55 | randombytes(k,crypto_stream_KEYBYTES); | ||
56 | randombytes(n,crypto_stream_NONCEBYTES); | ||
57 | randombytes(m,mlen); | ||
58 | randombytes(c,mlen); | ||
59 | for (i = 0;i <= TIMINGS;++i) { | ||
60 | cycles[i] = cpucycles(); | ||
61 | crypto_stream(c,mlen,n,k); | ||
62 | } | ||
63 | for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i]; | ||
64 | printentry(mlen,"cycles",cycles,TIMINGS); | ||
65 | for (i = 0;i <= TIMINGS;++i) { | ||
66 | cycles[i] = cpucycles(); | ||
67 | crypto_stream_xor(c,m,mlen,n,k); | ||
68 | } | ||
69 | for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i]; | ||
70 | printentry(mlen,"xor_cycles",cycles,TIMINGS); | ||
71 | } | ||
72 | } | ||
73 | } | ||