summaryrefslogtreecommitdiff
path: root/nacl/crypto_hash/measure.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/crypto_hash/measure.c')
-rw-r--r--nacl/crypto_hash/measure.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/nacl/crypto_hash/measure.c b/nacl/crypto_hash/measure.c
new file mode 100644
index 00000000..cec0404d
--- /dev/null
+++ b/nacl/crypto_hash/measure.c
@@ -0,0 +1,66 @@
1#include <stdlib.h>
2#include "randombytes.h"
3#include "cpucycles.h"
4#include "crypto_hash.h"
5
6extern void printentry(long long,const char *,long long *,long long);
7extern unsigned char *alignedcalloc(unsigned long long);
8extern const char *primitiveimplementation;
9extern const char *implementationversion;
10extern const char *sizenames[];
11extern const long long sizes[];
12extern void allocate(void);
13extern void measure(void);
14
15const char *primitiveimplementation = crypto_hash_IMPLEMENTATION;
16const char *implementationversion = crypto_hash_VERSION;
17const char *sizenames[] = { "outputbytes", 0 };
18const long long sizes[] = { crypto_hash_BYTES };
19
20#define MAXTEST_BYTES 4096
21#ifdef SUPERCOP
22#define MGAP 8192
23#else
24#define MGAP 8
25#endif
26
27static unsigned char *h;
28static unsigned char *m;
29
30void preallocate(void)
31{
32}
33
34void allocate(void)
35{
36 h = alignedcalloc(crypto_hash_BYTES);
37 m = alignedcalloc(MAXTEST_BYTES);
38}
39
40#define TIMINGS 15
41static long long cycles[TIMINGS + 1];
42
43static void printcycles(long long mlen)
44{
45 int i;
46 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
47 printentry(mlen,"cycles",cycles,TIMINGS);
48}
49
50void measure(void)
51{
52 int i;
53 int loop;
54 int mlen;
55
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);
62 }
63 printcycles(mlen);
64 }
65 }
66}