From 7737ec4198800562e2c6d46d6b8a15ce5282058c Mon Sep 17 00:00:00 2001 From: Mark Murray Date: Fri, 30 Aug 2013 17:47:53 +0000 Subject: [PATCH] Remove short-lived idea; thread to harvest (eg) RDRAND enropy into the usual harvest queues. It was a nifty idea, but too heavyweight. Submitted by: Arthur Mesh --- .../random_adaptor/random_adaptor_example.c | 20 +----- sys/dev/random/random_adaptors.c | 71 ------------------- sys/dev/random/random_adaptors.h | 2 - 3 files changed, 1 insertion(+), 92 deletions(-) diff --git a/share/examples/kld/random_adaptor/random_adaptor_example.c b/share/examples/kld/random_adaptor/random_adaptor_example.c index f94a7c20f3a3..c0ab10a83fc5 100644 --- a/share/examples/kld/random_adaptor/random_adaptor_example.c +++ b/share/examples/kld/random_adaptor/random_adaptor_example.c @@ -37,16 +37,13 @@ __FBSDID("$FreeBSD$"); #include #include -static int random_example_entropy_control; - #define RNG_NAME "example" static int random_example_read(void *, int); -static void random_example_init(void); struct random_adaptor random_example = { .ident = "Example RNG", - .init = random_example_init, + .init = (random_init_func_t *)random_null_func, .deinit = (random_deinit_func_t *)random_null_func, .read = random_example_read, .write = (random_write_func_t *)random_null_func, @@ -54,18 +51,6 @@ struct random_adaptor random_example = { .seeded = 1, }; -static void -random_example_init(void) -{ - - /* - * Init() is called only if this RNG was chosen to plugin in to - * random(4). In which case, we should no longer use this adaptor as - * an entropy source. - */ - random_example_entropy_control = 1; -} - /* * Used under the license provided @ http://xkcd.com/221/ * http://creativecommons.org/licenses/by-nc/2.5/ @@ -98,9 +83,6 @@ random_example_modevent(module_t mod, int type, void *unused) switch (type) { case MOD_LOAD: - /* start off by using this as an entropy source */ - random_adaptor_use_as_entropy(RNG_NAME, &random_example, - &random_example_entropy_control); random_adaptor_register(RNG_NAME, &random_example); EVENTHANDLER_INVOKE(random_adaptor_attach, &random_example); return (0); diff --git a/sys/dev/random/random_adaptors.c b/sys/dev/random/random_adaptors.c index b017993c1ecc..f6a21f6e08f4 100644 --- a/sys/dev/random/random_adaptors.c +++ b/sys/dev/random/random_adaptors.c @@ -55,11 +55,6 @@ static struct sysctl_ctx_list random_clist; MALLOC_DEFINE(M_RANDOM_ADAPTORS, "random_adaptors", "Random adaptors buffers"); -struct entropy_thread_ctx { - struct random_adaptor *adaptor; - int *control; -}; - int random_adaptor_register(const char *name, struct random_adaptor *rsp) { @@ -185,72 +180,6 @@ random_adaptor_choose(struct random_adaptor **adaptor) } } -static void -random_proc(void *arg) -{ - struct entropy_thread_ctx *ctx; - u_char randomness[HARVESTSIZE]; - int i; - - ctx = (struct entropy_thread_ctx *)arg; - - /* Sanity check. */ - if (ctx->adaptor == NULL || ctx->adaptor->read == NULL) - return; - - for (; *ctx->control == 0;) { - i = ctx->adaptor->read(randomness, sizeof(randomness)); - - if (i > 0) - /* Be very conservative with entropy estimation here. */ - random_harvest(randomness, i, 0, 0, RANDOM_PURE); - - /* Wake up every 10 secs. */ - tsleep_sbt(ctx->adaptor, PWAIT | PCATCH, "-", SBT_1M / 6, 0, 0); - } - - printf("<%s> entropy source is exiting\n", ctx->adaptor->ident); - free(ctx, M_RANDOM_ADAPTORS); - kproc_exit(0); -} - -/* - * Use RNG's output as an entropy source for another RNG. i.e.: - * +--------+ +--------+ - * | Intel | | Yarrow | - * | RDRAND +--------->| | - * +--------+ +--------+ - * Very useful for seeding software RNGs with output of - * Hardware RNGs like Intel's RdRand and VIA's Padlock. - * - * Returns a handle to the newly created kernel process. - */ -void * -random_adaptor_use_as_entropy(const char *id, struct random_adaptor *adaptor, - int *control) -{ - int error; - struct proc *random_chain_proc; - struct entropy_thread_ctx *ctx; - - KASSERT(adaptor != NULL, ("can't obtain randomness")); - KASSERT(control != NULL, ("can't control entropy process")); - - ctx = malloc(sizeof(struct entropy_thread_ctx), M_RANDOM_ADAPTORS, - M_WAITOK); - - ctx->control = control; - ctx->adaptor = adaptor; - - /* Start the thread */ - error = kproc_create(random_proc, ctx, &random_chain_proc, RFHIGHPID, - 0, "%s_entropy", id); - if (error != 0) - panic("Cannot create rng chaining thread"); - - return random_chain_proc; -} - static void random_adaptors_deinit(void *unused) { diff --git a/sys/dev/random/random_adaptors.h b/sys/dev/random/random_adaptors.h index b3038e750620..98f8c2ebe273 100644 --- a/sys/dev/random/random_adaptors.h +++ b/sys/dev/random/random_adaptors.h @@ -40,8 +40,6 @@ struct random_adaptors { struct random_adaptor *random_adaptor_get(const char *); int random_adaptor_register(const char *, struct random_adaptor *); void random_adaptor_choose(struct random_adaptor **); -void *random_adaptor_use_as_entropy(const char *, struct random_adaptor *, - int *); /* * random_adaptor's should be registered prior to