summaryrefslogtreecommitdiff
path: root/nacl/crypto_sign/measure.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-02 09:53:34 -0400
committerirungentoo <irungentoo@gmail.com>2013-07-02 09:53:34 -0400
commite2967396ac73cb7410787886cdaf072a184ffc49 (patch)
tree527a74d25a4a0705fc641994fd35bfab22662034 /nacl/crypto_sign/measure.c
parent8928c817df345f29aa0b194743595aa11bd6a8ba (diff)
Added NaCl crypto library.
Diffstat (limited to 'nacl/crypto_sign/measure.c')
-rw-r--r--nacl/crypto_sign/measure.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/nacl/crypto_sign/measure.c b/nacl/crypto_sign/measure.c
new file mode 100644
index 00000000..8d8495a8
--- /dev/null
+++ b/nacl/crypto_sign/measure.c
@@ -0,0 +1,83 @@
1#include <stdlib.h>
2#include "randombytes.h"
3#include "cpucycles.h"
4#include "crypto_sign.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_sign_IMPLEMENTATION;
16const char *implementationversion = crypto_sign_VERSION;
17const char *sizenames[] = { "outputbytes", "publickeybytes", "secretkeybytes", 0 };
18const long long sizes[] = { crypto_sign_BYTES, crypto_sign_PUBLICKEYBYTES, crypto_sign_SECRETKEYBYTES };
19
20#define MAXTEST_BYTES 100000
21
22static unsigned char *pk;
23static unsigned char *sk;
24static unsigned char *m; unsigned long long mlen;
25static unsigned char *sm; unsigned long long smlen;
26static unsigned char *t; unsigned long long tlen;
27
28void preallocate(void)
29{
30#ifdef RAND_R_PRNG_NOT_SEEDED
31 RAND_status();
32#endif
33}
34
35void allocate(void)
36{
37 pk = alignedcalloc(crypto_sign_PUBLICKEYBYTES);
38 sk = alignedcalloc(crypto_sign_SECRETKEYBYTES);
39 m = alignedcalloc(MAXTEST_BYTES + crypto_sign_BYTES);
40 sm = alignedcalloc(MAXTEST_BYTES + crypto_sign_BYTES);
41 t = alignedcalloc(MAXTEST_BYTES + crypto_sign_BYTES);
42}
43
44#define TIMINGS 31
45static long long cycles[TIMINGS + 1];
46static long long bytes[TIMINGS + 1];
47
48void measure(void)
49{
50 int i;
51 int loop;
52
53 for (loop = 0;loop < LOOPS;++loop) {
54 for (i = 0;i <= TIMINGS;++i) {
55 cycles[i] = cpucycles();
56 crypto_sign_keypair(pk,sk);
57 }
58 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
59 printentry(-1,"keypair_cycles",cycles,TIMINGS);
60
61 for (mlen = 0;mlen <= MAXTEST_BYTES;mlen += 1 + mlen / 4) {
62 randombytes(m,mlen);
63
64 for (i = 0;i <= TIMINGS;++i) {
65 cycles[i] = cpucycles();
66 bytes[i] = crypto_sign(sm,&smlen,m,mlen,sk);
67 if (bytes[i] == 0) bytes[i] = smlen;
68 }
69 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
70 printentry(mlen,"cycles",cycles,TIMINGS);
71 printentry(mlen,"bytes",bytes,TIMINGS);
72
73 for (i = 0;i <= TIMINGS;++i) {
74 cycles[i] = cpucycles();
75 bytes[i] = crypto_sign_open(t,&tlen,sm,smlen,pk);
76 if (bytes[i] == 0) bytes[i] = tlen;
77 }
78 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
79 printentry(mlen,"open_cycles",cycles,TIMINGS);
80 printentry(mlen,"open_bytes",bytes,TIMINGS);
81 }
82 }
83}