Module Name:    src
Committed By:   pooka
Date:           Fri Jan 17 01:32:53 UTC 2014

Modified Files:
        src/sys/rump/kern/lib/libcrypto: Makefile
        src/sys/rump/librump/rumpkern: Makefile.rumpkern emul.c rump.c
            rump_private.h
Added Files:
        src/sys/rump/librump/rumpkern: hyperentropy.c
Removed Files:
        src/sys/rump/librump/rumpkern: cprng_stub.c

Log Message:
Use subr_cprng.c instead of stub implementation.  Rijndael migrates from
rumpkern_crypto to rumpkern due to it being mandatory for cprng.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/kern/lib/libcrypto/Makefile
cvs rdiff -u -r1.134 -r1.135 src/sys/rump/librump/rumpkern/Makefile.rumpkern
cvs rdiff -u -r1.8 -r0 src/sys/rump/librump/rumpkern/cprng_stub.c
cvs rdiff -u -r1.160 -r1.161 src/sys/rump/librump/rumpkern/emul.c
cvs rdiff -u -r0 -r1.1 src/sys/rump/librump/rumpkern/hyperentropy.c
cvs rdiff -u -r1.281 -r1.282 src/sys/rump/librump/rumpkern/rump.c
cvs rdiff -u -r1.78 -r1.79 src/sys/rump/librump/rumpkern/rump_private.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/kern/lib/libcrypto/Makefile
diff -u src/sys/rump/kern/lib/libcrypto/Makefile:1.2 src/sys/rump/kern/lib/libcrypto/Makefile:1.3
--- src/sys/rump/kern/lib/libcrypto/Makefile:1.2	Tue Jan 14 17:05:50 2014
+++ src/sys/rump/kern/lib/libcrypto/Makefile	Fri Jan 17 01:32:53 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.2 2014/01/14 17:05:50 pgoyette Exp $
+#	$NetBSD: Makefile,v 1.3 2014/01/17 01:32:53 pooka Exp $
 #
 
 .PATH:	${.CURDIR}/../../../../crypto/arc4				\
@@ -27,7 +27,8 @@ SRCS+=	cast128.c
 SRCS+=	des_ecb.c des_setkey.c des_enc.c des_cbc.c des_module.c
 
 # rijndael
-SRCS+=	rijndael-alg-fst.c rijndael-api-fst.c rijndael.c
+# rijndael is in rumpkern due to it being used by cprng
+#SRCS+=	rijndael-alg-fst.c rijndael-api-fst.c rijndael.c
 
 # skipjack
 SRCS+=	skipjack.c

Index: src/sys/rump/librump/rumpkern/Makefile.rumpkern
diff -u src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.134 src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.135
--- src/sys/rump/librump/rumpkern/Makefile.rumpkern:1.134	Mon Dec  9 17:57:11 2013
+++ src/sys/rump/librump/rumpkern/Makefile.rumpkern	Fri Jan 17 01:32:53 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.rumpkern,v 1.134 2013/12/09 17:57:11 pooka Exp $
+#	$NetBSD: Makefile.rumpkern,v 1.135 2014/01/17 01:32:53 pooka Exp $
 #
 
 .include "${RUMPTOP}/Makefile.rump"
@@ -12,6 +12,8 @@ LIB=		rump
 	${RUMPTOP}/../uvm					\
 	${RUMPTOP}/../conf					\
 	${RUMPTOP}/../dev					\
+	${RUMPTOP}/../crypto/nist_ctr_drbg			\
+	${RUMPTOP}/../crypto/rijndael				\
 	${RUMPTOP}/../secmodel					\
 	${RUMPTOP}/../secmodel/suser				\
 	${RUMPTOP}/../compat/common
@@ -21,7 +23,7 @@ LIB=		rump
 # 
 SRCS+=	rump.c rumpcopy.c cons.c emul.c intr.c lwproc.c klock.c	\
 	kobj_rename.c ltsleep.c scheduler.c			\
-	signals.c sleepq.c threads.c vm.c cprng_stub.c
+	signals.c sleepq.c threads.c vm.c hyperentropy.c
 
 # autogenerated into the correct namespace
 RUMPOBJ_NORENAME= rump_syscalls.*o
@@ -98,6 +100,7 @@ SRCS+=	init_sysctl_base.c	\
 	subr_devsw.c		\
 	subr_callback.c		\
 	subr_copy.c		\
+	subr_cprng.c		\
 	subr_device.c		\
 	subr_evcnt.c		\
 	subr_extent.c		\
@@ -140,6 +143,14 @@ SRCS+=	vnode_if.c
 # sys/dev
 SRCS+=	clock_subr.c
 
+# sys/dev/crypto
+# Note: these are here only for cprng.  More crypto algos for drivers
+# are available from the rumpkern_crypto component
+SRCS+=	nist_ctr_drbg.c
+SRCS+=	rijndael-alg-fst.c
+SRCS+=	rijndael-api-fst.c
+SRCS+=	rijndael.c	
+
 # compat
 SRCS+=	kern_select_50.c
 

