-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
QSP-6: Enforces crypto-secure PRNGs #6401
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
farazdagi
changed the title
QSP-6: Adds cryptorand analyzer
QSP-6: Enforces crypto-secure PRNGs
Jun 26, 2020
nisdas
previously approved these changes
Jun 26, 2020
Codecov Report
@@ Coverage Diff @@
## master #6401 +/- ##
==========================================
+ Coverage 60.07% 61.37% +1.30%
==========================================
Files 323 349 +26
Lines 27422 28741 +1319
==========================================
+ Hits 16473 17639 +1166
- Misses 8733 8745 +12
- Partials 2216 2357 +141 |
rauljordan
approved these changes
Jun 26, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent PR and thank you for the comprehensive explanation. Having a shared rand package enforced is great as it helps us keep control of how things work.
61 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Feature/Enforces Strong Crypto
What does this PR do? Why is it needed?
math/rand
API (which is convenient)github.com/pryam/shared/rand
(drop-in replacement formath/rand
)Which issues(s) does this PR fix?
Part of #6327
Other notes for review
Tool will not allow any packages ending in "/rand", except for "prysm/shared/rand":
Tool is capable of handling aliased imports, if you import as
mrand "math/rand"
and use as, for instance,mrand.Intn(32)
(instead ofrand.Intn(32)
) - analyser will be able to catch that code too!Normally, no rand related code is expected to be imported directly: no imports of
math/rand
,golang.org/x/exp/rand
, or evencrypto/rand
. Generators must be instantiated via/shared/rand/rand.NewGenerator()
(or, occasionally, when you know what you are doing via/shared/rand/rand.NewDetermenisticGenerator()
.In tests, no enforcement is done -- one can use any source of randomness.
Extra (for brave and curious)
Rationale of defining a new package, directly from
github.com/prysm/shared/rand
package docs:Package rand defines methods of obtaining cryptographically secure random number generators.
One is expected to use randomness from this package only, without introducing any other packages.
This limits the scope of code that needs to be hardened.
There are two modes, one for deterministic and another non-deterministic randomness:
In this mode, only seed is generated using cryptographically secure source (crypto/rand). So,
once seed is obtained, and generator is seeded, the next generations are deterministic, thus fast.
This method is still better than using unix time for source of randomness - since time is not a
good source of seed randomness, when you have many concurrent servers using it (and they have
coinciding random generators' start times).
Again, any of the functions from
math/rand
can be used, however, they all use custom sourceof randomness (crypto/rand), on every step. This makes randomness non-deterministic. However,
you take a performance hit -- as it is an order of magnitude slower.