fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #72883 - Mark-Simulacrum:stable-next, r=Mark-Simulacrum49cae55760d

1.44.0
569 B33 linesraw
1#include <assert.h>
2#include <stdint.h>
3#include <sys/ioctl.h>
4#include <stdio.h>
5#include <unistd.h>
6#include <fcntl.h>
7#include <linux/random.h>
8
9#define N 2048
10
11struct entropy {
12  int ent_count;
13  int size;
14  unsigned char data[N];
15};
16
17int main() {
18  struct entropy buf;
19  ssize_t n;
20
21  int random_fd = open("/dev/random", O_RDWR);
22  assert(random_fd >= 0);
23
24  while ((n = read(0, &buf.data, N)) > 0) {
25    buf.ent_count = n * 8;
26    buf.size = n;
27    if (ioctl(random_fd, RNDADDENTROPY, &buf) != 0) {
28      perror("failed to add entropy");
29    }
30  }
31
32  return 0;
33}