summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qrandom.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Replace usage of Q_DECL_ALIGN with C++11 alignas keywordVolker Hilsheimer2019-10-291-2/+2
| | | | | | | | | | | | | The macro is not documented, so can be considered private API. Pre-C++11 compilers that don't support alignas will no longer be supported with Qt 6. The macro definition for the standard case of compilers supporting the alignof keyword is left in place. Task-number: QTBUG-76414 Change-Id: I7d722e4faf09ae998a972d3ed914de808ab316d7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Merge remote-tracking branch 'origin/5.13' into 5.14Liang Qi2019-09-301-43/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/global/qrandom.cpp src/corelib/io/qfileinfo.cpp src/corelib/kernel/qeventdispatcher_win.cpp src/corelib/kernel/qeventdispatcher_win_p.h src/gui/text/qfontdatabase.cpp src/platformsupport/fontdatabases/mac/qcoretextfontdatabase.mm src/plugins/platforms/windows/qwindowsglcontext.cpp src/testlib/qtestcase.cpp Done-With: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Done-With: Edward Welbourne <edward.welbourne@qt.io> Change-Id: I4893212471aa24be804c989a581810e2f714545c
| * Fix QRandomGenerator initialization on AMD CPUsDmitry Kazakov2019-09-261-43/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Some AMD CPUs (e.g. AMD A4-6250J and AMD Ryzen 3000-series) have a failing random generation instruction, which always returns 0xffffffff, even when generation was "successful". This code checks if hardware random generator generates four consecutive equal numbers. If it does, then we probably have a failing one and should disable it completely. Change-Id: I38c87920ca2e8cce4143afbff5e453ce3845d11a Fixes: QTBUG-69423 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* | Merge remote-tracking branch 'origin/5.13' into 5.14Friedemann Kleint2019-09-091-7/+12
|\| | | | | | | | | | | | | Conflicts: tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp Change-Id: Idd3ca5cb9a2b95a4c3513b2a4c8966e6f56193f1
| * QRandom: retry the use of RDRAND instruction as recommended by manualsThiago Macieira2019-09-081-7/+12
| | | | | | | | | | | | | | | | | | | | | | The Intel whitepaper[1] recommends retrying RDRAND some 10 times even after it fails, since the hardware has a fairness algorithm and reseeds itself quite quickly. [1] https://software.intel.com/en-us/articles/intel-digital-random-number-generator-drng-software-implementation-guide Change-Id: I907a43cd9a714da288a2fffd15baafd88242d8b6 Reviewed-by: André Hartmann <aha_1980@gmx.de>
* | Merge remote-tracking branch 'origin/5.13' into devLiang Qi2019-07-051-4/+12
|\| | | | | | | | | | | | | | | Conflicts: .qmake.conf qmake/generators/makefile.cpp Change-Id: Ifb2633a69d0bf8cdf12d799c6259beefc279c49e
| * QRandomGenerator: assert that bounded() calls have correct argumentsThiago Macieira2019-06-281-4/+12
| | | | | | | | | | | | | | | | Otherwise, the math will fail badly. Documentation improved to reflect reality. Change-Id: I9e3d261ad9bf41cfb2b6fffd159085cd38e3c388 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
| * Doc-fixes in QRandomGenerator::bounded(int...)Edward Welbourne2019-04-091-3/+2
| | | | | | | | | | | | | | | | They return int, not quint32. Change-Id: I9879b58cccf9ea324ea1fc0c567a9d30b82fa44d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> (cherry picked from commit 6ed2ea86db63c72a38a60543da5a95d3543d39b1)
* | Port from implicit to explicit atomic integer operationsMarc Mutz2019-06-281-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | The old code used the implicit conversions from QAtomicInteger<T> to T and vice versa. The semantics of these differ from the ones std::atomic uses, so we're going to deprecate these, like we did for load() and store(), too. This patch fixex some users of these APIs before we deprecate them. Change-Id: I4877276581757cd57e042efea8296fe535a493d1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Port from QAtomic::load() to loadRelaxed()Giuseppe D'Angelo2019-06-201-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Semi-automated, just needed ~20 manual fixes: $ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)load\(\)/$1loadRelaxed\(\)/g' -i \{\} + $ find \( -iname \*.cpp -or -iname \*.h \) -exec perl -pe 's/(\.|->)store\(/$1storeRelaxed\(/g' -i \{\} + It can be easily improved (e.g. for store check that there are no commas after the opening parens). The most common offender is QLibrary::load, and some code using std::atomic directly. Change-Id: I07c38a3c8ed32c924ef4999e85c7e45cf48f0f6c Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
* | Merge "Merge remote-tracking branch 'origin/5.13' into dev" into ↵Qt Forward Merge Bot2019-04-041-13/+12
|\ \ | | | | | | | | | refs/staging/dev
| * | Replace Q_DECL_NOEXCEPT with noexcept in corelibAllan Sandfeld Jensen2019-04-031-10/+10
| | | | | | | | | | | | | | | | | | | | | In preparation of Qt6 move away from pre-C++11 macros. Change-Id: I44126693c20c18eca5620caab4f7e746218e0ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
| * | Doc-fixes in QRandomGenerator::bounded(int...)Edward Welbourne2019-03-291-3/+2
| |/ | | | | | | | | | | | | They return int, not quint32. Change-Id: I9879b58cccf9ea324ea1fc0c567a9d30b82fa44d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* / Remove remaining Q_DECL_NOEXCEPT/Q_DECL_NOTHROW usageAllan Sandfeld Jensen2019-04-041-2/+2
|/ | | | | Change-Id: I91ac9e714a465cab226b211812aa46e8fe5ff2ab Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Do not use arc4random_buf() on GNU/kFreeBSDDmitry Shachnev2018-12-091-2/+2
| | | | | | | It is not available in the GNU C Library. Change-Id: I36dc92fca283c126669885b75406c8e57f563ce3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix compile issue with gcc 9Allan Sandfeld Jensen2018-11-141-0/+1
| | | | | | | | | | It appears messenne_twisters in the latest libstdc++ has one more requirement before it is willing to construct with our SystemGenerator struct as an sseq provider. Change-Id: If38151d1fa6f40a80274acc26d9ed6b4ac6049fe Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Doc: Move literal code block to a separate fileCristian Maureira-Fredes2018-10-151-64/+17
| | | | | | | | | | | We need to override this snippet for the documentation we generate for Qt for Python, and it is easier to have it on a separate file. Task-number: PYSIDE-801 Task-number: PYSIDE-691 Change-Id: Ideb5b6af25024279f167137d3b65660bb9c96a7e Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* Modernize the "thread" featureUlf Hermann2018-08-171-1/+1
| | | | | | | | | | Add it to configure.json and replace all occurrences of QT_NO_THREAD with QT_CONFIG(thread). Add conditions for other features that depend on thread support. Remove conditions where we can use the QMutex and QThreadStorage stubs. Change-Id: I284e5d794fda9a4c6f4a1ab29e55aa686272a0eb Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
* Fix non-existing QRandomGenerator::generate32() function in docsAlex Blasche2018-07-311-3/+3
| | | | | | | | The function does not exist. QRandomGenerator::generate() is the equivalent function Change-Id: I5d65f2913fc5a9e60004d206733993254885a5e6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Remove needless #include <sys/random.h> from qrandom.cppEdward Welbourne2018-03-131-3/+1
| | | | | | | | | | | Tripped over by Alexei Fedotov and brought to light on the developer list; Thiago says it's a left-over from before reworking to actually use getentropy() instead of getrandom(); it should no longer be needed. Change-Id: Id09b0628e58fa62170a0f0da35b2b121f3fb0172 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* Merge remote-tracking branch 'origin/5.10' into 5.11Liang Qi2018-02-151-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/corelib/corelib.pro src/corelib/global/qrandom.cpp src/network/access/qhttpnetworkrequest_p.h src/plugins/platforms/cocoa/qcocoamenu.mm src/plugins/platforms/cocoa/qcocoansmenu.mm src/plugins/platforms/cocoa/qcocoawindow.mm src/plugins/platforms/cocoa/qnsview.mm src/plugins/platforms/offscreen/qoffscreenintegration.h src/widgets/kernel/qaction.cpp src/widgets/widgets.pro Done-with: Andy Shaw <andy.shaw@qt.io> Change-Id: Ib01547cf4184023f19858ccf0ce7fb824fed2a8d
| * Merge remote-tracking branch 'origin/5.9' into 5.10Liang Qi2018-01-241-4/+4
| | | | | | | | | | | | | | | | | | Conflicts: src/corelib/global/qglobal.cpp src/corelib/global/qrandom.cpp tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp Change-Id: Icc10543a1f2db5d640d01796bfec70a63517a6b2
* | doc: Correct remaining qdoc warnings in qstring.cppMartin Smith2018-01-051-1/+1
| | | | | | | | | | | | | | | | | | | | | | Added missing template clause to \fn commands required by clang-qdoc. Removed several obsolete \sa targets. Added a few missing return types to \fn commands. Also changed a } to ] in a \fn command in qrandom.cpp. Change-Id: I0f004a1e57507ff5fb035e822ca8b1baa7faad9b Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
* | doc: Correct remaining qdoc warnings in QRandomGeneratorMartin Smith2018-01-021-15/+8
| | | | | | | | | | | | | | | | | | Due to the integration of clang in qdoc, several qdoc warnings appeared for class QRandomGenerator. This update corrects all the remaining qdoc warnings. Change-Id: I92fe9f7d9cb193e145ee8ad0e7198625b9a5bf7b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* | Merge remote-tracking branch 'origin/5.10' into devLars Knoll2018-01-021-31/+54
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: .qmake.conf sc/corelib/io/qfsfileengine_p.h src/corelib/io/qstorageinfo_unix.cpp src/platformsupport/eglconvenience/qeglpbuffer_p.h src/platformsupport/input/libinput/qlibinputkeyboard.cpp src/platformsupport/input/libinput/qlibinputpointer.cpp src/plugins/platforms/cocoa/qcocoamenu.mm src/plugins/platforms/ios/qiosscreen.h src/plugins/platforms/ios/qioswindow.h src/plugins/platforms/ios/quiview.mm src/printsupport/dialogs/qpagesetupdialog_unix_p.h src/printsupport/dialogs/qprintpreviewdialog.cpp src/printsupport/widgets/qcupsjobwidget_p.h src/widgets/widgets/qmenu.cpp tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp Change-Id: Iecb4883122efe97ef0ed850271e6c51bab568e9c
| * Doc: attempt to fix some qdoc errors for QRandomGeneratorThiago Macieira2017-12-241-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | This fixes only those that look fixable. There are a number of errors in the online documentation that look like qdoc tool bugs, like missing functions (operator==) and documentation text that does not exist in the source code. This fixes: - QRandomGenerator(System) constructor showing up - Links for C++ reference documentation not showing up as links Change-Id: I9e2892cb6c374e93bcb7fffd14fe21db5a6969d9 Reviewed-by: Martin Smith <martin.smith@qt.io>
| * Merge remote-tracking branch 'origin/5.10.0' into 5.10Liang Qi2017-12-081-20/+20
| |\ | | | | | | | | | Change-Id: I6dcf85067ec226136c207ea69ca9d66736c84db5
| | * Improve readability of code that uses the Qt signed size typev5.10.0-rc2Simon Hausmann2017-11-281-20/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | During the container BoF session at the Qt Contributor Summit 2017 the name of the signed size type became a subject of discussion in the context of readability of code using this type and the intention of using it for all length, size and count properties throughout the entire framework in future versions of Qt. This change proposes qsizetype as new name for qssize_t to emphasize the readability of code over POSIX compatibility, the former being potentially more relevant than the latter to the majority of users of Qt. Change-Id: Idb99cb4a8782703c054fa463a9e5af23a918e7f3 Reviewed-by: Samuel Gaist <samuel.gaist@edeltech.ch> Reviewed-by: David Faure <david.faure@kdab.com>
| * | Fix qdoc warnings for 5.10Friedemann Kleint2017-12-041-6/+27
| |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | src/corelib/global/qrandom.cpp:915: warning: Cannot find 'bounded(...)' in '\fn' qreal QRandomGenerator::bounded(qreal highest) src/corelib/tools/qstring.cpp:774: warning: Command '\snippet (//! [qCompareStrings-QSV-QSV])' failed at end of file 'qstring/main.cpp' src/corelib/tools/qstring.cpp:5281: warning: Cannot find 'qTrimmed(...)' in '\fn' QStringView qTrimmed(QStringView s) src/corelib/tools/qstring.cpp:5281: warning: Cannot find 'qTrimmed(...)' in '\fn' QLatin1String qTrimmed(QLatin1String s) src/corelib/global/qrandom.h:171: warning: No documentation for 'QRandomGenerator::System' src/corelib/global/qrandom.h:105: warning: No documentation for 'QRandomGenerator::bounded(double highest)' src/corelib/global/qrandom.h:84: warning: No documentation for 'QRandomGenerator::generate64()' src/corelib/global/qrandom.h:77: warning: No documentation for 'QRandomGenerator::generate()' src/corelib/global/qrandom.cpp:799: warning: No such parameter 'sseq' in QRandomGenerator::seed() src/corelib/global/qrandom.cpp:1096: warning: Can't link to 'operator()()' src/corelib/tools/qstring.cpp:8982: warning: Can't link to 'qStartsWith()' src/corelib/tools/qstring.cpp:9203: warning: Can't link to 'qTrimmed()' src/corelib/tools/qstring.cpp:4798: warning: Can't link to 'qConvertToLatin1()' src/corelib/tools/qstring.cpp:4825: warning: Can't link to 'qConvertToLocal8Bit()' src/corelib/tools/qstring.cpp:4928: warning: Can't link to 'qConvertToUcs4()' src/corelib/tools/qstring.cpp:4884: warning: Can't link to 'qConvertToUtf8()' Change-Id: I5c7c89b230d3d1de8a679c10833319a470a44e80 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* / Replace qrand() engine with C++11 <random> LCG and deprecateThiago Macieira2017-11-301-83/+59
|/ | | | | | | | | | | | | | | | Instead of trying to adapt to whatever the C library may have and using QThreadLocalStorage, let's use a simple linear congruential generator engine from <random>. We can't use a single instance because qsrand() is documented to work per thread. I thought of using QRandomEngine, but had to make the choice between growing the QtCore code size and growing the per-thread data size. Code is sharable and is actually smaller than the sizeof(QRandomEngine), which is over 2500 bytes. sizeof(std::minstd_rand) is just sizeof(uint_fast32_t). Change-Id: I0a103569c81b4711a649fffd14ec8e641d02bf20 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* A brute-force solution to get QRandomGenerator build on IntegrityLiang Qi2017-11-151-2/+3
| | | | | | Task-number: QTBUG-64451 Change-Id: Ife11c3448f54609ba6e85a269a3b5376c43a075f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRandomGenerator: optimize the global() and system() storageThiago Macieira2017-11-111-55/+137
| | | | | | | | | | | | We store both in a single memory structure, instead of two local statics. By construction, we also ensure that the global PRNG mutex is in a different cacheline from the global PRNG state itself. Finally, we don't store the full system QRandomGenerator, since we only need the type member from it. Change-Id: Icaa86fc7b54d4b368c0efffd14eecc48ff05ec27 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QRandomGenerator: add more of the std Random Engine APIThiago Macieira2017-11-111-9/+81
| | | | | | | | | | | This brings us to almost parity with the C++11 Random Engine API requirements (see chapter 26.5.1.4 [rand.req.eng]). We don't implement the templated Sseq requirements because it would require moving the implementation details to the public API. And we don't implement the <iostreams> code because we don't want to. Change-Id: Icaa86fc7b54d4b368c0efffd14f05ff813ebd759 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QRandomGenerator: add securelySeeded(), to ensure appropriate seedingThiago Macieira2017-11-111-9/+51
| | | | | | | | | | | | | | | Since we don't document how many bytes one needs (it's 2496), it's difficult for the caller to provide just enough data in the seed sequence. Moreover, since std::mt19937 doesn't make it easy to provide the ideal size either, we can't actually write code that operates optimally given a quint32 range either -- we only provide it via std::seed_seq, which is inefficient. However, we can do it internally by passing QRandomGenerator to the std::mersenne_twister_engine constructor, as it's designed to work. Change-Id: Icaa86fc7b54d4b368c0efffd14f0613c10998321 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Change QRandomGenerator to have a deterministic modeThiago Macieira2017-11-111-261/+446
| | | | | | | | | 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>
* QRandomGenerator: remove the per-thread bufferThiago Macieira2017-11-111-64/+8
| | | | | | | | | | | Since we're adding a deterministic generator that inherently does not use syscalls, and people should really use that one by default, there is no point in optimizing the secure generator wrt syscalls. Besides, keeping the random data in memory for longer than needed is likely inadviseable. Change-Id: Ib17dde1a1dbb49a7bba8fffd14ed0871117fe930 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix unused variable warning when compiling in release mode with GCC 7Thiago Macieira2017-11-031-0/+2
| | | | | | | error: unused variable ‘ret’ [-Werror=unused-variable] Change-Id: I6e9274c1e7444ad48c81fffd14dcff9278d4376b Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix build on Integrity: the compiler doesn't understand this constructThiago Macieira2017-10-231-1/+5
| | | | | | | | | "global/qrandom.cpp", line 155: error #2000-D: attribute "destructor" is not implemented and will be ignored Task-number: QTBUG-63948 Change-Id: Icaa86fc7b54d4b368c0efffd14efa35381d4e797 Reviewed-by: Liang Qi <liang.qi@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* QRandomGenerator: fix the timing of the closing of the Unix random fdThiago Macieira2017-10-201-2/+2
| | | | | | | | | | Let's make it happen even later: at the time of QtCore's unloading from memory. This prevents issues with something using QRandomGenerator after the global static destructor would have run. Change-Id: Icaa86fc7b54d4b368c0efffd14eed56bbbb51cb6 Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* configure: make C++11 <random> a required functionalityThiago Macieira2017-10-161-13/+6
| | | | | | | | | Error out if it's missing or broken (Mersenne Twister not present). This ensures that we never have a low-quality random generator in Qt. Change-Id: I0a103569c81b4711a649fffd14ec80649df7087e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Doc: fix QRandomGenerator missing updates after renameThiago Macieira2017-10-141-10/+10
| | | | | | | | | Commit 282065d443c2a2d6b9e32d786c2c1c7552ba3cb5 renamed the generator functions but we didn't update all the docs. Change-Id: I0a103569c81b4711a649fffd14ec877ffbfe710d Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* QRandomGenerator: improve internal noexceptnessThiago Macieira2017-10-141-5/+7
| | | | | | | | | There are a couple of Q_ASSERT wrapped by the new noexcepts, but most of those aren't validation of external parameters, only of internal construction. The two exceptions are the checks for pointer alignment. Change-Id: I0a103569c81b4711a649fffd14ec8523d741dfb6 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Fix element overwrite in QRandomGenerator's fallback functionEirik Aavitsland2017-09-281-1/+1
| | | | | | | | Copy into the intended array elements, not into the start of the array. Change-Id: I05c4ece2450583c9358aa1eddfd702262e995146 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QRandomGenerator: update API to better nameThiago Macieira2017-09-221-26/+43
| | | | | | | | | | | | "generate" is better than "get", and we already have "generate(it, it)" which uses std::generate(). This changes: - get32() → generate() - get64() → generate64() and QRandomGenerator64::generate() - getReal() → generateDouble() Change-Id: I6e1fe42ae4b742a7b811fffd14e5d7bd69abcdb3 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
* Merge remote-tracking branch 'origin/5.9' into devLiang Qi2017-08-311-36/+37
| | | | | | | | | | | | | | | | | | | | Conflicts: examples/examples.pro qmake/library/qmakebuiltins.cpp src/corelib/global/qglobal.cpp Re-apply b525ec2 to qrandom.cpp(code movement in 030782e) src/corelib/global/qnamespace.qdoc src/corelib/global/qrandom.cpp src/gui/kernel/qwindow.cpp Re-apply a3d59c7 to QWindowPrivate::setVisible() (code movement in d7a9e08) src/network/ssl/qsslkey_openssl.cpp src/plugins/platforms/android/androidjniinput.cpp src/plugins/platforms/xcb/qxcbconnection.cpp src/plugins/platforms/xcb/qxcbconnection_xi2.cpp src/widgets/widgets/qmenu.cpp tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp Change-Id: If7ab427804408877a93cbe02079fca58e568bfd3
* Doc: add warning against bulk random data creation to QRandomGeneratorSamuel Gaist2017-08-051-1/+4
| | | | | | | | | The full documentation explains it well but a more prominent warning will help avoid the wrong use of that class and encourage user to read further the documentation. Change-Id: I3178749f2b1b0350040f81eef253fd85c7ba0a5f Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix use of getentropy on larger blocksThiago Macieira2017-07-271-2/+16
| | | | | | | | | | | Found while working on suppressing the warning about the return value (which is either 0 or -1) was being ignored. Task-number: QTBUG-61968 Change-Id: I02d22222fff64d4dbda4fffd14d148b1724547ca Reviewed-by: Florian Bruhin <qt-project.org@the-compiler.org> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Rename the "sys_auxv" feature to "getauxval"Thiago Macieira2017-07-061-2/+2
| | | | | Change-Id: I8d96dea9955d4c749b99fffd14cdbd1e69940d33 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
* QRandomGenerator: use getentropy on Linux & OpenBSDThiago Macieira2017-06-301-9/+38
| | | | | | | | | | | | | | | | | | | | | | | 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 <lars.knoll@qt.io>
* QRandomGenerator: Rework the fallback seedingThiago Macieira2017-06-251-38/+58
| | | | | | | | | | | | | | | qdeadlinetimer.cpp and qelapsedtimer_*.cpp are not part of the bootstrap library. Instead of adding them there, just remove this entropy source from bootstrapped builds (instead of just qmake). To compensate, store all the bits instead of trying to combine them into just one 32-bit word. We've got a few new sources from the stack and libc, plus two more ELF auxvec values that the Linux kernel supplies (inspired by OpenBSD's getentropy_linux.c, which is used in Bionic). Task-number: QTBUG-61492 Change-Id: I1d5a585d4af842f9a66ffffd14c999ae8c44f46c Reviewed-by: Lars Knoll <lars.knoll@qt.io>