Changes to update Tomato RAF.
[tomato.git] / release / src / router / dnscrypt / src / libnacl / crypto_stream / measure.c
blobff3ab61078b6a919f591836531d5e313bf53ffb0
1 #include <stdlib.h>
2 #include "randombytes.h"
3 #include "cpucycles.h"
4 #include "crypto_stream.h"
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);
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 };
20 #define MAXTEST_BYTES 4096
21 #ifdef SUPERCOP
22 #define MGAP 8192
23 #else
24 #define MGAP 8
25 #endif
27 static unsigned char *k;
28 static unsigned char *n;
29 static unsigned char *m;
30 static unsigned char *c;
32 void preallocate(void)
36 void allocate(void)
38 k = alignedcalloc(crypto_stream_KEYBYTES);
39 n = alignedcalloc(crypto_stream_NONCEBYTES);
40 m = alignedcalloc(MAXTEST_BYTES);
41 c = alignedcalloc(MAXTEST_BYTES);
44 #define TIMINGS 15
45 static long long cycles[TIMINGS + 1];
47 void measure(void)
49 int i;
50 int loop;
51 int mlen;
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);
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);
69 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
70 printentry(mlen,"xor_cycles",cycles,TIMINGS);