aboutsummaryrefslogtreecommitdiff
path: root/src/random.h
Commit message (Collapse)AuthorAgeFilesLines
* Use RdSeed when available, and reduce RdRand loadPieter Wuille2019-02-031-1/+2
| | | | | | | | 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).
* Document RNG design in random.hPieter Wuille2019-01-161-0/+43
|
* Sprinkle some sweet noexcepts over the RNG codePieter Wuille2019-01-161-14/+14
|
* Switch all RNG code to the built-in PRNG.Pieter Wuille2019-01-161-12/+19
| | | | | | | | | | | | | | | | | | | | | | | 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().
* Automatically initialize RNG on first use.Pieter Wuille2019-01-161-1/+6
|
* Do not permit copying FastRandomContextsPieter Wuille2018-12-121-0/+8
|
* Introduce a Shuffle for FastRandomContext and use it in wallet and coinselectionPieter Wuille2018-12-121-0/+23
|
* Update copyright headers to 2018DrahtBot2018-07-271-1/+1
|
* Merge #12742: Make FastRandomContext support standard C++11 RNG interfaceMarcoFalke2018-03-221-0/+7
|\ | | | | | | | | | | | | | | | | | | 1ec1602a45 Make FastRandomContext support standard C++11 RNG interface (Pieter Wuille) Pull request description: This makes it possible to plug it into the various standard C++11 random distribution algorithms and other functions like `std::shuffle`. Tree-SHA512: 935eae9c4fae31e1964c16d9cf9d0fcfa899e04567f010d8b3e1ff824e55e2392aa838ba743d03c1b2a5010c5b8da04343f453983dfeed83747d85828a564713
| * Make FastRandomContext support standard C++11 RNG interfacePieter Wuille2018-03-201-0/+7
| | | | | | | | | | This makes it possible to plug it into the various standard C++11 random distribution algorithms and other functions like std::shuffle.
* | Fix typosDimitris Apostolou2018-03-211-1/+1
|/
* Increment MIT Licence copyright header year on files modified in 2017Akira Takizawa2018-01-031-1/+1
|
* Merge #11558: Minimal code changes to allow msvc compilationWladimir J. van der Laan2017-12-131-1/+1
|\ | | | | | | | | | | | | | | | | | | | | | | fbf327b Minimal code changes to allow msvc compilation. (Aaron Clauson) Pull request description: These changes are required to allow the Bitcoin source to build with Microsoft's C++ compiler (#11562 is also required). I looked around for a better place for the typedef of ssize_t which is in random.h. The best candidate looks like src/compat.h but I figured including that header in random.h is a bigger change than the typedef. Note that the same typedef is in at least two other places including the OpenSSL and Berkeley DB headers so some of the Bitcoin code already picks it up. Tree-SHA512: aa6cc6283015e08ab074641f9abdc116c4dc58574dc90f75e7a5af4cc82946d3052370e5cbe855fb6180c00f8dc66997d3724ff0412e4b7417e51b6602154825
| * Minimal code changes to allow msvc compilation.Aaron Clauson2017-11-101-1/+1
| |
* | scripted-diff: Replace #include "" with #include <> (ryanofsky)MeshCollider2017-11-161-3/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | -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 #10377: Use rdrand as entropy source on supported platformsWladimir J. van der Laan2017-06-141-0/+3
|\ | | | | | | | | | | 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/+3
| |
* | Add FastRandomContext::rand256() and ::randbytes()Pieter Wuille2017-06-051-0/+6
|/ | | | | FastRandomContext now provides all functionality that the real Rand* functions provide.
* Add perf counter data to GetStrongRandBytes state in schedulerMatt Corallo2017-05-221-0/+7
|
* Add a FastRandomContext::randrange and use itPieter Wuille2017-03-291-0/+12
|
* Switch FastRandomContext to ChaCha20Pieter Wuille2017-03-291-9/+57
|
* Introduce FastRandomContext::randbool()Pieter Wuille2017-03-291-0/+4
|
* sanity: Move OS random to sanity check functionWladimir J. van der Laan2017-02-221-0/+5
| | | | | | | | Move the OS random test to a sanity check function that is called every time bitcoind is initialized. Keep `src/test/random_tests.cpp` for the case that later random tests are added, and keep a rudimentary test that just calls the sanity check.
* squashme: comment that NUM_OS_RANDOM_BYTES should not be changed lightlyWladimir J. van der Laan2017-02-221-1/+5
|
* util: Specific GetOSRandom for Linux/FreeBSD/OpenBSDWladimir J. van der Laan2017-02-211-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These are available in sandboxes without access to files or devices. Also [they are safer and more straightforward](https://en.wikipedia.org/wiki/Entropy-supplying_system_calls) to use than `/dev/urandom` as reading from a file has quite a few edge cases: - Linux: `getrandom(buf, buflen, 0)`. [getrandom(2)](http://man7.org/linux/man-pages/man2/getrandom.2.html) was introduced in version 3.17 of the Linux kernel. - OpenBSD: `getentropy(buf, buflen)`. The [getentropy(2)](http://man.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man2/getentropy.2) function appeared in OpenBSD 5.6. - FreeBSD and NetBSD: `sysctl(KERN_ARND)`. Not sure when this was added but it has existed for quite a while. Alternatives: - Linux has sysctl `CTL_KERN` / `KERN_RANDOM` / `RANDOM_UUID` which gives 16 bytes of randomness. This may be available on older kernels, however [sysctl is deprecated on Linux](https://lwn.net/Articles/605392/) and even removed in some distros so we shouldn't use it. Add tests for `GetOSRand()`: - Test that no error happens (otherwise `RandFailure()` which aborts) - Test that all 32 bytes are overwritten (initialize with zeros, try multiple times) Discussion: - When to use these? Currently they are always used when available. Another option would be to use them only when `/dev/urandom` is not available. But this would mean these code paths receive less testing, and I'm not sure there is any reason to prefer `/dev/urandom`. Closes: #9676
* Increment MIT Licence copyright header year on files modified in 2016isle29832016-12-311-1/+1
| | | | | | Edited via: $ contrib/devtools/copyright_header.py update .
* Kill insecure_random and associated global stateWladimir J. van der Laan2016-10-171-19/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are only a few uses of `insecure_random` outside the tests. This PR replaces uses of insecure_random (and its accompanying global state) in the core code with an FastRandomContext that is automatically seeded on creation. This is meant to be used for inner loops. The FastRandomContext can be in the outer scope, or the class itself, then rand32() is used inside the loop. Useful e.g. for pushing addresses in CNode or the fee rounding, or randomization for coin selection. As a context is created per purpose, thus it gets rid of cross-thread unprotected shared usage of a single set of globals, this should also get rid of the potential race conditions. - I'd say TxMempool::check is not called enough to warrant using a special fast random context, this is switched to GetRand() (open for discussion...) - The use of `insecure_rand` in ConnectThroughProxy has been replaced by an atomic integer counter. The only goal here is to have a different credentials pair for each connection to go on a different Tor circuit, it does not need to be random nor unpredictable. - To avoid having a FastRandomContext on every CNode, the context is passed into PushAddress as appropriate. There remains an insecure_random for test usage in `test_random.h`.
* Always require OS randomness when generating secret keysPieter Wuille2016-05-291-4/+7
|
* Added "Core" to copyright headerssandakersmann2014-12-191-1/+1
| | | | | Github-Pull: #5494 Rebased-From: 15de949bb9277e442302bdd8dee299a8d6deee60
* Remove references to X11 licenceMichael Ford2014-12-161-1/+1
|
* Fix typo in doxygen comment.Pavel Janík2014-11-251-1/+1
|
* Make sure that GetRandomBytes never failsWladimir J. van der Laan2014-11-071-1/+1
| | | | | | | | | We're using GetRandomBytes in several contexts where it's either unwieldy to return an error, or an error would mean a fatal exception anyhow. @gmaxwell checked OpenSSL a while ago and discovered that it never actually fails, but it can't hurt to be a bit paranoid here.
* Apply clang-format on some infrequently-updated filesPieter Wuille2014-09-191-1/+1
|
* move rand functions from util to new random.h/.cppPhilip Kaufmann2014-07-091-0/+49