File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change 1313# include <wincrypt.h> /* CryptAcquireContext, CryptGenRandom */
1414#endif /* defined(_WIN32) */
1515
16+ /* wasi */
17+ #if defined(__wasi__ )
18+ #include <stdlib.h>
19+ #endif
1620
1721#if defined(__linux__ )
1822/* Linux */
@@ -78,6 +82,12 @@ static int randombytes_win32_randombytes(void* buf, const size_t n)
7882}
7983#endif /* defined(_WIN32) */
8084
85+ #if defined(__wasi__ )
86+ static int randombytes_wasi_randombytes (void * buf , size_t n ) {
87+ arc4random_buf (buf , n );
88+ return 0 ;
89+ }
90+ #endif /* defined(__wasi__) */
8191
8292#if defined(__linux__ ) && defined(SYS_getrandom )
8393static int randombytes_linux_randombytes_getrandom (void * buf , size_t n )
@@ -302,6 +312,10 @@ int randombytes(void *buf, size_t n)
302312# pragma message("Using Windows cryptographic API")
303313 /* Use windows API */
304314 return randombytes_win32_randombytes (buf , n );
315+ #elif defined(__wasi__ )
316+ # pragma message("Using WASI arc4random_buf system call")
317+ /* Use WASI */
318+ return randombytes_wasi_randombytes (buf , n );
305319#else
306320# error "randombytes(...) is not supported on this platform"
307321#endif
You can’t perform that action at this time.
0 commit comments