-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improvements to random seed in src/tests.c #516
Conversation
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
the two middle arguments to fread() are easily confused, and cause the checking of return value to fail incorrectly (and possibly succeed incorrectly.)
utACK 8b3841c |
bump |
src/tests.c
Outdated
@@ -4918,7 +4918,8 @@ 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)) { | |||
fprintf(stderr, "WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/tests.c: In function ‘main’:
src/tests.c:4923:13: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
uint64_t t = time(NULL) * (uint64_t)1337;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hdon to fix this, move the fprint down a line. Then we should be good to merge.
Reported-by: Jonas Nick <jonasd.nick@gmail.com>
@sipa @jonasnick @real-or-random @hdon please at least utACK my trivial fixup commit so I can merge. :P |
utACK |
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
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 offread()
always failed!