-
Notifications
You must be signed in to change notification settings - Fork 670
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
rand_core::RngCore & CryptoRng support for CryptoProvider #1853
Comments
I avoided the I chose not to pass the random provider down to lower level primitives because:
One option you have is having interior mutability inside whatever struct that |
I'm not sure I really understand what problem it is you're describing. None of the rustls |
Yes this is what we need for doing key exchange at CryptoProvider but it's not there sadly 😿 x25519 ECDHE key exchange requires randomness that is used by EphemeralSecret and we need to pass source of randomness to the x25519-dalek library from within the CryptoProvider which would not know where to pull that randomness e.g. in a wasm virtual machine - unless it is implemented in the primitive level itself which is not going to happen as this would require supporting all the different types of sources of randomness if every given possible platform.
Could this be an optional feature ? for any primitive that supports optionally be given randomness from rustls that was passed to it by the provider believing the randomness source is the preferred one - given the provider also was responsible for selecting the used primitive in the first place ?
These primitives are very low level and requiring interior mutability w/ Send + Sync as CryptoProvider is would require Mutex etc that are not available in no_std core due to this requiring the operating system - crypto primitives typically don't know much about operating systems at least in rustcrypto ecosystem. We could implement the Mutex etc. at CryptoProvider but then again we'll bring std there when we are trying to aim the CryptoProvider for all environments which may not have operating system.
fips was still optional ? is the requirement for a provider to be fips compliant ? rsa crate has interface for CryptoRng. Also if the interface uses to get the optional randomness then the provider could be marked as fips()==false marker |
Disclaimer: I am a member of the
Please raise these issues in the I can understand why you may feel this way about the whole
In the next breaking release Now, as for Finally,
So you just want to distinguish between fallible and infallible RNGs at compile time? I think it can be easily amended by introducing a new marker trait for "infallible" RNGs. But I am not sure how useful it would be in practice for |
Just on this point: FIPS140 (validation and certification of cryptographic modules) is a different standard to FIPS186 (digital signatures). rustls doesn't, won't and can't require that a given RSA implementation adheres to any particular standard. But my point wasn't to discuss issues with the |
For somebody else finding this problem - hope this saves some research time in the future searching this issue: There is getrandom::register_custom_getrandom macro that can be used to provide custom getrandom at bin-level ring's less-safe-getrandom-drand with with target_os = "none" may provide some reference as well. Supporting the trait would be nice but I'll check the testing around using the macro sans plain build-target only CI test. Since the answer is no here I'll just close - thanks for your time in any case evaluating the proposal ❤️ |
Thanks for filing the issue and following up with the workaround you arrived at 👍 |
Checklist
Is your feature request related to a problem? Please describe.
Low level cryptography primitives, e.g. x25519-dalek::EphemeralSecret constructors expect to be provided a CryptoRng impl
This was made so no_std environments can provide their own chosen randomness, e.g. wasm32-unknown-unknown with a runtime that has a virtual machine that provides source of secure randomness that can be presented via CryptoRng trait.
Lower level crypto primitives have started pulling the rand_core trait so different random implementations don't need to be supported at lower level primitive.
Meanwhile SecureRandom is neither accessible within the interface to lower level primitives within CryptoProvider:
Lower level primitives don't generally offer a lot of choice when it comes to source of randomness leading to limited platform support where the primitive can be used unless it is provided the appropriate source of randomness.
Describe the solution you'd like
Ideally it would be great of rustls relays rand_core::CryptoRng that implements several methods over tls::SecureRandom for crypto primitive use that can be used to pass the primitives within ecosystem which expects this trait implementation.
Describe alternatives you've considered
I thought about using slow getrandom = ["custom"] - primitives I'm dealing with use rand_core::OsRng when constructor is called with rand_core/getrandom feature
Also thought about storing a state within the wrapper provider struct but then it leads to complications of navigating
Arc<Mutex<>>
landscape (which typically also requires std) which should be left to runtimes which may not implement threading etc. permutations involved.Additional context
The text was updated successfully, but these errors were encountered: