-
-
Notifications
You must be signed in to change notification settings - Fork 440
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
Let rand::rng()
use OsRng
unless thread_rng
is enabled?
#1545
Comments
Personally, I would be somewhat surprised by such behavior, so I lean slightly against it. Though, it's not a strong opinion, so I would be fine with such change. |
FWIW IMO All features should be deterministic & additive where it should not change behavior of any surface under the hood. This can cause issues if someone is expecting explicit rng and is given another instead when there is another transient crate can change the behavior for another given there is no bifurcation of features. We went through quite an exercise here between features and cfg's:
I personally would like explicit selections and nothing else - or at least deterministic overides - given it only takes one single transient dependency to change the global behaviour - given the features do not bifurcate between the crates. Also with say |
In this case, the behaviour change would be mostly unobservable which is the only reason I would consider it. Nevertheless, it is possibly observable through side-effects:
The only purpose I think would be to reduce code and state size where some code in a dependency uses |
FIPS causes potentially a complication here given it dictates that cryptography library must choose explicitly which Rng it uses. I hit this problem when trying to motivate rustls to adopt CryptoRng via it's CryptoProvider API. However on another side composable cryptography primitives don't care about the environment unlike monolithic libraries like OpenSSL rustls etc. which make an opinion which one to use. @tarcieri might have informed take on this. |
ThreadRng
adds some thread-local memory. In case not all users want this, we could add athread_rng
feature flag (probably default-enabled).Where the
thread_rng
feature is not enabled,rand::rngs::ThreadRng
would not be available.rand::rng()
would instead useOsRng
(assuming thatgetrandom
is available), thusthread_rng
would mostly be a performance boost (at the cost of extra code and thread-local memory).The text was updated successfully, but these errors were encountered: