1524bc
From deeb93c2fb7cc131741ced4877b75bcd3a64cef4 Mon Sep 17 00:00:00 2001
1524bc
From: Andreas Schneider <asn@samba.org>
1524bc
Date: Wed, 31 Jul 2019 15:38:50 +0200
1524bc
Subject: [PATCH 070/187] lib:util: Add better documentation for
1524bc
 generate_secret_buffer()
1524bc
1524bc
Signed-off-by: Andreas Schneider <asn@samba.org>
1524bc
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
1524bc
(cherry picked from commit bf52ab7d2982de84a68a1b9c6d2f68250b7e7cca)
1524bc
---
1524bc
 lib/util/genrand.c | 17 ++++++++++++-----
1524bc
 lib/util/genrand.h |  6 +++++-
1524bc
 2 files changed, 17 insertions(+), 6 deletions(-)
1524bc
1524bc
diff --git a/lib/util/genrand.c b/lib/util/genrand.c
1524bc
index 76c2cb81962..a5809aa2bc9 100644
1524bc
--- a/lib/util/genrand.c
1524bc
+++ b/lib/util/genrand.c
1524bc
@@ -25,19 +25,26 @@
1524bc
 #include <gnutls/gnutls.h>
1524bc
 #include <gnutls/crypto.h>
1524bc
 
1524bc
+/*
1524bc
+ * Details about the GnuTLS CSPRNG:
1524bc
+ *
1524bc
+ * https://nikmav.blogspot.com/2017/03/improving-by-simplifying-gnutls-prng.html
1524bc
+ */
1524bc
+
1524bc
 _PUBLIC_ void generate_random_buffer(uint8_t *out, int len)
1524bc
 {
1524bc
 	/* Thread and fork safe random number generator for temporary keys. */
1524bc
 	gnutls_rnd(GNUTLS_RND_RANDOM, out, len);
1524bc
 }
1524bc
 
1524bc
-/*
1524bc
- * Keep generate_secret_buffer in case we ever want to do something
1524bc
- * different
1524bc
- */
1524bc
 _PUBLIC_ void generate_secret_buffer(uint8_t *out, int len)
1524bc
 {
1524bc
-	/* Thread and fork safe random number generator for long term keys. */
1524bc
+	/* The key generator, will re-seed after a fixed amount of bytes is
1524bc
+	 * generated (typically less than the nonce), and will also re-seed
1524bc
+	 * based on time, i.e., after few hours of operation without reaching
1524bc
+	 * the limit for a re-seed. For its re-seed it mixes mixes data obtained
1524bc
+	 * from the OS random device with the previous key.
1524bc
+	 */
1524bc
 	gnutls_rnd(GNUTLS_RND_KEY, out, len);
1524bc
 }
1524bc
 
1524bc
diff --git a/lib/util/genrand.h b/lib/util/genrand.h
1524bc
index 5af23100596..abb8ce2c10a 100644
1524bc
--- a/lib/util/genrand.h
1524bc
+++ b/lib/util/genrand.h
1524bc
@@ -25,7 +25,11 @@
1524bc
 void generate_random_buffer(uint8_t *out, int len);
1524bc
 
1524bc
 /**
1524bc
- * Thread and fork safe random number generator for long term keys.
1524bc
+ * @brief Generate random values for key buffers (e.g. session keys)
1524bc
+ *
1524bc
+ * @param[in]  out  A pointer to the buffer to fill with random data.
1524bc
+ *
1524bc
+ * @param[in]  len  The size of the buffer to fill.
1524bc
  */
1524bc
 void generate_secret_buffer(uint8_t *out, int len);
1524bc
 
1524bc
-- 
1524bc
2.23.0
1524bc