Supply randomness source for the rnd device.
authormickey <mickey@openbsd.org>
Wed, 24 Apr 1996 21:26:36 +0000 (21:26 +0000)
committermickey <mickey@openbsd.org>
Wed, 24 Apr 1996 21:26:36 +0000 (21:26 +0000)
sys/dev/rnd.c
sys/dev/rndvar.h
sys/kern/tty.c

index 242343a..7730f1b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rnd.c,v 1.2 1996/04/17 04:59:48 mickey Exp $  */
+/*     $OpenBSD: rnd.c,v 1.3 1996/04/24 21:26:41 mickey Exp $  */
 
 /*
  * Copyright (c) 1996 Michael Shalayeff.
@@ -266,7 +266,7 @@ struct timer_rand_state {
 /* tags for different random sources */
 #define        ENT_NET         0x100
 #define        ENT_BLKDEV      0x200
-#define ENT_IRQ                0x300
+#define ENT_TTY                0x300
 
 /* device functions prototypes: XXX move em to dev_conf.h */
 cdev_decl(rnd);
@@ -278,6 +278,7 @@ static struct timer_rand_state mouse_timer_state;
 static struct timer_rand_state extract_timer_state;
 static struct timer_rand_state net_timer_state[32];    /* XXX */
 static struct timer_rand_state *blkdev_timer_state;
+static struct timer_rand_state *tty_timer_state;
 static int     rnd_sleep = 0;
 
 #ifndef MIN
@@ -297,6 +298,9 @@ rndattach(num)
        blkdev_timer_state = malloc(nblkdev*sizeof(*blkdev_timer_state),
                                    M_DEVBUF, M_WAITOK);
        bzero(blkdev_timer_state, nblkdev*sizeof(*blkdev_timer_state));
+       tty_timer_state = malloc(nchrdev*sizeof(*tty_timer_state),
+                                   M_DEVBUF, M_WAITOK);
+       bzero(tty_timer_state, nchrdev*sizeof(*tty_timer_state));
        extract_timer_state.dont_count_entropy = 1;
 }
 
@@ -466,13 +470,25 @@ void
 add_blkdev_randomness(dev)
        dev_t   dev;
 {
-       if (major(dev) >= nblkdev || blkdev_timer_state == NULL)
+       if (major(dev) <= nblkdev || blkdev_timer_state == NULL)
                return;
 
        add_timer_randomness(&random_state, &blkdev_timer_state[major(dev)],
                             ENT_BLKDEV + major(dev));
 }
 
+void
+add_tty_randomness(dev, c)
+       dev_t   dev;
+       int     c;
+{
+       if (major(dev) <= nchrdev || tty_timer_state == NULL)
+               return;
+
+       add_timer_randomness(&random_state, &tty_timer_state[major(dev)],
+                            ENT_TTY + c);
+}
+
 #if POOLWORDS % 16
 #error extract_entropy() assumes that POOLWORDS is a multiple of 16 words.
 #endif
index 44b37d9..a808f0d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: rndvar.h,v 1.1 1996/03/29 12:09:58 mickey Exp $       */
+/*     $OpenBSD: rndvar.h,v 1.2 1996/04/24 21:26:43 mickey Exp $       */
 
 /*
  * Copyright (c) 1996 Michael Shalayeff.
 
 #ifdef _KERNEL
 
-extern void add_keyboard_randomness __P((u_char));
 extern void add_mouse_randomness __P((u_int32_t));
 extern void add_net_randomness __P((int));
 extern void add_blkdev_randomness __P((dev_t));
+extern void add_tty_randomness __P((dev_t, int));
 
 extern void get_random_bytes __P((void *, size_t));
 
index 5b1d770..021f477 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tty.c,v 1.4 1996/04/21 22:27:28 deraadt Exp $ */
+/*     $OpenBSD: tty.c,v 1.5 1996/04/24 21:26:36 mickey Exp $  */
 /*     $NetBSD: tty.c,v 1.68 1996/03/29 01:55:12 christos Exp $        */
 
 /*-
 
 #include <vm/vm.h>
 
+#include "rnd.h"
+#if NRND
+#include <dev/rndvar.h>
+#endif
+
 static int ttnread __P((struct tty *));
 static void ttyblock __P((struct tty *));
 static void ttyecho __P((int, struct tty *));
@@ -225,6 +230,9 @@ ttyinput(c, tp)
        register u_char *cc;
        int i, error;
 
+#if NRND
+       add_tty_randomness(tp->t_dev, c);
+#endif
        /*
         * If input is pending take it first.
         */