diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2023-10-31 12:16:25 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-31 12:16:25 +0000 |
| commit | eb261f5b28a8d3cddc3dc21441f33775bb3ced95 (patch) | |
| tree | 55014f5e1ffe0c099376699945a1800cc4d16246 /core/crypto | |
| parent | bbd4c1054e18f18e934828b5160efce076027d1e (diff) | |
| parent | f5febb633c92ee1cf7b5d88f0146ffac3e2481b7 (diff) | |
Merge branch 'master' into new-sys-unix
Diffstat (limited to 'core/crypto')
| -rw-r--r-- | core/crypto/rand_generic.odin | 4 | ||||
| -rw-r--r-- | core/crypto/rand_js.odin | 20 |
2 files changed, 22 insertions, 2 deletions
diff --git a/core/crypto/rand_generic.odin b/core/crypto/rand_generic.odin index 52abfe4d7..fde91f85a 100644 --- a/core/crypto/rand_generic.odin +++ b/core/crypto/rand_generic.odin @@ -1,7 +1,7 @@ package crypto -when ODIN_OS != .Linux && ODIN_OS != .OpenBSD && ODIN_OS != .Windows { - _rand_bytes :: proc (dst: []byte) { +when ODIN_OS != .Linux && ODIN_OS != .OpenBSD && ODIN_OS != .Windows && ODIN_OS != .JS { + _rand_bytes :: proc(dst: []byte) { unimplemented("crypto: rand_bytes not supported on this OS") } } diff --git a/core/crypto/rand_js.odin b/core/crypto/rand_js.odin new file mode 100644 index 000000000..353b1e6b9 --- /dev/null +++ b/core/crypto/rand_js.odin @@ -0,0 +1,20 @@ +package crypto + +foreign import "odin_env" +foreign odin_env { + @(link_name = "rand_bytes") + env_rand_bytes :: proc "contextless" (buf: []byte) --- +} + +_MAX_PER_CALL_BYTES :: 65536 // 64kiB + +_rand_bytes :: proc(dst: []byte) { + dst := dst + + for len(dst) > 0 { + to_read := min(len(dst), _MAX_PER_CALL_BYTES) + env_rand_bytes(dst[:to_read]) + + dst = dst[to_read:] + } +} |