Skip to content

Commit

Permalink
tests: add warning message when /dev/urandom fails
Browse files Browse the repository at this point in the history
in case this code should ever be used as an example, a warning is a nice
way of helping ensure insecure keys are not generated
  • Loading branch information
hdon committed Mar 6, 2018
1 parent cd329db commit cddef0c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -4919,6 +4919,7 @@ int main(int argc, char **argv) {
} else {
FILE *frand = fopen("/dev/urandom", "r");
if ((frand == NULL) || fread(&seed16, sizeof(seed16), 1, frand) != sizeof(seed16)) {
fprintf(stderr, "WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n");
uint64_t t = time(NULL) * (uint64_t)1337;
seed16[0] ^= t;
seed16[1] ^= t >> 8;
Expand Down

0 comments on commit cddef0c

Please sign in to comment.