mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-23 20:15:19 -07:00
Merge branch 'master' of github.com:jedisct1/libsodium
* 'master' of github.com:jedisct1/libsodium: Bench: don't tie the printed result to the number of iterations Make the number of iterations configurable; reduce the default Add an interesting test case for a custom randombytes_uniform implementation Add a benchmark mode randombytes test: restore the salsa20-based rng at the end, for benchmarks Indent
This commit is contained in:
commit
8f0953b31f
@ -30,7 +30,53 @@
|
||||
|
||||
int xmain(void);
|
||||
|
||||
#ifndef BROWSER_TESTS
|
||||
#ifdef BENCHMARKS
|
||||
|
||||
# include <sys/time.h>
|
||||
|
||||
# ifndef ITERATIONS
|
||||
# define ITERATIONS 128
|
||||
# endif
|
||||
|
||||
static unsigned long long now(void)
|
||||
{
|
||||
struct timeval tp;
|
||||
unsigned long long now;
|
||||
|
||||
if (gettimeofday(&tp, NULL) != 0) {
|
||||
abort();
|
||||
}
|
||||
now = ((unsigned long long) tp.tv_sec * 1000000ULL) +
|
||||
(unsigned long long) tp.tv_usec;
|
||||
|
||||
return now;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned long long ts_start;
|
||||
unsigned long long ts_end;
|
||||
unsigned int i;
|
||||
|
||||
if (sodium_init() != 0) {
|
||||
return 99;
|
||||
}
|
||||
randombytes_set_implementation(&randombytes_salsa20_implementation);
|
||||
ts_start = now();
|
||||
for (i = 0; i < ITERATIONS; i++) {
|
||||
if (xmain() != 0) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
ts_end = now();
|
||||
printf("%llu\n", 1000000ULL * (ts_end - ts_start) / ITERATIONS);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define printf(...) do { } while(0)
|
||||
|
||||
#elif !defined(BROWSER_TESTS)
|
||||
|
||||
FILE *fp_res;
|
||||
|
||||
|
@ -39,12 +39,14 @@ randombytes_tests(void)
|
||||
unsigned int i;
|
||||
uint32_t n;
|
||||
|
||||
#ifndef BENCHMARKS
|
||||
# ifdef __EMSCRIPTEN__
|
||||
assert(strcmp(randombytes_implementation_name(), "js") == 0);
|
||||
# elif defined(__native_client__)
|
||||
assert(strcmp(randombytes_implementation_name(), "nativeclient") == 0);
|
||||
# else
|
||||
assert(strcmp(randombytes_implementation_name(), "sysrandom") == 0);
|
||||
# endif
|
||||
#endif
|
||||
randombytes(x, 1U);
|
||||
do {
|
||||
@ -137,6 +139,7 @@ impl_tests(void)
|
||||
impl.uniform = randombytes_uniform_impl;
|
||||
randombytes_close();
|
||||
randombytes_set_implementation(&impl);
|
||||
assert(randombytes_uniform(1) == 1);
|
||||
assert(randombytes_uniform(v) == v);
|
||||
assert(randombytes_uniform(v) == v);
|
||||
assert(randombytes_uniform(v) == v);
|
||||
@ -158,5 +161,7 @@ main(void)
|
||||
#endif
|
||||
printf("OK\n");
|
||||
|
||||
randombytes_set_implementation(&randombytes_salsa20_implementation);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user