summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-11-13 20:57:20 -0500
committerAlex Xu (Hello71) <alex_y_xu@yahoo.ca>2020-11-13 20:57:20 -0500
commite54a8ed3686c6de17b284937b7828e471db83a3f (patch)
tree389153d4f4c24666b49be55be98dcd0b86b837a1
parent6084e986f8affc7045c6aa2043acb6cc86fea920 (diff)
downloadminitramfs-e54a8ed3686c6de17b284937b7828e471db83a3f.tar.xz
minitramfs-e54a8ed3686c6de17b284937b7828e471db83a3f.zip
drop load-random-seed for good
-rw-r--r--load-random-seed.c65
1 files changed, 0 insertions, 65 deletions
diff --git a/load-random-seed.c b/load-random-seed.c
deleted file mode 100644
index 491afba..0000000
--- a/load-random-seed.c
+++ /dev/null
@@ -1,65 +0,0 @@
-#include <fcntl.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-
-// musl forbids include/linux
-#define RNDADDENTROPY _IOW( 'R', 0x03, int [2] )
-
-#define RAND_POOL_SIZE 512
-
-int main(int argc, char *argv[]) {
- if (argc != 2) {
- fputs("usage: load-random-seed FILE\n", stderr);
- exit(1);
- }
-
- int seed_fd = open(argv[1], O_RDONLY);
- if (seed_fd == -1) {
- perror("error opening seed file");
- exit(1);
- }
- struct {
- int entropy_count;
- int buf_size;
- char buf[RAND_POOL_SIZE];
- } rpi = {
- .entropy_count = RAND_POOL_SIZE * CHAR_BIT,
- .buf_size = RAND_POOL_SIZE
- };
- size_t sz = 0;
- do {
- ssize_t r = read(seed_fd, &rpi.buf[sz], RAND_POOL_SIZE - sz);
- if (r == -1) {
- perror("error reading seed file");
- exit(1);
- }
- sz += r;
- } while (sz < RAND_POOL_SIZE);
-
- if (close(seed_fd) == -1) {
- perror("error closing seed file");
- exit(1);
- }
-
- int urandom_fd = open("/dev/urandom", O_RDWR);
- if (urandom_fd == -1) {
- perror("error opening /dev/urandom");
- exit(1);
- }
- if (ioctl(urandom_fd, RNDADDENTROPY, &rpi) == -1) {
- perror("error adding entropy");
- exit(1);
- }
- if (close(urandom_fd) == -1) {
- perror("error closing /dev/urandom");
- exit(1);
- }
-
- return 0;
-}