mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-27 22:40:00 +00:00
Added missing file.
This commit is contained in:
parent
ba6354e758
commit
6e5ef709e3
36
randombytes.c
Normal file
36
randombytes.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/* it's really stupid that there isn't a syscall for this */
|
||||||
|
|
||||||
|
static int fd = -1;
|
||||||
|
|
||||||
|
void randombytes(unsigned char *x,unsigned long long xlen)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (fd == -1) {
|
||||||
|
for (;;) {
|
||||||
|
fd = open("/dev/urandom",O_RDONLY);
|
||||||
|
if (fd != -1) break;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (xlen > 0) {
|
||||||
|
if (xlen < 1048576) i = xlen; else i = 1048576;
|
||||||
|
|
||||||
|
i = read(fd,x,i);
|
||||||
|
if (i < 1) {
|
||||||
|
sleep(1);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
x += i;
|
||||||
|
xlen -= i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user