tfrand: first cmdline argument defines random source file name.

This commit is contained in:
Andrey Rys 2019-05-16 19:43:03 +02:00
parent 65a3fc67f2
commit 488716ef22
No known key found for this signature in database
GPG Key ID: ED732729967CDBC5
1 changed files with 19 additions and 3 deletions

View File

@ -1,3 +1,5 @@
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -13,11 +15,25 @@ static char key[TFNG_KEY_SIZE];
int main(int argc, char **argv)
{
int fd;
char *randsource;
fd = open("/dev/urandom", O_RDONLY);
if (argc > 1 && argv[1]) {
if (!strcmp(argv[1], "-")) {
fd = 0;
goto _stdinrnd;
}
randsource = argv[1];
}
else randsource = "/dev/urandom";
fd = open(randsource, O_RDONLY);
if (fd != -1) {
read(fd, key, sizeof(key));
close(fd);
_stdinrnd: read(fd, key, sizeof(key));
if (fd != 0) close(fd);
}
else {
perror(argv[1]);
return 1;
}
tfng_prng_seedkey(key);