|
|
1524bc |
From 45c34e04c2018d839be71371bee594bc4794de2d Mon Sep 17 00:00:00 2001
|
|
|
1524bc |
From: Andreas Schneider <asn@samba.org>
|
|
|
1524bc |
Date: Wed, 31 Jul 2019 15:16:37 +0200
|
|
|
1524bc |
Subject: [PATCH 067/187] lib:util: Add generate_nonce_buffer()
|
|
|
1524bc |
|
|
|
1524bc |
Signed-off-by: Andreas Schneider <asn@samba.org>
|
|
|
1524bc |
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
|
|
|
1524bc |
(cherry picked from commit 70ff216935acc099b762b527033b6191ba3307d0)
|
|
|
1524bc |
---
|
|
|
1524bc |
lib/util/genrand.c | 12 ++++++++++--
|
|
|
1524bc |
lib/util/genrand.h | 11 +++++++++++
|
|
|
1524bc |
2 files changed, 21 insertions(+), 2 deletions(-)
|
|
|
1524bc |
|
|
|
1524bc |
diff --git a/lib/util/genrand.c b/lib/util/genrand.c
|
|
|
1524bc |
index 55997c3dd55..76c2cb81962 100644
|
|
|
1524bc |
--- a/lib/util/genrand.c
|
|
|
1524bc |
+++ b/lib/util/genrand.c
|
|
|
1524bc |
@@ -25,8 +25,6 @@
|
|
|
1524bc |
#include <gnutls/gnutls.h>
|
|
|
1524bc |
#include <gnutls/crypto.h>
|
|
|
1524bc |
|
|
|
1524bc |
-/* TODO: Add API for generating nonce or use gnutls_rnd directly everywhere. */
|
|
|
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 |
@@ -42,3 +40,13 @@ _PUBLIC_ void generate_secret_buffer(uint8_t *out, int len)
|
|
|
1524bc |
/* Thread and fork safe random number generator for long term keys. */
|
|
|
1524bc |
gnutls_rnd(GNUTLS_RND_KEY, out, len);
|
|
|
1524bc |
}
|
|
|
1524bc |
+
|
|
|
1524bc |
+_PUBLIC_ void generate_nonce_buffer(uint8_t *out, int len)
|
|
|
1524bc |
+{
|
|
|
1524bc |
+ /*
|
|
|
1524bc |
+ * The nonce generator will reseed after outputting a fixed amount of
|
|
|
1524bc |
+ * bytes (typically few megabytes), or after few hours of operation
|
|
|
1524bc |
+ * without reaching the limit has passed.
|
|
|
1524bc |
+ */
|
|
|
1524bc |
+ gnutls_rnd(GNUTLS_RND_NONCE, out, len);
|
|
|
1524bc |
+}
|
|
|
1524bc |
diff --git a/lib/util/genrand.h b/lib/util/genrand.h
|
|
|
1524bc |
index 899ce8badc0..5af23100596 100644
|
|
|
1524bc |
--- a/lib/util/genrand.h
|
|
|
1524bc |
+++ b/lib/util/genrand.h
|
|
|
1524bc |
@@ -28,3 +28,14 @@ void generate_random_buffer(uint8_t *out, int len);
|
|
|
1524bc |
* Thread and fork safe random number generator for long term keys.
|
|
|
1524bc |
*/
|
|
|
1524bc |
void generate_secret_buffer(uint8_t *out, int len);
|
|
|
1524bc |
+
|
|
|
1524bc |
+/**
|
|
|
1524bc |
+ * @brief Generate random values for a nonce buffer.
|
|
|
1524bc |
+ *
|
|
|
1524bc |
+ * This is also known as initialization vector.
|
|
|
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_nonce_buffer(uint8_t *out, int len);
|
|
|
1524bc |
--
|
|
|
1524bc |
2.23.0
|
|
|
1524bc |
|