Index: src/sys/rump/librump/rumpkern/emul.c
diff -u src/sys/rump/librump/rumpkern/emul.c:1.160 src/sys/rump/librump/rumpkern/emul.c:1.161
--- src/sys/rump/librump/rumpkern/emul.c:1.160	Mon Dec 16 15:36:29 2013
+++ src/sys/rump/librump/rumpkern/emul.c	Fri Jan 17 01:32:53 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: emul.c,v 1.160 2013/12/16 15:36:29 pooka Exp $	*/
+/*	$NetBSD: emul.c,v 1.161 2014/01/17 01:32:53 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.160 2013/12/16 15:36:29 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.161 2014/01/17 01:32:53 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/null.h>
@@ -52,6 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: emul.c,v 1.1
 #include <sys/syscallvar.h>
 #include <sys/xcall.h>
 #include <sys/sleepq.h>
+#include <sys/cprng.h>
 
 #include <dev/cons.h>
 
@@ -140,6 +141,8 @@ struct emul emul_netbsd = {
 
 u_int nprocs = 1;
 
+cprng_strong_t *kern_cprng;
+
 int
 kpause(const char *wmesg, bool intr, int timeo, kmutex_t *mtx)
 {

Index: src/sys/rump/librump/rumpkern/rump.c
diff -u src/sys/rump/librump/rumpkern/rump.c:1.281 src/sys/rump/librump/rumpkern/rump.c:1.282
--- src/sys/rump/librump/rumpkern/rump.c:1.281	Mon Dec 16 15:36:30 2013
+++ src/sys/rump/librump/rumpkern/rump.c	Fri Jan 17 01:32:53 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump.c,v 1.281 2013/12/16 15:36:30 pooka Exp $	*/
+/*	$NetBSD: rump.c,v 1.282 2014/01/17 01:32:53 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.281 2013/12/16 15:36:30 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rump.c,v 1.282 2014/01/17 01:32:53 pooka Exp $");
 
 #include <sys/systm.h>
 #define ELFSIZE ARCH_ELFSIZE
@@ -338,13 +338,10 @@ rump_init(void)
 	secmodel_init();
 
 	rnd_init();
-
-	/*
-	 * Create the kernel cprng.  Yes, it's currently stubbed out
-	 * to arc4random() for RUMP, but this won't always be so.
-	 */
+	cprng_init();
 	kern_cprng = cprng_strong_create("kernel", IPL_VM,
-					 CPRNG_INIT_ANY|CPRNG_REKEY_ANY);
+	    CPRNG_INIT_ANY|CPRNG_REKEY_ANY);
+	rump_hyperentropy_init();
 
 	procinit();
 	proc0_init();
@@ -404,6 +401,8 @@ rump_init(void)
 	/* CPUs are up.  allow kernel threads to run */
 	rump_thread_allow();
 
+	rnd_init_softint();
+
 	mksysctls();
 	kqueue_init();
 	iostat_init();

Index: src/sys/rump/librump/rumpkern/rump_private.h
diff -u src/sys/rump/librump/rumpkern/rump_private.h:1.78 src/sys/rump/librump/rumpkern/rump_private.h:1.79
--- src/sys/rump/librump/rumpkern/rump_private.h:1.78	Sun Oct 27 20:25:45 2013
+++ src/sys/rump/librump/rumpkern/rump_private.h	Fri Jan 17 01:32:53 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: rump_private.h,v 1.78 2013/10/27 20:25:45 pooka Exp $	*/
+/*	$NetBSD: rump_private.h,v 1.79 2014/01/17 01:32:53 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
@@ -150,4 +150,6 @@ void	rump_thread_allow(void);
 
 void	rump_consdev_init(void);
 
+void	rump_hyperentropy_init(void);
+
 #endif /* _SYS_RUMP_PRIVATE_H_ */

Added files:

Index: src/sys/rump/librump/rumpkern/hyperentropy.c
diff -u /dev/null src/sys/rump/librump/rumpkern/hyperentropy.c:1.1
--- /dev/null	Fri Jan 17 01:32:53 2014
+++ src/sys/rump/librump/rumpkern/hyperentropy.c	Fri Jan 17 01:32:53 2014
@@ -0,0 +1,68 @@
+/*	$NetBSD: hyperentropy.c,v 1.1 2014/01/17 01:32:53 pooka Exp $	*/
+
+/*
+ * Copyright (c) 2014 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: hyperentropy.c,v 1.1 2014/01/17 01:32:53 pooka Exp $");
+
+#include <sys/param.h>
+#include <sys/kmem.h>
+#include <sys/rnd.h>
+
+#include <rump/rumpuser.h>
+
+#include "rump_private.h"
+
+static krndsource_t rndsrc;
+
+static void
+feedrandom(size_t bytes, void *arg)
+{
+	uint8_t rnddata[1024];
+	size_t dsize;
+
+	/* stuff max 1k worth, we'll be called again if necessary */
+	if (rumpuser_getrandom(rnddata, MIN(sizeof(rnddata), bytes),
+	    RUMPUSER_RANDOM_HARD|RUMPUSER_RANDOM_NOWAIT, &dsize) == 0)
+		rnd_add_data(&rndsrc, rnddata, dsize, 8*dsize);
+}
+
+void
+rump_hyperentropy_init(void)
+{
+
+	if (rump_threads) {
+		rndsource_setcb(&rndsrc, feedrandom, &rndsrc);
+		rnd_attach_source(&rndsrc, "rump_hyperent", RND_TYPE_VM,
+		    RND_FLAG_NO_ESTIMATE|RND_FLAG_HASCB);
+		feedrandom(128, NULL);
+	} else {
+		/* without threads, 1024 bytes ought to be enough for anyone */
+		rnd_attach_source(&rndsrc, "rump_hyperent", RND_TYPE_VM,
+		    RND_FLAG_NO_ESTIMATE);
+		feedrandom(1024, NULL);
+	}
+}

Reply via email to