From 120ecc976fc3d5504d234702f68c2ad3898b77a4 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 16 Jun 2017 21:39:04 -0700 Subject: QRandomGenerator: use getentropy on Linux & OpenBSD The getentropy function, first found in OpenBSD, is present in glibc since version 2.25 and Bionic since Android 6.0 and NDK r11. It uses the Linux 3.17 getrandom system call. Unlike glibc's getrandom() wrapper, the glibc implementation of getentropy() function is not a POSIX thread cancellation point, so we prefer to use that even though we have to break the reading into 256-byte blocks. The big advantage is that these functions work even in the absence of a /dev/urandom device node, in addition to a few cycles shaved off by not having to open a file descriptor and close it at exit. What's more, the glibc implementation blocks until entropy is available on early boot, so we don't have to worry about a failure mode. The Bionic implementation will fall back by itself to /dev/urandom and, failing that, gathering entropy from elsewhere in the system in a way it cannot fail either. uClibc has a wrapper to getrandom(2) but no getentropy(3). MUSL has neither. Change-Id: Ia53158e207a94bf49489fffd14c8cee1b968a619 Reviewed-by: Lars Knoll --- src/corelib/configure.json | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/corelib/configure.json') diff --git a/src/corelib/configure.json b/src/corelib/configure.json index 0da3bff713..5e2cb025d3 100644 --- a/src/corelib/configure.json +++ b/src/corelib/configure.json @@ -163,6 +163,11 @@ "type": "compile", "test": "unix/futimesat" }, + "getentropy": { + "label": "getentropy()", + "type": "compile", + "test": "unix/getentropy" + }, "posix-iconv": { "label": "POSIX iconv", "type": "compile", @@ -277,6 +282,11 @@ "condition": "!config.win32 && !features.futimens && !features.futimes && tests.futimesat", "output": [ "privateFeature" ] }, + "getentropy": { + "label": "getentropy()", + "condition": "config.unix && tests.getentropy", + "output": [ "privateFeature" ] + }, "glib": { "label": "GLib", "autoDetect": "!config.win32", -- cgit v1.2.3