From 6e74d4ee377a5f1933444cb28406f322b5fc0273 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Sat, 7 Aug 2021 00:39:27 -0700 Subject: [PATCH] WASI: use getentropy to get randomized bytes --- Sources/UUID/uuid.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Sources/UUID/uuid.c b/Sources/UUID/uuid.c index 8282995df2..5dc4aca97a 100644 --- a/Sources/UUID/uuid.c +++ b/Sources/UUID/uuid.c @@ -88,6 +88,12 @@ static inline void read_random(void *buffer, unsigned numBytes) { BCryptGenRandom(NULL, buffer, numBytes, BCRYPT_RNG_USE_ENTROPY_IN_BUFFER | BCRYPT_USE_SYSTEM_PREFERRED_RNG); } +#elif TARGET_OS_WASI +#include + +static inline void read_random(void *buffer, unsigned numBytes) { + getentropy(buffer, numBytes); +} #else static inline void read_random(void *buffer, unsigned numBytes) { int fd = open("/dev/urandom", O_RDONLY);