-
Notifications
You must be signed in to change notification settings - Fork 182
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
cpu: Have "rdrand" feature take precedence over "custom" #150
Conversation
Right now, features are always enabled across all targets. This means that if _any_ Custom RNG is used _anywhere_ in a crate's dependancy graph on _any_ target. The "custom" feature will be active on all targets. This makes it impossible to have a bare metal target that uses "cpu" on x86_64 and a Custom RNG on aarch64. This solution also makes sure that any implementation `getrandom` itself provides cannot be overridden. Signed-off-by: Joe Richey <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I would prefer to move CPU randomness into a custom crate, assuming you'll find the approach proposed here viable.
Strictly speaking adding ARM support would require bumping getrandom
's MSRV, which is not ideal. Yes, we could say that it's fine, since majority of the users will not be affected, but having the functionality in a separate crate would allow us more flexibility (e.g. we could bump getrandom-cpu
version independently from getrandom
) and would solve the issue as well.
@dhardy
Thoughts?
I agree that CPU-based RNG would ideally just use the custom RNG mechanism. In fact, I think this makes more sense than having the We need the rdrand implementation for SGX, so having a separate crate poses issues regarding out-of-tree modules and code duplication. After thinking about this some more (and incorporating your feedback), I have two proposals: Proposal 1: Just rename the feature to
|
Sounds good. |
Done, let me know what you think. I updated the PR description. I didn't update the docs, I'm going to do all of that in #135 |
Signed-off-by: Joe Richey <[email protected]>
Right now, features are always enabled across all targets. This means
that if any Custom RNG is used anywhere in a crate's dependancy
graph on any target. The "custom" feature will be active on all
targets.
This old code made it impossible to have a bare metal target that uses "rdrand" on
x86_64 and a Custom RNG on aarch64. This change fixes this issue, and makes
sure that any implementation
getrandom
itself provides cannot be overridden.I proposed the old precedence order in #84 (comment), but I think part of that was a mistake, given how Cargo treats features.
This also renames the "cpu" feature to "rdrand". While other CPU architectures have RNG intrinsic, they can behave differently than x86's, so it doesn't make sense to group them.
Signed-off-by: Joe Richey [email protected]