|
|
|
@ -44,6 +44,7 @@ |
|
|
|
|
#define DEFAULT_RANDOM_BYTES 8 |
|
|
|
|
#define DEFAULT_LOOP_ITERATIONS 1 |
|
|
|
|
#define DEFAULT_LOOP_INTERVAL 10 |
|
|
|
|
#define DEFAULT_ENTROPY_FACTOR 8 |
|
|
|
|
|
|
|
|
|
static void |
|
|
|
|
usage(int status) |
|
|
|
@ -71,6 +72,11 @@ specified, the default is %d bytes.\n\n", DEFAULT_RANDOM_BYTES); |
|
|
|
|
Set to 0 (default) to always add entropy.\n\
|
|
|
|
|
"); |
|
|
|
|
|
|
|
|
|
printf("\
|
|
|
|
|
-e, --entropy-bits N Set the entropic value of a random byte.\n\
|
|
|
|
|
Must be between 1 and 8. Default is %d.\n\
|
|
|
|
|
\n", DEFAULT_ENTROPY_FACTOR); |
|
|
|
|
|
|
|
|
|
printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT); |
|
|
|
|
|
|
|
|
|
exit(status); |
|
|
|
@ -184,12 +190,14 @@ wait_for_threshold(unsigned threshold, unsigned interval) |
|
|
|
|
* The function only returns in the parent process; the child process |
|
|
|
|
* remains in a loop until it terminates. |
|
|
|
|
* |
|
|
|
|
* @param factor The number of entropy bits in a single byte. |
|
|
|
|
* |
|
|
|
|
* @return |
|
|
|
|
* A file descriptor for the pipe connecting the parent process to |
|
|
|
|
* its child. |
|
|
|
|
*/ |
|
|
|
|
static int |
|
|
|
|
start_privileged_process(void) |
|
|
|
|
start_privileged_process(unsigned factor) |
|
|
|
|
{ |
|
|
|
|
int fd[2]; |
|
|
|
|
pid_t pid; |
|
|
|
@ -218,7 +226,7 @@ start_privileged_process(void) |
|
|
|
|
if ( n == 0 ) /* EOF, parent process must have closed its end. */ |
|
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
|
|
|
|
|
rpi->entropy_count = n * 8; |
|
|
|
|
rpi->entropy_count = n * factor; |
|
|
|
|
rpi->buf_size = n; |
|
|
|
|
memcpy(&(rpi->buf[0]), buffer, n); |
|
|
|
|
|
|
|
|
@ -259,28 +267,31 @@ int |
|
|
|
|
main(int argc, char **argv) |
|
|
|
|
{ |
|
|
|
|
int c, fd, n, loop; |
|
|
|
|
unsigned nbytes, interval, threshold; |
|
|
|
|
unsigned nbytes, interval, threshold, factor; |
|
|
|
|
assuan_context_t ctx; |
|
|
|
|
gpg_error_t e; |
|
|
|
|
unsigned char random_buffer[MAX_RANDOM_BYTES]; |
|
|
|
|
|
|
|
|
|
struct option options[] = { |
|
|
|
|
{ "help", 0, NULL, 'h' }, |
|
|
|
|
{ "version", 0, NULL, 'v' }, |
|
|
|
|
{ "loop", 0, NULL, 'l' }, |
|
|
|
|
{ "max-loop", 1, NULL, 'L' }, |
|
|
|
|
{ "interval", 1, NULL, 'i' }, |
|
|
|
|
{ "threshold", 1, NULL, 't' }, |
|
|
|
|
{ NULL, 0, NULL, 0 } |
|
|
|
|
{ "help", 0, NULL, 'h' }, |
|
|
|
|
{ "version", 0, NULL, 'v' }, |
|
|
|
|
{ "loop", 0, NULL, 'l' }, |
|
|
|
|
{ "max-loop", 1, NULL, 'L' }, |
|
|
|
|
{ "interval", 1, NULL, 'i' }, |
|
|
|
|
{ "threshold", 1, NULL, 't' }, |
|
|
|
|
{ "entropy-bits", 1, NULL, 'e' }, |
|
|
|
|
{ NULL, 0, NULL, 0 } |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
setprogname(argv[0]); |
|
|
|
|
nbytes = DEFAULT_RANDOM_BYTES; |
|
|
|
|
loop = DEFAULT_LOOP_ITERATIONS; |
|
|
|
|
interval = DEFAULT_LOOP_INTERVAL; |
|
|
|
|
factor = DEFAULT_ENTROPY_FACTOR; |
|
|
|
|
threshold = 0; |
|
|
|
|
|
|
|
|
|
while ( (c = getopt_long(argc, argv, "hvlL:i:t:", options, NULL)) != -1 ) { |
|
|
|
|
while ( (c = getopt_long(argc, argv, "hvlL:i:t:e:", |
|
|
|
|
options, NULL)) != -1 ) { |
|
|
|
|
switch ( c ) { |
|
|
|
|
case 'h': |
|
|
|
|
usage(EXIT_SUCCESS); |
|
|
|
@ -309,10 +320,16 @@ main(int argc, char **argv) |
|
|
|
|
case 't': |
|
|
|
|
threshold = get_uinteger_or_die(optarg); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'e': |
|
|
|
|
factor = get_uinteger_or_die(optarg); |
|
|
|
|
if ( factor == 0 || factor > 8 ) |
|
|
|
|
errx(EXIT_FAILURE, "Expected an entropy factor between 1 and 8"); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fd = start_privileged_process(); |
|
|
|
|
fd = start_privileged_process(factor); |
|
|
|
|
|
|
|
|
|
if ( optind < argc ) { |
|
|
|
|
nbytes = get_uinteger_or_die(argv[optind++]); |
|
|
|
|