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: Remove checking for 0 and !0 and instead check CPU family and do a self-test #335

Merged
merged 6 commits into from Feb 9, 2023

Conversation

josephlr
Copy link
Member

@josephlr josephlr commented Feb 2, 2023

Fixes #228

This is essentially the plan discussed in #228 (comment)

I changed the rdrand function to return Option<u64> as that makes reusing it in the self-test much nicer.

The main complexity here comes from:

  • Checking if the CPU is AMD with family < 0x17
  • Performing the self test. See the Linux implementation

There are also some minor commits which:

src/rdrand.rs Outdated Show resolved Hide resolved
src/rdrand.rs Outdated Show resolved Hide resolved
The flag name is +rdrand not +rdrnd

Signed-off-by: Joe Richey <joerichey@google.com>
Also makes rdrand() return an integer instead of an array of bytes. This
will make the self-test implementation easier. As we can just return a
`usize` we no longer need the `WORD_SIZE` constant.

Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
We could use core::usize::MAX, but that is deprecated.

Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
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 this pull request may close these issues.

RDRAND-based output is (too) biased
2 participants