From a320c7d0de4cd7a6d0a1c68f8e3284ae807a6659 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Wed, 23 Mar 2022 07:22:55 +0000 Subject: [PATCH] Random: Small fixes in documentation. --- ucw/random-strong.c | 2 +- ucw/random.h | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ucw/random-strong.c b/ucw/random-strong.c index f5728233..760a6e65 100644 --- a/ucw/random-strong.c +++ b/ucw/random-strong.c @@ -226,7 +226,7 @@ static void strongrand_std_read_buffered(struct strongrand *sr, byte *ptr, int s DBG("RANDOM[%s]: Detected changed pid from %u to %u", sr->name, (uint)srs->last_pid, (uint)pid); srs->last_pid = pid; if (srs->flags & STRONGRAND_STD_ASSERT_RESET) - ASSERT(!srs->buf_avail); + ASSERT(!srs->buf_avail); // Note: Does not catch all cases of wrong usage (already read multiples of buf_size) srs->buf_avail = 0; } } diff --git a/ucw/random.h b/ucw/random.h index ec31b0de..d4c510e3 100644 --- a/ucw/random.h +++ b/ucw/random.h @@ -118,7 +118,7 @@ double fastrand_double(struct fastrand *c); * need that. **/ struct strongrand { - const char *name; /* Context name for logging. */ + const char *name; /* (mandatory) Context name for logging. */ void (*read)(struct strongrand *sr, byte *ptr, int size); /* (mandatory) Generate @size random bytes. */ void (*close)(struct strongrand *sr); /* Called from strongrand_close(). */ void (*reset)(struct strongrand *sr); /* Called from strongrand_reset(). */ @@ -138,21 +138,24 @@ void strongrand_reset(struct strongrand *sr); /** Generate @size random bytes. **/ void strongrand_mem(struct strongrand *c, void *ptr, size_t size); -/** Kernel's random generator. **/ - /** * Open kernel's random generator. * Requires exactly one of these flags, among others: * -- STRONGRAND_STD_URANDOM * -- STRONGRAND_STD_RANDOM * + * Since glibc 2.25 and kernel 3.17, we use getrandom() syscall, + * otherwise we open and read from "/dev/[u]random" device. + * * @buf_size can be 0 for unbuffered reading. * - * If at least one of the following conditions are met, - * strongrand_reset() after fork() is not necessary: + * STRONGRAND_STD_x_RESET flags are only useful for buffered reading. + * + * If at least one of the following conditions are met, strongrand_reset() + * after fork() is not necessary: * -- zero @buf_size * -- STRONGRAND_STD_AUTO_RESET flag - * -- no read since open (empty buffer) + * -- no read since open or last reset (empty buffer) **/ struct strongrand *strongrand_std_open(uint buf_size, uint flags); -- 2.39.2