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>
This commit is contained in:
Mark Murray 2013-08-30 17:47:53 +00:00
parent 77de2c3f58
commit 7737ec4198
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/projects/random_number_generator/; revision=255075
3 changed files with 1 additions and 92 deletions

View File

@ -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, 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);

View File

@ -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)
{

View File

@ -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