Closed dsprenkels closed 6 years ago
Libsodium does not seem to actually check the entropy level of the pool. Instead, they block on /dev/random
once and assume that after the kernel passes back control, the pool is sufficiently filled.
I am personally not sure about the entropy levels in this case (did not find any documentation), so to me it seems that we have two options:
RNDGETENTCNT
, which reads from /proc/sys/kernel/random/entropy_avail
.RNDGETENTCNT
at all, but only read from /proc/sys/kernel/random/entropy_avail
./dev/random
once (using a global value to make sure we don't block again)./dev/random
on every call to randombytes
.~I would personally opt for 1., with a fallback that if /proc/sys/kernel/random/entropy_avail
cannot be read, we will block on /dev/random
(every time).~ This will not fix the include error. Linux header files are still needed in this case as build dependency. Also, including linux headers directly seems to be frowned upon.
You may not like what you see :^) but this is how I solved it (for now?) https://github.com/DECODEproject/zenroom/blob/develop/src/randombytes.c this builds correctly on all zenroom targets (musl,osx,win,arm-gcc,arm-musl,emscripten)
Yeah, bypassing the entropy check is not an option. :P
RNDGETENTCNT
inline.my favorites are 1. and 2. - thanks for taking care of details :^)
Is fixed by #12. Used option 5.
@jaromil gets compilation errors when compiling with the musl libc:
Note that compilation also fails on
getrandom
, becauselinux/random.h
cannot be found (header file redundant, because ofsys/syscall.h
?).Musl does not seem to be able to import linux symbols (because of portability issues). They say they will support
getrandom()
(notSYS_getrandom
) here: http://www.openwall.com/lists/musl/2017/09/28/8. But in my case musl (1.1.19-1
) hasn't yet added support.In these cases we should indeed fall back to using
/dev/urandom
. ButRNDGETENTCNT
is (probably) glib-specific. I hesitate to skip the entropy test. Maybe see what libsodium does here.[ ]
getrandom
syscall fix[ ]
/dev/urandom
fix