2 Star 1 Fork 0

src-oepkgs/samba

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0067-lib-util-Add-generate_nonce_buffer.patch 2.06 KB
一键复制 编辑 原始数据 按行查看 历史
张一诺 提交于 2022-12-05 23:46 . 4.11.2
From 45c34e04c2018d839be71371bee594bc4794de2d Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@samba.org>
Date: Wed, 31 Jul 2019 15:16:37 +0200
Subject: [PATCH 067/187] lib:util: Add generate_nonce_buffer()
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit 70ff216935acc099b762b527033b6191ba3307d0)
---
lib/util/genrand.c | 12 ++++++++++--
lib/util/genrand.h | 11 +++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
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 <gnutls/gnutls.h>
#include <gnutls/crypto.h>
-/* 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);
--
2.23.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/src-oepkgs/samba.git
git@gitee.com:src-oepkgs/samba.git
src-oepkgs
samba
samba
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385