[][src]Struct rdrand::RdRand

pub struct RdRand(_);

A cryptographically secure statistically uniform, non-periodic and non-deterministic random bit generator.

Note that this generator may be implemented using a deterministic algorithm that is reseeded routinely from a non-deterministic entropy source to achieve the desirable properties.

This generator is a viable replacement to any generator, however, since nobody has audited Intel or AMD hardware yet, the usual disclaimers as to their suitability apply.

It is potentially faster than OsRng, but is only supported on more recent Intel (Ivy Bridge and later) and AMD (Ryzen and later) processors.

Methods

impl RdRand[src]

pub fn new() -> Result<Self, Error>[src]

Create a new instance of the random number generator.

This constructor checks whether the CPU the program is running on supports the instruction necessary for this generator to operate. If the instruction is not supported, an error is returned.

pub fn try_next_u16(&self) -> Option<u16>[src]

Generate a single random u16 value.

The underlying instruction may fail for variety reasons (such as actual hardware failure or exhausted entropy), however the exact reason for the failure is not usually exposed.

This method will retry calling the instruction a few times, however if all the attempts fail, it will return None.

In case None is returned, the caller should assume that an non-recoverable hardware failure has occured and use another random number genrator instead.

pub fn try_next_u32(&self) -> Option<u32>[src]

Generate a single random u32 value.

The underlying instruction may fail for variety reasons (such as actual hardware failure or exhausted entropy), however the exact reason for the failure is not usually exposed.

This method will retry calling the instruction a few times, however if all the attempts fail, it will return None.

In case None is returned, the caller should assume that an non-recoverable hardware failure has occured and use another random number genrator instead.

pub fn try_next_u64(&self) -> Option<u64>[src]

Generate a single random u64 value.

The underlying instruction may fail for variety reasons (such as actual hardware failure or exhausted entropy), however the exact reason for the failure is not usually exposed.

This method will retry calling the instruction a few times, however if all the attempts fail, it will return None.

In case None is returned, the caller should assume that an non-recoverable hardware failure has occured and use another random number genrator instead.

Note, that on 32-bit targets, there’s no underlying instruction to generate a 64-bit number, so it is emulated with the 32-bit version of the instruction.

Trait Implementations

impl Clone for RdRand[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Copy for RdRand[src]

impl CryptoRng for RdRand[src]

impl RngCore for RdRand[src]

fn next_u32(&mut self) -> u32[src]

Generate a single random u32 value.

The underlying instruction may fail for variety reasons (such as actual hardware failure or exhausted entropy), however the exact reason for the failure is not usually exposed.

Panic

This method will retry calling the instruction a few times, however if all the attempts fail, it will panic.

In case panic occurs, the caller should assume that an non-recoverable hardware failure has occured and use another random number genrator instead.

fn next_u64(&mut self) -> u64[src]

Generate a single random u64 value.

The underlying instruction may fail for variety reasons (such as actual hardware failure or exhausted entropy), however the exact reason for the failure is not usually exposed.

Note, that on 32-bit targets, there’s no underlying instruction to generate a 64-bit number, so it is emulated with the 32-bit version of the instruction.

Panic

This method will retry calling the instruction a few times, however if all the attempts fail, it will panic.

In case panic occurs, the caller should assume that an non-recoverable hardware failure has occured and use another random number genrator instead.

fn fill_bytes(&mut self, dest: &mut [u8])[src]

Fill a buffer dest with random data.

See try_fill_bytes for a more extensive documentation.

Panic

This method will panic any time try_fill_bytes would return an error.

fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Error>[src]

Fill a buffer dest with random data.

This method will use the most appropriate variant of the instruction available on the machine to achieve the greatest single-core throughput, however it has a slightly higher setup cost than the plain next_u32 or next_u64 methods.

The underlying instruction may fail for variety reasons (such as actual hardware failure or exhausted entropy), however the exact reason for the failure is not usually exposed.

This method will retry calling the instruction a few times, however if all the attempts fail, it will return an error.

If an error is returned, the caller should assume that an non-recoverable hardware failure has occured and use another random number genrator instead.

Auto Trait Implementations

impl Send for RdRand

impl Sync for RdRand

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.