Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

39 righe
644 B

  1. /*
  2. This code was taken from the SPHINCS reference implementation and is public domain.
  3. */
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8. /* it's really stupid that there isn't a syscall for this */
  9. static int fd = -1;
  10. void randombytes(unsigned char *x,unsigned long long xlen)
  11. {
  12. int i;
  13. if (fd == -1) {
  14. for (;;) {
  15. fd = open("/dev/urandom",O_RDONLY);
  16. if (fd != -1) break;
  17. sleep(1);
  18. }
  19. }
  20. while (xlen > 0) {
  21. if (xlen < 1048576) i = xlen; else i = 1048576;
  22. i = read(fd,x,i);
  23. if (i < 1) {
  24. sleep(1);
  25. continue;
  26. }
  27. x += i;
  28. xlen -= i;
  29. }
  30. }