5 ms·
For comparison, here‘s a sane interface: https://fuchsia.dev/fuchsia-src/reference/syscalls/cprng_draw.md https://fuchsia.dev/fuchsia-src/reference/syscalls/cpr
by xmmrm 7y ago
For comparison, here‘s a sane interface: https://fuchsia.dev/fuchsia-src/reference/syscalls/cprng_draw.md https://fuchsia.dev/fuchsia-src/reference/syscalls/cprng_dra...
- saagarjha 7y agoHow is this different from read(open("/dev/random", O_RDONLY), buffer, sizeof(buffer))?
- dchest 7y ago- It won't fail if there's no /dev/random device mounted (e.g. in chroot) - It won't fail if there are no file descriptors available - No error handling needed: the call always succeeds and random bytes are always returned
- ben_bai 7y agoSo like the standard arc4random_buf(3) which everybody has except for Linux. Don't worry the name is historic it does not us the arc4 cipher any longer, at least on OpenBSD. They switched to chacha20 as stream cipher.
- dchest 7y agoThe interface is the same, but arc4random_buf is a user-space CSPRNG. The analog of zx_cprng_draw is getentropy(2): http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2 http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/... except zx_cprng_draw kills the process, while getentropy returns an error.
- cyphar 7y agoLinux has had getrandom(2) for quite a few years, and there are glibc wrappers which use it.