summaryrefslogtreecommitdiffstats
path: root/sys/dev/random/randomdev.c
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2015-07-12 18:14:38 +0000
committermarkm <markm@FreeBSD.org>2015-07-12 18:14:38 +0000
commit4637ff6821091c57822745d18854f54b02203327 (patch)
tree5ad967e986577467824558c7d72ffc554a5b9df7 /sys/dev/random/randomdev.c
parent69cdb114a9d0ef83c599d0e47901b96584f2c361 (diff)
downloadFreeBSD-src-4637ff6821091c57822745d18854f54b02203327.zip
FreeBSD-src-4637ff6821091c57822745d18854f54b02203327.tar.gz
* Address review (and add a bit myself).
- Tweek man page. - Remove all mention of RANDOM_FORTUNA. If the system owner wants YARROW or DUMMY, they ask for it, otherwise they get FORTUNA. - Tidy up headers a bit. - Tidy up declarations a bit. - Make static in a couple of places where needed. - Move Yarrow/Fortuna SYSINIT/SYSUNINIT to randomdev.c, moving us towards a single file where the algorithm context is used. - Get rid of random_*_process_buffer() functions. They were only used in one place each, and are better subsumed into those places. - Remove *_post_read() functions as they are stubs everywhere. - Assert against buffer size illegalities. - Clean up some silly code in the randomdev_read() routine. - Make the harvesting more consistent. - Make some requested argument name changes. - Tidy up and clarify a few comments. - Make some requested comment changes. - Make some requested macro changes. * NOTE: the thing calling itself a 'unit test' is not yet a proper unit test, but it helps me ensure things work. It may be a proper unit test at some time in the future, but for now please don't make any assumptions or hold any expectations. Differential Revision: https://reviews.freebsd.org/D2025 Approved by: so (/dev/random blanket)
Diffstat (limited to 'sys/dev/random/randomdev.c')
-rw-r--r--sys/dev/random/randomdev.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/sys/dev/random/randomdev.c b/sys/dev/random/randomdev.c
index 1d9dcbe..a70b3f2 100644
--- a/sys/dev/random/randomdev.c
+++ b/sys/dev/random/randomdev.c
@@ -62,7 +62,7 @@ __FBSDID("$FreeBSD$");
#error "Cannot define both RANDOM_DUMMY and RANDOM_YARROW"
#endif
-#define RANDOM_MINOR 0
+#define RANDOM_UNIT 0
static d_read_t randomdev_read;
static d_write_t randomdev_write;
@@ -107,12 +107,13 @@ dummy_random(void)
struct random_algorithm random_alg_context = {
.ra_ident = "Dummy",
- .ra_reseed = dummy_random,
- .ra_seeded = (random_alg_seeded_t *)dummy_random_zero,
+ .ra_init_alg = NULL,
+ .ra_deinit_alg = NULL,
.ra_pre_read = dummy_random,
.ra_read = (random_alg_read_t *)dummy_random_zero,
- .ra_post_read = dummy_random,
.ra_write = (random_alg_write_t *)dummy_random_zero,
+ .ra_reseed = dummy_random,
+ .ra_seeded = (random_alg_seeded_t *)dummy_random_zero,
.ra_event_processor = NULL,
.ra_poolcount = 0,
};
@@ -123,6 +124,23 @@ LIST_HEAD(sources_head, random_sources);
static struct sources_head source_list = LIST_HEAD_INITIALIZER(source_list);
static u_int read_rate;
+static void
+random_alg_context_ra_init_alg(void *data)
+{
+
+ random_alg_context.ra_init_alg(data);
+}
+
+static void
+random_alg_context_ra_deinit_alg(void *data)
+{
+
+ random_alg_context.ra_deinit_alg(data);
+}
+
+SYSINIT(random_device, SI_SUB_RANDOM, SI_ORDER_THIRD, random_alg_context_ra_init_alg, NULL);
+SYSUNINIT(random_device, SI_SUB_RANDOM, SI_ORDER_THIRD, random_alg_context_ra_deinit_alg, NULL);
+
#endif /* defined(RANDOM_DUMMY) */
static struct selinfo rsel;
@@ -142,15 +160,15 @@ randomdev_read(struct cdev *dev __unused, struct uio *uio, int flags)
random_alg_context.ra_pre_read();
/* (Un)Blocking logic */
error = 0;
- while (!random_alg_context.ra_seeded() && error == 0) {
+ while (!random_alg_context.ra_seeded()) {
if (flags & O_NONBLOCK) {
error = EWOULDBLOCK;
break;
}
- tsleep(&random_alg_context, 0, "randrd", hz/10);
+ tsleep(&random_alg_context, 0, "randseed", hz/10);
/* keep tapping away at the pre-read until we seed/unblock. */
random_alg_context.ra_pre_read();
- printf("random: %s unblock (error = %d)\n", __func__, error);
+ printf("random: %s unblock wait\n", __func__);
}
if (error == 0) {
#if !defined(RANDOM_DUMMY)
@@ -160,10 +178,10 @@ randomdev_read(struct cdev *dev __unused, struct uio *uio, int flags)
nbytes = uio->uio_resid;
while (uio->uio_resid && !error) {
c = MIN(uio->uio_resid, PAGE_SIZE);
+ /* See the random_buf size requirements in the Yarrow/Fortuna code */
random_alg_context.ra_read(random_buf, c);
error = uiomove(random_buf, c, uio);
}
- random_alg_context.ra_post_read();
if (nbytes != uio->uio_resid && (error == ERESTART || error == EINTR) )
/* Return partial read, not error. */
error = 0;
@@ -204,7 +222,6 @@ read_random(void *random_buf, u_int len)
memcpy(random_buf, local_buf, len);
} else
len = 0;
- random_alg_context.ra_post_read();
return (len);
}
@@ -382,7 +399,7 @@ randomdev_modevent(module_t mod __unused, int type, void *data __unused)
case MOD_LOAD:
printf("random: entropy device external interface\n");
random_dev = make_dev_credf(MAKEDEV_ETERNAL_KLD, &random_cdevsw,
- RANDOM_MINOR, NULL, UID_ROOT, GID_WHEEL, 0644, "random");
+ RANDOM_UNIT, NULL, UID_ROOT, GID_WHEEL, 0644, "random");
make_dev_alias(random_dev, "urandom"); /* compatibility */
break;
case MOD_UNLOAD:
OpenPOWER on IntegriCloud