]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Switch the CSPRNG function from RAND_bytes() to uv_random()
authorOndřej Surý <ondrej@isc.org>
Thu, 22 Sep 2022 08:36:53 +0000 (10:36 +0200)
committerOndřej Surý <ondrej@isc.org>
Mon, 26 Sep 2022 13:13:11 +0000 (15:13 +0200)
The RAND_bytes() implementation differs between the OpenSSL versions and
uses the system entropy only for seeding its internal CSPRNG.  The
uv_random() on the other hand uses the system provided CSPRNG.

Switch from RAND_bytes() to uv_random() to use system provided CSPRNG.

lib/isc/Makefile.am
lib/isc/entropy.c
lib/isc/hash.c
lib/isc/include/isc/entropy.h [moved from lib/isc/entropy_private.h with 85% similarity]
lib/isc/nonce.c
lib/isc/random.c

index c23ebf31380c661145049144499d17930b8efc12..35657e889e081cd7d8344c92e01579110da6b035 100644 (file)
@@ -26,6 +26,7 @@ libisc_la_HEADERS =                   \
        include/isc/deprecated.h        \
        include/isc/dir.h               \
        include/isc/endian.h            \
+       include/isc/entropy.h           \
        include/isc/errno.h             \
        include/isc/error.h             \
        include/isc/event.h             \
@@ -132,7 +133,6 @@ libisc_la_SOURCES =         \
        crc64.c                 \
        dir.c                   \
        entropy.c               \
-       entropy_private.h       \
        errno.c                 \
        errno2result.c          \
        errno2result.h          \
index ce79ba21c3b676d13986adb4c1d808d13797042f..a037960bd1859d3a9f74a77f0f4b63c4eedb3a50 100644 (file)
  * information regarding copyright ownership.
  */
 
-#include <openssl/err.h>
-#include <openssl/rand.h>
-
+#include <isc/entropy.h>
 #include <isc/types.h>
 #include <isc/util.h>
-
-#include "entropy_private.h"
+#include <isc/uv.h>
 
 void
 isc_entropy_get(void *buf, size_t buflen) {
-       if (RAND_bytes(buf, buflen) < 1) {
-               FATAL_ERROR(__FILE__, __LINE__, "RAND_bytes(): %s",
-                           ERR_error_string(ERR_get_error(), NULL));
-       }
+       int r = uv_random(NULL, NULL, buf, buflen, 0, NULL);
+
+       UV_RUNTIME_CHECK(uv_random, r);
 }
index 37622ea8c590e23a6cd45f8f97222c75727c3969..8dcc788ab65bfb513ac5280dea0369d7a2029cd6 100644 (file)
 #include <stdbool.h>
 #include <stddef.h>
 
-#include "entropy_private.h"
-#include "isc/ascii.h"
-#include "isc/hash.h" /* IWYU pragma: keep */
-#include "isc/once.h"
-#include "isc/random.h"
-#include "isc/result.h"
-#include "isc/siphash.h"
-#include "isc/string.h"
-#include "isc/types.h"
-#include "isc/util.h"
+#include <isc/ascii.h>
+#include <isc/entropy.h>
+#include <isc/hash.h> /* IWYU pragma: keep */
+#include <isc/once.h>
+#include <isc/random.h>
+#include <isc/result.h>
+#include <isc/siphash.h>
+#include <isc/string.h>
+#include <isc/types.h>
+#include <isc/util.h>
 
 static uint8_t isc_hash_key[16];
 static uint8_t isc_hash32_key[8];
similarity index 85%
rename from lib/isc/entropy_private.h
rename to lib/isc/include/isc/entropy.h
index df9a38274ac909cd23a5584fc93b69b90d831e48..4e2dc5f884231c206f1cc1522cb8c8d7445cacc7 100644 (file)
 
 #include <isc/lang.h>
 
-/*! \file isc/entropy_private.h
+/*! \file isc/entropy.h
  * \brief Implements wrapper around CSPRNG cryptographic library calls
  * for getting cryptographically secure pseudo-random numbers.
  *
- * - If OpenSSL is used, it uses RAND_bytes()
- * - If PKCS#11 is used, it uses pkcs_C_GenerateRandom()
- *
+ * Uses synchronous version of uv_random().
  */
 
 ISC_LANG_BEGINDECLS
index 4c2baff77d8be51bb16e4f9db823b93d05e547f4..316498a6136b357d8c358374750e18b1f70bccaf 100644 (file)
  * information regarding copyright ownership.
  */
 
+#include <isc/entropy.h>
 #include <isc/nonce.h>
 
-#include "entropy_private.h"
-
 void
 isc_nonce_buf(void *buf, size_t buflen) {
        isc_entropy_get(buf, buflen);
index e37366d8cd06f8a0897790cbdcba5e1a460bc572..5d67f81b147275a75cc16df0fb78bbe631c43561 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
+#include <isc/entropy.h>
 #include <isc/random.h>
 #include <isc/result.h>
 #include <isc/thread.h>
 #include <isc/types.h>
 #include <isc/util.h>
 
-#include "entropy_private.h"
 #include "random_p.h"
 
 /*