diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2017-04-13 13:19:32 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2017-06-12 06:14:46 +0000 |
commit | f17095653ed54c7c253ade6ff639cae6a372cb08 (patch) | |
tree | 6147e6f03d025b41a7a6fa36b68eca999319067a /src/corelib/tools/qhash.cpp | |
parent | 5483b30868e44bc0799d7a1998f1907775f50fec (diff) |
QUuid, QHttpMultipart and QHash: use QRandomGenerator
QRandomGenerator can produce more than 31 bits of data. And it uses
/dev/urandom for us on Unix, so QHash does not need to duplicate that
part.
Change-Id: Icd0e0d4b27cb4e5eb892fffd14b52a0d91f179eb
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/corelib/tools/qhash.cpp')
-rw-r--r-- | src/corelib/tools/qhash.cpp | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 59aab32347..9d8c276cff 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -63,13 +63,9 @@ #ifndef QT_BOOTSTRAPPED #include <qcoreapplication.h> +#include <qrandom.h> #endif // QT_BOOTSTRAPPED -#ifdef Q_OS_UNIX -#include <stdio.h> -#include "private/qcore_unix_p.h" -#endif // Q_OS_UNIX - #include <limits.h> QT_BEGIN_NAMESPACE @@ -298,39 +294,7 @@ static uint qt_create_qhash_seed() return seed; } -#ifdef Q_OS_UNIX - int randomfd = qt_safe_open("/dev/urandom", O_RDONLY); - if (randomfd == -1) - randomfd = qt_safe_open("/dev/random", O_RDONLY | O_NONBLOCK); - if (randomfd != -1) { - if (qt_safe_read(randomfd, reinterpret_cast<char *>(&seed), sizeof(seed)) == sizeof(seed)) { - qt_safe_close(randomfd); - return seed; - } - qt_safe_close(randomfd); - } -#endif // Q_OS_UNIX - -#if defined(Q_OS_WIN32) && !defined(Q_CC_GNU) - errno_t err; - err = rand_s(&seed); - if (err == 0) - return seed; -#endif // Q_OS_WIN32 - - // general fallback: initialize from the current timestamp, pid, - // and address of a stack-local variable - quint64 timestamp = QDateTime::currentMSecsSinceEpoch(); - seed ^= timestamp; - seed ^= (timestamp >> 32); - - quint64 pid = QCoreApplication::applicationPid(); - seed ^= pid; - seed ^= (pid >> 32); - - quintptr seedPtr = reinterpret_cast<quintptr>(&seed); - seed ^= seedPtr; - seed ^= (qulonglong(seedPtr) >> 32); // no-op on 32-bit platforms + seed = QRandomGenerator::get32(); #endif // QT_BOOTSTRAPPED return seed; |