diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-22 12:59:14 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-07-22 12:59:14 +0100 |
commit | e460a6dc4b48f3bb31b072ee058475f08b6432d1 (patch) | |
tree | 7fde32707229ed38fb17cc5204d6672d41fb65da /contrib | |
parent | e3115479423efb1d864021fa30e5d454f02ae1ea (diff) | |
download | rspamd-e460a6dc4b48f3bb31b072ee058475f08b6432d1.tar.gz rspamd-e460a6dc4b48f3bb31b072ee058475f08b6432d1.zip |
[Minor] Fix randomness part in torch
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/torch/torch7/lib/TH/THRandom.c | 33 |
1 files changed, 4 insertions, 29 deletions
diff --git a/contrib/torch/torch7/lib/TH/THRandom.c b/contrib/torch/torch7/lib/TH/THRandom.c index fbaf2820c..0dca555fd 100644 --- a/contrib/torch/torch7/lib/TH/THRandom.c +++ b/contrib/torch/torch7/lib/TH/THRandom.c @@ -1,17 +1,13 @@ #include "THGeneral.h" #include "THRandom.h" - -#ifndef _WIN32 -#include <fcntl.h> -#include <unistd.h> -#endif +#include "ottery.h" /* Code for the Mersenne Twister random generator.... */ #define n _MERSENNE_STATE_N #define m _MERSENNE_STATE_M /* Creates (unseeded) new generator*/ -static THGenerator* THGenerator_newUnseeded() +static THGenerator* THGenerator_newUnseeded(void) { THGenerator *self = THAlloc(sizeof(THGenerator)); memset(self, 0, sizeof(THGenerator)); @@ -22,7 +18,7 @@ static THGenerator* THGenerator_newUnseeded() } /* Creates new generator and makes sure it is seeded*/ -THGenerator* THGenerator_new() +THGenerator* THGenerator_new(void) { THGenerator *self = THGenerator_newUnseeded(); THRandom_seed(self); @@ -49,30 +45,9 @@ int THGenerator_isValid(THGenerator *_generator) return 0; } -#ifndef _WIN32 -static unsigned long readURandomLong() -{ - int randDev = open("/dev/urandom", O_RDONLY); - unsigned long randValue; - if (randDev < 0) { - THError("Unable to open /dev/urandom"); - } - ssize_t readBytes = read(randDev, &randValue, sizeof(randValue)); - if (readBytes < sizeof(randValue)) { - THError("Unable to read from /dev/urandom"); - } - close(randDev); - return randValue; -} -#endif // _WIN32 - unsigned long THRandom_seed(THGenerator *_generator) { -#ifdef _WIN32 - unsigned long s = (unsigned long)time(0); -#else - unsigned long s = readURandomLong(); -#endif + unsigned long s = ottery_rand_uint64(); THRandom_manualSeed(_generator, s); return s; } |