nobody should really be using srandom, but we provide it and it's a 
tempting target, so they do.  let's give them arandom instead.  they'll 
never know the difference, except it may actually work.  :)

i included a conversion for urandom on the same principle.

Index: rnd.c
===================================================================
RCS file: /home/tedu/cvs/src/sys/dev/rnd.c,v
retrieving revision 1.102
diff -u -r1.102 rnd.c
--- rnd.c       20 Apr 2010 22:05:41 -0000      1.102
+++ rnd.c       30 Sep 2010 00:28:48 -0000
@@ -985,7 +985,7 @@
 int
 randomopen(dev_t dev, int flag, int mode, struct proc *p)
 {
-       return (minor (dev) < RND_NODEV) ? 0 : ENXIO;
+       return (minor(dev) < RND_NODEV ? 0 : ENXIO);
 }
 
 int
@@ -1013,41 +1013,7 @@
                        ret = EIO;      /* no chip -- error */
                        break;
                case RND_SRND:
-                       if (random_state.entropy_count < 16 * 8) {
-                               if (ioflag & IO_NDELAY) {
-                                       ret = EWOULDBLOCK;
-                                       break;
-                               }
-#ifdef RNDEBUG
-                               if (rnd_debug & RD_WAIT)
-                                       printf("rnd: sleep[%u]\n",
-                                           random_state.asleep);
-#endif
-                               random_state.asleep++;
-                               rndstats.rnd_waits++;
-                               ret = tsleep(&random_state.asleep,
-                                   PWAIT | PCATCH, "rndrd", 0);
-#ifdef RNDEBUG
-                               if (rnd_debug & RD_WAIT)
-                                       printf("rnd: awakened(%d)\n", ret);
-#endif
-                               if (ret)
-                                       break;
-                       }
-                       if (n > random_state.entropy_count / 8)
-                               n = random_state.entropy_count / 8;
-                       rndstats.rnd_reads++;
-#ifdef RNDEBUG
-                       if (rnd_debug & RD_OUTPUT)
-                               printf("rnd: %u possible output\n", n);
-#endif
                case RND_URND:
-                       get_random_bytes((char *)buf, n);
-#ifdef RNDEBUG
-                       if (rnd_debug & RD_OUTPUT)
-                               printf("rnd: %u bytes for output\n", n);
-#endif
-                       break;
                case RND_ARND_OLD:
                case RND_ARND:
                        arc4random_buf(buf, n);
@@ -1073,10 +1039,7 @@
 
        revents = events & (POLLOUT | POLLWRNORM);      /* always writable */
        if (events & (POLLIN | POLLRDNORM)) {
-               if (minor(dev) == RND_SRND && random_state.entropy_count <= 0)
-                       selrecord(p, &rnd_rsel);
-               else
-                       revents |= events & (POLLIN | POLLRDNORM);
+               revents |= events & (POLLIN | POLLRDNORM);
        }
 
        return (revents);
@@ -1164,8 +1127,7 @@
                }
        }
 
-       if ((minor(dev) == RND_ARND || minor(dev) == RND_ARND_OLD) &&
-           !ret)
+       if (!ret)
                arc4random_initialized = 0;
 
        free(buf, M_TEMP);

Reply via email to