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;
}
}
* 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(). */
/** 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);