Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
getrandom
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
felixmoebius
getrandom
Commits
5b567346
Commit
5b567346
authored
5 years ago
by
Joseph Richey
Committed by
Artyom Pavlov
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Check for AMD RDRAND bug (#43)
parent
11eefaaa
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/rdrand.rs
+9
-2
9 additions, 2 deletions
src/rdrand.rs
with
9 additions
and
2 deletions
src/rdrand.rs
+
9
−
2
View file @
5b567346
...
...
@@ -23,6 +23,13 @@ unsafe fn rdrand() -> Result<[u8; WORD_SIZE], Error> {
for
_
in
0
..
RETRY_LIMIT
{
let
mut
el
=
mem
::
uninitialized
();
if
_rdrand64_step
(
&
mut
el
)
==
1
{
// AMD CPUs from families 14h to 16h (pre Ryzen) will sometimes give
// bogus random data. Discard these values and warn the user.
// See https://github.com/systemd/systemd/issues/11810#issuecomment-489727505
if
cfg!
(
not
(
target_env
=
"sgx"
))
&&
(
el
==
0
||
el
==
!
0
)
{
error!
(
"RDRAND returned suspicious value {}, CPU RNG is broken"
,
el
);
return
Err
(
Error
::
UNKNOWN
)
}
return
Ok
(
el
.to_ne_bytes
());
}
}
...
...
@@ -36,14 +43,14 @@ compile_error!(
"SGX targets require 'rdrand' target feature. Enable by using -C target-feature=+rdrnd."
);
#[cfg(
any(target_env
=
"sgx"
,
target_feature
=
"rdrand"
)
)
]
#[cfg(target_feature
=
"rdrand"
)]
fn
is_rdrand_supported
()
->
bool
{
true
}
// TODO use is_x86_feature_detected!("rdrand") when that works in core. See:
// https://github.com/rust-lang-nursery/stdsimd/issues/464
#[cfg(not(
any(target_env
=
"sgx"
,
target_feature
=
"rdrand"
))
)
]
#[cfg(not(target_feature
=
"rdrand"
))]
fn
is_rdrand_supported
()
->
bool
{
use
core
::
arch
::
x86_64
::
__cpuid
;
use
lazy_static
::
lazy_static
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment