]> mj.ucw.cz Git - libucw.git/commitdiff
Random: Small fixes in documentation.
authorPavel Charvat <pchar@ucw.cz>
Wed, 23 Mar 2022 07:22:55 +0000 (07:22 +0000)
committerPavel Charvat <pchar@ucw.cz>
Wed, 23 Mar 2022 07:22:55 +0000 (07:22 +0000)
ucw/random-strong.c
ucw/random.h

index f5728233eada8cb786fb2e7d3bee3b3033e88fe1..760a6e65178c753f16caba80ee9fb508c90e3306 100644 (file)
@@ -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;
        }
     }
index ec31b0dec292e9a71f453afa3635ff61cf269165..d4c510e3414bcc64d0b25b1f1099b590eee04916 100644 (file)
@@ -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);