[Change] Instead of seeding the MT with a bit of random, we use full urandom.
This commit is contained in:
parent
ceb96b0f13
commit
1391fabc65
12
src/rng.c
12
src/rng.c
@ -24,13 +24,16 @@ static uint32_t mt_getInt(void);
|
|||||||
|
|
||||||
void rng_init(void) {
|
void rng_init(void) {
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
int need_init;
|
||||||
|
|
||||||
|
need_init = 1; // Initialize by default.
|
||||||
#ifdef LINUX
|
#ifdef LINUX
|
||||||
int fd; char buf[4];
|
int fd;
|
||||||
fd = open("/dev/random", O_RDONLY);
|
fd = open("/dev/urandom", O_RDONLY); // /dev/urandom is better then time seed.
|
||||||
if(fd != -1) {
|
if(fd != -1) {
|
||||||
if(read(fd, buf, 4) < 4)
|
i = sizeof(uint32_t)*624;
|
||||||
memcpy(&i, buf, 4);
|
if(read(fd, &MT, i) == 1)
|
||||||
|
need_init = 0;
|
||||||
else
|
else
|
||||||
i = rng_timeEntropy();
|
i = rng_timeEntropy();
|
||||||
close(fd);
|
close(fd);
|
||||||
@ -39,6 +42,7 @@ void rng_init(void) {
|
|||||||
#else
|
#else
|
||||||
i = rng_timeEntropy();
|
i = rng_timeEntropy();
|
||||||
#endif
|
#endif
|
||||||
|
if(need_init)
|
||||||
mt_initArray(i);
|
mt_initArray(i);
|
||||||
for(i = 0; i < 10; i++)
|
for(i = 0; i < 10; i++)
|
||||||
// Generate numbers to get away from poor initial values.
|
// Generate numbers to get away from poor initial values.
|
||||||
|
Loading…
Reference in New Issue
Block a user