diff options
author | irungentoo <irungentoo@gmail.com> | 2013-07-02 09:53:34 -0400 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-07-02 09:53:34 -0400 |
commit | e2967396ac73cb7410787886cdaf072a184ffc49 (patch) | |
tree | 527a74d25a4a0705fc641994fd35bfab22662034 /nacl/crypto_sign/measure.c | |
parent | 8928c817df345f29aa0b194743595aa11bd6a8ba (diff) |
Added NaCl crypto library.
Diffstat (limited to 'nacl/crypto_sign/measure.c')
-rw-r--r-- | nacl/crypto_sign/measure.c | 83 |
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 | |||
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); | ||
14 | |||
15 | const char *primitiveimplementation = crypto_sign_IMPLEMENTATION; | ||
16 | const char *implementationversion = crypto_sign_VERSION; | ||
17 | const char *sizenames[] = { "outputbytes", "publickeybytes", "secretkeybytes", 0 }; | ||
18 | const long long sizes[] = { crypto_sign_BYTES, crypto_sign_PUBLICKEYBYTES, crypto_sign_SECRETKEYBYTES }; | ||
19 | |||
20 | #define MAXTEST_BYTES 100000 | ||
21 | |||
22 | static unsigned char *pk; | ||
23 | static unsigned char *sk; | ||
24 | static unsigned char *m; unsigned long long mlen; | ||
25 | static unsigned char *sm; unsigned long long smlen; | ||
26 | static unsigned char *t; unsigned long long tlen; | ||
27 | |||
28 | void preallocate(void) | ||
29 | { | ||
30 | #ifdef RAND_R_PRNG_NOT_SEEDED | ||
31 | RAND_status(); | ||
32 | #endif | ||
33 | } | ||
34 | |||
35 | void 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 | ||
45 | static long long cycles[TIMINGS + 1]; | ||
46 | static long long bytes[TIMINGS + 1]; | ||
47 | |||
48 | void 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 | } | ||