#include <unistd.h>
static int o_test_fast;
+static int o_test_strong;
static double o_bench_scale = 1.0;
static int o_bench_only_safe;
static int o_bench_libs;
static int o_bench_legacy;
static int o_bench_fast;
+static int o_bench_strong;
static struct opt_section options = {
OPT_ITEMS {
OPT_HELP("Options:"),
OPT_HELP_OPTION,
OPT_BOOL(0, "test-fast", o_test_fast, 0, "\tTest fast random generator"),
+ OPT_BOOL(0, "test-strong", o_test_strong, 0, "\tTest strong random generator"),
OPT_BOOL(0, "bench-all", o_bench_all, 0, "\tBench everything"),
OPT_BOOL(0, "bench-libs", o_bench_libs, 0, "\tBench libc"),
OPT_BOOL(0, "bench-legacy", o_bench_legacy, 0, "\tBench legacy interface"),
OPT_BOOL(0, "bench-fast", o_bench_fast, 0, "\tBench fast random generator"),
+ OPT_BOOL(0, "bench-strong", o_bench_strong, 0, "\tBench strong random generator"),
OPT_DOUBLE(0, "bench-scale", o_bench_scale, OPT_REQUIRED_VALUE, "<scale>\tIncrease/decrease the length of benchmark (default: 1.0)"),
OPT_BOOL(0, "bench-only-safe", o_bench_only_safe, 0, "\tDon't benchmark too verbose or risky functions"),
OPT_END,
printf("OK\n");
}
+static void test_strong(void)
+{
+ byte buf[100];
+ for (uint j = 0; j < 2; j++)
+ {
+ struct strongrand *r = strongrand_std_open((j == 0) ? 0 : 128, STRONGRAND_STD_URANDOM);
+ for (uint i = 1; i <= 100; i++)
+ {
+ strongrand_mem(r, buf, i);
+ if (i % 10 == 0)
+ strongrand_reset(r);
+ }
+ strongrand_close(r);
+ }
+ printf("OK\n");
+}
+
#define BENCH(func) BENCH_SLOW(1, func)
#define BENCH_SLOW(mult, func) \
do { \
fastrand_delete(r);
}
+static void bench_strong(void)
+{
+ byte buf[100];
+ struct strongrand *r;
+
+ msg(L_INFO, "Benchmarking unbuffered strong random generator");
+ r = strongrand_std_open(0, STRONGRAND_STD_URANDOM);
+ BENCH_SLOW(50, strongrand_mem(r, buf, 1));
+ BENCH_SLOW(200, strongrand_mem(r, buf, 100));
+ strongrand_close(r);
+
+ msg(L_INFO, "Benchmarking buffered strong random generator");
+ r = strongrand_std_open(128, STRONGRAND_STD_URANDOM);
+ BENCH_SLOW(50, strongrand_mem(r, buf, 1));
+ BENCH_SLOW(200, strongrand_mem(r, buf, 100));
+ strongrand_close(r);
+
+ msg(L_INFO, "Benchmarking buffered strong random generator with autoreset");
+ r = strongrand_std_open(128, STRONGRAND_STD_URANDOM | STRONGRAND_STD_AUTO_RESET);
+ BENCH_SLOW(50, strongrand_mem(r, buf, 1));
+ BENCH_SLOW(200, strongrand_mem(r, buf, 100));
+ strongrand_close(r);
+}
+
int main(int argc UNUSED, char **argv)
{
cf_def_file = INSTALL_CONFIG_DIR "/common";
if (o_test_fast)
test_fast();
+ if (o_test_strong)
+ test_strong();
if (o_bench_all || o_bench_libs)
bench_libs();
bench_legacy();
if (o_bench_all || o_bench_fast)
bench_fast();
+ if (o_bench_all || o_bench_strong)
+ bench_strong();
return 0;
}