From: Andreas Schneider Date: Wed, 31 Jul 2019 13:16:37 +0000 (+0200) Subject: lib:util: Add generate_nonce_buffer() X-Git-Tag: tdb-1.4.2~162 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=70ff216935acc099b762b527033b6191ba3307d0;p=thirdparty%2Fsamba.git lib:util: Add generate_nonce_buffer() Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/lib/util/genrand.c b/lib/util/genrand.c index 55997c3dd55..76c2cb81962 100644 --- a/lib/util/genrand.c +++ b/lib/util/genrand.c @@ -25,8 +25,6 @@ #include #include -/* TODO: Add API for generating nonce or use gnutls_rnd directly everywhere. */ - _PUBLIC_ void generate_random_buffer(uint8_t *out, int len) { /* Thread and fork safe random number generator for temporary keys. */ @@ -42,3 +40,13 @@ _PUBLIC_ void generate_secret_buffer(uint8_t *out, int len) /* Thread and fork safe random number generator for long term keys. */ gnutls_rnd(GNUTLS_RND_KEY, out, len); } + +_PUBLIC_ void generate_nonce_buffer(uint8_t *out, int len) +{ + /* + * The nonce generator will reseed after outputting a fixed amount of + * bytes (typically few megabytes), or after few hours of operation + * without reaching the limit has passed. + */ + gnutls_rnd(GNUTLS_RND_NONCE, out, len); +} diff --git a/lib/util/genrand.h b/lib/util/genrand.h index 899ce8badc0..5af23100596 100644 --- a/lib/util/genrand.h +++ b/lib/util/genrand.h @@ -28,3 +28,14 @@ void generate_random_buffer(uint8_t *out, int len); * Thread and fork safe random number generator for long term keys. */ void generate_secret_buffer(uint8_t *out, int len); + +/** + * @brief Generate random values for a nonce buffer. + * + * This is also known as initialization vector. + * + * @param[in] out A pointer to the buffer to fill with random data. + * + * @param[in] len The size of the buffer to fill. + */ +void generate_nonce_buffer(uint8_t *out, int len);