2 #include "randombytes.h"
4 #include "crypto_stream.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_stream_IMPLEMENTATION
;
16 const char *implementationversion
= crypto_stream_VERSION
;
17 const char *sizenames
[] = { "keybytes", "noncebytes", 0 };
18 const long long sizes
[] = { crypto_stream_KEYBYTES
, crypto_stream_NONCEBYTES
};
20 #define MAXTEST_BYTES 4096
27 static unsigned char *k
;
28 static unsigned char *n
;
29 static unsigned char *m
;
30 static unsigned char *c
;
32 void preallocate(void)
38 k
= alignedcalloc(crypto_stream_KEYBYTES
);
39 n
= alignedcalloc(crypto_stream_NONCEBYTES
);
40 m
= alignedcalloc(MAXTEST_BYTES
);
41 c
= alignedcalloc(MAXTEST_BYTES
);
45 static long long cycles
[TIMINGS
+ 1];
53 for (loop
= 0;loop
< LOOPS
;++loop
) {
54 for (mlen
= 0;mlen
<= MAXTEST_BYTES
;mlen
+= 1 + mlen
/ MGAP
) {
55 randombytes(k
,crypto_stream_KEYBYTES
);
56 randombytes(n
,crypto_stream_NONCEBYTES
);
59 for (i
= 0;i
<= TIMINGS
;++i
) {
60 cycles
[i
] = cpucycles();
61 crypto_stream(c
,mlen
,n
,k
);
63 for (i
= 0;i
< TIMINGS
;++i
) cycles
[i
] = cycles
[i
+ 1] - cycles
[i
];
64 printentry(mlen
,"cycles",cycles
,TIMINGS
);
65 for (i
= 0;i
<= TIMINGS
;++i
) {
66 cycles
[i
] = cpucycles();
67 crypto_stream_xor(c
,m
,mlen
,n
,k
);
69 for (i
= 0;i
< TIMINGS
;++i
) cycles
[i
] = cycles
[i
+ 1] - cycles
[i
];
70 printentry(mlen
,"xor_cycles",cycles
,TIMINGS
);