emscripten doesnt have arc4random but wasi does?

This commit is contained in:
lizzie 2026-06-08 23:33:26 +00:00
parent 4b3b735486
commit 7bf1ed8ce6

View file

@ -30,16 +30,18 @@ index e62721e..6fcea0d 100644
"uClinux-dist" => { "uClinux-dist" => {
inherit_from => [ "BASE_unix" ], inherit_from => [ "BASE_unix" ],
diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c
index d9e8f02..0bd63b0 100644 index d9e8f02..7faf347 100644
--- a/crypto/rand/rand_lib.c --- a/crypto/rand/rand_lib.c
+++ b/crypto/rand/rand_lib.c +++ b/crypto/rand/rand_lib.c
@@ -379,17 +379,25 @@ void RAND_add(const void *buf, int num, double randomness) @@ -379,17 +379,27 @@ void RAND_add(const void *buf, int num, double randomness)
#if !defined(OPENSSL_NO_DEPRECATED_1_1_0) #if !defined(OPENSSL_NO_DEPRECATED_1_1_0)
int RAND_pseudo_bytes(unsigned char *buf, int num) int RAND_pseudo_bytes(unsigned char *buf, int num)
{ {
+#ifdef __EMSCRIPTEN__ +#if defined(__wasi__)
+ arc4random_buf(buf, num); + arc4random_buf(buf, num);
+ return 1; + return 1;
+#elif defined(__EMSCRIPTEN__)
+ return 1;
+#else +#else
const RAND_METHOD *meth = RAND_get_rand_method(); const RAND_METHOD *meth = RAND_get_rand_method();
@ -53,13 +55,13 @@ index d9e8f02..0bd63b0 100644
int RAND_status(void) int RAND_status(void)
{ {
+#ifdef __EMSCRIPTEN__ +#if defined(__EMSCRIPTEN__) || defined(__wasi__)
+ return 1; + return 1;
+#else +#else
EVP_RAND_CTX *rand; EVP_RAND_CTX *rand;
#ifndef OPENSSL_NO_DEPRECATED_3_0 #ifndef OPENSSL_NO_DEPRECATED_3_0
const RAND_METHOD *meth = RAND_get_rand_method(); const RAND_METHOD *meth = RAND_get_rand_method();
@@ -401,6 +409,7 @@ int RAND_status(void) @@ -401,6 +411,7 @@ int RAND_status(void)
if ((rand = RAND_get0_primary(NULL)) == NULL) if ((rand = RAND_get0_primary(NULL)) == NULL)
return 0; return 0;
return EVP_RAND_get_state(rand) == EVP_RAND_STATE_READY; return EVP_RAND_get_state(rand) == EVP_RAND_STATE_READY;
@ -67,18 +69,20 @@ index d9e8f02..0bd63b0 100644
} }
#else /* !FIPS_MODULE */ #else /* !FIPS_MODULE */
@@ -420,6 +429,10 @@ const RAND_METHOD *RAND_get_rand_method(void) @@ -420,6 +431,12 @@ const RAND_METHOD *RAND_get_rand_method(void)
int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num,
unsigned int strength) unsigned int strength)
{ {
+#ifdef __EMSCRIPTEN__ +#if defined(__wasi__)
+ arc4random_buf(buf, num); + arc4random_buf(buf, num);
+ return 1; + return 1;
+#elif defined(__EMSCRIPTEN__)
+ return 1;
+#else +#else
RAND_GLOBAL *dgbl; RAND_GLOBAL *dgbl;
EVP_RAND_CTX *rand; EVP_RAND_CTX *rand;
#if !defined(OPENSSL_NO_DEPRECATED_3_0) && !defined(FIPS_MODULE) #if !defined(OPENSSL_NO_DEPRECATED_3_0) && !defined(FIPS_MODULE)
@@ -451,6 +464,7 @@ int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num, @@ -451,6 +468,7 @@ int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num,
return EVP_RAND_generate(rand, buf, num, strength, 0, NULL, 0); return EVP_RAND_generate(rand, buf, num, strength, 0, NULL, 0);
return 0; return 0;