Commit 4e2e6f4174 for openssl.org
commit 4e2e6f4174bb4098727314afea8e8decb80c0d92
Author: Steven WdV <swdv@cs.ru.nl>
Date: Tue Jul 7 14:52:30 2026 +0200
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 <kurt@roeckx.be>
Reviewed-by: Daniel Kubec <kubec@openssl.foundation>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Tomas Mraz <tomas@openssl.foundation>
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 1af996b25f..95742eb848 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;