diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | src/krng-add-entropy.c | 49 |
3 files changed, 53 insertions, 1 deletions
@@ -40,3 +40,4 @@ rootfs/_build/ | |||
40 | stack.yaml.lock | 40 | stack.yaml.lock |
41 | samizdat.iso | 41 | samizdat.iso |
42 | TEST_CHILD.*.log | 42 | TEST_CHILD.*.log |
43 | krng-add-entropy | ||
@@ -1,6 +1,6 @@ | |||
1 | prefix?=/usr/local | 1 | prefix?=/usr/local |
2 | 2 | ||
3 | cc_files=wait_for_files samizdat-pinentry | 3 | cc_files=wait_for_files samizdat-pinentry krng-add-entropy |
4 | cpp_files=dynmenu | 4 | cpp_files=dynmenu |
5 | 5 | ||
6 | compiled_programs=${cc_files} ${cpp_files} | 6 | compiled_programs=${cc_files} ${cpp_files} |
@@ -28,6 +28,8 @@ dynmenu: src/dynmenu.cpp | build-deps | |||
28 | $(CXX) $(CFLAGS) $< -o $@ -lcurses | 28 | $(CXX) $(CFLAGS) $< -o $@ -lcurses |
29 | samizdat-pinentry: src/samizdat-pinentry.c | build-deps | 29 | samizdat-pinentry: src/samizdat-pinentry.c | build-deps |
30 | $(CC) $(CFLAGS) $< -o $@ -lcurses | 30 | $(CC) $(CFLAGS) $< -o $@ -lcurses |
31 | krng-add-entropy: src/krng-add-entropy.c | build-deps | ||
32 | $(CC) $(CFLAGS) $< -o $@ | ||
31 | wait_for_files: src/wait_for_files.c | build-deps | 33 | wait_for_files: src/wait_for_files.c | build-deps |
32 | $(CC) $(CFLAGS) $< -o $@ | 34 | $(CC) $(CFLAGS) $< -o $@ |
33 | 35 | ||
diff --git a/src/krng-add-entropy.c b/src/krng-add-entropy.c new file mode 100644 index 0000000..fc81d29 --- /dev/null +++ b/src/krng-add-entropy.c | |||
@@ -0,0 +1,49 @@ | |||
1 | #include <sys/types.h> | ||
2 | #include <sys/stat.h> | ||
3 | #include <fcntl.h> | ||
4 | #include <sys/ioctl.h> | ||
5 | #include <stdio.h> | ||
6 | #include <stdlib.h> | ||
7 | #include <asm/types.h> | ||
8 | #include <linux/random.h> | ||
9 | #include <errno.h> | ||
10 | #include <error.h> | ||
11 | #include <string.h> | ||
12 | |||
13 | char *program_name; | ||
14 | void usage() | ||
15 | { | ||
16 | error(1, 0, "usage: %s [--bytes] <bits>", program_name); | ||
17 | } | ||
18 | |||
19 | int main(int argc, char **argv) | ||
20 | { | ||
21 | argc--, program_name = *argv++; | ||
22 | int multiplier = 1; | ||
23 | int bits; | ||
24 | while (argc > 1) { | ||
25 | if (!strcmp(*argv, "--bytes")) { | ||
26 | multiplier = 8; | ||
27 | } else { | ||
28 | usage(); | ||
29 | } | ||
30 | argc--, argv++; | ||
31 | } | ||
32 | if ((argc != 1) || (bits = multiplier * atoi(*argv)) <= 0) | ||
33 | usage(); | ||
34 | |||
35 | struct rand_pool_info *output; | ||
36 | int fd = open("/dev/random", O_WRONLY); | ||
37 | if (fd < 0) | ||
38 | error(1, errno, "opening /dev/random"); | ||
39 | |||
40 | output = (struct rand_pool_info *) malloc(sizeof(struct rand_pool_info)); | ||
41 | output -> entropy_count = bits; | ||
42 | output -> buf_size = 0; | ||
43 | |||
44 | int r = ioctl(fd, RNDADDENTROPY, output); | ||
45 | if (r < 0) | ||
46 | error(1, errno, "ioctl(RNDADDENTROPY)"); | ||
47 | |||
48 | return 0; | ||
49 | } | ||