torproject / tor Public
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
Fast rng #685
Closed
Closed
Fast rng #685
Conversation
Using an anonymous mmap() is a good way to get pages that we can set kernel-level flags on, like minherit() or madvise() or mlock(). We're going to use that so that we can make uninheritable locked pages to store PRNG data.
I don't know how this got here, but this kind of a wrapper only belongs in a header file.
Some of the code for getting a random value within a range wants to be shared between crypto_rand() and the new crypto_fast_rng() code.
This is the second part of refactoring the random-int-in-range code.
test_crypto.c is pretty big; it wouldn't hurt to split it up some more before I start adding stuff to the PRNG tests.
This module is currently implemented to use the same technique as libottery (later used by the bsds' arc4random replacement), using AES-CTR-256 as its underlying stream cipher. It's backtracking- resistant immediately after each call, and prediction-resistant after a while. Here's how it works: We generate psuedorandom bytes using AES-CTR-256. We generate BUFLEN bytes at a time. When we do this, we keep the first SEED_LEN bytes as the key and the IV for our next invocation of AES_CTR, and yield the remaining BUFLEN - SEED_LEN bytes to the user as they invoke the PRNG. As we yield bytes to the user, we clear them from the buffer. Every RESEED_AFTER times we refill the buffer, we mix in an additional SEED_LEN bytes from our strong PRNG into the seed. If the user ever asks for a huge number of bytes at once, we pull SEED_LEN bytes from the PRNG and use them with our stream cipher to fill the user's request.
Pull Request Test Coverage Report for Build 3798
|
asn-d6
reviewed
Feb 13, 2019
asn-d6
reviewed
Feb 13, 2019
asn-d6
reviewed
Feb 13, 2019
asn-d6
reviewed
Feb 13, 2019
asn-d6
reviewed
Feb 13, 2019
asn-d6
reviewed
Feb 13, 2019
asn-d6
reviewed
Feb 13, 2019
asn-d6
reviewed
Feb 13, 2019
Explain why crypto_rand_int doesn't call IMPLEMENT_RAND_UNSIGNED() directly.
Fix a typo.
Clarify RESEED_AFTER.
Use a symbolic value instead of 4 in the definition of BUFLEN
Clarify that "seed" means "key and IV" in a few more comments.
Use KEY_BITS.
Rename a variable in crypto_fast_rng_getbytes_impl(); add an assert. [I've verified that for me the assert doesn't slow us down.]
|
making a new squashed PR |
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.
No description provided.
The text was updated successfully, but these errors were encountered: