| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <errno.h> |
| 4 |
#include <unistd.h> |
| 5 |
#include <sys/types.h> |
| 6 |
#include <sys/stat.h> |
| 7 |
#include <sys/ioctl.h> |
| 8 |
#include <fcntl.h> |
| 9 |
|
| 10 |
#include <linux/random.h> |
| 11 |
|
| 12 |
|
| 13 |
int main(int argc, char **argv) |
| 14 |
{ |
| 15 |
int count, fd; |
| 16 |
|
| 17 |
if (argc != 2) { |
| 18 |
printf("Usage: rndaddtoentcnt <entropy-bit-count>\n"); |
| 19 |
exit(1); |
| 20 |
} |
| 21 |
|
| 22 |
count = strtoul(argv[1], NULL, 0); |
| 23 |
|
| 24 |
if (count < 1 || count > 4096) { |
| 25 |
printf("Count range is 1 to 4096\n"); |
| 26 |
exit(1); |
| 27 |
} |
| 28 |
|
| 29 |
fd = open("/dev/urandom", O_WRONLY); |
| 30 |
|
| 31 |
if (fd < 0) { |
| 32 |
perror("open(/dev/urandom)"); |
| 33 |
exit(1); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
if (ioctl(fd, RNDADDTOENTCNT, &count) < 0) { |
| 38 |
perror("ioctl(RNDADDTOENTCNT)"); |
| 39 |
close(fd); |
| 40 |
exit(1); |
| 41 |
} |
| 42 |
|
| 43 |
close(fd); |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |