diff options
author | des <des@FreeBSD.org> | 2013-10-09 20:14:16 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2013-10-09 20:14:16 +0000 |
commit | 512bff9c9fd0cf3326b33cd3e68ca57b094887b5 (patch) | |
tree | 47e682bf6550bccf9eeacad418b6d8392f4fcded /sys/dev/random | |
parent | 70d43b7c68540a603be107ab5b94dc720bccdb6d (diff) | |
download | FreeBSD-src-512bff9c9fd0cf3326b33cd3e68ca57b094887b5.zip FreeBSD-src-512bff9c9fd0cf3326b33cd3e68ca57b094887b5.tar.gz |
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.
Diffstat (limited to 'sys/dev/random')
-rw-r--r-- | sys/dev/random/random_harvestq.c | 15 | ||||
-rw-r--r-- | sys/dev/random/randomdev_soft.c | 30 | ||||
-rw-r--r-- | sys/dev/random/rwfile.c | 6 | ||||
-rw-r--r-- | sys/dev/random/rwfile.h | 4 |
4 files changed, 36 insertions, 19 deletions
diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c index 84067aa..471a266 100644 --- a/sys/dev/random/random_harvestq.c +++ b/sys/dev/random/random_harvestq.c @@ -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) diff --git a/sys/dev/random/randomdev_soft.c b/sys/dev/random/randomdev_soft.c index 9c3aa53..db0b016 100644 --- a/sys/dev/random/randomdev_soft.c +++ b/sys/dev/random/randomdev_soft.c @@ -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 diff --git a/sys/dev/random/rwfile.c b/sys/dev/random/rwfile.c index 85afcb0..9b38957 100644 --- a/sys/dev/random/rwfile.c +++ b/sys/dev/random/rwfile.c @@ -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 diff --git a/sys/dev/random/rwfile.h b/sys/dev/random/rwfile.h index 22ac06d..f14fd7b 100644 --- a/sys/dev/random/rwfile.h +++ b/sys/dev/random/rwfile.h @@ -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 |