Date: Fri, 30 Aug 2013 17:47:53 +0000 (UTC) From: Mark Murray <markm@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r255075 - in projects/random_number_generator: share/examples/kld/random_adaptor sys/dev/random Message-ID: <201308301747.r7UHlr88098379@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markm Date: Fri Aug 30 17:47:53 2013 New Revision: 255075 URL: http://svnweb.freebsd.org/changeset/base/255075 Log: 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 <arthurmesh@gmail.com> Modified: projects/random_number_generator/share/examples/kld/random_adaptor/random_adaptor_example.c projects/random_number_generator/sys/dev/random/random_adaptors.c projects/random_number_generator/sys/dev/random/random_adaptors.h Modified: projects/random_number_generator/share/examples/kld/random_adaptor/random_adaptor_example.c ============================================================================== --- projects/random_number_generator/share/examples/kld/random_adaptor/random_adaptor_example.c Fri Aug 30 15:26:45 2013 (r255074) +++ projects/random_number_generator/share/examples/kld/random_adaptor/random_adaptor_example.c Fri Aug 30 17:47:53 2013 (r255075) @@ -37,16 +37,13 @@ __FBSDID("$FreeBSD$"); #include <dev/random/random_adaptors.h> #include <dev/random/randomdev.h> -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, in 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); Modified: projects/random_number_generator/sys/dev/random/random_adaptors.c ============================================================================== --- projects/random_number_generator/sys/dev/random/random_adaptors.c Fri Aug 30 15:26:45 2013 (r255074) +++ projects/random_number_generator/sys/dev/random/random_adaptors.c Fri Aug 30 17:47:53 2013 (r255075) @@ -55,11 +55,6 @@ static struct sysctl_ctx_list random_cli 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) { @@ -186,72 +181,6 @@ random_adaptor_choose(struct random_adap } 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) { Modified: projects/random_number_generator/sys/dev/random/random_adaptors.h ============================================================================== --- projects/random_number_generator/sys/dev/random/random_adaptors.h Fri Aug 30 15:26:45 2013 (r255074) +++ projects/random_number_generator/sys/dev/random/random_adaptors.h Fri Aug 30 17:47:53 2013 (r255075) @@ -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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308301747.r7UHlr88098379>