From 8c19166361339fef87a5a5fb737bdb0ce9e69b94 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 8 Oct 2002 12:12:56 +0000 Subject: [PATCH] Comment initialisation conditions for rnd better, and don't uselessly call rnd_init - instead assert that it has already been called earlier. change assert() -> KASSERT() --- sys/dev/rnd.c | 24 +++++++++++++----------- sys/dev/rndpool.c | 8 ++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/sys/dev/rnd.c b/sys/dev/rnd.c index d8f0b814a72e..47e3f6563042 100644 --- a/sys/dev/rnd.c +++ b/sys/dev/rnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: rnd.c,v 1.33 2002/10/08 09:59:27 dan Exp $ */ +/* $NetBSD: rnd.c,v 1.34 2002/10/08 12:12:56 dan Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rnd.c,v 1.33 2002/10/08 09:59:27 dan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rnd.c,v 1.34 2002/10/08 12:12:56 dan Exp $"); #include #include @@ -280,27 +280,29 @@ rnd_estimate_entropy(rndsource_t *rs, u_int32_t t) } /* - * Attach the random device, and initialize the global random pool - * for our use. + * "Attach" the random device. This is an (almost) empty stub, since + * pseudo-devices don't get attached until after config, after the + * entropy sources will attach. We just use the timing of this event + * as another potential source of initial entropy. */ void rndattach(int num) { u_int32_t c; - /* - * rnd_init() is actually called very early on in the boot - * process, pseudo's don't get attached until much later - * (after many of the sources have been attached). - * XXX Maybe this is left "in case", maybe it should be an assert? - */ - rnd_init(); + /* Trap unwary players who don't call rnd_init() early */ + KASSERT(rnd_ready); /* mix in another counter */ c = rnd_counter(); rndpool_add_data(&rnd_pool, &c, sizeof(u_int32_t), 0); } +/* + * initialize the global random pool for our use. + * rnd_init() must be called very early on in the boot process, so + * the pool is ready for other devices to attach as sources. + */ void rnd_init(void) { diff --git a/sys/dev/rndpool.c b/sys/dev/rndpool.c index 6a2fdf23c959..5a1e9feea4e9 100644 --- a/sys/dev/rndpool.c +++ b/sys/dev/rndpool.c @@ -1,4 +1,4 @@ -/* $NetBSD: rndpool.c,v 1.14 2001/11/15 09:48:03 lukem Exp $ */ +/* $NetBSD: rndpool.c,v 1.15 2002/10/08 12:12:57 dan Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: rndpool.c,v 1.14 2001/11/15 09:48:03 lukem Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rndpool.c,v 1.15 2002/10/08 12:12:57 dan Exp $"); #include #include @@ -71,7 +71,7 @@ rndpool_init(rndpool_t *rp) rp->stats.threshold = RND_ENTROPY_THRESHOLD; rp->stats.maxentropy = RND_POOLBITS; - assert(RND_ENTROPY_THRESHOLD*2 <= 20); /* XXX sha knowledge */ + KASSERT(RND_ENTROPY_THRESHOLD*2 <= 20); /* XXX sha knowledge */ } u_int32_t @@ -241,7 +241,7 @@ rndpool_extract_data(rndpool_t *rp, void *p, u_int32_t len, u_int32_t mode) else good = (rp->stats.curentropy >= (8 * RND_ENTROPY_THRESHOLD)); - assert(RND_ENTROPY_THRESHOLD*2 <= 20); /* XXX SHA knowledge */ + KASSERT(RND_ENTROPY_THRESHOLD*2 <= 20); /* XXX SHA knowledge */ while (good && (remain != 0)) { /*