summaryrefslogtreecommitdiffstats
path: root/sys/dev/random/nehemiah.c
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2014-10-30 21:21:53 +0000
committermarkm <markm@FreeBSD.org>2014-10-30 21:21:53 +0000
commitfce6747f55fd538917f2bd60e601dc95866c16d0 (patch)
treed5dfa61a018a7d209b25f173c6ee76709037035a /sys/dev/random/nehemiah.c
parentda82006ada584e84400ef56335e9df6c4e72bc6e (diff)
downloadFreeBSD-src-fce6747f55fd538917f2bd60e601dc95866c16d0.zip
FreeBSD-src-fce6747f55fd538917f2bd60e601dc95866c16d0.tar.gz
This is the much-discussed major upgrade to the random(4) device, known to you all as /dev/random.
This code has had an extensive rewrite and a good series of reviews, both by the author and other parties. This means a lot of code has been simplified. Pluggable structures for high-rate entropy generators are available, and it is most definitely not the case that /dev/random can be driven by only a hardware souce any more. This has been designed out of the device. Hardware sources are stirred into the CSPRNG (Yarrow, Fortuna) like any other entropy source. Pluggable modules may be written by third parties for additional sources. The harvesting structures and consequently the locking have been simplified. Entropy harvesting is done in a more general way (the documentation for this will follow). There is some GREAT entropy to be had in the UMA allocator, but it is disabled for now as messing with that is likely to annoy many people. The venerable (but effective) Yarrow algorithm, which is no longer supported by its authors now has an alternative, Fortuna. For now, Yarrow is retained as the default algorithm, but this may be changed using a kernel option. It is intended to make Fortuna the default algorithm for 11.0. Interested parties are encouraged to read ISBN 978-0-470-47424-2 "Cryptography Engineering" By Ferguson, Schneier and Kohno for Fortuna's gory details. Heck, read it anyway. Many thanks to Arthur Mesh who did early grunt work, and who got caught in the crossfire rather more than he deserved to. My thanks also to folks who helped me thresh this out on whiteboards and in the odd "Hallway track", or otherwise. My Nomex pants are on. Let the feedback commence! Reviewed by: trasz,des(partial),imp(partial?),rwatson(partial?) Approved by: so(des)
Diffstat (limited to 'sys/dev/random/nehemiah.c')
-rw-r--r--sys/dev/random/nehemiah.c37
1 files changed, 18 insertions, 19 deletions
diff --git a/sys/dev/random/nehemiah.c b/sys/dev/random/nehemiah.c
index b60689e..4740250 100644
--- a/sys/dev/random/nehemiah.c
+++ b/sys/dev/random/nehemiah.c
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2013 Mark R V Murray
+ * Copyright (c) 2013 David E. O'Brien <obrien@NUXI.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -30,11 +31,11 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/kernel.h>
+#include <sys/conf.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/random.h>
-#include <sys/selinfo.h>
#include <sys/systm.h>
#include <machine/segments.h>
@@ -44,21 +45,20 @@ __FBSDID("$FreeBSD$");
#include <dev/random/randomdev.h>
#include <dev/random/randomdev_soft.h>
-#include <dev/random/random_harvestq.h>
-#include <dev/random/live_entropy_sources.h>
#include <dev/random/random_adaptors.h>
+#include <dev/random/live_entropy_sources.h>
static void random_nehemiah_init(void);
static void random_nehemiah_deinit(void);
-static int random_nehemiah_read(void *, int);
+static u_int random_nehemiah_read(void *, u_int);
-static struct random_hardware_source random_nehemiah = {
- .ident = "Hardware, VIA Nehemiah Padlock RNG",
- .source = RANDOM_PURE_NEHEMIAH,
- .read = random_nehemiah_read
+static struct live_entropy_source random_nehemiah = {
+ .les_ident = "VIA Nehemiah Padlock RNG",
+ .les_source = RANDOM_PURE_NEHEMIAH,
+ .les_read = random_nehemiah_read
};
-/* TODO: now that the Davies-Meyer hash is gone and we only use
+/* XXX: FIX? Now that the Davies-Meyer hash is gone and we only use
* the 'xstore' instruction, do we still need to preserve the
* FPU state with fpu_kern_(enter|leave)() ?
*/
@@ -75,7 +75,7 @@ VIA_RNG_store(void *buf)
#ifdef __GNUCLIKE_ASM
__asm __volatile(
"movl $0,%%edx\n\t"
- ".byte 0x0f, 0xa7, 0xc0" /* xstore */
+ "xstore"
: "=a" (retval), "+d" (rate), "+D" (buf)
:
: "memory"
@@ -100,8 +100,9 @@ random_nehemiah_deinit(void)
fpu_kern_free_ctx(fpu_ctx_save);
}
-static int
-random_nehemiah_read(void *buf, int c)
+/* It is specifically allowed that buf is a multiple of sizeof(long) */
+static u_int
+random_nehemiah_read(void *buf, u_int c)
{
uint8_t *b;
size_t count, ret;
@@ -131,13 +132,9 @@ nehemiah_modevent(module_t mod, int type, void *unused)
case MOD_LOAD:
if (via_feature_rng & VIA_HAS_RNG) {
live_entropy_source_register(&random_nehemiah);
+ printf("random: live provider: \"%s\"\n", random_nehemiah.les_ident);
random_nehemiah_init();
- } else
-#ifndef KLD_MODULE
- if (bootverbose)
-#endif
- printf("%s: VIA Padlock RNG not present\n",
- random_nehemiah.ident);
+ }
break;
case MOD_UNLOAD:
@@ -158,4 +155,6 @@ nehemiah_modevent(module_t mod, int type, void *unused)
return (error);
}
-LIVE_ENTROPY_SRC_MODULE(nehemiah, nehemiah_modevent, 1);
+DEV_MODULE(nehemiah, nehemiah_modevent, NULL);
+MODULE_VERSION(nehemiah, 1);
+MODULE_DEPEND(nehemiah, random_adaptors, 1, 1, 1);
OpenPOWER on IntegriCloud