From c44ce9e923da14c04730340347ac2bfe9b6b61ea Mon Sep 17 00:00:00 2001 From: wiire-a Date: Thu, 11 Jan 2018 23:31:50 +0100 Subject: [PATCH] Give possibility to make glibc PRNG work for every seed Because of the modulo trick the current glibc PRNG version doesn't work for seed == 0x7fffffff or seed == 0xfffffffe. The former is used only if the user specifically uses --start / --end 02/2038. The latter is never used as negative values are not legal for time. In any case a compilation guard (PWPS_UNERRING) has been added for correctness to make the PRNG spit correct values even for those 2 seeds. --- src/random/glibc_random_yura.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/random/glibc_random_yura.c b/src/random/glibc_random_yura.c index 64c69c5..abafac7 100644 --- a/src/random/glibc_random_yura.c +++ b/src/random/glibc_random_yura.c @@ -18,6 +18,11 @@ static inline uint32_t *glibc_fast_nonce(uint32_t seed, uint32_t *dest) { uint32_t word0 = 0, word1 = 0, word2 = 0, word3 = 0; +#ifdef PWPS_UNERRING + if (seed == 0x7fffffff) seed = 0x13f835f3; + else if (seed == 0xfffffffe) seed = 0x5df735f1; +#endif + for (int j = 0; j < 31; j++) { word0 += seed * glibc_seed_tbl[j + 3]; word1 += seed * glibc_seed_tbl[j + 2]; @@ -42,6 +47,11 @@ static inline uint32_t glibc_fast_seed(uint32_t seed) { uint32_t word0 = 0; +#ifdef PWPS_UNERRING + if (seed == 0x7fffffff) seed = 0x13f835f3; + else if (seed == 0xfffffffe) seed = 0x5df735f1; +#endif + for (int j = 3; j < 31 + 3 - 1; j++) { word0 += seed * glibc_seed_tbl[j];