From: Pavel Charvat Date: Wed, 23 Mar 2022 07:42:09 +0000 (+0000) Subject: Random: Switched flags and buf_size arguments of strongrand (slightly nicer usage). X-Git-Tag: v6.5.14~1 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=6b2d4845f29db16affed3b1967043bc61990d1b0;p=libucw.git Random: Switched flags and buf_size arguments of strongrand (slightly nicer usage). --- diff --git a/ucw/random-strong.c b/ucw/random-strong.c index 760a6e65..4391b736 100644 --- a/ucw/random-strong.c +++ b/ucw/random-strong.c @@ -246,7 +246,7 @@ static void strongrand_std_read_buffered(struct strongrand *sr, byte *ptr, int s } } -static struct strongrand *strongrand_std_open_internal(int fd, const char *name, uint buf_size, uint flags) +static struct strongrand *strongrand_std_open_internal(int fd, const char *name, uint flags, uint buf_size) { struct strongrand_std *srs = xmalloc(sizeof(*srs) + buf_size); bzero(srs, sizeof(*srs)); @@ -262,7 +262,7 @@ static struct strongrand *strongrand_std_open_internal(int fd, const char *name, return &srs->sr; } -struct strongrand *strongrand_std_open(uint buf_size, uint flags) +struct strongrand *strongrand_std_open(uint flags, uint buf_size) { const char *name; if (flags & STRONGRAND_STD_URANDOM) @@ -277,9 +277,9 @@ struct strongrand *strongrand_std_open(uint buf_size, uint flags) } #ifdef CONFIG_UCW_GETRANDOM if (strongrand_getrandom_detect()) - return strongrand_std_open_internal(STRONGRAND_FD_KERNEL_GETRANDOM, name, buf_size, flags); + return strongrand_std_open_internal(STRONGRAND_FD_KERNEL_GETRANDOM, name, flags, buf_size); #endif - struct strongrand *sr = strongrand_std_open_internal(STRONGRAND_FD_KERNEL_DEVICE, name, buf_size, flags); + struct strongrand *sr = strongrand_std_open_internal(STRONGRAND_FD_KERNEL_DEVICE, name, flags, buf_size); if (!(flags & STRONGRAND_STD_DELAYED)) strongrand_std_open_device((struct strongrand_std *)sr); return sr; diff --git a/ucw/random-test.c b/ucw/random-test.c index 2fd37595..59d54b6c 100644 --- a/ucw/random-test.c +++ b/ucw/random-test.c @@ -88,7 +88,7 @@ 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); + struct strongrand *r = strongrand_std_open(STRONGRAND_STD_URANDOM, (j == 0) ? 0 : 128); for (uint i = 1; i <= 100; i++) { strongrand_mem(r, buf, i); @@ -216,19 +216,19 @@ static void bench_strong(void) struct strongrand *r; msg(L_INFO, "Benchmarking unbuffered strong random generator"); - r = strongrand_std_open(0, STRONGRAND_STD_URANDOM); + r = strongrand_std_open(STRONGRAND_STD_URANDOM, 0); 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); + r = strongrand_std_open(STRONGRAND_STD_URANDOM, 128); 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); + r = strongrand_std_open(STRONGRAND_STD_URANDOM | STRONGRAND_STD_AUTO_RESET, 128); BENCH_SLOW(50, strongrand_mem(r, buf, 1)); BENCH_SLOW(200, strongrand_mem(r, buf, 100)); strongrand_close(r); diff --git a/ucw/random.h b/ucw/random.h index d4c510e3..dfe7494b 100644 --- a/ucw/random.h +++ b/ucw/random.h @@ -157,7 +157,7 @@ void strongrand_mem(struct strongrand *c, void *ptr, size_t size); * -- STRONGRAND_STD_AUTO_RESET flag * -- no read since open or last reset (empty buffer) **/ -struct strongrand *strongrand_std_open(uint buf_size, uint flags); +struct strongrand *strongrand_std_open(uint flags, uint buf_size); enum strongrand_std_flags { STRONGRAND_STD_URANDOM = 0x1, // Use kernel's "urandom" source.