Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 9 Oct 2013 20:14:16 +0000 (UTC)
From:      Dag-Erling Smørgrav <des@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r256240 - in projects/random_number_generator/sys: conf dev/random
Message-ID:  <201310092014.r99KEGmv002798@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <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)

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 <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, 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 <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 *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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310092014.r99KEGmv002798>