aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-03-15 20:19:48 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-03-15 20:19:48 +0000
commit92f20993f94c91ad03213c5fcc2984ee3b487a67 (patch)
treea7394303404fa53efa61e3bd0d01c8853d19a1fe /src/libutil
parente264bccde335bfd0f5c0f31cb33f3d52ac50682b (diff)
downloadrspamd-92f20993f94c91ad03213c5fcc2984ee3b487a67.tar.gz
rspamd-92f20993f94c91ad03213c5fcc2984ee3b487a67.zip
[Minor] Automatically init xoroshifto PRG
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/libutil/util.c b/src/libutil/util.c
index 47856f716..49d61e87e 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -1766,7 +1766,19 @@ rspamd_random_double (void)
}
-static guint64 xorshifto_seed[4];
+static guint64*
+xorshifto_seed (void)
+{
+ static guint64 xorshifto_seed[4];
+ static bool initialized = false;
+
+ if (G_UNLIKELY(!initialized)) {
+ ottery_rand_bytes((void *)xorshifto_seed, sizeof (xorshifto_seed));
+ initialized = true;
+ }
+
+ return xorshifto_seed;
+}
static inline guint64
xoroshiro_rotl (const guint64 x, int k) {
@@ -1776,7 +1788,7 @@ xoroshiro_rotl (const guint64 x, int k) {
gdouble
rspamd_random_double_fast (void)
{
- return rspamd_random_double_fast_seed (xorshifto_seed);
+ return rspamd_random_double_fast_seed (xorshifto_seed());
}
/* xoshiro256+ */
@@ -1822,13 +1834,13 @@ rspamd_random_uint64_fast_seed (guint64 seed[4])
guint64
rspamd_random_uint64_fast (void)
{
- return rspamd_random_uint64_fast_seed (xorshifto_seed);
+ return rspamd_random_uint64_fast_seed (xorshifto_seed());
}
void
rspamd_random_seed_fast (void)
{
- ottery_rand_bytes (xorshifto_seed, sizeof (xorshifto_seed));
+ (void)xorshifto_seed();
}
gdouble