summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>1996-04-24 21:26:44 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>1996-04-24 21:26:44 +0000
commitd75a6262c9d4b16c12eec1d91f48d682bd42a75d (patch)
treeda1782838bbdc61a80636dc3a8981380fddf26a8 /sys
parent4a62f54b689d2fa867d78306a66cd87925df3e6c (diff)
Supply randomness source for the rnd device.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/rnd.c22
-rw-r--r--sys/dev/rndvar.h4
-rw-r--r--sys/kern/tty.c10
3 files changed, 30 insertions, 6 deletions
diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c
index 242343ada66..7730f1baf0d 100644
--- a/sys/dev/rnd.c
+++ b/sys/dev/rnd.c
@@ -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
diff --git a/sys/dev/rndvar.h b/sys/dev/rndvar.h
index 44b37d98f0d..a808f0dfe3e 100644
--- a/sys/dev/rndvar.h
+++ b/sys/dev/rndvar.h
@@ -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.
@@ -46,10 +46,10 @@
#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));
diff --git a/sys/kern/tty.c b/sys/kern/tty.c
index 5b1d770befb..021f4774291 100644
--- a/sys/kern/tty.c
+++ b/sys/kern/tty.c
@@ -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 $ */
/*-
@@ -61,6 +61,11 @@
#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.
*/