/* ISC license. */ #include #ifdef SKALIBS_HASARC4RANDOM #include #include void random_string (char *s, unsigned int n) { arc4random_buf(s, n) ; } #else #ifdef SKALIBS_HASGETRANDOM #include #include #include #include static int getrandom (void *buf, size_t buflen, unsigned int flags) { return syscall(SYS_getrandom, buf, buflen, flags) ; } void random_string (char *s, unsigned int n) { while (n) { register int r = getrandom(s, n, 0) ; if (r >= 0) { s += r ; n -= r ; } } } #else #ifdef SKALIBS_HASDEVURANDOM #include #include #include "random-internal.h" void random_string (char *s, unsigned int n) { unsigned int r = allread(random_fd, s, n) ; if (r < n) surf(&surf_here, s+r, n-r) ; } #else /* default */ #include #include "random-internal.h" void random_string (char *s, unsigned int n) { surf(&surf_here, s, n) ; } #endif #endif #endif