-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentropy_gen.c
More file actions
57 lines (43 loc) · 873 Bytes
/
entropy_gen.c
File metadata and controls
57 lines (43 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/random.h>
#define N 1024
int main()
{
struct {
int ent_count;
int size;
unsigned char data[N];
} entropy;
int src, dst;
FILE *source;
if ( (dst = open("/dev/random", O_WRONLY)) < 0) {
perror("random" );
exit(1);
}
if ( (src=open("/dev/urandom", O_RDONLY )) < 0 ) {
perror("urandom");
exit(1);
}
for ( ; ; ) {
char buf[N];
if ( N != read( src, entropy.data, N ) ) {
perror("read");
exit(1);
}
entropy.ent_count = entropy.size = N;
if ( ioctl(dst, RNDADDENTROPY, &entropy) < 0 ) {
perror("ioctl");
exit(1);
}
sleep( 1 );
}
exit( 0 );
}