Petr Menšík 595af1
From 71dbb3a1a96a012683125a22e9bf263efb97df4d Mon Sep 17 00:00:00 2001
Petr Menšík 595af1
From: Evan Hunt <each@isc.org>
Petr Menšík 595af1
Date: Thu, 28 Sep 2017 10:09:22 -0700
Petr Menšík 595af1
Subject: [PATCH] [master] completed and corrected the crypto-random change
Petr Menšík 595af1
Petr Menšík 595af1
4724.	[func]		By default, BIND now uses the random number
Petr Menšík 595af1
			functions provided by the crypto library (i.e.,
Petr Menšík 595af1
			OpenSSL or a PKCS#11 provider) as a source of
Petr Menšík 595af1
			randomness rather than /dev/random.  This is
Petr Menšík 595af1
			suitable for virtual machine environments
Petr Menšík 595af1
			which have limited entropy pools and lack
Petr Menšík 595af1
			hardware random number generators.
Petr Menšík 595af1
Petr Menšík 595af1
			This can be overridden by specifying another
Petr Menšík 595af1
			entropy source via the "random-device" option
Petr Menšík 595af1
			in named.conf, or via the -r command line option;
Petr Menšík 595af1
			however, for functions requiring full cryptographic
Petr Menšík 595af1
			strength, such as DNSSEC key generation, this
Petr Menšík 595af1
			cannot be overridden. In particular, the -r
Petr Menšík 595af1
			command line option no longer has any effect on
Petr Menšík 595af1
			dnssec-keygen.
Petr Menšík 595af1
Petr Menšík 595af1
			This can be disabled by building with
Petr Menšík 595af1
			"configure --disable-crypto-rand".
Petr Menšík 595af1
			[RT #31459] [RT #46047]
Petr Menšík 595af1
---
Petr Menšík 595af1
 bin/confgen/keygen.c                     | 12 +++----
Petr Menšík 595af1
 bin/dnssec/dnssec-keygen.docbook         | 24 +++++++++-----
Petr Menšík 595af1
 bin/dnssec/dnssectool.c                  | 12 +++----
Petr Menšík 595af1
 bin/named/client.c                       |  3 +-
Petr Menšík 595af1
 bin/named/config.c                       |  4 ++-
Petr Menšík 595af1
 bin/named/controlconf.c                  | 19 +++++++----
Petr Menšík 595af1
 bin/named/include/named/server.h         |  2 ++
Petr Menšík 595af1
 bin/named/interfacemgr.c                 |  1 +
Petr Menšík 595af1
 bin/named/query.c                        |  1 +
Petr Menšík 595af1
 bin/named/server.c                       | 52 ++++++++++++++++++------------
Petr Menšík 595af1
 bin/nsupdate/nsupdate.c                  |  4 +--
Petr Menšík 595af1
 bin/tests/system/pipelined/pipequeries.c |  4 +--
Petr Menšík 595af1
 bin/tests/system/tkey/keycreate.c        |  4 +--
Petr Menšík 595af1
 bin/tests/system/tkey/keydelete.c        |  4 +--
Petr Menšík 595af1
 doc/arm/Bv9ARM-book.xml                  | 55 ++++++++++++++++++++++----------
Petr Menšík 595af1
 doc/arm/notes.xml                        | 26 +++++++++++++++
Petr Menšík 595af1
 lib/dns/dst_api.c                        |  7 ++--
Petr Menšík 595af1
 lib/dns/include/dst/dst.h                | 14 ++++++--
Petr Menšík 595af1
 lib/dns/openssl_link.c                   |  3 +-
Petr Menšík 595af1
 lib/isc/include/isc/entropy.h            | 50 +++++++++++++++++++++--------
Petr Menšík 595af1
 lib/isc/include/isc/random.h             | 28 ++++++++++------
Petr Menšík 595af1
 lib/isccfg/namedconf.c                   |  2 +-
Petr Menšík 595af1
 22 files changed, 222 insertions(+), 109 deletions(-)
Petr Menšík 595af1
Petr Menšík 595af1
diff --git a/bin/confgen/keygen.c b/bin/confgen/keygen.c
Petr Menšík 595af1
index fa439cc158..a7ad417a18 100644
Petr Menšík 595af1
--- a/bin/confgen/keygen.c
Petr Menšík 595af1
+++ b/bin/confgen/keygen.c
Petr Menšík 595af1
@@ -161,17 +161,15 @@ generate_key(isc_mem_t *mctx, const char *randomfile, dns_secalg_t alg,
Petr Menšík 595af1
 
Petr Menšík 595af1
 	DO("create entropy context", isc_entropy_create(mctx, &ectx));
Petr Menšík 595af1
 
Petr Menšík 595af1
-	if (randomfile != NULL && strcmp(randomfile, "keyboard") == 0) {
Petr Menšík 595af1
-		randomfile = NULL;
Petr Menšík 595af1
-		open_keyboard = ISC_ENTROPY_KEYBOARDYES;
Petr Menšík 595af1
-	}
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
-	if (randomfile != NULL &&
Petr Menšík 595af1
-	    strcmp(randomfile, ISC_PLATFORM_CRYPTORANDOM) == 0) {
Petr Menšík 595af1
-		randomfile = NULL;
Petr Menšík 595af1
+	if (randomfile == NULL) {
Petr Menšík 595af1
 		isc_entropy_usehook(ectx, ISC_TRUE);
Petr Menšík 595af1
 	}
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
+	if (randomfile != NULL && strcmp(randomfile, "keyboard") == 0) {
Petr Menšík 595af1
+		randomfile = NULL;
Petr Menšík 595af1
+		open_keyboard = ISC_ENTROPY_KEYBOARDYES;
Petr Menšík 595af1
+	}
Petr Menšík 595af1
 	DO("start entropy source", isc_entropy_usebestsource(ectx,
Petr Menšík 595af1
 							     &entropy_source,
Petr Menšík 595af1
 							     randomfile,
Petr Menšík 595af1
diff --git a/bin/dnssec/dnssec-keygen.docbook b/bin/dnssec/dnssec-keygen.docbook
Petr Menšík 595af1
index 96dfef64b4..1c84b06126 100644
Petr Menšík 595af1
--- a/bin/dnssec/dnssec-keygen.docbook
Petr Menšík 595af1
+++ b/bin/dnssec/dnssec-keygen.docbook
Petr Menšík 595af1
@@ -349,15 +349,23 @@
Petr Menšík 595af1
 	<term>-r <replaceable class="parameter">randomdev</replaceable></term>
Petr Menšík 595af1
 	<listitem>
Petr Menšík 595af1
 	  <para>
Petr Menšík 595af1
-	    Specifies the source of randomness.  If the operating
Petr Menšík 595af1
-	    system does not provide a <filename>/dev/random</filename>
Petr Menšík 595af1
-	    or equivalent device, the default source of randomness
Petr Menšík 595af1
-	    is keyboard input.  <filename>randomdev</filename>
Petr Menšík 595af1
-	    specifies
Petr Menšík 595af1
+	    Specifies a source of randomness.  Normally, when generating
Petr Menšík 595af1
+	    DNSSEC keys, this option has no effect; the random number
Petr Menšík 595af1
+	    generation function provided by the cryptographic library will
Petr Menšík 595af1
+	    be used.
Petr Menšík 595af1
+	  </para>
Petr Menšík 595af1
+	  <para>
Petr Menšík 595af1
+	    If that behavior is disabled at compile time, however,
Petr Menšík 595af1
+	    the specified file will be used as entropy source
Petr Menšík 595af1
+	    for key generation.  <filename>randomdev</filename> is
Petr Menšík 595af1
 	    the name of a character device or file containing random
Petr Menšík 595af1
-	    data to be used instead of the default.  The special value
Petr Menšík 595af1
-	    <filename>keyboard</filename> indicates that keyboard
Petr Menšík 595af1
-	    input should be used.
Petr Menšík 595af1
+	    data to be used.  The special value <filename>keyboard</filename>
Petr Menšík 595af1
+	    indicates that keyboard input should be used.
Petr Menšík 595af1
+	  </para>
Petr Menšík 595af1
+	  <para>
Petr Menšík 595af1
+	    The default is <filename>/dev/random</filename> if the
Petr Menšík 595af1
+	    operating system provides it or an equivalent device;
Petr Menšík 595af1
+	    if not, the default source of randomness is keyboard input.
Petr Menšík 595af1
 	  </para>
Petr Menšík 595af1
 	</listitem>
Petr Menšík 595af1
       </varlistentry>
Petr Menšík 595af1
diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c
Petr Menšík 595af1
index 4ea9eafa44..5dd9475dd3 100644
Petr Menšík 595af1
--- a/bin/dnssec/dnssectool.c
Petr Menšík 595af1
+++ b/bin/dnssec/dnssectool.c
Petr Menšík 595af1
@@ -239,18 +239,16 @@ setup_entropy(isc_mem_t *mctx, const char *randomfile, isc_entropy_t **ectx) {
Petr Menšík 595af1
 		ISC_LIST_INIT(sources);
Petr Menšík 595af1
 	}
Petr Menšík 595af1
 
Petr Menšík 595af1
+#ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
+	if (randomfile == NULL) {
Petr Menšík 595af1
+		isc_entropy_usehook(*ectx, ISC_TRUE);
Petr Menšík 595af1
+	}
Petr Menšík 595af1
+#endif
Petr Menšík 595af1
 	if (randomfile != NULL && strcmp(randomfile, "keyboard") == 0) {
Petr Menšík 595af1
 		usekeyboard = ISC_ENTROPY_KEYBOARDYES;
Petr Menšík 595af1
 		randomfile = NULL;
Petr Menšík 595af1
 	}
Petr Menšík 595af1
 
Petr Menšík 595af1
-#ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
-	if (randomfile != NULL &&
Petr Menšík 595af1
-	    strcmp(randomfile, ISC_PLATFORM_CRYPTORANDOM) == 0) {
Petr Menšík 595af1
-		randomfile = NULL;
Petr Menšík 595af1
-		isc_entropy_usehook(*ectx, ISC_TRUE);
Petr Menšík 595af1
-	}
Petr Menšík 595af1
-#endif
Petr Menšík 595af1
 	result = isc_entropy_usebestsource(*ectx, &source, randomfile,
Petr Menšík 595af1
 					   usekeyboard);
Petr Menšík 595af1
 
Petr Menšík 595af1
diff --git a/bin/named/client.c b/bin/named/client.c
Petr Menšík 595af1
index b9ebc93094..20e5f395d4 100644
Petr Menšík 595af1
--- a/bin/named/client.c
Petr Menšík 595af1
+++ b/bin/named/client.c
Petr Menšík 595af1
@@ -1605,7 +1605,8 @@ ns_client_addopt(ns_client_t *client, dns_message_t *message,
Petr Menšík 595af1
 
Petr Menšík 595af1
 		isc_buffer_init(&buf, cookie, sizeof(cookie));
Petr Menšík 595af1
 		isc_stdtime_get(&now;;
Petr Menšík 595af1
-		isc_random_get(&nonce);
Petr Menšík 595af1
+		nonce = ((isc_rng_random(ns_g_server->rngctx) << 16) |
Petr Menšík 595af1
+			 isc_rng_random(ns_g_server->rngctx));
Petr Menšík 595af1
 
Petr Menšík 595af1
 		compute_cookie(client, now, nonce, ns_g_server->secret, &buf;;
Petr Menšík 595af1
 
Petr Menšík 595af1
diff --git a/bin/named/config.c b/bin/named/config.c
Petr Menšík 595af1
index c50f759ddd..c1e72ef996 100644
Petr Menšík 595af1
--- a/bin/named/config.c
Petr Menšík 595af1
+++ b/bin/named/config.c
Petr Menšík 595af1
@@ -92,7 +92,9 @@ options {\n\
Petr Menšík 595af1
 #	pid-file \"" NS_LOCALSTATEDIR "/run/named/named.pid\"; /* or /lwresd.pid */\n\
Petr Menšík 595af1
 	port 53;\n\
Petr Menšík 595af1
 	prefetch 2 9;\n"
Petr Menšík 595af1
-#ifdef PATH_RANDOMDEV
Petr Menšík 595af1
+#if defined(ISC_PLATFORM_CRYPTORANDOM)
Petr Menšík 595af1
+"	random-device none;\n"
Petr Menšík 595af1
+#elif defined(PATH_RANDOMDEV)
Petr Menšík 595af1
 "	random-device \"" PATH_RANDOMDEV "\";\n"
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
 "	recursing-file \"named.recursing\";\n\
Petr Menšík 595af1
diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c
Petr Menšík 595af1
index 237e8dc31d..b905475890 100644
Petr Menšík 595af1
--- a/bin/named/controlconf.c
Petr Menšík 595af1
+++ b/bin/named/controlconf.c
Petr Menšík 595af1
@@ -322,9 +322,10 @@ log_invalid(isccc_ccmsg_t *ccmsg, isc_result_t result) {
Petr Menšík 595af1
 
Petr Menšík 595af1
 static void
Petr Menšík 595af1
 control_recvmessage(isc_task_t *task, isc_event_t *event) {
Petr Menšík 595af1
-	controlconnection_t *conn;
Petr Menšík 595af1
-	controllistener_t *listener;
Petr Menšík 595af1
-	controlkey_t *key;
Petr Menšík 595af1
+	controlconnection_t *conn = NULL;
Petr Menšík 595af1
+	controllistener_t *listener = NULL;
Petr Menšík 595af1
+	ns_server_t *server = NULL;
Petr Menšík 595af1
+	controlkey_t *key = NULL;
Petr Menšík 595af1
 	isccc_sexpr_t *request = NULL;
Petr Menšík 595af1
 	isccc_sexpr_t *response = NULL;
Petr Menšík 595af1
 	isc_uint32_t algorithm;
Petr Menšík 595af1
@@ -335,16 +336,17 @@ control_recvmessage(isc_task_t *task, isc_event_t *event) {
Petr Menšík 595af1
 	isc_buffer_t *text;
Petr Menšík 595af1
 	isc_result_t result;
Petr Menšík 595af1
 	isc_result_t eresult;
Petr Menšík 595af1
-	isccc_sexpr_t *_ctrl;
Petr Menšík 595af1
+	isccc_sexpr_t *_ctrl = NULL;
Petr Menšík 595af1
 	isccc_time_t sent;
Petr Menšík 595af1
 	isccc_time_t exp;
Petr Menšík 595af1
 	isc_uint32_t nonce;
Petr Menšík 595af1
-	isccc_sexpr_t *data;
Petr Menšík 595af1
+	isccc_sexpr_t *data = NULL;
Petr Menšík 595af1
 
Petr Menšík 595af1
 	REQUIRE(event->ev_type == ISCCC_EVENT_CCMSG);
Petr Menšík 595af1
 
Petr Menšík 595af1
 	conn = event->ev_arg;
Petr Menšík 595af1
 	listener = conn->listener;
Petr Menšík 595af1
+	server = listener->controls->server;
Petr Menšík 595af1
 	algorithm = DST_ALG_UNKNOWN;
Petr Menšík 595af1
 	secret.rstart = NULL;
Petr Menšík 595af1
 	text = NULL;
Petr Menšík 595af1
@@ -455,8 +457,11 @@ control_recvmessage(isc_task_t *task, isc_event_t *event) {
Petr Menšík 595af1
 	 * Establish nonce.
Petr Menšík 595af1
 	 */
Petr Menšík 595af1
 	if (conn->nonce == 0) {
Petr Menšík 595af1
-		while (conn->nonce == 0)
Petr Menšík 595af1
-			isc_random_get(&conn->nonce);
Petr Menšík 595af1
+		while (conn->nonce == 0) {
Petr Menšík 595af1
+			isc_uint16_t r1 = isc_rng_random(server->rngctx);
Petr Menšík 595af1
+			isc_uint16_t r2 = isc_rng_random(server->rngctx);
Petr Menšík 595af1
+			conn->nonce = (r1 << 16) | r2;
Petr Menšík 595af1
+		}
Petr Menšík 595af1
 		eresult = ISC_R_SUCCESS;
Petr Menšík 595af1
 	} else
Petr Menšík 595af1
 		eresult = ns_control_docommand(request, listener->readonly, &text);
Petr Menšík 595af1
diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h
Petr Menšík 595af1
index d8179a60a0..e03d24d85d 100644
Petr Menšík 595af1
--- a/bin/named/include/named/server.h
Petr Menšík 595af1
+++ b/bin/named/include/named/server.h
Petr Menšík 595af1
@@ -17,6 +17,7 @@
Petr Menšík 595af1
 #include <isc/log.h>
Petr Menšík 595af1
 #include <isc/magic.h>
Petr Menšík 595af1
 #include <isc/quota.h>
Petr Menšík 595af1
+#include <isc/random.h>
Petr Menšík 595af1
 #include <isc/sockaddr.h>
Petr Menšík 595af1
 #include <isc/types.h>
Petr Menšík 595af1
 #include <isc/xml.h>
Petr Menšík 595af1
@@ -131,6 +132,7 @@ struct ns_server {
Petr Menšík 595af1
 	char *			lockfile;
Petr Menšík 595af1
 
Petr Menšík 595af1
 	isc_uint16_t		transfer_tcp_message_size;
Petr Menšík 595af1
+	isc_rng_t *		rngctx;
Petr Menšík 595af1
 };
Petr Menšík 595af1
 
Petr Menšík 595af1
 struct ns_altsecret {
Petr Menšík 595af1
diff --git a/bin/named/interfacemgr.c b/bin/named/interfacemgr.c
Petr Menšík 595af1
index d8c7188186..50f924eadb 100644
Petr Menšík 595af1
--- a/bin/named/interfacemgr.c
Petr Menšík 595af1
+++ b/bin/named/interfacemgr.c
Petr Menšík 595af1
@@ -15,6 +15,7 @@
Petr Menšík 595af1
 
Petr Menšík 595af1
 #include <isc/interfaceiter.h>
Petr Menšík 595af1
 #include <isc/os.h>
Petr Menšík 595af1
+#include <isc/random.h>
Petr Menšík 595af1
 #include <isc/string.h>
Petr Menšík 595af1
 #include <isc/task.h>
Petr Menšík 595af1
 #include <isc/util.h>
Petr Menšík 595af1
diff --git a/bin/named/query.c b/bin/named/query.c
Petr Menšík 595af1
index accbf3b24d..d89622d835 100644
Petr Menšík 595af1
--- a/bin/named/query.c
Petr Menšík 595af1
+++ b/bin/named/query.c
Petr Menšík 595af1
@@ -18,6 +18,7 @@
Petr Menšík 595af1
 #include <isc/hex.h>
Petr Menšík 595af1
 #include <isc/mem.h>
Petr Menšík 595af1
 #include <isc/print.h>
Petr Menšík 595af1
+#include <isc/random.h>
Petr Menšík 595af1
 #include <isc/rwlock.h>
Petr Menšík 595af1
 #include <isc/serial.h>
Petr Menšík 595af1
 #include <isc/stats.h>
Petr Menšík 595af1
diff --git a/bin/named/server.c b/bin/named/server.c
Petr Menšík 595af1
index ee5186c165..553e0f1ae6 100644
Petr Menšík 595af1
--- a/bin/named/server.c
Petr Menšík 595af1
+++ b/bin/named/server.c
Petr Menšík 595af1
@@ -8076,21 +8076,30 @@ load_configuration(const char *filename, ns_server_t *server,
Petr Menšík 595af1
 	 * Open the source of entropy.
Petr Menšík 595af1
 	 */
Petr Menšík 595af1
 	if (first_time) {
Petr Menšík 595af1
+		const char *randomdev = NULL;
Petr Menšík 595af1
+		int level = ISC_LOG_ERROR;
Petr Menšík 595af1
 		obj = NULL;
Petr Menšík 595af1
 		result = ns_config_get(maps, "random-device", &obj);
Petr Menšík 595af1
-		if (result != ISC_R_SUCCESS) {
Petr Menšík 595af1
-			isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
Petr Menšík 595af1
-				      NS_LOGMODULE_SERVER, ISC_LOG_INFO,
Petr Menšík 595af1
-				      "no source of entropy found");
Petr Menšík 595af1
-		} else {
Petr Menšík 595af1
-			const char *randomdev = cfg_obj_asstring(obj);
Petr Menšík 595af1
+		if (result == ISC_R_SUCCESS) {
Petr Menšík 595af1
+			if (!cfg_obj_isvoid(obj)) {
Petr Menšík 595af1
+				level = ISC_LOG_INFO;
Petr Menšík 595af1
+				randomdev = cfg_obj_asstring(obj);
Petr Menšík 595af1
+			}
Petr Menšík 595af1
+		}
Petr Menšík 595af1
+		if (randomdev == NULL) {
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
-			if (strcmp(randomdev, ISC_PLATFORM_CRYPTORANDOM) == 0)
Petr Menšík 595af1
-				isc_entropy_usehook(ns_g_entropy, ISC_TRUE);
Petr Menšík 595af1
+			isc_entropy_usehook(ns_g_entropy, ISC_TRUE);
Petr Menšík 595af1
 #else
Petr Menšík 595af1
-			int level = ISC_LOG_ERROR;
Petr Menšík 595af1
-			result = isc_entropy_createfilesource(ns_g_entropy,
Petr Menšík 595af1
-							      randomdev);
Petr Menšík 595af1
+			if ((obj != NULL) && !cfg_obj_isvoid(obj))
Petr Menšík 595af1
+				level = ISC_LOG_INFO;
Petr Menšík 595af1
+			isc_log_write(named_g_lctx, NS_LOGCATEGORY_GENERAL,
Petr Menšík 595af1
+				      NS_LOGMODULE_SERVER, level,
Petr Menšík 595af1
+				      "no source of entropy found");
Petr Menšík 595af1
+			if ((obj == NULL) || cfg_obj_isvoid(obj)) {
Petr Menšík 595af1
+				CHECK(ISC_R_FAILURE);
Petr Menšík 595af1
+			}
Petr Menšík 595af1
+#endif
Petr Menšík 595af1
+		} else {
Petr Menšík 595af1
 #ifdef PATH_RANDOMDEV
Petr Menšík 595af1
 			if (ns_g_fallbackentropy != NULL) {
Petr Menšík 595af1
 				level = ISC_LOG_INFO;
Petr Menšík 595af1
@@ -8101,8 +8110,8 @@ load_configuration(const char *filename, ns_server_t *server,
Petr Menšík 595af1
 					      NS_LOGCATEGORY_GENERAL,
Petr Menšík 595af1
 					      NS_LOGMODULE_SERVER,
Petr Menšík 595af1
 					      level,
Petr Menšík 595af1
-					      "could not open entropy source "
Petr Menšík 595af1
-					      "%s: %s",
Petr Menšík 595af1
+					      "could not open "
Petr Menšík 595af1
+					      "entropy source %s: %s",
Petr Menšík 595af1
 					      randomdev,
Petr Menšík 595af1
 					      isc_result_totext(result));
Petr Menšík 595af1
 			}
Petr Menšík 595af1
@@ -8122,7 +8131,6 @@ load_configuration(const char *filename, ns_server_t *server,
Petr Menšík 595af1
 				}
Petr Menšík 595af1
 				isc_entropy_detach(&ns_g_fallbackentropy);
Petr Menšík 595af1
 			}
Petr Menšík 595af1
-#endif
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
 		}
Petr Menšík 595af1
 	}
Petr Menšík 595af1
@@ -8911,6 +8919,8 @@ ns_server_create(isc_mem_t *mctx, ns_server_t **serverp) {
Petr Menšík 595af1
 	CHECKFATAL(dns_tkeyctx_create(ns_g_mctx, ns_g_entropy,
Petr Menšík 595af1
 				      &server->tkeyctx),
Petr Menšík 595af1
 		   "creating TKEY context");
Petr Menšík 595af1
+	CHECKFATAL(isc_rng_create(ns_g_mctx, ns_g_entropy, &server->rngctx),
Petr Menšík 595af1
+	           "creating random numbers context");
Petr Menšík 595af1
 
Petr Menšík 595af1
 	/*
Petr Menšík 595af1
 	 * Setup the server task, which is responsible for coordinating
Petr Menšík 595af1
@@ -9117,7 +9127,8 @@ ns_server_destroy(ns_server_t **serverp) {
Petr Menšík 595af1
 
Petr Menšík 595af1
 	if (server->zonemgr != NULL)
Petr Menšík 595af1
 		dns_zonemgr_detach(&server->zonemgr);
Petr Menšík 595af1
-
Petr Menšík 595af1
+	if (server->rngctx != NULL)
Petr Menšík 595af1
+		isc_rng_detach(&server->rngctx);
Petr Menšík 595af1
 	if (server->tkeyctx != NULL)
Petr Menšík 595af1
 		dns_tkeyctx_destroy(&server->tkeyctx);
Petr Menšík 595af1
 
Petr Menšík 595af1
@@ -13018,10 +13029,10 @@ newzone_cfgctx_destroy(void **cfgp) {
Petr Menšík 595af1
 
Petr Menšík 595af1
 static isc_result_t
Petr Menšík 595af1
 generate_salt(unsigned char *salt, size_t saltlen) {
Petr Menšík 595af1
-	int i, n;
Petr Menšík 595af1
+	size_t i, n;
Petr Menšík 595af1
 	union {
Petr Menšík 595af1
 		unsigned char rnd[256];
Petr Menšík 595af1
-		isc_uint32_t rnd32[64];
Petr Menšík 595af1
+		isc_uint16_t rnd16[128];
Petr Menšík 595af1
 	} rnd;
Petr Menšík 595af1
 	unsigned char text[512 + 1];
Petr Menšík 595af1
 	isc_region_t r;
Petr Menšík 595af1
@@ -13031,9 +13042,10 @@ generate_salt(unsigned char *salt, size_t saltlen) {
Petr Menšík 595af1
 	if (saltlen > 256U)
Petr Menšík 595af1
 		return (ISC_R_RANGE);
Petr Menšík 595af1
 
Petr Menšík 595af1
-	n = (int) (saltlen + sizeof(isc_uint32_t) - 1) / sizeof(isc_uint32_t);
Petr Menšík 595af1
-	for (i = 0; i < n; i++)
Petr Menšík 595af1
-		isc_random_get(&rnd.rnd32[i]);
Petr Menšík 595af1
+	n = (saltlen + sizeof(isc_uint16_t) - 1) / sizeof(isc_uint16_t);
Petr Menšík 595af1
+	for (i = 0; i < n; i++) {
Petr Menšík 595af1
+		rnd.rnd16[i] = isc_rng_random(ns_g_server->rngctx);
Petr Menšík 595af1
+	}
Petr Menšík 595af1
 
Petr Menšík 595af1
 	memmove(salt, rnd.rnd, saltlen);
Petr Menšík 595af1
 
Petr Menšík 595af1
diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c
Petr Menšík 595af1
index 46c7acf4dc..a0d0278635 100644
Petr Menšík 595af1
--- a/bin/nsupdate/nsupdate.c
Petr Menšík 595af1
+++ b/bin/nsupdate/nsupdate.c
Petr Menšík 595af1
@@ -281,9 +281,7 @@ setup_entropy(isc_mem_t *mctx, const char *randomfile, isc_entropy_t **ectx) {
Petr Menšík 595af1
 	}
Petr Menšík 595af1
 
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
-	if (randomfile != NULL &&
Petr Menšík 595af1
-	    strcmp(randomfile, ISC_PLATFORM_CRYPTORANDOM) == 0) {
Petr Menšík 595af1
-		randomfile = NULL;
Petr Menšík 595af1
+	if (randomfile == NULL) {
Petr Menšík 595af1
 		isc_entropy_usehook(*ectx, ISC_TRUE);
Petr Menšík 595af1
 	}
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c
Petr Menšík 595af1
index 810d99e267..d7d10e2e3c 100644
Petr Menšík 595af1
--- a/bin/tests/system/pipelined/pipequeries.c
Petr Menšík 595af1
+++ b/bin/tests/system/pipelined/pipequeries.c
Petr Menšík 595af1
@@ -279,9 +279,7 @@ main(int argc, char *argv[]) {
Petr Menšík 595af1
 	ectx = NULL;
Petr Menšík 595af1
 	RUNCHECK(isc_entropy_create(mctx, &ectx));
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
-	if (randomfile != NULL &&
Petr Menšík 595af1
-	    strcmp(randomfile, ISC_PLATFORM_CRYPTORANDOM) == 0) {
Petr Menšík 595af1
-		randomfile = NULL;
Petr Menšík 595af1
+	if (randomfile == NULL) {
Petr Menšík 595af1
 		isc_entropy_usehook(ectx, ISC_TRUE);
Petr Menšík 595af1
 	}
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
diff --git a/bin/tests/system/tkey/keycreate.c b/bin/tests/system/tkey/keycreate.c
Petr Menšík 595af1
index 4f2f5b4cc5..0894db7066 100644
Petr Menšík 595af1
--- a/bin/tests/system/tkey/keycreate.c
Petr Menšík 595af1
+++ b/bin/tests/system/tkey/keycreate.c
Petr Menšík 595af1
@@ -255,9 +255,7 @@ main(int argc, char *argv[]) {
Petr Menšík 595af1
 	ectx = NULL;
Petr Menšík 595af1
 	RUNCHECK(isc_entropy_create(mctx, &ectx));
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
-	if (randomfile != NULL &&
Petr Menšík 595af1
-	    strcmp(randomfile, ISC_PLATFORM_CRYPTORANDOM) == 0) {
Petr Menšík 595af1
-		randomfile = NULL;
Petr Menšík 595af1
+	if (randomfile == NULL) {
Petr Menšík 595af1
 		isc_entropy_usehook(ectx, ISC_TRUE);
Petr Menšík 595af1
 	}
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
diff --git a/bin/tests/system/tkey/keydelete.c b/bin/tests/system/tkey/keydelete.c
Petr Menšík 595af1
index 0975bbe4ea..5b8a4701a8 100644
Petr Menšík 595af1
--- a/bin/tests/system/tkey/keydelete.c
Petr Menšík 595af1
+++ b/bin/tests/system/tkey/keydelete.c
Petr Menšík 595af1
@@ -182,9 +182,7 @@ main(int argc, char **argv) {
Petr Menšík 595af1
 	ectx = NULL;
Petr Menšík 595af1
 	RUNCHECK(isc_entropy_create(mctx, &ectx));
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
-	if (randomfile != NULL &&
Petr Menšík 595af1
-	    strcmp(randomfile, ISC_PLATFORM_CRYPTORANDOM) == 0) {
Petr Menšík 595af1
-		randomfile = NULL;
Petr Menšík 595af1
+	if (randomfile == NULL) {
Petr Menšík 595af1
 		isc_entropy_usehook(ectx, ISC_TRUE);
Petr Menšík 595af1
 	}
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
diff --git a/doc/arm/Bv9ARM-book.xml b/doc/arm/Bv9ARM-book.xml
Petr Menšík 595af1
index 3ecdc046d0..34c9e85f52 100644
Petr Menšík 595af1
--- a/doc/arm/Bv9ARM-book.xml
Petr Menšík 595af1
+++ b/doc/arm/Bv9ARM-book.xml
Petr Menšík 595af1
@@ -5070,22 +5070,45 @@ badresp:1,adberr:0,findfail:0,valfail:0]
Petr Menšík 595af1
 	    <term><command>random-device</command></term>
Petr Menšík 595af1
 	    <listitem>
Petr Menšík 595af1
 	      <para>
Petr Menšík 595af1
-		The source of entropy to be used by the server.  Entropy is
Petr Menšík 595af1
-		primarily needed
Petr Menšík 595af1
-		for DNSSEC operations, such as TKEY transactions and dynamic
Petr Menšík 595af1
-		update of signed
Petr Menšík 595af1
-		zones.  This options specifies the device (or file) from which
Petr Menšík 595af1
-		to read
Petr Menšík 595af1
-		entropy.  If this is a file, operations requiring entropy will
Petr Menšík 595af1
-		fail when the
Petr Menšík 595af1
-		file has been exhausted.  If not specified, the default value
Petr Menšík 595af1
-		is
Petr Menšík 595af1
-		<filename>/dev/random</filename>
Petr Menšík 595af1
-		(or equivalent) when present, and none otherwise.  The
Petr Menšík 595af1
-		<command>random-device</command> option takes
Petr Menšík 595af1
-		effect during
Petr Menšík 595af1
-		the initial configuration load at server startup time and
Petr Menšík 595af1
-		is ignored on subsequent reloads.
Petr Menšík 595af1
+		Specifies a source of entropy to be used by the server.
Petr Menšík 595af1
+		This is a device or file from which to read entropy.
Petr Menšík 595af1
+		If it is a file, operations requiring entropy
Petr Menšík 595af1
+		will fail when the file has been exhausted.
Petr Menšík 595af1
+	      </para>
Petr Menšík 595af1
+	      <para>
Petr Menšík 595af1
+		Entropy is needed for cryptographic operations such as
Petr Menšík 595af1
+		TKEY transactions, dynamic update of signed zones, and
Petr Menšík 595af1
+		generation of TSIG session keys. It is also used for
Petr Menšík 595af1
+		seeding and stirring the pseudo-random number generator,
Petr Menšík 595af1
+		which is used for less critical functions requiring
Petr Menšík 595af1
+		randomness such as generation of DNS message transaction
Petr Menšík 595af1
+		ID's.
Petr Menšík 595af1
+	      </para>
Petr Menšík 595af1
+	      <para>
Petr Menšík 595af1
+		If <command>random-device</command> is not specified, or
Petr Menšík 595af1
+		if it is set to <literal>none</literal>, entropy will be
Petr Menšík 595af1
+		read from the random number generation function supplied
Petr Menšík 595af1
+		by the cryptographic library with which BIND was linked
Petr Menšík 595af1
+		(i.e.  OpenSSL or a PKCS#11 provider).
Petr Menšík 595af1
+	      </para>
Petr Menšík 595af1
+	      <para>
Petr Menšík 595af1
+		The <command>random-device</command> option takes
Petr Menšík 595af1
+		effect during the initial configuration load at server
Petr Menšík 595af1
+		startup time and is ignored on subsequent reloads.
Petr Menšík 595af1
+	      </para>
Petr Menšík 595af1
+	      <para>
Petr Menšík 595af1
+		If BIND is built with
Petr Menšík 595af1
+		<command>configure --disable-crypto-rand</command>, then
Petr Menšík 595af1
+		entropy is <emphasis>not</emphasis> sourced from the
Petr Menšík 595af1
+		cryptographic library. In this case, if
Petr Menšík 595af1
+		<command>random-device</command> is not specified, the
Petr Menšík 595af1
+		default value is the system random device,
Petr Menšík 595af1
+		<filename>/dev/random</filename> or the equivalent.
Petr Menšík 595af1
+		This default can be overridden with
Petr Menšík 595af1
+		<command>configure --with-randomdev</command>.
Petr Menšík 595af1
+		If no system random device exists, then no entropy source
Petr Menšík 595af1
+		will be configured, and <command>named</command> will only
Petr Menšík 595af1
+		be able to use pseudo-random numbers.
Petr Menšík 595af1
 	      </para>
Petr Menšík 595af1
 	    </listitem>
Petr Menšík 595af1
 	  </varlistentry>
Petr Menšík 595af1
diff --git a/doc/arm/notes.xml b/doc/arm/notes.xml
Petr Menšík 595af1
index 7b7475b58f..49fe0a413e 100644
Petr Menšík 595af1
--- a/doc/arm/notes.xml
Petr Menšík 595af1
+++ b/doc/arm/notes.xml
Petr Menšík 595af1
@@ -128,6 +128,32 @@
Petr Menšík 595af1
 	  necessary.
Petr Menšík 595af1
 	</para>
Petr Menšík 595af1
       </listitem>
Petr Menšík 595af1
+      <listitem>
Petr Menšík 595af1
+	<para>
Petr Menšík 595af1
+	  By default, BIND now uses the random number generation functions
Petr Menšík 595af1
+	  in the cryptographic library (i.e., OpenSSL or a PKCS#11
Petr Menšík 595af1
+	  provider) as a source of high-quality randomness rather than
Petr Menšík 595af1
+	  <filename>/dev/random</filename>.  This is suitable for virtual
Petr Menšík 595af1
+	  machine environments, which may have limited entropy pools and
Petr Menšík 595af1
+	  lack hardware random number generators.
Petr Menšík 595af1
+	</para>
Petr Menšík 595af1
+	<para>
Petr Menšík 595af1
+	  This can be overridden by specifying another entropy source via
Petr Menšík 595af1
+	  the <command>random-device</command> option in
Petr Menšík 595af1
+	  <filename>named.conf</filename>, or via the <command>-r</command>
Petr Menšík 595af1
+	  command line option.  However, for functions requiring full
Petr Menšík 595af1
+	  cryptographic strength, such as DNSSEC key generation, this
Petr Menšík 595af1
+	  <emphasis>cannot</emphasis> be overridden. In particular, the
Petr Menšík 595af1
+	  <command>-r</command> command line option no longer has any
Petr Menšík 595af1
+	  effect on <command>dnssec-keygen</command>.
Petr Menšík 595af1
+	</para>
Petr Menšík 595af1
+	<para>
Petr Menšík 595af1
+	  This can be disabled by building with
Petr Menšík 595af1
+	  <command>configure --disable-crypto-rand</command>, in which
Petr Menšík 595af1
+	  case <filename>/dev/random</filename> will be the default
Petr Menšík 595af1
+	  entropy source.  [RT #31459] [RT #46047]
Petr Menšík 595af1
+	</para>
Petr Menšík 595af1
+      </listitem>
Petr Menšík 595af1
     </itemizedlist>
Petr Menšík 595af1
   </section>
Petr Menšík 595af1
 
Petr Menšík 595af1
diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c
Petr Menšík 595af1
index 803e7b3538..29a4fef44b 100644
Petr Menšík 595af1
--- a/lib/dns/dst_api.c
Petr Menšík 595af1
+++ b/lib/dns/dst_api.c
Petr Menšík 595af1
@@ -276,8 +276,9 @@ dst_lib_init2(isc_mem_t *mctx, isc_entropy_t *ectx,
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
 #if defined(OPENSSL) || defined(PKCS11CRYPTO)
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
-	if (dst_entropy_pool != NULL)
Petr Menšík 595af1
+	if (dst_entropy_pool != NULL) {
Petr Menšík 595af1
 		isc_entropy_sethook(dst_random_getdata);
Petr Menšík 595af1
+	}
Petr Menšík 595af1
 #endif
Petr Menšík 595af1
 #endif /* defined(OPENSSL) || defined(PKCS11CRYPTO) */
Petr Menšík 595af1
 	dst_initialized = ISC_TRUE;
Petr Menšík 595af1
@@ -2015,10 +2016,12 @@ dst__entropy_getdata(void *buf, unsigned int len, isc_boolean_t pseudo) {
Petr Menšík 595af1
 	else
Petr Menšík 595af1
 		flags |= ISC_ENTROPY_BLOCKING;
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
+	/* get entropy directly from crypto provider */
Petr Menšík 595af1
 	return (dst_random_getdata(buf, len, NULL, flags));
Petr Menšík 595af1
 #else
Petr Menšík 595af1
+	/* get entropy from entropy source or hook function */
Petr Menšík 595af1
 	return (isc_entropy_getdata(dst_entropy_pool, buf, len, NULL, flags));
Petr Menšík 595af1
-#endif
Petr Menšík 595af1
+#endif /* ISC_PLATFORM_CRYPTORANDOM */
Petr Menšík 595af1
 #endif /* PKCS11CRYPTO */
Petr Menšík 595af1
 }
Petr Menšík 595af1
 
Petr Menšík 595af1
diff --git a/lib/dns/include/dst/dst.h b/lib/dns/include/dst/dst.h
Petr Menšík 595af1
index d9b6ab6bfb..e8c1a3c287 100644
Petr Menšík 595af1
--- a/lib/dns/include/dst/dst.h
Petr Menšík 595af1
+++ b/lib/dns/include/dst/dst.h
Petr Menšík 595af1
@@ -161,8 +161,18 @@ isc_result_t
Petr Menšík 595af1
 dst_random_getdata(void *data, unsigned int length,
Petr Menšík 595af1
 		   unsigned int *returned, unsigned int flags);
Petr Menšík 595af1
 /*%<
Petr Menšík 595af1
- * \brief Return data from the crypto random generator.
Petr Menšík 595af1
- * Specialization of isc_entropy_getdata().
Petr Menšík 595af1
+ * Gets random data from the random generator provided by the
Petr Menšík 595af1
+ * crypto library, if BIND was built with --enable-crypto-rand.
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * See isc_entropy_getdata() for parameter usage. Normally when
Petr Menšík 595af1
+ * this function is available, it will be set up as a hook in the
Petr Menšík 595af1
+ * entropy context, so that isc_entropy_getdata() is a front-end to
Petr Menšík 595af1
+ * this function.
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * Returns:
Petr Menšík 595af1
+ * \li	ISC_R_SUCCESS on success
Petr Menšík 595af1
+ * \li	ISC_R_NOTIMPLEMENTED if BIND is built with --disable-crypto-rand
Petr Menšík 595af1
+ * \li	DST_R_OPENSSLFAILURE, DST_R_CRYPTOFAILURE, or other codes on error
Petr Menšík 595af1
  */
Petr Menšík 595af1
 
Petr Menšík 595af1
 isc_boolean_t
Petr Menšík 595af1
diff --git a/lib/dns/openssl_link.c b/lib/dns/openssl_link.c
Petr Menšík 595af1
index c1e1bde95a..91e87d00b4 100644
Petr Menšík 595af1
--- a/lib/dns/openssl_link.c
Petr Menšík 595af1
+++ b/lib/dns/openssl_link.c
Petr Menšík 595af1
@@ -482,7 +482,8 @@ dst__openssl_getengine(const char *engine) {
Petr Menšík 595af1
 
Petr Menšík 595af1
 isc_result_t
Petr Menšík 595af1
 dst_random_getdata(void *data, unsigned int length,
Petr Menšík 595af1
-		   unsigned int *returned, unsigned int flags) {
Petr Menšík 595af1
+		   unsigned int *returned, unsigned int flags)
Petr Menšík 595af1
+{
Petr Menšík 595af1
 #ifdef ISC_PLATFORM_CRYPTORANDOM
Petr Menšík 595af1
 #ifndef DONT_REQUIRE_DST_LIB_INIT
Petr Menšík 595af1
 	INSIST(dst__memory_pool != NULL);
Petr Menšík 595af1
diff --git a/lib/isc/include/isc/entropy.h b/lib/isc/include/isc/entropy.h
Petr Menšík 595af1
index d9deb8ad9b..2d373630ae 100644
Petr Menšík 595af1
--- a/lib/isc/include/isc/entropy.h
Petr Menšík 595af1
+++ b/lib/isc/include/isc/entropy.h
Petr Menšík 595af1
@@ -9,8 +9,6 @@
Petr Menšík 595af1
  * information regarding copyright ownership.
Petr Menšík 595af1
  */
Petr Menšík 595af1
 
Petr Menšík 595af1
-/* $Id: entropy.h,v 1.35 2009/10/19 02:37:08 marka Exp $ */
Petr Menšík 595af1
-
Petr Menšík 595af1
 #ifndef ISC_ENTROPY_H
Petr Menšík 595af1
 #define ISC_ENTROPY_H 1
Petr Menšík 595af1
 
Petr Menšík 595af1
@@ -190,9 +188,8 @@ isc_entropy_createcallbacksource(isc_entropy_t *ent,
Petr Menšík 595af1
 /*!<
Petr Menšík 595af1
  * \brief Create an entropy source that is polled via a callback.
Petr Menšík 595af1
  *
Petr Menšík 595af1
- * This would
Petr Menšík 595af1
- * be used when keyboard input is used, or a GUI input method.  It can
Petr Menšík 595af1
- * also be used to hook in any external entropy source.
Petr Menšík 595af1
+ * This would be used when keyboard input is used, or a GUI input method.
Petr Menšík 595af1
+ * It can also be used to hook in any external entropy source.
Petr Menšík 595af1
  *
Petr Menšík 595af1
  * Samples are added via isc_entropy_addcallbacksample(), below.
Petr Menšík 595af1
  * _addcallbacksample() is the only function which may be called from
Petr Menšík 595af1
@@ -233,15 +230,32 @@ isc_result_t
Petr Menšík 595af1
 isc_entropy_getdata(isc_entropy_t *ent, void *data, unsigned int length,
Petr Menšík 595af1
 		    unsigned int *returned, unsigned int flags);
Petr Menšík 595af1
 /*!<
Petr Menšík 595af1
- * \brief Extract data from the entropy pool.  This may load the pool from various
Petr Menšík 595af1
- * sources.
Petr Menšík 595af1
+ * \brief Get random data from entropy pool 'ent'.
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * If a hook has been set up using isc_entropy_sethook() and
Petr Menšík 595af1
+ * isc_entropy_usehook(), then the hook function will be called to get
Petr Menšík 595af1
+ * random data.
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * Otherwise, randomness is extracted from the entropy pool set up in BIND.
Petr Menšík 595af1
+ * This may cause the pool to be loaded from various sources. Ths is done
Petr Menšík 595af1
+ * by stirring the pool and returning a part of hash as randomness.
Petr Menšík 595af1
+ * (Note that no secrets are given away here since parts of the hash are
Petr Menšík 595af1
+ * XORed together before returning.)
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * 'flags' may contain ISC_ENTROPY_GOODONLY, ISC_ENTROPY_PARTIAL, or
Petr Menšík 595af1
+ * ISC_ENTROPY_BLOCKING. These will be honored if the hook function is
Petr Menšík 595af1
+ * not in use. If it is, the flags will be passed to the hook function
Petr Menšík 595af1
+ * but it may ignore them.
Petr Menšík 595af1
  *
Petr Menšík 595af1
- * Do this by stiring the pool and returning a part of hash as randomness.
Petr Menšík 595af1
- * Note that no secrets are given away here since parts of the hash are
Petr Menšík 595af1
- * xored together before returned.
Petr Menšík 595af1
+ * Up to 'length' bytes of randomness are retrieved and copied into 'data'.
Petr Menšík 595af1
+ * (If 'returned' is not NULL, and the number of bytes copied is less than
Petr Menšík 595af1
+ * 'length' - which may happen if ISC_ENTROPY_PARTIAL was used - then the
Petr Menšík 595af1
+ * number of bytes copied will be stored in *returned.)
Petr Menšík 595af1
  *
Petr Menšík 595af1
- * Honor the request from the caller to only return good data, any data,
Petr Menšík 595af1
- * etc.
Petr Menšík 595af1
+ * Returns:
Petr Menšík 595af1
+ * \li	ISC_R_SUCCESS on success
Petr Menšík 595af1
+ * \li	ISC_R_NOENTROPY if entropy pool is empty
Petr Menšík 595af1
+ * \li	other error codes are possible when a hook is in use
Petr Menšík 595af1
  */
Petr Menšík 595af1
 
Petr Menšík 595af1
 void
Petr Menšík 595af1
@@ -306,13 +320,21 @@ isc_entropy_usebestsource(isc_entropy_t *ectx, isc_entropysource_t **source,
Petr Menšík 595af1
 void
Petr Menšík 595af1
 isc_entropy_usehook(isc_entropy_t *ectx, isc_boolean_t onoff);
Petr Menšík 595af1
 /*!<
Petr Menšík 595af1
- * \brief Mark/unmark the given entropy structure as being hooked.
Petr Menšík 595af1
+ * \brief Configure entropy context 'ectx' to use the hook function
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * Sets the entropy context to call the hook function for random number
Petr Menšík 595af1
+ * generation, if such a function has been configured via
Petr Menšík 595af1
+ * isc_entropy_sethook(), whenever isc_entropy_getdata() is called.
Petr Menšík 595af1
  */
Petr Menšík 595af1
 
Petr Menšík 595af1
 void
Petr Menšík 595af1
 isc_entropy_sethook(isc_entropy_getdata_t myhook);
Petr Menšík 595af1
 /*!<
Petr Menšík 595af1
- * \brief Set the getdata hook (e.g., for a crypto random generator).
Petr Menšík 595af1
+ * \brief Set the hook function.
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * The hook function is a global value: only one hook function
Petr Menšík 595af1
+ * can be set in the system. Individual entropy contexts may be
Petr Menšík 595af1
+ * configured to use it, or not, by calling isc_entropy_usehook().
Petr Menšík 595af1
  */
Petr Menšík 595af1
 
Petr Menšík 595af1
 ISC_LANG_ENDDECLS
Petr Menšík 595af1
diff --git a/lib/isc/include/isc/random.h b/lib/isc/include/isc/random.h
Petr Menšík 595af1
index ba53ebf35c..b57572842c 100644
Petr Menšík 595af1
--- a/lib/isc/include/isc/random.h
Petr Menšík 595af1
+++ b/lib/isc/include/isc/random.h
Petr Menšík 595af1
@@ -9,8 +9,6 @@
Petr Menšík 595af1
  * information regarding copyright ownership.
Petr Menšík 595af1
  */
Petr Menšík 595af1
 
Petr Menšík 595af1
-/* $Id: random.h,v 1.20 2009/01/17 23:47:43 tbox Exp $ */
Petr Menšík 595af1
-
Petr Menšík 595af1
 #ifndef ISC_RANDOM_H
Petr Menšík 595af1
 #define ISC_RANDOM_H 1
Petr Menšík 595af1
 
Petr Menšík 595af1
@@ -21,13 +19,23 @@
Petr Menšík 595af1
 #include <isc/mutex.h>
Petr Menšík 595af1
 
Petr Menšík 595af1
 /*! \file isc/random.h
Petr Menšík 595af1
- * \brief Implements a random state pool which will let the caller return a
Petr Menšík 595af1
- * series of possibly non-reproducible random values.
Petr Menšík 595af1
+ * \brief Implements pseudo random number generators.
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * Two pseudo-random number generators are implemented, in isc_random_*
Petr Menšík 595af1
+ * and isc_rng_*. Neither one is very strong; they should not be used
Petr Menšík 595af1
+ * in cryptography functions.
Petr Menšík 595af1
+ *
Petr Menšík 595af1
+ * isc_random_* is based on arc4random if it is available on the system.
Petr Menšík 595af1
+ * Otherwise it is based on the posix srand() and rand() functions.
Petr Menšík 595af1
+ * It is useful for jittering values a bit here and there, such as
Petr Menšík 595af1
+ * timeouts, etc, but should not be relied upon to generate
Petr Menšík 595af1
+ * unpredictable sequences (for example, when choosing transaction IDs).
Petr Menšík 595af1
  *
Petr Menšík 595af1
- * Note that the
Petr Menšík 595af1
- * strength of these numbers is not all that high, and should not be
Petr Menšík 595af1
- * used in cryptography functions.  It is useful for jittering values
Petr Menšík 595af1
- * a bit here and there, such as timeouts, etc.
Petr Menšík 595af1
+ * isc_rng_* is based on ChaCha20, and is seeded and stirred from the
Petr Menšík 595af1
+ * system entropy source. It is stronger than isc_random_* and can
Petr Menšík 595af1
+ * be used for generating unpredictable sequences. It is still not as
Petr Menšík 595af1
+ * good as using system entropy directly (see entropy.h) and should not
Petr Menšík 595af1
+ * be used for cryptographic functions such as key generation.
Petr Menšík 595af1
  */
Petr Menšík 595af1
 
Petr Menšík 595af1
 ISC_LANG_BEGINDECLS
Petr Menšík 595af1
@@ -115,8 +123,8 @@ isc_rng_random(isc_rng_t *rngctx);
Petr Menšík 595af1
 isc_uint16_t
Petr Menšík 595af1
 isc_rng_uniformrandom(isc_rng_t *rngctx, isc_uint16_t upper_bound);
Petr Menšík 595af1
 /*%<
Petr Menšík 595af1
- * Returns a uniformly distributed pseudo random 16-bit unsigned
Petr Menšík 595af1
- * integer.
Petr Menšík 595af1
+ * Returns a uniformly distributed pseudo-random 16-bit unsigned integer
Petr Menšík 595af1
+ * less than 'upper_bound'.
Petr Menšík 595af1
  */
Petr Menšík 595af1
 
Petr Menšík 595af1
 ISC_LANG_ENDDECLS
Petr Menšík 595af1
diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c
Petr Menšík 595af1
index 8d496ff9ce..dd08187312 100644
Petr Menšík 595af1
--- a/lib/isccfg/namedconf.c
Petr Menšík 595af1
+++ b/lib/isccfg/namedconf.c
Petr Menšík 595af1
@@ -1106,7 +1106,7 @@ options_clauses[] = {
Petr Menšík 595af1
 	{ "pid-file", &cfg_type_qstringornone, 0 },
Petr Menšík 595af1
 	{ "port", &cfg_type_uint32, 0 },
Petr Menšík 595af1
 	{ "querylog", &cfg_type_boolean, 0 },
Petr Menšík 595af1
-	{ "random-device", &cfg_type_qstring, 0 },
Petr Menšík 595af1
+	{ "random-device", &cfg_type_qstringornone, 0 },
Petr Menšík 595af1
 	{ "recursing-file", &cfg_type_qstring, 0 },
Petr Menšík 595af1
 	{ "recursive-clients", &cfg_type_uint32, 0 },
Petr Menšík 595af1
 	{ "reserved-sockets", &cfg_type_uint32, 0 },
Petr Menšík 595af1
-- 
Petr Menšík 595af1
2.14.4
Petr Menšík 595af1