Add a RANDOM_RWFILE option and hide the entropy cache code behind it.

Rename YARROW_RNG and FORTUNA_RNG to RANDOM_YARROW and RANDOM_FORTUNA.
Add the RANDOM_* options to LINT.
This commit is contained in:
Dag-Erling Smørgrav 2013-10-09 20:14:16 +00:00
parent 6916062296
commit 997b0a641d
6 changed files with 44 additions and 21 deletions

@ -2962,3 +2962,8 @@ options RCTL
options BROOKTREE_ALLOC_PAGES=(217*4+1)
options MAXFILES=999
# Random number generator
options RANDOM_YARROW # Yarrow RNG
##options RANDOM_FORTUNA # Fortuna RNG - not yet implemented
options RANDOM_DEBUG # Debugging messages
options RANDOM_RWFILE # Read and write entropy cache

@ -906,6 +906,7 @@ RACCT opt_global.h
RCTL opt_global.h
# Random number generator(s)
YARROW_RNG opt_random.h
FORTUNA_RNG opt_random.h
RANDOM_YARROW opt_random.h
RANDOM_FORTUNA opt_random.h
RANDOM_DEBUG opt_random.h
RANDOM_RWFILE opt_random.h

@ -30,6 +30,8 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "opt_random.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/eventhandler.h>
@ -79,11 +81,12 @@ int random_kthread_control = 0;
static struct proc *random_kthread_proc;
#ifdef NOTYET /* This is full of policy stuff, needs further discussion */
#ifdef RANDOM_RWFILE
static const char *entropy_files[] = {
"/entropy",
NULL
};
#endif
/* Deal with entropy cached externally if this is present.
* Lots of policy may eventually arrive in this function.
@ -92,10 +95,13 @@ static const char *entropy_files[] = {
static void
random_harvestq_cache(void *arg __unused)
{
const char **entropy_file;
uint8_t *keyfile, *data, *zbuf;
uint8_t *keyfile, *data;
size_t size, i;
#ifdef RANDOM_RWFILE
const char **entropy_file;
uint8_t *zbuf;
int error;
#endif
/* Get stuff that may have been preloaded by loader(8) */
keyfile = preload_search_by_type("/boot/entropy");
@ -112,6 +118,7 @@ random_harvestq_cache(void *arg __unused)
printf("random: no preloaded entropy cache available\n");
}
#ifdef RANDOM_RWFILE
/* Read and attempt to overwrite the entropy cache files.
* If the file exists, can be read and then overwritten,
* then use it. Ignore it otherwise, but print out what is
@ -137,9 +144,9 @@ random_harvestq_cache(void *arg __unused)
}
bzero(data, PAGE_SIZE);
free(data, M_ENTROPY);
#endif
}
EVENTHANDLER_DEFINE(mountroot, random_harvestq_cache, NULL, 0);
#endif /* NOTYET */
static void
random_kthread(void *arg)

@ -28,12 +28,12 @@
#include "opt_random.h"
#if !defined(YARROW_RNG) && !defined(FORTUNA_RNG)
#define YARROW_RNG
#elif defined(YARROW_RNG) && defined(FORTUNA_RNG)
#error "Must define either YARROW_RNG or FORTUNA_RNG"
#if !defined(RANDOM_YARROW) && !defined(RANDOM_FORTUNA)
#define RANDOM_YARROW
#elif defined(RANDOM_YARROW) && defined(RANDOM_FORTUNA)
#error "Must define either RANDOM_YARROW or RANDOM_FORTUNA"
#endif
#if defined(FORTUNA_RNG)
#if defined(RANDOM_FORTUNA)
#error "Fortuna is not yet implemented"
#endif
@ -62,10 +62,10 @@ __FBSDID("$FreeBSD$");
#include <dev/random/randomdev_soft.h>
#include <dev/random/random_harvestq.h>
#include <dev/random/random_adaptors.h>
#if defined(YARROW_RNG)
#if defined(RANDOM_YARROW)
#include <dev/random/yarrow.h>
#endif
#if defined(FORTUNA_RNG)
#if defined(RANDOM_FORTUNA)
#include <dev/random/fortuna.h>
#endif
@ -74,7 +74,7 @@ static int randomdev_poll(int event, struct thread *td);
static int randomdev_block(int flag);
static void randomdev_flush_reseed(void);
#if defined(YARROW_RNG)
#if defined(RANDOM_YARROW)
static struct random_adaptor random_context = {
.ident = "Software, Yarrow",
.init = randomdev_init,
@ -89,7 +89,7 @@ static struct random_adaptor random_context = {
#define RANDOM_CSPRNG_NAME "yarrow"
#endif
#if defined(FORTUNA_RNG)
#if defined(RANDOM_FORTUNA)
static struct random_adaptor random_context = {
.ident = "Software, Fortuna",
.init = randomdev_init,
@ -123,10 +123,10 @@ randomdev_init(void)
{
struct sysctl_oid *random_sys_o, *random_sys_harvest_o;
#if defined(YARROW_RNG)
#if defined(RANDOM_YARROW)
random_yarrow_init_alg(&random_clist);
#endif
#if defined(FORTUNA_RNG)
#if defined(RANDOM_FORTUNA)
random_fortuna_init_alg(&random_clist);
#endif
@ -186,10 +186,10 @@ randomdev_deinit(void)
random_kthread_control = -1;
tsleep((void *)&random_kthread_control, 0, "term", 0);
#if defined(YARROW_RNG)
#if defined(RANDOM_YARROW)
random_yarrow_deinit_alg();
#endif
#if defined(FORTUNA_RNG)
#if defined(RANDOM_FORTUNA)
random_fortuna_deinit_alg();
#endif
@ -258,11 +258,11 @@ randomdev_flush_reseed(void)
while (random_kthread_control)
pause("-", hz / 10);
#if defined(YARROW_RNG)
#if defined(RANDOM_YARROW)
/* This ultimately calls randomdev_unblock() */
random_yarrow_reseed();
#endif
#if defined(FORTUNA_RNG)
#if defined(RANDOM_FORTUNA)
/* This ultimately calls randomdev_unblock() */
random_fortuna_reseed();
#endif

@ -28,6 +28,10 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include "opt_random.h"
#ifdef RANDOM_RWFILE
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@ -88,3 +92,5 @@ randomdev_write_file(const char *filename, void *buf, size_t length)
return (error);
}
#endif

@ -29,7 +29,11 @@
#ifndef SYS_DEV_RANDOM_RWFILE_H_INCLUDED
#define SYS_DEV_RANDOM_RWFILE_H_INCLUDED
#ifdef RANDOM_RWFILE
int randomdev_read_file(const char *filename, void *buf, size_t);
int randomdev_write_file(const char *filename, void *buf, size_t);
#endif
#endif