tfrand: first cmdline argument defines random source file name.
This commit is contained in:
parent
65a3fc67f2
commit
488716ef22
22
tfrand.c
22
tfrand.c
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue