Changes to update Tomato RAF.
[tomato.git] / release / src / router / dnscrypt / src / libnacl / crypto_sign / measure.c
blob8d8495a8b96da4ad749f490a31b8793ab89504da
1 #include <stdlib.h>
2 #include "randombytes.h"
3 #include "cpucycles.h"
4 #include "crypto_sign.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_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 };
20 #define MAXTEST_BYTES 100000
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;
28 void preallocate(void)
30 #ifdef RAND_R_PRNG_NOT_SEEDED
31 RAND_status();
32 #endif
35 void allocate(void)
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);
44 #define TIMINGS 31
45 static long long cycles[TIMINGS + 1];
46 static long long bytes[TIMINGS + 1];
48 void measure(void)
50 int i;
51 int loop;
53 for (loop = 0;loop < LOOPS;++loop) {
54 for (i = 0;i <= TIMINGS;++i) {
55 cycles[i] = cpucycles();
56 crypto_sign_keypair(pk,sk);
58 for (i = 0;i < TIMINGS;++i) cycles[i] = cycles[i + 1] - cycles[i];
59 printentry(-1,"keypair_cycles",cycles,TIMINGS);
61 for (mlen = 0;mlen <= MAXTEST_BYTES;mlen += 1 + mlen / 4) {
62 randombytes(m,mlen);
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;
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);
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;
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);