From owner-svn-src-projects@FreeBSD.ORG Wed Oct 9 20:14:18 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 05BA3BAE; Wed, 9 Oct 2013 20:14:18 +0000 (UTC) (envelope-from des@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D887C22D3; Wed, 9 Oct 2013 20:14:17 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r99KEHaA002840; Wed, 9 Oct 2013 20:14:17 GMT (envelope-from des@svn.freebsd.org) Received: (from des@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r99KEGmv002798; Wed, 9 Oct 2013 20:14:16 GMT (envelope-from des@svn.freebsd.org) Message-Id: <201310092014.r99KEGmv002798@svn.freebsd.org> From: Dag-Erling Smørgrav Date: Wed, 9 Oct 2013 20:14:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r256240 - in projects/random_number_generator/sys: conf dev/random X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Oct 2013 20:14:18 -0000 Author: des Date: Wed Oct 9 20:14:16 2013 New Revision: 256240 URL: http://svnweb.freebsd.org/changeset/base/256240 Log: 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. Modified: projects/random_number_generator/sys/conf/NOTES projects/random_number_generator/sys/conf/options projects/random_number_generator/sys/dev/random/random_harvestq.c projects/random_number_generator/sys/dev/random/randomdev_soft.c projects/random_number_generator/sys/dev/random/rwfile.c projects/random_number_generator/sys/dev/random/rwfile.h Modified: projects/random_number_generator/sys/conf/NOTES ============================================================================== --- projects/random_number_generator/sys/conf/NOTES Wed Oct 9 20:12:59 2013 (r256239) +++ projects/random_number_generator/sys/conf/NOTES Wed Oct 9 20:14:16 2013 (r256240) @@ -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 Modified: projects/random_number_generator/sys/conf/options ============================================================================== --- projects/random_number_generator/sys/conf/options Wed Oct 9 20:12:59 2013 (r256239) +++ projects/random_number_generator/sys/conf/options Wed Oct 9 20:14:16 2013 (r256240) @@ -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 Modified: projects/random_number_generator/sys/dev/random/random_harvestq.c ============================================================================== --- projects/random_number_generator/sys/dev/random/random_harvestq.c Wed Oct 9 20:12:59 2013 (r256239) +++ projects/random_number_generator/sys/dev/random/random_harvestq.c Wed Oct 9 20:14:16 2013 (r256240) @@ -30,6 +30,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_random.h" + #include #include #include @@ -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) Modified: projects/random_number_generator/sys/dev/random/randomdev_soft.c ============================================================================== --- projects/random_number_generator/sys/dev/random/randomdev_soft.c Wed Oct 9 20:12:59 2013 (r256239) +++ projects/random_number_generator/sys/dev/random/randomdev_soft.c Wed Oct 9 20:14:16 2013 (r256240) @@ -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 #include #include -#if defined(YARROW_RNG) +#if defined(RANDOM_YARROW) #include #endif -#if defined(FORTUNA_RNG) +#if defined(RANDOM_FORTUNA) #include #endif @@ -74,7 +74,7 @@ static int randomdev_poll(int event, str 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_cont #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 Modified: projects/random_number_generator/sys/dev/random/rwfile.c ============================================================================== --- projects/random_number_generator/sys/dev/random/rwfile.c Wed Oct 9 20:12:59 2013 (r256239) +++ projects/random_number_generator/sys/dev/random/rwfile.c Wed Oct 9 20:14:16 2013 (r256240) @@ -28,6 +28,10 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_random.h" + +#ifdef RANDOM_RWFILE + #include #include #include @@ -88,3 +92,5 @@ randomdev_write_file(const char *filenam return (error); } + +#endif Modified: projects/random_number_generator/sys/dev/random/rwfile.h ============================================================================== --- projects/random_number_generator/sys/dev/random/rwfile.h Wed Oct 9 20:12:59 2013 (r256239) +++ projects/random_number_generator/sys/dev/random/rwfile.h Wed Oct 9 20:14:16 2013 (r256240) @@ -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