randombytes
randombytes copied to clipboard
Avoid getrandom or syscall(SYS_getrandom) in Android __ANDROID_API__ < 28
Android Os older than Android 9.0 (API_LEVEL = 28) broken syscall(SYS_getrandom).
Please, avoid it when building with NDK. Add something like
....
#elif defined(__linux__) || defined(__GNU__) || defined(GNU_KFREEBSD)
//---------- ADD THESE CODE --------------
#if defined(SYS_getrandom) && ((!defined(__ANDROID__) || __ANDROID_API__ >= 28)
// use getrandom
return randombytes_linux_randombytes_getrandom(buf, n);
#else
// use /dev/urandom
return randombytes_linux_randombytes_urandom(buf, n);
#endif
//---------------------------------------
#elif defined(BSD) ....
For details see https://github.com/briansmith/ring/issues/852
I feel like in this case, because of the inability to determine which version of linux the Android system will run on, should we (like ring) always fall back to /dev/urandom/
if getrandom
fails? Cc @thomwiggers
Android versions < SDK API level 30 are no longer allowed for submission to the Google Play store, so this seems like an update that would not help very many people.
Relatedly, it seems that all supported Linux kernels have getrandom
; of course, there might be some redhat box kicking around though.