]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/random-strong.c
Random: Switched flags and buf_size arguments of strongrand (slightly nicer usage).
[libucw.git] / ucw / random-strong.c
index f5728233eada8cb786fb2e7d3bee3b3033e88fe1..4391b736c89be1a3afe584767eb872123ebc6fa7 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;
        }
     }
@@ -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;