Page MenuHomePhabricator

Switch all RNG code to the built-in PRNG.
ClosedPublic

Authored by nakihito on Tue, Nov 5, 23:01.

Details

Reviewers
deadalnix
Fabien
jasonbcox
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Restricted Project
Commits
rABC478736a84541: Switch all RNG code to the built-in PRNG.
Summary

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().

Partial backport of Core PR14955
https://github.com/bitcoin/bitcoin/pull/14955/commits/9d7032e4f066777c97c58b1394884716e213790a

Depends on D4394

Test Plan
make check
test_runner.py

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

nakihito created this revision.Tue, Nov 5, 23:01
Owners added a reviewer: Restricted Owners Package.Tue, Nov 5, 23:01
Herald added a reviewer: Restricted Project. · View Herald TranscriptTue, Nov 5, 23:01
Fabien added a comment.Wed, Nov 6, 09:26

You may want to run builds (and ideally tests) on some other platforms, as this code embeds platform-dependent behavior.

nakihito added a comment.Thu, Nov 7, 19:07

You may want to run builds (and ideally tests) on some other platforms, as this code embeds platform-dependent behavior.

I don't have a machine to do this on.

Fabien accepted this revision.Fri, Nov 8, 07:44
Fabien added inline comments.
src/random.cpp
404 ↗(On Diff #13947)

Braces

This revision is now accepted and ready to land.Fri, Nov 8, 07:44
nakihito updated this revision to Diff 13993.Fri, Nov 8, 16:09

Rebased and added braces.