aboutsummaryrefslogtreecommitdiff
path: root/src/random.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Merge #15250: Use RdSeed when available, and reduce RdRand loadWladimir J. van der Laan2019-02-181-38/+134
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | 1435fabc19d2143187efb493cbe23225eaf851ae Use RdSeed when available, and reduce RdRand load (Pieter Wuille) Pull request description: This introduces support for autodetecting and using the RdSeed instruction on x86/x86_64 systems. In addition: * In SeedFast, only 64 bits of entropy are generated through RdRand (256 was relatively slow). * In SeedStartup, 256 bits of entropy are generated, using RdSeed (preferably) or RdRand (otherwise). Tree-SHA512: fb7d3e22e93e14592f4b07282aa79d7c3cc4e9debdd9978580b8d2562bbad345e289bf3f80de2c50c9b50b8bac2aa9b838f9f272f7f8d43f1efc0913aa8acce3
| * Use RdSeed when available, and reduce RdRand loadPieter Wuille2019-02-031-38/+134
| | | | | | | | | | | | | | | | This introduces support for autodetecting and using the RdSeed instruction. In addition: * In SeedFast, only 64 bits of entropy are generated through RdRand (256 was relatively slow). * In SeedStartup, 256 bits of entropy are generated, using RdSeed (preferably) or RdRand (otherwise).
* | test: Make bloom tests deterministicMarcoFalke2019-02-021-1/+3
|/
* Document RNG design in random.hPieter Wuille2019-01-161-0/+8
|
* Use secure allocator for RNG statePieter Wuille2019-01-161-2/+4
|
* Encapsulate RNGState betterPieter Wuille2019-01-161-3/+6
|
* DRY: Implement GetRand using FastRandomContext::randrangePieter Wuille2019-01-161-11/+1
|
* Sprinkle some sweet noexcepts over the RNG codePieter Wuille2019-01-161-17/+32
|
* Remove hwrand_initialized.Pieter Wuille2019-01-161-4/+0
| | | | All access to hwrand is now gated by GetRNGState, which initializes the hwrand code.
* Switch all RNG code to the built-in PRNG.Pieter Wuille2019-01-161-67/+118
| | | | | | | | | | | | | | | | | | | | | | | It includes the following policy changes: * All GetRand* functions seed the stack pointer and rdrand result (in addition to the performance counter) * The periodic entropy added by the idle scheduler now seeds stack pointer, rdrand and perfmon data (once every 10 minutes) in addition to just a sleep timing. * The entropy added when calling GetStrongRandBytes no longer includes the once-per-10-minutes perfmon data on windows (it is moved to the idle scheduler instead, where latency matters less). Other changes: * OpenSSL is no longer seeded directly anywhere. Instead, any generated randomness through our own RNG is fed back to OpenSSL (after an additional hashing step to prevent leaking our RNG state). * Seeding that was previously done directly in RandAddSeedSleep is now moved to SeedSleep(), which is indirectly invoked through ProcRand from RandAddSeedSleep. * Seeding that was previously done directly in GetStrongRandBytes() is now moved to SeedSlow(), which is indirectly invoked through ProcRand from GetStrongRandBytes().
* Integrate util/system's CInit into RNGStatePieter Wuille2019-01-161-0/+43
| | | | | | | | | This guarantees that OpenSSL is initialized properly whenever randomness is used, even when that randomness is invoked from global constructors. Note that this patch uses Mutex directly, rather than CCriticalSection. This is because the lock-detection code is not necessarily initialized during global constructors.
* Abstract out seeding/extracting entropy into RNGState::MixExtractPieter Wuille2019-01-161-24/+36
|
* Add thread safety annotations to RNG statePieter Wuille2019-01-161-3/+4
|
* Rename some hardware RNG related functionsPieter Wuille2019-01-161-8/+13
|
* Automatically initialize RNG on first use.Pieter Wuille2019-01-161-18/+50
|
* Don't log RandAddSeedPerfmon detailsPieter Wuille2019-01-161-6/+6
| | | | | These are hard to deal with, as in a follow-up this function can get called before the logging infrastructure is initialized.
* Do not permit copying FastRandomContextsPieter Wuille2018-12-121-0/+14
|
* Bugfix: randbytes should seed when needed (non reachable issue)Pieter Wuille2018-12-121-0/+1
|
* scripted-diff: Move util files to separate directory.Jim Posen2018-11-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -BEGIN VERIFY SCRIPT- mkdir -p src/util git mv src/util.h src/util/system.h git mv src/util.cpp src/util/system.cpp git mv src/utilmemory.h src/util/memory.h git mv src/utilmoneystr.h src/util/moneystr.h git mv src/utilmoneystr.cpp src/util/moneystr.cpp git mv src/utilstrencodings.h src/util/strencodings.h git mv src/utilstrencodings.cpp src/util/strencodings.cpp git mv src/utiltime.h src/util/time.h git mv src/utiltime.cpp src/util/time.cpp sed -i 's/<util\.h>/<util\/system\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/<utilmemory\.h>/<util\/memory\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/<utilmoneystr\.h>/<util\/moneystr\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/<utilstrencodings\.h>/<util\/strencodings\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/<utiltime\.h>/<util\/time\.h>/g' $(git ls-files 'src/*.h' 'src/*.cpp') sed -i 's/BITCOIN_UTIL_H/BITCOIN_UTIL_SYSTEM_H/g' src/util/system.h sed -i 's/BITCOIN_UTILMEMORY_H/BITCOIN_UTIL_MEMORY_H/g' src/util/memory.h sed -i 's/BITCOIN_UTILMONEYSTR_H/BITCOIN_UTIL_MONEYSTR_H/g' src/util/moneystr.h sed -i 's/BITCOIN_UTILSTRENCODINGS_H/BITCOIN_UTIL_STRENCODINGS_H/g' src/util/strencodings.h sed -i 's/BITCOIN_UTILTIME_H/BITCOIN_UTIL_TIME_H/g' src/util/time.h sed -i 's/ util\.\(h\|cpp\)/ util\/system\.\1/g' src/Makefile.am sed -i 's/utilmemory\.\(h\|cpp\)/util\/memory\.\1/g' src/Makefile.am sed -i 's/utilmoneystr\.\(h\|cpp\)/util\/moneystr\.\1/g' src/Makefile.am sed -i 's/utilstrencodings\.\(h\|cpp\)/util\/strencodings\.\1/g' src/Makefile.am sed -i 's/utiltime\.\(h\|cpp\)/util\/time\.\1/g' src/Makefile.am sed -i 's/-> util ->/-> util\/system ->/' test/lint/lint-circular-dependencies.sh sed -i 's/src\/util\.cpp/src\/util\/system\.cpp/g' test/lint/lint-format-strings.py test/lint/lint-locale-dependence.sh sed -i 's/src\/utilmoneystr\.cpp/src\/util\/moneystr\.cpp/g' test/lint/lint-locale-dependence.sh sed -i 's/src\/utilstrencodings\.\(h\|cpp\)/src\/util\/strencodings\.\1/g' test/lint/lint-locale-dependence.sh sed -i 's/src\\utilstrencodings\.cpp/src\\util\\strencodings\.cpp/' build_msvc/libbitcoinconsensus/libbitcoinconsensus.vcxproj -END VERIFY SCRIPT-
* scripted-diff: Small locking renameRussell Yanofsky2018-08-311-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Call sync.h primitives "locks" and "mutexes" instead of "blocks" and "waitable critical sections" to match current coding conventions and c++11 standard names. This PR does not rename the "CCriticalSection" class (though this could be done as a followup) because it is used everywhere and would swamp the other changes in this PR. Plain mutexes should mostly be preferred instead of recursive mutexes in new code anyway. -BEGIN VERIFY SCRIPT- set -x set -e ren() { git grep -l $1 | xargs sed -i s/$1/$2/; } ren CCriticalBlock UniqueLock ren CWaitableCriticalSection Mutex ren CConditionVariable std::condition_variable ren cs_GenesisWait g_genesis_wait_mutex ren condvar_GenesisWait g_genesis_wait_cv perl -0777 -pi -e 's/.*typedef.*condition_variable.*\n\n?//g' src/sync.h -END VERIFY SCRIPT-
* Merge #11640: Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSectionWladimir J. van der Laan2018-08-311-3/+4
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | 9c4dc597ddc66acfd58a945a5ab11f833731abba Use LOCK macros for non-recursive locks (Russell Yanofsky) 1382913e61f5db6ba849b1e261e8aefcd5a1ae68 Make LOCK, LOCK2, TRY_LOCK work with CWaitableCriticalSection (Russell Yanofsky) ba1f095aadf29bddb0bd8176d2e0b908f92a5623 MOVEONLY Move AnnotatedMixin declaration (Russell Yanofsky) 41b88e93375d57db12da923f45f87b9a2db8e730 Add unit test for DEBUG_LOCKORDER code (Russell Yanofsky) Pull request description: Make LOCK macros work with non-recursive mutexes, and use wherever possible for better deadlock detection. Also add unit test for DEBUG_LOCKORDER code. Tree-SHA512: 64ef209307f28ecd0813a283f15c6406138c6ffe7f6cbbd084161044db60e2c099a7d0d2edcd1c5e7770a115e9b931b486e86c9a777bdc96d2e8a9f4dc192942
| * Use LOCK macros for non-recursive locksRussell Yanofsky2018-08-031-3/+4
| | | | | | | | Instead of std::unique_lock.
* | Update copyright headers to 2018DrahtBot2018-07-271-1/+1
|/
* Fix FreeBSD build by including utilstrencodings.hWladimir J. van der Laan2018-05-241-0/+1
| | | | | | | `random.cpp` needs to explicitly include `utilstrencodings.h` to get `ARRAYLEN`. This fixes the FreeBSD build. This was broken in 84f41946b9026e8bf7bc44ed848dfb945394b693.
* break circular dependency: random/sync -> util -> random/syncChun Kuan Lee2018-05-171-2/+3
|
* Make it clear which functions that are intended to be translation unit localpracticalswift2018-05-031-1/+1
| | | | | Do not share functions that are meant to be translation unit local with other translation units. Use internal linkage for those consistently.
* Remove duplicate includespracticalswift2018-04-091-1/+0
|
* Increment MIT Licence copyright header year on files modified in 2017Akira Takizawa2018-01-031-1/+1
|
* scripted-diff: Replace #include "" with #include <> (ryanofsky)MeshCollider2017-11-161-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT-
* Merge #10843: Add attribute [[noreturn]] (C++11) to functions that will not ↵Wladimir J. van der Laan2017-08-221-2/+2
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | return b82c55a Add attribute [[noreturn]] (C++11) to functions that will not return (practicalswift) Pull request description: Add attribute `[[noreturn]]` (C++11) to functions that will not return. Rationale: * Reduce the number of false positives/false negatives from static analyzers with regards to things such as unused or unreachable code * Potentially enable additional compiler optimizations Tree-SHA512: 899683fe8b2fcf19bd334352271d368b46b805be9d426aac1808335fd95732d6d7078d3296951b9879196f3f6e3ec0fdb7695d0afdc3fbe4dd78a2ca70e91ff7
| * Add attribute [[noreturn]] (C++11) to functions that will not returnpracticalswift2017-07-171-2/+2
| | | | | | | | | | | | Rationale: * Reduce the number of false positives from static analyzers * Potentially enable additional compiler optimizations
* | Document the preference of nullptr over NULL or (void*)0practicalswift2017-08-181-1/+1
| |
* | Merge #10483: scripted-diff: Use the C++11 keyword nullptr to denote the ↵Wladimir J. van der Laan2017-08-141-3/+3
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | pointer literal instead of the macro NULL 90d4d89 scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal instead of the macro NULL (practicalswift) Pull request description: Since C++11 the macro `NULL` may be: * an integer literal with value zero, or * a prvalue of type `std::nullptr_t` By using the C++11 keyword `nullptr` we are guaranteed a prvalue of type `std::nullptr_t`. For a more thorough discussion, see "A name for the null pointer: nullptr" (Sutter & Stroustrup), http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2431.pdf With this patch applied there are no `NULL` macro usages left in the repo: ``` $ git grep NULL -- "*.cpp" "*.h" | egrep -v '(/univalue/|/secp256k1/|/leveldb/|_NULL|NULLDUMMY|torcontrol.*NULL|NULL cert)' | wc -l 0 ``` The road towards `nullptr` (C++11) is split into two PRs: * `NULL` → `nullptr` is handled in PR #10483 (scripted, this PR) * `0` → `nullptr` is handled in PR #10645 (manual) Tree-SHA512: 3c395d66f2ad724a8e6fed74b93634de8bfc0c0eafac94e64e5194c939499fefd6e68f047de3083ad0b4eff37df9a8a3a76349aa17d55eabbd8e0412f140a297
| * | scripted-diff: Use the C++11 keyword nullptr to denote the pointer literal ↵practicalswift2017-08-071-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | instead of the macro NULL -BEGIN VERIFY SCRIPT- sed -i 's/\<NULL\>/nullptr/g' src/*.cpp src/*.h src/*/*.cpp src/*/*.h src/qt/*/*.cpp src/qt/*/*.h src/wallet/*/*.cpp src/wallet/*/*.h src/support/allocators/*.h sed -i 's/Prefer nullptr, otherwise SAFECOOKIE./Prefer NULL, otherwise SAFECOOKIE./g' src/torcontrol.cpp sed -i 's/tor: Using nullptr authentication/tor: Using NULL authentication/g' src/torcontrol.cpp sed -i 's/METHODS=nullptr/METHODS=NULL/g' src/test/torcontrol_tests.cpp src/torcontrol.cpp sed -i 's/nullptr certificates/NULL certificates/g' src/qt/paymentserver.cpp sed -i 's/"nullptr"/"NULL"/g' src/torcontrol.cpp src/test/torcontrol_tests.cpp -END VERIFY SCRIPT-
* | | Check if sys/random.h is required for getentropy on OSX.James Hilliard2017-07-271-1/+13
|/ /
* | random: only use getentropy on openbsdCory Fields2017-07-171-1/+3
| |
* | Merge #10837: Fix resource leak on error in GetDevURandomWladimir J. van der Laan2017-07-171-0/+1
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | a8ae0b2 Fix resource leak (Dag Robole) Pull request description: Fixes a potential file handle leak when size of entropy is invalid Tree-SHA512: 692d24daaf370bba1f842925b037275126f9494f54769650bcf5829c794a0fb8561a86f42347bdf088a484e4f107bce7fa14cd7bdbfb4ecfbeb51968953da3ae
| * | Fix resource leakDag Robole2017-07-151-0/+1
| |/
* | Clarify entropy sourcePieter Wuille2017-07-141-1/+1
| |
* | Use cpuid intrinsics instead of asm codePieter Wuille2017-07-131-11/+6
|/
* random: fix crash on some 64bit platformsCory Fields2017-06-161-2/+8
| | | | | | | | rbx needs to be stashed in a 64bit register on 64bit platforms. With this crash in particular, it was holding a stack canary which was not properly restored after the cpuid. Split out the x86+PIC case so that x86_64 doesn't have to worry about it.
* Merge #10377: Use rdrand as entropy source on supported platformsWladimir J. van der Laan2017-06-141-0/+68
|\ | | | | | | | | | | cb24c85 Use rdrand as entropy source on supported platforms (Pieter Wuille) Tree-SHA512: c42eaa01a14e6bc097c70b6bf8540d61854c2f76cb32be69c2a3c411a126f7b4bf4a4486e4493c4cc367cc689319abde0d4adb799d29a54fd3e81767ce0766fc
| * Use rdrand as entropy source on supported platformsPieter Wuille2017-06-131-0/+68
| |
* | Add FastRandomContext::rand256() and ::randbytes()Pieter Wuille2017-06-051-0/+20
|/ | | | | FastRandomContext now provides all functionality that the real Rand* functions provide.
* Add perf counter data to GetStrongRandBytes state in schedulerMatt Corallo2017-05-221-0/+17
|
* Add internal method to add new random data to our internal RNG stateMatt Corallo2017-05-221-0/+16
|
* Merge #10338: Maintain state across GetStrongRandBytes callsPieter Wuille2017-05-091-1/+16
|\ | | | | | | | | | | 97477c5 Maintain state across GetStrongRandBytes calls (Pieter Wuille) Tree-SHA512: 77e9b1f3c6eeb0c2a3e0c64358150767222ff0b7120ccd5f4ae0276cea0e4fa275c1b757e3f20be07dc0b4ef07f70ab0b70112080c8d3d0cb6ed703db8a59168
| * Maintain state across GetStrongRandBytes callsPieter Wuille2017-05-041-1/+16
| |
* | Use sanity check timestamps as entropyPieter Wuille2017-05-051-0/+4
| |
* | Test that GetPerformanceCounter() incrementsPieter Wuille2017-05-051-1/+11
| |