Changes to update Tomato RAF.
[tomato.git] / release / src / router / dnscrypt / src / libnacl / crypto_hash / measure.c
blobcec0404dfba14d675c10491cafe7b5ae254e8fed
1 #include <stdlib.h>
2 #include "randombytes.h"
3 #include "cpucycles.h"
4 #include "crypto_hash.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_hash_IMPLEMENTATION;
16 const char *implementationversion = crypto_hash_VERSION;
17 const char *sizenames[] = { "outputbytes", 0 };
18 const long long sizes[] = { crypto_hash_BYTES };
20 #define MAXTEST_BYTES 4096
21 #ifdef SUPERCOP
22 #define MGAP 8192
23 #else
24 #define MGAP 8
25 #endif
27 static unsigned char *h;
28 static unsigned char *m;
30 void preallocate(void)
34 void allocate(void)
36 h = alignedcalloc(crypto_hash_BYTES);
37 m = alignedcalloc(MAXTEST_BYTES);
40 #define TIMINGS 15
41 static long long cycles[TIMINGS + 1];
43 static void printcycles(long long mlen)
45 int i;
46 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
47 printentry(mlen,"cycles",cycles,TIMINGS);
50 void measure(void)
52 int i;
53 int loop;
54 int mlen;
56 for (loop = 0;loop < LOOPS;++loop) {
57 for (mlen = 0;mlen <= MAXTEST_BYTES;mlen += 1 + mlen / MGAP) {
58 randombytes(m,mlen);
59 for (i = 0;i <= TIMINGS;++i) {
60 cycles[i] = cpucycles();
61 crypto_hash(h,m,mlen);
63 printcycles(mlen);