Skip to content

Commit 1feab84

Browse files
WASI: use getentropy to get randomized bytes (#323)
Resolves swiftwasm/swift#3320
1 parent 9ba6589 commit 1feab84

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/UUID/uuid.c

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ static inline void read_random(void *buffer, unsigned numBytes) {
8888
BCryptGenRandom(NULL, buffer, numBytes,
8989
BCRYPT_RNG_USE_ENTROPY_IN_BUFFER | BCRYPT_USE_SYSTEM_PREFERRED_RNG);
9090
}
91+
#elif TARGET_OS_WASI
92+
#include <sys/random.h>
93+
94+
static inline void read_random(void *buffer, unsigned numBytes) {
95+
getentropy(buffer, numBytes);
96+
}
9197
#else
9298
static inline void read_random(void *buffer, unsigned numBytes) {
9399
int fd = open("/dev/urandom", O_RDONLY);

0 commit comments

Comments
 (0)