forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented rdrand and rdseed intrinsics (rust-lang#326)
* implemented rdrand and rdseed intrinsics * added "unsigned short*" case * moved rdrand from i686 to x86_64 * 64 bit rdrand functions in x86_64, 16 and 32 in i686
- Loading branch information
1 parent
d0a6c2c
commit dacb3c2
Showing
6 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
mod aes; | ||
pub use self::aes::*; | ||
|
||
mod rdrand; | ||
pub use self::rdrand::*; | ||
|
||
mod mmx; | ||
pub use self::mmx::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! RDRAND and RDSEED instructions for returning random numbers from an Intel | ||
//! on-chip hardware random number generator which has been seeded by an on-chip | ||
//! entropy source. | ||
extern "platform-intrinsic" { | ||
fn x86_rdrand16_step() -> (u16, i32); | ||
fn x86_rdrand32_step() -> (u32, i32); | ||
fn x86_rdseed16_step() -> (u16, i32); | ||
fn x86_rdseed32_step() -> (u32, i32); | ||
} | ||
|
||
#[cfg(test)] | ||
use stdsimd_test::assert_instr; | ||
|
||
/// Read a hardware generated 16-bit random value and store the result in val. | ||
/// Return 1 if a random value was generated, and 0 otherwise. | ||
#[inline] | ||
#[target_feature(enable = "rdrand")] | ||
#[cfg_attr(test, assert_instr(rdrand))] | ||
pub unsafe fn _rdrand16_step(val: &mut u16) -> i32 { | ||
let (v, flag) = x86_rdrand16_step(); | ||
*val = v; | ||
flag | ||
} | ||
|
||
/// Read a hardware generated 32-bit random value and store the result in val. | ||
/// Return 1 if a random value was generated, and 0 otherwise. | ||
#[inline] | ||
#[target_feature(enable = "rdrand")] | ||
#[cfg_attr(test, assert_instr(rdrand))] | ||
pub unsafe fn _rdrand32_step(val: &mut u32) -> i32 { | ||
let (v, flag) = x86_rdrand32_step(); | ||
*val = v; | ||
flag | ||
} | ||
|
||
/// Read a 16-bit NIST SP800-90B and SP800-90C compliant random value and store | ||
/// in val. Return 1 if a random value was generated, and 0 otherwise. | ||
#[inline] | ||
#[target_feature(enable = "rdseed")] | ||
#[cfg_attr(test, assert_instr(rdseed))] | ||
pub unsafe fn _rdseed16_step(val: &mut u16) -> i32 { | ||
let (v, flag) = x86_rdseed16_step(); | ||
*val = v; | ||
flag | ||
} | ||
|
||
/// Read a 32-bit NIST SP800-90B and SP800-90C compliant random value and store | ||
/// in val. Return 1 if a random value was generated, and 0 otherwise. | ||
#[inline] | ||
#[target_feature(enable = "rdseed")] | ||
#[cfg_attr(test, assert_instr(rdseed))] | ||
pub unsafe fn _rdseed32_step(val: &mut u32) -> i32 { | ||
let (v, flag) = x86_rdseed32_step(); | ||
*val = v; | ||
flag | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,3 +37,6 @@ pub use self::avx2::*; | |
|
||
mod bswap; | ||
pub use self::bswap::*; | ||
|
||
mod rdrand; | ||
pub use self::rdrand::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//! RDRAND and RDSEED instructions for returning random numbers from an Intel | ||
//! on-chip hardware random number generator which has been seeded by an on-chip | ||
//! entropy source. | ||
extern "platform-intrinsic" { | ||
fn x86_rdrand64_step() -> (u64, i32); | ||
fn x86_rdseed64_step() -> (u64, i32); | ||
} | ||
|
||
#[cfg(test)] | ||
use stdsimd_test::assert_instr; | ||
|
||
/// Read a hardware generated 64-bit random value and store the result in val. | ||
/// Return 1 if a random value was generated, and 0 otherwise. | ||
#[inline] | ||
#[target_feature(enable = "rdrand")] | ||
#[cfg_attr(test, assert_instr(rdrand))] | ||
pub unsafe fn _rdrand64_step(val: &mut u64) -> i32 { | ||
let (v, flag) = x86_rdrand64_step(); | ||
*val = v; | ||
flag | ||
} | ||
|
||
/// Read a 64-bit NIST SP800-90B and SP800-90C compliant random value and store | ||
/// in val. Return 1 if a random value was generated, and 0 otherwise. | ||
#[inline] | ||
#[target_feature(enable = "rdseed")] | ||
#[cfg_attr(test, assert_instr(rdseed))] | ||
pub unsafe fn _rdseed64_step(val: &mut u64) -> i32 { | ||
let (v, flag) = x86_rdseed64_step(); | ||
*val = v; | ||
flag | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters