diff --git a/src/random.h b/src/random.h index 1667038..53ed51b 100644 --- a/src/random.h +++ b/src/random.h @@ -42,6 +42,26 @@ static int fill_random(unsigned char* data, size_t size) { } else { return 1; } +#elif defined(__ANDROID__) + int fd = open("/dev/urandom", O_RDONLY); + if (fd < 0) { + return 0; // Failed to open /dev/urandom + } + ssize_t read_bytes = 0; + while (size > 0) { + read_bytes = read(fd, data, size); + if (read_bytes <= 0) { + if (errno == EINTR) { + continue; // If interrupted by signal, try again + } + close(fd); + return 0; // Failed to read + } + data += read_bytes; + size -= read_bytes; + } + close(fd); + return 1; #elif defined(__linux__) || defined(__FreeBSD__) /* If `getrandom(2)` is not available you should fallback to /dev/urandom */ ssize_t res = getrandom(data, size, 0);