tests: add warning message when /dev/urandom fails
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
This commit is contained in:
parent
cd329dbc3e
commit
cddef0c0be
|
@ -4919,6 +4919,7 @@ int main(int argc, char **argv) {
|
||||||
} else {
|
} else {
|
||||||
FILE *frand = fopen("/dev/urandom", "r");
|
FILE *frand = fopen("/dev/urandom", "r");
|
||||||
if ((frand == NULL) || fread(&seed16, sizeof(seed16), 1, frand) != sizeof(seed16)) {
|
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;
|
uint64_t t = time(NULL) * (uint64_t)1337;
|
||||||
seed16[0] ^= t;
|
seed16[0] ^= t;
|
||||||
seed16[1] ^= t >> 8;
|
seed16[1] ^= t >> 8;
|
||||||
|
|
Loading…
Reference in New Issue