#include #include #include #include #include #include #include #include #include #include #include char *program_name; void usage() { error(1, 0, "usage: %s [--bytes] ", program_name); } int main(int argc, char **argv) { argc--, program_name = *argv++; int multiplier = 1; int bits; while (argc > 1) { if (!strcmp(*argv, "--bytes")) { multiplier = 8; } else { usage(); } argc--, argv++; } if ((argc != 1) || (bits = multiplier * atoi(*argv)) <= 0) usage(); struct rand_pool_info *output; int fd = open("/dev/random", O_WRONLY); if (fd < 0) error(1, errno, "opening /dev/random"); output = (struct rand_pool_info *) malloc(sizeof(struct rand_pool_info)); output -> entropy_count = bits; output -> buf_size = 0; int r = ioctl(fd, RNDADDENTROPY, output); if (r < 0) error(1, errno, "ioctl(RNDADDENTROPY)"); return 0; }