aboutsummaryrefslogtreecommitdiff
path: root/core/crypto/rand_js.odin
blob: 353b1e6b90701f928d82bd2579d1d406428daa12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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:]
	}
}