You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

19 line
352 B

  1. #include "rng.h"
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <fcntl.h>
  5. void randombytes(void *x, size_t l)
  6. {
  7. static int fd = -1;
  8. ssize_t n;
  9. if (fd < 0 && 0 > (fd = open("/dev/urandom", O_RDONLY)))
  10. exit(1);
  11. for (size_t i = 0; i < l; i += n)
  12. if (0 >= (n = read(fd, (char *) x + i, l - i)))
  13. exit(2);
  14. }