From f988debc44f8bc212950405ab86940e90b25e8d7 Mon Sep 17 00:00:00 2001 From: mickey Date: Fri, 29 Mar 1996 12:05:34 +0000 Subject: [PATCH] Initial commit of random source driver. --- sys/arch/i386/i386/conf.c | 5 ++++- sys/arch/i386/isa/pccons.c | 10 ++++++++++ sys/arch/i386/isa/pcvt/pcvt_drv.c | 7 +++++++ sys/arch/i386/isa/pcvt/pcvt_kbd.c | 7 +++++++ sys/conf/files | 2 ++ sys/kern/vfs_bio.c | 9 +++++++++ sys/net/netisr.h | 11 +++++++++-- sys/sys/conf.h | 8 +++++++- 8 files changed, 55 insertions(+), 4 deletions(-) diff --git a/sys/arch/i386/i386/conf.c b/sys/arch/i386/i386/conf.c index f94045cb83b..179a571219d 100644 --- a/sys/arch/i386/i386/conf.c +++ b/sys/arch/i386/i386/conf.c @@ -197,6 +197,8 @@ cdev_decl(svr4_net); cdev_decl(ccd); #include "joy.h" cdev_decl(joy); +#include "rnd.h" +cdev_decl(rnd); cdev_decl(ipl); #ifdef IPFILTER @@ -257,7 +259,8 @@ struct cdevsw cdevsw[] = #else cdev_notdef(), /* 43 */ #endif - cdev_gen_ipf(NIPF,ipl), /* 44 */ + cdev_gen_ipf(NIPF,ipl), /* 44 ip filtering */ + cdev_rnd_init(NRND,rnd), /* 45 random data source */ }; int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); diff --git a/sys/arch/i386/isa/pccons.c b/sys/arch/i386/isa/pccons.c index cc952ed2adf..aefc27ac224 100644 --- a/sys/arch/i386/isa/pccons.c +++ b/sys/arch/i386/isa/pccons.c @@ -1,3 +1,4 @@ +/* $OpenBSD: pccons.c,v 1.6 1996/03/29 12:05:39 mickey Exp $ */ /* $NetBSD: pccons.c,v 1.91 1995/12/24 02:30:25 mycroft Exp $ */ /*- @@ -69,6 +70,11 @@ #include #include +#include "rnd.h" +#if NRND +#include +#endif + #define XFREE86_BUG_COMPAT #ifndef BEEP_FREQ @@ -1421,6 +1427,10 @@ top: goto loop; } +#if NRND + add_keyboard_randomness(dt); +#endif + if (pc_xmode > 0) { #if defined(DDB) && defined(XSERVER_DDB) /* F12 enters the debugger while in X mode */ diff --git a/sys/arch/i386/isa/pcvt/pcvt_drv.c b/sys/arch/i386/isa/pcvt/pcvt_drv.c index 0f71a01d6fd..9644eb909d9 100644 --- a/sys/arch/i386/isa/pcvt/pcvt_drv.c +++ b/sys/arch/i386/isa/pcvt/pcvt_drv.c @@ -90,6 +90,10 @@ #define EXTERN /* allocate mem */ #include "pcvt_hdr.h" /* global include */ +#include "rnd.h" +#if NRND +#include +#endif #ifdef NOTDEF unsigned __debug = 0; /*0xffe */; @@ -874,6 +878,9 @@ pcrint(void) dt = inb(CONTROLLER_DATA); /* get it 8042 data */ +#if NRND + add_keyboard_randomness(dt); +#endif if (pcvt_kbd_count >= PCVT_KBD_FIFO_SZ) /* fifo overflow ? */ { log (LOG_WARNING, "pcvt: keyboard buffer overflow\n"); diff --git a/sys/arch/i386/isa/pcvt/pcvt_kbd.c b/sys/arch/i386/isa/pcvt/pcvt_kbd.c index d13008c230b..61773c803ba 100644 --- a/sys/arch/i386/isa/pcvt/pcvt_kbd.c +++ b/sys/arch/i386/isa/pcvt/pcvt_kbd.c @@ -75,6 +75,10 @@ #if NVT > 0 #include "pcvt_hdr.h" /* global include */ +#include "rnd.h" +#if NRND +#include +#endif static void fkey1(void), fkey2(void), fkey3(void), fkey4(void); static void fkey5(void), fkey6(void), fkey7(void), fkey8(void); @@ -999,6 +1003,9 @@ loop: PCVT_KBD_DELAY(); /* 7 us delay */ dt = inb(CONTROLLER_DATA); /* yes, get data */ +#if NRND + add_keyboard_randomness(dt) +#endif #endif /* !PCVT_KBD_FIFO */ /* diff --git a/sys/conf/files b/sys/conf/files index 273212533a4..4d790ad6dad 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -38,6 +38,7 @@ pseudo-device sl: ifnet pseudo-device ppp: ifnet pseudo-device tun: ifnet pseudo-device bpfilter: ifnet +pseudo-device rnd # XXX machine-independent SCSI files should live somewhere here, maybe @@ -69,6 +70,7 @@ file dev/ic/ncr5380sbc.c ncr5380sbc file dev/ic/pdq.c pdq file dev/ic/pdq_ifsubr.c pdq file dev/mulaw.c mulaw +file dev/rnd.c rnd needs-flag file dev/vnd.c vnd needs-flag file isofs/cd9660/cd9660_bmap.c cd9660 file isofs/cd9660/cd9660_lookup.c cd9660 diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index 0667f8ed409..1db9d352799 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -60,6 +60,11 @@ #include #include +#include "rnd.h" +#if NRND > 0 +#include +#endif + /* Macros to clear/set/test flags. */ #define SET(t, f) (t) |= (f) #define CLR(t, f) (t) &= ~(f) @@ -790,6 +795,10 @@ biodone(bp) panic("biodone already"); SET(bp->b_flags, B_DONE); /* note that it's done */ +#if NRND > 0 + add_blkdev_randomness(bp->b_dev); +#endif + if (!ISSET(bp->b_flags, B_READ)) /* wake up reader */ vwakeup(bp); diff --git a/sys/net/netisr.h b/sys/net/netisr.h index ed6a6325d73..32db862d910 100644 --- a/sys/net/netisr.h +++ b/sys/net/netisr.h @@ -61,10 +61,17 @@ #define NETISR_ARP 18 /* same as AF_LINK */ #define NETISR_PPP 26 /* for PPP processing */ -#define schednetisr(anisr) { netisr |= 1<<(anisr); setsoftnet(); } - #ifndef _LOCORE #ifdef _KERNEL int netisr; /* scheduling bits for network */ + +#include "rnd.h" +#if NRND > 0 +#include +#define schednetisr(anisr) \ + { netisr |= 1<<(anisr); add_net_randomness(anisr); setsoftnet(); } +#else /* no rnd */ +#define schednetisr(anisr) { netisr |= 1<<(anisr); setsoftnet(); } +#endif #endif #endif diff --git a/sys/sys/conf.h b/sys/sys/conf.h index e4cb5e72632..f4efd834fcb 100644 --- a/sys/sys/conf.h +++ b/sys/sys/conf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.h,v 1.3 1996/03/03 12:11:27 niklas Exp $ */ +/* $OpenBSD: conf.h,v 1.4 1996/03/29 12:05:56 mickey Exp $ */ /* $NetBSD: conf.h,v 1.30 1996/02/13 21:08:50 christos Exp $ */ /*- @@ -305,6 +305,12 @@ extern struct cdevsw cdevsw[]; (dev_type_stop((*))) enodev, 0, (dev_type_select((*))) enodev, \ (dev_type_mmap((*))) enodev } +/* open, close, read, write, ioctl, select */ +#define cdev_rnd_init(c,n) { \ + dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \ + dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \ + 0, dev_init(c,n,select), (dev_type_mmap((*))) enodev } + /* symbolic sleep message strings */ extern char devopn[], devio[], devwait[], devin[], devout[]; extern char devioc[], devcls[]; -- 2.20.1