-
Notifications
You must be signed in to change notification settings - Fork 2
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
Auto-seeded randomness: thread_rng
, weak_rng
, random()
#23
Comments
Good overview.
What would the use be? I can only see performance as a reason. It seems to me there are better options than going down that route. If / when we get support for PCG streams and jumping could be good solutions to get a separate rng quickly from an existing one. An other is to initialize a cryptographic rng once, and use that to initialize others. If someone really has a need for this, it could also be part of an external crate. That seems better to me, as anything I would not mind removing
There has been some discussion that maybe it should be. Would ChaCha with fewer rounds be a possible replacement?
If we end up with something that works well, it could potentially be useful for As a note about fallback generators: RDRAND could be useful here too. |
Then you and I are both surprised by @alexcrichton merging rust-random#181. |
@dhardy oh sorry I thought you were already ok with it! If you're worried about that I'm ok reverting |
The question really is are people using |
I would be happy with something stronger too. As discussed in #21 (comment) something based on jitterentropy-library may be even better. I now have a rust implementation of that mostly ready. The C code is translated, assembly looks sufficiently non-optimized, and PractRand is happy with the results. It still needs some better comments and documentation, a few statistical test (from older versions of jitterentropy), and a bit more detailed errors. If there is not a great hurry, maybe that is a better option. |
@dhardy oh I was basing it off https://docs.rs/rand/0.3.17/rand/#cryptographic-security which states:
|
That's the intended way of obtaining secure entropy @alexcrichton; that doesn't mean people always read the instructions. That plus potential DoS attacks on |
True! I'm not sure how else it's possible to fix rust-random#180 though? |
Leave it as is for now @alexcrichton; we'll open a new PR when we have a stronger candidate. I don't think there's any other strategy available (other than don't fix). |
@pitdicker now that |
Yes, we promised to try and improve upon that. I suppose that we can't just merge this whole branch in I will be careful with credit for others, but don't mind it much for myself. This is just for fun. And it seems you did about as much work around this code as I did ;-). If you want to make a pr feel free, otherwise I will prepare one this weekend. |
Ok, I'll probably look at that tomorrow. No, I don't think we can just merge the whole branch. There's still some work to finish the |
I don't think this is useful any more; we have |
The
rand
crate currently has:weak_rng()
— seeds a newXorShiftRng
fromOsRng
on each callthread_rng()
— initialises a per-thread ISAAC generator fromOsRng
on first call and returns a referencerandom()
— convenience wrapper aroundthread_rng()
OsRng::new()
— unlike other generators, can be created directly since it uses external entropyBut what do we want to provide? In terms of entropy:
OsRng
OsRng
or a fallback for cases where entropy is still important but not critical (stuff likeHashMap
which might possibly be open to a DoS attack or randomised algorithms)In terms of convenient random numbers it gets more complicated, because we potentially have a matrix of entropy vs speed and memory requirements, via a thread-local generator or a fresh generator. But most importantly:
OsRng
)OsRng
or fallback)ClockRng
or some such)thread_rng
The existing
weak_rng()
really satisfies only one variant of the last case, and personally I see little justification for keeping it over something likeSmallFastRng::from_rng(reliable_entropy())
. On the other hand, one shouldn't useSmallFastRng
directly for deterministic generation (since the underlying generator may change), soSmallFastRng::from_rng(reliable_entropy())
appears to be the only use-case.The existing
StdRng
is in a similar position: it shouldn't be used for reproducibility, hence its only real use is the currentthread_rng()
.To do:
weak_rng
+thread_rng
+ direct access to entropy generators sufficient?thread_rng
is not for cryptography)?The text was updated successfully, but these errors were encountered: