summaryrefslogtreecommitdiff
path: root/nacl/crypto_box/measure.c
diff options
context:
space:
mode:
Diffstat (limited to 'nacl/crypto_box/measure.c')
-rw-r--r--nacl/crypto_box/measure.c137
1 files changed, 0 insertions, 137 deletions
diff --git a/nacl/crypto_box/measure.c b/nacl/crypto_box/measure.c
deleted file mode 100644
index 08df1e39..00000000
--- a/nacl/crypto_box/measure.c
+++ /dev/null
@@ -1,137 +0,0 @@
1#include <stdlib.h>
2#include "randombytes.h"
3#include "cpucycles.h"
4#include "crypto_box.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_box_IMPLEMENTATION;
16const char *implementationversion = crypto_box_VERSION;
17const char *sizenames[] = { "publickeybytes", "secretkeybytes", "beforenmbytes", "noncebytes", "zerobytes", "boxzerobytes", 0 };
18const long long sizes[] = { crypto_box_PUBLICKEYBYTES, crypto_box_SECRETKEYBYTES, crypto_box_BEFORENMBYTES, crypto_box_NONCEBYTES, crypto_box_ZEROBYTES, crypto_box_BOXZEROBYTES };
19
20#define MAXTEST_BYTES 4096
21
22static unsigned char *ska;
23static unsigned char *pka;
24static unsigned char *skb;
25static unsigned char *pkb;
26static unsigned char *n;
27static unsigned char *m;
28static unsigned char *c;
29static unsigned char *sa;
30static unsigned char *sb;
31
32void preallocate(void)
33{
34}
35
36void allocate(void)
37{
38 ska = alignedcalloc(crypto_box_SECRETKEYBYTES);
39 pka = alignedcalloc(crypto_box_PUBLICKEYBYTES);
40 skb = alignedcalloc(crypto_box_SECRETKEYBYTES);
41 pkb = alignedcalloc(crypto_box_PUBLICKEYBYTES);
42 n = alignedcalloc(crypto_box_NONCEBYTES);
43 m = alignedcalloc(MAXTEST_BYTES + crypto_box_ZEROBYTES);
44 c = alignedcalloc(MAXTEST_BYTES + crypto_box_ZEROBYTES);
45 sa = alignedcalloc(crypto_box_BEFORENMBYTES);
46 sb = alignedcalloc(crypto_box_BEFORENMBYTES);
47}
48
49#define TIMINGS 15
50static long long cycles[TIMINGS + 1];
51
52void measure(void)
53{
54 int i;
55 int loop;
56 int mlen;
57
58 for (loop = 0;loop < LOOPS;++loop) {
59 for (i = 0;i <= TIMINGS;++i) {
60 cycles[i] = cpucycles();
61 crypto_box_keypair(pka,ska);
62 }
63 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
64 printentry(-1,"keypair_cycles",cycles,TIMINGS);
65
66 for (i = 0;i <= TIMINGS;++i) {
67 cycles[i] = cpucycles();
68 crypto_box_keypair(pkb,skb);
69 }
70 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
71 printentry(-1,"keypair_cycles",cycles,TIMINGS);
72
73 for (i = 0;i <= TIMINGS;++i) {
74 cycles[i] = cpucycles();
75 crypto_box_beforenm(sa,pkb,ska);
76 }
77 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
78 printentry(-1,"beforenm_cycles",cycles,TIMINGS);
79
80 for (i = 0;i <= TIMINGS;++i) {
81 cycles[i] = cpucycles();
82 crypto_box_beforenm(sb,pka,skb);
83 }
84 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
85 printentry(-1,"beforenm_cycles",cycles,TIMINGS);
86
87 for (mlen = 0;mlen <= MAXTEST_BYTES;mlen += 1 + mlen / 8) {
88 randombytes(n,crypto_box_NONCEBYTES);
89 randombytes(m + crypto_box_ZEROBYTES,mlen);
90 randombytes(c,mlen + crypto_box_ZEROBYTES);
91
92 for (i = 0;i <= TIMINGS;++i) {
93 cycles[i] = cpucycles();
94 crypto_box(c,m,mlen + crypto_box_ZEROBYTES,n,pka,skb);
95 }
96 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
97 printentry(mlen,"cycles",cycles,TIMINGS);
98
99 for (i = 0;i <= TIMINGS;++i) {
100 cycles[i] = cpucycles();
101 crypto_box_open(m,c,mlen + crypto_box_ZEROBYTES,n,pkb,ska);
102 }
103 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
104 printentry(mlen,"open_cycles",cycles,TIMINGS);
105
106 ++c[crypto_box_ZEROBYTES];
107 for (i = 0;i <= TIMINGS;++i) {
108 cycles[i] = cpucycles();
109 crypto_box_open(m,c,mlen + crypto_box_ZEROBYTES,n,pkb,ska);
110 }
111 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
112 printentry(mlen,"forgery_open_cycles",cycles,TIMINGS);
113
114 for (i = 0;i <= TIMINGS;++i) {
115 cycles[i] = cpucycles();
116 crypto_box_afternm(c,m,mlen + crypto_box_ZEROBYTES,n,sb);
117 }
118 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
119 printentry(mlen,"afternm_cycles",cycles,TIMINGS);
120
121 for (i = 0;i <= TIMINGS;++i) {
122 cycles[i] = cpucycles();
123 crypto_box_open_afternm(m,c,mlen + crypto_box_ZEROBYTES,n,sa);
124 }
125 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
126 printentry(mlen,"open_afternm_cycles",cycles,TIMINGS);
127
128 ++c[crypto_box_ZEROBYTES];
129 for (i = 0;i <= TIMINGS;++i) {
130 cycles[i] = cpucycles();
131 crypto_box_open_afternm(m,c,mlen + crypto_box_ZEROBYTES,n,sa);
132 }
133 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
134 printentry(mlen,"forgery_open_afternm_cycles",cycles,TIMINGS);
135 }
136 }
137}