Created
May 4, 2021 13:09
-
-
Save szaydel/06c7a8c1c0cd1fc228ad88fea3f6eaca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/ioctl.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <linux/random.h> | |
#define BUFSIZE 256 | |
typedef struct { | |
int entropy_count; | |
int buf_size; | |
unsigned int buf[0]; | |
} entropy_t; | |
int main(void) { | |
entropy_t *en = malloc(sizeof(*en) + sizeof(unsigned int[BUFSIZE])); | |
// for (int i = 0 ; i < BUFSIZE; i++) { | |
// en->buf[i] = i; | |
// } | |
// for (int i = 0 ; i < BUFSIZE; i++) { | |
// printf("(%d) => %d\n", i, en->buf[i]); | |
// } | |
// printf("sizeof(*en): %zu\n", sizeof(*en)); | |
// printf("sizeof(en): %zu\n", sizeof(en)); | |
// printf("sizeof(unsigned int[%d]): %zu\n", BUFSIZE, sizeof(unsigned int[BUFSIZE])); | |
int fd = open("/dev/random", O_WRONLY); | |
int rc = ioctl(fd, RNDADDENTROPY, en); | |
if (rc != 0) { | |
perror("ioctl()"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment