diff --git a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c index a84c107a..dbd89716 100644 --- a/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c +++ b/src/libsodium/randombytes/salsa20/randombytes_salsa20_random.c @@ -6,7 +6,11 @@ # include #endif #ifdef __linux__ +#ifdef __dietlibc__ +#define _LINUX_SOURCE +#else # include +#endif # include #endif @@ -207,7 +211,7 @@ randombytes_salsa20_random_random_dev_open(void) } # endif -# if defined(SYS_getrandom) && defined(__NR_getrandom) +# if defined(__dietlibc__) || (defined(SYS_getrandom) && defined(__NR_getrandom)) static int _randombytes_linux_getrandom(void * const buf, const size_t size) { @@ -215,7 +219,11 @@ _randombytes_linux_getrandom(void * const buf, const size_t size) assert(size <= 256U); do { +#ifdef __dietlibc__ + readnb = getrandom(buf, size, 0); +#else readnb = syscall(SYS_getrandom, buf, (int) size, 0); +#endif } while (readnb < 0 && (errno == EINTR || errno == EAGAIN)); return (readnb == (int) size) - 1; diff --git a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c index 83c8a39f..e7c902c8 100644 --- a/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c +++ b/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c @@ -6,7 +6,11 @@ # include #endif #ifdef __linux__ +#ifdef __dietlibc__ +#define _LINUX_SOURCE +#else # include +#endif # include #endif @@ -189,7 +193,7 @@ randombytes_sysrandom_random_dev_open(void) /* LCOV_EXCL_STOP */ } -# if defined(SYS_getrandom) && defined(__NR_getrandom) +# if defined(__dietlibc__) || (defined(SYS_getrandom) && defined(__NR_getrandom)) static int _randombytes_linux_getrandom(void * const buf, const size_t size) { @@ -197,7 +201,11 @@ _randombytes_linux_getrandom(void * const buf, const size_t size) assert(size <= 256U); do { +#ifdef __dietlibc__ + readnb = getrandom( buf, size, 0); +#else readnb = syscall(SYS_getrandom, buf, (int) size, 0); +#endif } while (readnb < 0 && (errno == EINTR || errno == EAGAIN)); return (readnb == (int) size) - 1;