diff --git a/libretroshare/src/util/rsrandom.cc b/libretroshare/src/util/rsrandom.cc index fc668ded2..3b275eb9c 100644 --- a/libretroshare/src/util/rsrandom.cc +++ b/libretroshare/src/util/rsrandom.cc @@ -3,11 +3,8 @@ #include #include "rsrandom.h" -#define RSRANDOM_USE_SSL - -#ifdef RSRANDOM_USE_SSL #include -#endif + uint32_t RSRandom::index = RSRandom::N ; std::vector RSRandom::MT(RSRandom::N,0u) ; RsMutex RSRandom::rndMtx("RSRandom") ; @@ -16,22 +13,9 @@ RsMutex RSRandom::rndMtx("RSRandom") ; // OpenSSL random bytes: // - on systems that only have /dev/urandom (linux, BSD, MacOS), we don't need to call the seed // - on windows, we need to -// MT19937 pseudo random -// - always seed. // #ifdef WINDOWS_SYS static bool auto_seed = RSRandom::seed( (time(NULL) + ((uint32_t) pthread_self().p)*0x1293fe)^0x18e34a12 ) ; -#else -#ifndef RSRANDOM_USE_SSL - #ifdef __APPLE__ - static bool auto_seed = RSRandom::seed( (time(NULL) + pthread_mach_thread_np(pthread_self())*0x1293fe + (getpid()^0x113ef76b))^0x18e34a12 ) ; - #elif defined(__FreeBSD__) - // since this is completely insecure anyway, just kludge for now - static bool auto_seed = RSRandom::seed(time(NULL)); - #else - static bool auto_seed = RSRandom::seed( (time(NULL) + pthread_self()*0x1293fe + (getpid()^0x113ef76b))^0x18e34a12 ) ; - #endif -#endif #endif bool RSRandom::seed(uint32_t s) @@ -45,9 +29,9 @@ bool RSRandom::seed(uint32_t s) for (j=1; j> 30)) + j) & 0xffffffffUL ; -#ifdef RSRANDOM_USE_SSL RAND_seed((unsigned char *)&MT[0],N*sizeof(uint32_t)) ; -#endif + locked_next_state() ; + return true ; } @@ -57,19 +41,7 @@ void RSRandom::random_bytes(unsigned char *data,uint32_t size) } void RSRandom::locked_next_state() { -#ifdef RSRANDOM_USE_SSL RAND_bytes((unsigned char *)&MT[0],N*sizeof(uint32_t)) ; -#else - for(uint32_t i=0;i> 1) ; - - if((y & 1) == 1) - MT[i] = MT[i] ^ 0x9908b0df ; - } -#endif index = 0 ; } diff --git a/libretroshare/src/util/rsrandom.h b/libretroshare/src/util/rsrandom.h index f69211405..8cd66f7f6 100644 --- a/libretroshare/src/util/rsrandom.h +++ b/libretroshare/src/util/rsrandom.h @@ -51,12 +51,7 @@ class RSRandom private: static RsMutex rndMtx ; - static const uint32_t N = 624; - static const uint32_t M = 397; - - static const uint32_t MATRIX_A = 0x9908b0dfUL; - static const uint32_t UMASK = 0x80000000UL; - static const uint32_t LMASK = 0x7fffffffUL; + static const uint32_t N = 1024; static void locked_next_state() ; static uint32_t index ;