From: Scott Ellis Date: Fri, 7 Dec 2018 13:50:13 +0000 (-0500) Subject: Initial commit X-Git-Tag: hippotat/1.0.0~303^2~2 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=5790bda0c5667b151a2b9c8fd9526d25746b751c;p=hippotat.git Initial commit --- 5790bda0c5667b151a2b9c8fd9526d25746b751c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a997b67 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +rndaddtoentcnt diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3c24ce5 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +rndaddtoentcnt: rndaddtoentcnt.c + $(CC) rndaddtoentcnt.c -o rndaddtoentcnt diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f85b29 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +### rndaddtoentcnt + +Seeding the random number generator by writing to /dev/urandom does not update the entropy count. + +This utility makes the RNDADDTOENTCNT ioctl call needed to do this. + +Used in startup scripts after initializing /dev/urandom with a presaved seed. + +Example: + + dd if=/path/to/some/random-seed-file of=/dev/urandom bs=512 count=1 + + /path/to/rdnaddtoentcnt + +where entropy-bit-count is a number between 1 and (8 * 512) depending on how much you trust the seed file. diff --git a/rndaddtoentcnt.c b/rndaddtoentcnt.c new file mode 100644 index 0000000..929bf4d --- /dev/null +++ b/rndaddtoentcnt.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +int main(int argc, char **argv) +{ + int count, fd; + + if (argc != 2) { + printf("Usage: rndaddtoentcnt \n"); + exit(1); + } + + count = strtoul(argv[1], NULL, 0); + + if (count < 1 || count > 4096) { + printf("Count range is 1 to 4096\n"); + exit(1); + } + + fd = open("/dev/urandom", O_WRONLY); + + if (fd < 0) { + perror("open(/dev/urandom)"); + exit(1); + } + + + if (ioctl(fd, RNDADDTOENTCNT, &count) < 0) { + perror("ioctl(RNDADDTOENTCNT)"); + close(fd); + exit(1); + } + + close(fd); + + return 0; +}