mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-17 03:12:22 -07:00
b155fdf8c9
This allows runtime detection as to if `rand_bytes` is supported or not, and lets us enable the test-case on all of the supported targets.
25 lines
417 B
Odin
25 lines
417 B
Odin
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:]
|
|
}
|
|
}
|
|
|
|
_has_rand_bytes :: proc () -> bool {
|
|
return true
|
|
}
|