| 1 | #include "kernelrandombytes.h" |
| 2 | #include <unistd.h> |
| 3 | #include <sys/random.h> |
| 4 | |
| 5 | void kernelrandombytes(unsigned char *x,unsigned long long xlen) |
| 6 | { |
| 7 | int i; |
| 8 | |
| 9 | while (xlen > 0) { |
| 10 | if (xlen < 1048576) i = xlen; else i = 1048576; |
| 11 | |
| 12 | i = getrandom(x,i,0); |
| 13 | if (i < 1) { |
| 14 | sleep(1); |
| 15 | continue; |
| 16 | } |
| 17 | |
| 18 | x += i; |
| 19 | xlen -= i; |
| 20 | } |
| 21 | } |