diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-10-11 15:28:40 +0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-11-11 08:11:00 +0000 |
commit | af456842e13ab83cfeb44f3638b62652b201281c (patch) | |
tree | b745ec099e586804e0cbb28aa73333310f778e20 /src/corelib/global/qrandom_p.h | |
parent | 4502999ff054f16aab1fdd99fbd9256b22ecadf9 (diff) |
Change QRandomGenerator to have a deterministic mode
Now only QRandomGenerator::system() will access the system-wide RNG,
which we document to be cryptographically-safe and possibly backed by a
true HWRNG. Everything else just wraps a Mersenne Twister.
Change-Id: I0a103569c81b4711a649fffd14ec8cd3469425df
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/global/qrandom_p.h')
-rw-r--r-- | src/corelib/global/qrandom_p.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/corelib/global/qrandom_p.h b/src/corelib/global/qrandom_p.h index 525a73cce4..917a91098e 100644 --- a/src/corelib/global/qrandom_p.h +++ b/src/corelib/global/qrandom_p.h @@ -52,10 +52,12 @@ // #include "qglobal_p.h" +#include <private/qsimd_p.h> QT_BEGIN_NAMESPACE enum QRandomGeneratorControl { + UseSystemRNG = 1, SkipSystemRNG = 2, SkipHWRNG = 4, SetRandomData = 8, @@ -64,6 +66,11 @@ enum QRandomGeneratorControl { RandomDataMask = 0xfffffff0 }; +enum RNGType { + SystemRNG = 0, + MersenneTwister = 1 +}; + #if defined(QT_BUILD_INTERNAL) && defined(QT_BUILD_CORE_LIB) Q_CORE_EXPORT QBasicAtomicInteger<uint> qt_randomdevice_control = Q_BASIC_ATOMIC_INITIALIZER(0U); #elif defined(QT_BUILD_INTERNAL) @@ -72,6 +79,16 @@ extern Q_CORE_EXPORT QBasicAtomicInteger<uint> qt_randomdevice_control; enum { qt_randomdevice_control = 0 }; #endif +inline bool qt_has_hwrng() +{ +#if defined(Q_PROCESSOR_X86) && QT_COMPILER_SUPPORTS_HERE(RDRND) + return qCpuHasFeature(RDRND); +#else + return false; +#endif +} + + QT_END_NAMESPACE #endif // QRANDOM_P_H |