Skip to content

Commit b524ff6

Browse files
authored
chore: patch random functions in openssl to use arc4random_buf when compiled to wasi (#460)
1 parent 1962289 commit b524ff6

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

c-dependencies/js-compute-runtime/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ wasi_snapshot_preview1.reactor.wasm:
176176
openssl: $(BUILD)/openssl/token
177177

178178
# Extract and prepare the openssl build directory.
179-
$(BUILD)/openssl-$(OPENSSL_VERSION)/token: $(BUILD)/openssl-$(OPENSSL_VERSION).tar.gz $(FSM_SRC)/third_party/getuid.patch
179+
$(BUILD)/openssl-$(OPENSSL_VERSION)/token: $(BUILD)/openssl-$(OPENSSL_VERSION).tar.gz $(FSM_SRC)/third_party/getuid.patch $(FSM_SRC)/third_party/rand.patch
180180
$Q tar -C $(BUILD) -xf $<
181181
$Q patch -d $(BUILD)/openssl-$(OPENSSL_VERSION) -p1 < $(FSM_SRC)/third_party/getuid.patch
182+
$Q patch -d $(BUILD)/openssl-$(OPENSSL_VERSION) -p1 < $(FSM_SRC)/third_party/rand.patch
182183
$Q touch $@
183184

184185
OPENSSL_OPTS := -static -no-sock -no-asm -no-ui-console -no-egd
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
diff --git openssl-3.0.7/crypto/rand/rand_lib.c openssl-3.0.7/crypto/rand/rand_lib.c
2+
--- a/crypto/rand/rand_lib.c
3+
+++ b/crypto/rand/rand_lib.c
4+
@@ -320,6 +320,10 @@ const RAND_METHOD *RAND_get_rand_method(void)
5+
int RAND_priv_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num,
6+
unsigned int strength)
7+
{
8+
+#ifdef __wasi__
9+
+ arc4random_buf(buf, num);
10+
+ return 1;
11+
+#endif
12+
EVP_RAND_CTX *rand;
13+
#if !defined(OPENSSL_NO_DEPRECATED_3_0) && !defined(FIPS_MODULE)
14+
const RAND_METHOD *meth = RAND_get_rand_method();
15+
@@ -349,6 +353,10 @@ int RAND_priv_bytes(unsigned char *buf, int num)
16+
int RAND_bytes_ex(OSSL_LIB_CTX *ctx, unsigned char *buf, size_t num,
17+
unsigned int strength)
18+
{
19+
+#ifdef __wasi__
20+
+ arc4random_buf(buf, num);
21+
+ return 1;
22+
+#endif
23+
EVP_RAND_CTX *rand;
24+
#if !defined(OPENSSL_NO_DEPRECATED_3_0) && !defined(FIPS_MODULE)
25+
const RAND_METHOD *meth = RAND_get_rand_method();

0 commit comments

Comments
 (0)