Skip to content
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

rdrand implementation should enable the feature itself #27

Closed
nagisa opened this issue Jun 10, 2019 · 3 comments · Fixed by #30
Closed

rdrand implementation should enable the feature itself #27

nagisa opened this issue Jun 10, 2019 · 3 comments · Fixed by #30

Comments

@nagisa
Copy link

nagisa commented Jun 10, 2019

Current implementation of rdrand code fails to compile if the user does not enable the rdrand feature during compilation. Instead, the code should enable the feature for the relevant portions of the code itself with #[target_feature(enable="rdrand")].

@newpavlov
Copy link
Member

newpavlov commented Jun 10, 2019

I believe the current approach is correct (although indeed somewhat inconvenient). If you enable target feature for part of the code, you should make sure via runtime checks that it will not be called on platforms without used target feature(s) support.

We could add runtime detection and return error if RDRAND is not supported, but CPUID is not a cheap instruction and IIRC all currently existing SGX-capable platforms support RDRAND. How about proposing rdrand target feature (and maybe others?) to be enabled by default for SGX target?

@josephlr
Copy link
Member

So right now the only supported rust target that would use getrandom's RDRAND implementation is x86_64-fortanix-unknown-sgx which does have the rdrand feature enabled.

However, if we want to have this implementation also run on platforms with target_os = "uefi" or target_os = "none", then we would need a check for RDRAND support (i.e. calling CPUID exactly once if the target doesn't have the rdrand feature).

@newpavlov
Copy link
Member

if we want to have this implementation also run on platforms with target_os = "uefi" or target_os = "none", then we would need a check for RDRAND support

I am not familiar with uefi targets, but shouldn't we use EFI_RNG_ALGORITHM_RAW instead of RDRAND? Plus don't forget about #4, applications which target exotic platforms or want some special source of randomness can just overwrite getrandom.

Since right now only SGX uses RDRAND and rdrand target feature is already enabled by default, I think we should leave everything as-is and discuss how to handle future targets separately after their introduction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants