]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Allow `getentropy` for Emscripten
authorSteven WdV <swdv@cs.ru.nl>
Tue, 7 Jul 2026 12:52:30 +0000 (14:52 +0200)
committerTomas Mraz <tomas@openssl.foundation>
Wed, 8 Jul 2026 17:50:54 +0000 (19:50 +0200)
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)

providers/implementations/rands/seeding/rand_unix.c

index 1af996b25fefe84f3323c0bedc8e3a6a6243b9ae..95742eb8482c48d0ead51fdafc261324f2446811 100644 (file)
@@ -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;