diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-06-06 17:38:06 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-06-12 06:14:53 +0000 |
commit | ec63fcb314c7f83d9504297c69483f944d5ee29b (patch) | |
tree | 3f0d9a2ea17f1bec8f887a1084cc8d9890cb7d84 /src/corelib/global/qrandom.cpp | |
parent | 0c355e78f0cf51d4ad6cfb2eb0f289979cba843a (diff) |
QRandomGenerator: use arc4random as fallback on BSDs (including Darwin)
This function works even in chroots where /dev is not available. Since
it's part of the OS, it may have better ways of gathering entropy even
when we don't.
Change-Id: Ia3e896da908f42939148fffd14c5afedc8569dbc
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/global/qrandom.cpp')
-rw-r--r-- | src/corelib/global/qrandom.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/global/qrandom.cpp b/src/corelib/global/qrandom.cpp index 954e879887..5c2548184b 100644 --- a/src/corelib/global/qrandom.cpp +++ b/src/corelib/global/qrandom.cpp @@ -200,6 +200,13 @@ static void fallback_fill(quint32 *ptr, qssize_t left) Q_DECL_NOTHROW return value; }); } +#elif defined(Q_OS_BSD4) +static void fallback_update_seed(unsigned) {} +static void fallback_fill(quint32 *ptr, qssize_t left) Q_DECL_NOTHROW +{ + // BSDs have arc4random(4) and these work even in chroot(2) + arc4random_buf(ptr, left * sizeof(*ptr)); +} #elif QT_HAS_INCLUDE(<chrono>) static QBasicAtomicInteger<unsigned> seed = Q_BASIC_ATOMIC_INITIALIZER(0U); static void fallback_update_seed(unsigned value) |