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>
bb10
Thiago Macieira 2017-06-06 17:38:06 -07:00
parent 0c355e78f0
commit ec63fcb314
1 changed files with 7 additions and 0 deletions

View File

@ -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)