-
Notifications
You must be signed in to change notification settings - Fork 714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Refactor] Update RNG code from upstream #2278
[Refactor] Update RNG code from upstream #2278
Commits on Apr 14, 2021
-
Make FastRandomContext support standard C++11 RNG interface
This makes it possible to plug it into the various standard C++11 random distribution algorithms and other functions like std::shuffle.
Configuration menu - View commit details
-
Copy full SHA for 94b2ead - Browse repository at this point
Copy the full SHA 94b2eadView commit details -
Configuration menu - View commit details
-
Copy full SHA for e862564 - Browse repository at this point
Copy the full SHA e862564View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1cdf124 - Browse repository at this point
Copy the full SHA 1cdf124View commit details -
Configuration menu - View commit details
-
Copy full SHA for 746d466 - Browse repository at this point
Copy the full SHA 746d466View commit details -
Configuration menu - View commit details
-
Copy full SHA for af52bf5 - Browse repository at this point
Copy the full SHA af52bf5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 972effa - Browse repository at this point
Copy the full SHA 972effaView commit details -
Configuration menu - View commit details
-
Copy full SHA for 32e6c42 - Browse repository at this point
Copy the full SHA 32e6c42View commit details -
Don't log RandAddSeedPerfmon details
These are hard to deal with, as in a follow-up this function can get called before the logging infrastructure is initialized.
Configuration menu - View commit details
-
Copy full SHA for 1a5dbc5 - Browse repository at this point
Copy the full SHA 1a5dbc5View commit details -
Configuration menu - View commit details
-
Copy full SHA for d76ee83 - Browse repository at this point
Copy the full SHA d76ee83View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2326535 - Browse repository at this point
Copy the full SHA 2326535View commit details -
Configuration menu - View commit details
-
Copy full SHA for 298f97c - Browse repository at this point
Copy the full SHA 298f97cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5f20e62 - Browse repository at this point
Copy the full SHA 5f20e62View commit details -
Integrate util/system's CInit into RNGState
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.
Configuration menu - View commit details
-
Copy full SHA for 038a45a - Browse repository at this point
Copy the full SHA 038a45aView commit details -
Switch all RNG code to the built-in PRNG.
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().
Configuration menu - View commit details
-
Copy full SHA for 698d133 - Browse repository at this point
Copy the full SHA 698d133View commit details -
All access to hwrand is now gated by GetRNGState, which initializes the hwrand code.
Configuration menu - View commit details
-
Copy full SHA for 774899f - Browse repository at this point
Copy the full SHA 774899fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 5bc2583 - Browse repository at this point
Copy the full SHA 5bc2583View commit details -
Configuration menu - View commit details
-
Copy full SHA for 787d72f - Browse repository at this point
Copy the full SHA 787d72fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 080deb3 - Browse repository at this point
Copy the full SHA 080deb3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2b6381e - Browse repository at this point
Copy the full SHA 2b6381eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4ffda1f - Browse repository at this point
Copy the full SHA 4ffda1fView commit details -
Use RdSeed when available, and reduce RdRand load
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).
Configuration menu - View commit details
-
Copy full SHA for 67e336d - Browse repository at this point
Copy the full SHA 67e336dView commit details -
Add hash strengthening to the RNG
Once every minute, this will feed the RNG state through repeated SHA512 for 10ms. The timings of that operation are used as entropy source as well.
Configuration menu - View commit details
-
Copy full SHA for 0190dec - Browse repository at this point
Copy the full SHA 0190decView commit details -
Configuration menu - View commit details
-
Copy full SHA for 7b33223 - Browse repository at this point
Copy the full SHA 7b33223View commit details -
Configuration menu - View commit details
-
Copy full SHA for c82e359 - Browse repository at this point
Copy the full SHA c82e359View commit details -
Configuration menu - View commit details
-
Copy full SHA for 28c9cdb - Browse repository at this point
Copy the full SHA 28c9cdbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6966aa9 - Browse repository at this point
Copy the full SHA 6966aa9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 79e7fd3 - Browse repository at this point
Copy the full SHA 79e7fd3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 22a7121 - Browse repository at this point
Copy the full SHA 22a7121View commit details -
gui: remove OpenSSL PRNG seeding (Windows, Qt only)
This removes the code introduced in [dashpay#4399](bitcoin#4399) that attempts to add additional entroy to the OpenSSL PRNG using Windows messages. Note that this is specific to bitcoin-qt running on Windows. ``` RAND_event() collects the entropy from Windows events such as mouse movements and other user interaction. It should be called with the iMsg, wParam and lParam arguments of all messages sent to the window procedure. It will estimate the entropy contained in the event message (if any), and add it to the PRNG. The program can then process the messages as usual. ``` Besides BIP70, this is the last place we are directly using OpenSSL in the GUI code. All other OpenSSL usage is in random.cpp. Note that we are still also doing Windows specific entropy gathering in multiple other places. Such as [RandAddSeedPerfmon](https://github.com/bitcoin/bitcoin/blob/master/src/random.cpp#L268) and [RAND_screen()](https://github.com/bitcoin/bitcoin/blob/master/src/random.cpp#L600). Also note that if RAND_event returns 0 (PRNG has NOT been seeded with enough data), we're just logging a message and continuing on, which seems less than ideal.
Configuration menu - View commit details
-
Copy full SHA for ada9868 - Browse repository at this point
Copy the full SHA ada9868View commit details -
random: remove call to RAND_screen() (Windows only)
Follow up to bitcoin#17151 where there were multiple calls to also remove our call to RAND_screen().
Configuration menu - View commit details
-
Copy full SHA for 5eed08c - Browse repository at this point
Copy the full SHA 5eed08cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 630931f - Browse repository at this point
Copy the full SHA 630931fView commit details -
Fix FreeBSD build by including utilstrencodings.h
`random.cpp` needs to explicitly include `utilstrencodings.h` to get `ARRAYLEN`. This fixes the FreeBSD build.
Configuration menu - View commit details
-
Copy full SHA for 909473e - Browse repository at this point
Copy the full SHA 909473eView commit details -
Configuration menu - View commit details
-
Copy full SHA for fccd2b8 - Browse repository at this point
Copy the full SHA fccd2b8View commit details -
doc: minor corrections in random.cpp
This should have been part of bitcoin#17151.
Configuration menu - View commit details
-
Copy full SHA for 27cf995 - Browse repository at this point
Copy the full SHA 27cf995View commit details -
Configuration menu - View commit details
-
Copy full SHA for 52b5336 - Browse repository at this point
Copy the full SHA 52b5336View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7bde8b7 - Browse repository at this point
Copy the full SHA 7bde8b7View commit details -
Seed randomness with process id / thread id / various clocks
This sort of data is also used by OpenSSL.
Configuration menu - View commit details
-
Copy full SHA for 6142e1f - Browse repository at this point
Copy the full SHA 6142e1fView commit details -
Gather additional entropy from the environment
This based on code by Gregory Maxwell. # Conflicts: # src/randomenv.cpp
Configuration menu - View commit details
-
Copy full SHA for 67de246 - Browse repository at this point
Copy the full SHA 67de246View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8f5b9c9 - Browse repository at this point
Copy the full SHA 8f5b9c9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 88d97d0 - Browse repository at this point
Copy the full SHA 88d97d0View commit details -
Add information gathered through getauxval()
Suggested by Wladimir van der Laan.
Configuration menu - View commit details
-
Copy full SHA for 4679181 - Browse repository at this point
Copy the full SHA 4679181View commit details -
Run background seeding periodically instead of unpredictably
* Instead of calling RandAddSeedSleep anytime the scheduler goes idle, call its replacement (RandAddSeedPeriodic) just once per minute. This has better guarantees of actually being run, and helps limit how frequently the dynamic env data is gathered. * Since this code runs once per minute regardless now, we no longer need to keep track of the last time strengthening was run; just do it always. * Make strengthening time context dependent (100 ms at startup, 10 ms once per minute afterwards).
Configuration menu - View commit details
-
Copy full SHA for 7d6ddcb - Browse repository at this point
Copy the full SHA 7d6ddcbView commit details -
Configuration menu - View commit details
-
Copy full SHA for f363ea9 - Browse repository at this point
Copy the full SHA f363ea9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 81d382f - Browse repository at this point
Copy the full SHA 81d382fView commit details -
random: mark RandAddPeriodic and SeedPeriodic as noexcept
The usage of MilliSleep() in SeedPeriodic (previously SeedSleep) was removed in bitcoin#17270, meaning it, and its users can now be marked noexcept.
Configuration menu - View commit details
-
Copy full SHA for 88c2ae5 - Browse repository at this point
Copy the full SHA 88c2ae5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8a9bbb1 - Browse repository at this point
Copy the full SHA 8a9bbb1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 41ab1ff - Browse repository at this point
Copy the full SHA 41ab1ffView commit details -
Configuration menu - View commit details
-
Copy full SHA for fec460c - Browse repository at this point
Copy the full SHA fec460cView commit details -
Configuration menu - View commit details
-
Copy full SHA for b70b26f - Browse repository at this point
Copy the full SHA b70b26fView commit details -
Configuration menu - View commit details
-
Copy full SHA for 77bddd7 - Browse repository at this point
Copy the full SHA 77bddd7View commit details -
Configuration menu - View commit details
-
Copy full SHA for 3a039d6 - Browse repository at this point
Copy the full SHA 3a039d6View commit details -
rand: only try and use freeifaddrs if available
# Conflicts: # src/randomenv.cpp
Configuration menu - View commit details
-
Copy full SHA for 414f405 - Browse repository at this point
Copy the full SHA 414f405View commit details -
Configuration menu - View commit details
-
Copy full SHA for e906436 - Browse repository at this point
Copy the full SHA e906436View commit details -
Configuration menu - View commit details
-
Copy full SHA for d9f67da - Browse repository at this point
Copy the full SHA d9f67daView commit details -
Use secure.h header for secure allocators
PIVX-Project#2276 split the `allocators.h` header and has been merged
Configuration menu - View commit details
-
Copy full SHA for cecbf6c - Browse repository at this point
Copy the full SHA cecbf6cView commit details