From: Steven WdV Date: Tue, 7 Jul 2026 12:52:30 +0000 (+0200) Subject: Allow `getentropy` for Emscripten X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=4e2e6f4174bb4098727314afea8e8decb80c0d92;p=thirdparty%2Fopenssl.git Allow `getentropy` for Emscripten Usually Emscripten emulates `/dev/urandom`, but in some cases, like with `-sNODERAWFS`, it doesn't. This means that on non-Unix platforms, where `/dev/urandom` does not exist on the host, OpenSSL will fail to seed its PRNG. This fixes that by instead using the POSIX function it implements, like which was already done for WASI. See https://github.com/emscripten-core/emscripten/issues/9628#issuecomment-4892658766 for more context. CLA: trivial Reviewed-by: Kurt Roeckx Reviewed-by: Daniel Kubec Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz MergeDate: Wed Jul 8 17:50:39 2026 (Merged from https://github.com/openssl/openssl/pull/31882) (cherry picked from commit dc219a04088d08de7df5afdb14263b3e9a4c7915) --- diff --git a/providers/implementations/rands/seeding/rand_unix.c b/providers/implementations/rands/seeding/rand_unix.c index 1af996b25fe..95742eb8482 100644 --- a/providers/implementations/rands/seeding/rand_unix.c +++ b/providers/implementations/rands/seeding/rand_unix.c @@ -396,7 +396,7 @@ static ssize_t syscall_random(void *buf, size_t buflen) return getrandom(buf, buflen, 0); #elif (defined(__FreeBSD__) || defined(__NetBSD__)) && defined(KERN_ARND) return sysctl_random(buf, buflen); -#elif defined(__wasi__) +#elif defined(__wasi__) || defined(__EMSCRIPTEN__) if (getentropy(buf, buflen) == 0) return (ssize_t)buflen; return -1;