Merge #516: improvements to random seed in src/tests.c
be40c4d
Fixup for C90 mixed declarations. (Gregory Maxwell)8b3841c
fix bug in fread() failure check (Don Viszneki)cddef0c
tests: add warning message when /dev/urandom fails (Don Viszneki) Pull request description: I've made two small changes to `src/tests.c` circa random seed generation. Added a warning when `/dev/urandom` fails, mostly to defend against the case that someone should use the code verbatim, but also to enhance its illustrative power. Also I fixed a bug with how the return value of `fread()` was being evaluated. In fact, `/dev/urandom` was never being applied before as the check on the return value of `fread()` always failed! Tree-SHA512: 239dbe8316220c2f0e5b370bf9a18f78196e96cc4a7edea58cf2521b2c9cbc8da065be96aa859f90324d57e388d30f7670ce6bc1cca52e5162e5ca66b1a55b34
This commit is contained in:
commit
20c5869df2
|
@ -4994,8 +4994,9 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
} else {
|
||||
FILE *frand = fopen("/dev/urandom", "r");
|
||||
if ((frand == NULL) || fread(&seed16, sizeof(seed16), 1, frand) != sizeof(seed16)) {
|
||||
if ((frand == NULL) || fread(&seed16, 1, sizeof(seed16), frand) != sizeof(seed16)) {
|
||||
uint64_t t = time(NULL) * (uint64_t)1337;
|
||||
fprintf(stderr, "WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n");
|
||||
seed16[0] ^= t;
|
||||
seed16[1] ^= t >> 8;
|
||||
seed16[2] ^= t >> 16;
|
||||
|
|
Loading…
Reference in New Issue