diff options
author | Jaremy Creechley <creechley@gmail.com> | 2021-11-14 03:49:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-14 12:49:30 +0100 |
commit | 6976d18519d102c9cc857a84a4b10b009c1e1a38 (patch) | |
tree | 83dc40e9c9809ffe39fa70a7b3247b31c27c2158 /lib/std/sysrand.nim | |
parent | bec490016548e73f01317736ff8863f9ce6aab31 (diff) | |
download | Nim-6976d18519d102c9cc857a84a4b10b009c1e1a38.tar.gz |
Implement zephyr urandom and monotime (#19142)
* implement urandom for Zephyr * add monotime on zephyr Co-authored-by: Jaremy Creechley <jaremy.creechley@panthalassa.com>
Diffstat (limited to 'lib/std/sysrand.nim')
-rw-r--r-- | lib/std/sysrand.nim | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/std/sysrand.nim b/lib/std/sysrand.nim index 6b354e5a3..1b7b2c024 100644 --- a/lib/std/sysrand.nim +++ b/lib/std/sysrand.nim @@ -63,7 +63,7 @@ when defined(posix): import posix const - batchImplOS = defined(freebsd) or defined(openbsd) or (defined(macosx) and not defined(ios)) + batchImplOS = defined(freebsd) or defined(openbsd) or defined(zephyr) or (defined(macosx) and not defined(ios)) batchSize {.used.} = 256 when batchImplOS: @@ -207,6 +207,16 @@ elif defined(openbsd): proc getRandomImpl(p: pointer, size: int): int {.inline.} = result = getentropy(p, cint(size)).int +elif defined(zephyr): + proc sys_csrand_get(dst: pointer, length: csize_t): cint {.importc: "sys_csrand_get", header: "<random/rand32.h>".} + # Fill the destination buffer with cryptographically secure + # random data values + # + + proc getRandomImpl(p: pointer, size: int): int {.inline.} = + # 0 if success, -EIO if entropy reseed error + result = sys_csrand_get(p, csize_t(size)).int + elif defined(freebsd): type cssize_t {.importc: "ssize_t", header: "<sys/types.h>".} = int |