From 517ecd9a12471e662c877abe100bc8dfc29db630 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 8 Feb 2017 14:18:56 +0200 Subject: [PATCH] Remove unnecessary spinlocks from random_jkiss Removing the locks will increase the randomness of the random number generation by introducing race conditions into the code. --- server/core/random_jkiss.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/server/core/random_jkiss.c b/server/core/random_jkiss.c index bc81b9fcc..b21ce42f4 100644 --- a/server/core/random_jkiss.c +++ b/server/core/random_jkiss.c @@ -31,7 +31,6 @@ #include #include #include -#include #include /* Public domain code for JKISS RNG - Comment header added */ @@ -42,8 +41,6 @@ static unsigned int x = 123456789, y = 987654321, z = 43219876, c = 6543217; /* Seed variables */ static bool init = false; -static SPINLOCK random_jkiss_spinlock = SPINLOCK_INIT; - static unsigned int random_jkiss_devrand(void); static void random_init_jkiss(void); @@ -60,14 +57,11 @@ random_jkiss(void) unsigned long long t; unsigned int result; - spinlock_acquire(&random_jkiss_spinlock); if (!init) { /* Must set init first because initialisation calls this function */ init = true; - spinlock_release(&random_jkiss_spinlock); random_init_jkiss(); - spinlock_acquire(&random_jkiss_spinlock); } x = 314527869 * x + 1234567; y ^= y << 5; @@ -77,7 +71,6 @@ random_jkiss(void) c = t >> 32; z = t; result = x + y + z; - spinlock_release(&random_jkiss_spinlock); return result; } @@ -120,7 +113,6 @@ random_init_jkiss(void) { int newrand, i; - spinlock_acquire(&random_jkiss_spinlock); if ((newrand = random_jkiss_devrand()) != 0) { x = newrand; @@ -140,7 +132,6 @@ random_init_jkiss(void) { c = newrand % 698769068 + 1; /* Should be less than 698769069 */ } - spinlock_release(&random_jkiss_spinlock); /* "Warm up" our random number generator */ for (i = 0; i < 100; i++)