-
Notifications
You must be signed in to change notification settings - Fork 432
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
Add a feature flag to OsRng to allow use of RDRAND on modern systems #410
Comments
How did you manage to make your hyperlink link back to this same issue? RDRAND support of some kind is something we want (maybe in Rand or maybe outside); @nagisa is working on a separate crate for that. I'm less convinced about making
We could instead let There are some other things we could use RDRAND for but they're beyond the scope of |
@dhardy
I can buy that, although I'd suggest we want to make it very clear that Strictly speaking, Intel suggests we use I do understand the hesitation in using an opaque random number generator from what some would perceive to be an untrustworthy source. However, there are now two sources - Intel and AMD.
Not sure I buy that; that's more a limitation of the platform.
Both of those would work the use cases I've experienced, although I think |
Ultimately I'm not sure if we do want
There has been some push to make So possibly just adding a
That's what
Plus several ARM chips, plus the PowerPC you mentioned — but we need to trust all of these to trust RDRAND, not just one of them, which is very good motivation for not using it for important keys. (Granted, this does leave plenty of other uses for RDRAND.)
If an API behaves completely differently on different platforms then it's not a portable API. There's no good reason to relegate platforms without RDRAND to third-rate support. |
Why is this preferable to just using the |
Oh, that's not really what I wanted to imply. Just that if some platforms have a slower random number generator than others, we shouldn't make all platforms slow. My points and yours though do suggest that there needs to be:-
All need to be (perhaps excessively so for some) clear about where they get their randomness and what they are good for and not good for. * Then there's the argument about compile-time coding of a cpu feature vs runtime detection via cpuid. This argument can be solved by deciding what the purpose of such a random number generator is. Is it the high-performance, best-efforts but not quite cryptographically strong, or is it as a fallback for platforms missing a random number generator (eg for |
@vks That crate is X86-specific and used to use runtime detection IIRC |
RDRAND is not that fast. It does provide high-quality random numbers, but both throughput and latency of RDRAND is lower than pretty much anything that’s not a bare
AMD is known to use a ring oscillator as a base for their RDRAND, but nobody has verified that this is exactly what’s implemented in the silicon. This is just something that AMD claims. For Intel it is still unknown what the underlying implementation is, to the best of my knowledge. |
I'm not sure this issue brings anything new to the discussion, and we were already well aware of RDRAND. The real problem seems to be @raphaelcohn that you want a fast RNG, but don't want to thread the state of the RNG through your API and don't want to use thread-local memory. As an alternative you want to use RDRAND can be a good solution in your case, or a custom non-cryptographic RNG that lives in TLS and uses less memory. We already have an issue about the possibility of letting But I don't think a flag to replace |
I was cogniscant of that before posting this issue - I even caveat-ed that in my opening paragraph "I've opened this as a new issue as I think this is something that needs proper tracking." I studied the background as best I could, and took the decision to post it. It may not have been your intention, but this comes across as snippy, and certainly puts me off wanting to engage further.
@pitdicker I mildly disagree. It's shown that the modelling of the different sources of randomness, their usefulness for different tasks, and how they can be consumed, isn't yet particularly to consumers, and that the rand crate doesn't make its prescriptions clear. In particular, it'd be nice to make clearer the purpose of |
I expect the snippiness is caused by stress trying to tie many threads together... I'm sorry if you feel put off from engaging! I don't follow your last paragraph exactly. We are still working on the docs; on the other hand trying to avoid having to use the docs at all is not so simple. Avoiding use of acronyms altogether actually makes it harder to learn/talk about a topic in my experience, although for sure one should avoid using too many acronyms. We will revisit |
Apologies. Yes, you did a good job on finding #109. My remark was not directed at you, but more that this issue is evolving into something touching many different topics that are tracked elsewhere, or are not really things that can change. In a way we already have a tracking issue for what you want, #313. I don't know if you read it, and that of the PR, but I am afraid it won't completely explain the thoughts and problems floating around at the time. Roughly the idea at the moment is that We want to solve another problem at the same time, and that is better support for embedded. So it would be nice if RDRAND is not the only option, but to have it be user-configurable.
It is not an easy subject. We do our best to improve the documentation at the moment, so I hope things are better in the future. Different names are not going to solve everything, there are too many aspects to capture in a reasonable way in just the names. But to come back to the motivation of this issue. I think it is better to focus this issue on finding some solution that helps with your use case, than to talk about possible redesigns of Rand (the past 9 months were already spend on that). I believe @dhardy is playing with the idea of having some sort of light-weight variant of |
It seems there is not really much we can do with this issue.
|
This is related to pull request #109. I've opened this as a new issue as I think this is something that needs proper tracking.
When working with highly concurrent modern data structures, it's often important to be able to pick a (hyper) thread local random number very, very quickly for a small value - a u32 or u64 or usize, for example. The
RDRAND
instruction on Ivy Bridge and later CPUs makes this straightforward, but one then needs a fallback - and therand
crate providesThreadRng
. This, however, eats into thread TLS space (threads aren't necessarily present on low-end platforms), requires initialisation, etc.It'd be far more elegant to have perhaps a create compilation feature, or even better, when
#[cfg(target_feature)]
lands, to be able to have theOsRng
switch over toRDRAND
instead of using a syscall, and then to be able to eliminateThreadRng
set up entirely.RDRAND
is also a preferable source of randomness in early Unix system init, and in systems using#[no_std]
.I've recently created a temporary stop gap crate hyper-thread-random to provide randomness for hyper threads with
RDRAND
and a fallback to ThreadRng, but it seems only logical that all things randomness-related are better 'made at home' in the rand crate.The text was updated successfully, but these errors were encountered: