fn create_rdrand_seed() -> [u8; SEED_BYTES] {
    let mut rng = [0; SEED_BYTES];
    let mut have_seeded = false;
    #[cfg(target_arch = "x86_64")]
    {
        if CpuId::new().get_feature_info().unwrap().has_rdrand() {
            for i in 0..SEED_BYTES / 8 {
                // We get 8 bytes at a time from rdrand instruction
                let rand: u64;
                unsafe {
                    llvm_asm!("rdrand rax"
                    : "={rax}"(rand)
                    :
                    :
                    : "intel", "volatile");
                }

                rng[i * 8..(i * 8 + 8)].copy_from_slice(&rand.to_le_bytes());
            }
            have_seeded = true;
        }
    } // TODO integrate alternative entropy sources
    if !have_seeded {
        println!("randd: Seeding failed, no entropy source.  Random numbers on this platform are NOT SECURE");
    }
    rng
}
/// Create a true random seed for the RNG from the Intel x64 rdrand instruction if present.
/// Will seed with a zero (insecure) if rdrand not present.
Create a true random seed for the RNG from the Intel x64 rdrand instruction if present.
Will seed with a zero (insecure) if rdrand not present.
Create a true random seed for the RNG from the Intel x64 rdrand instruction if present . Will seed with a zero ( insecure ) if rdrand not present .
fn create_rdrand_seed() -> [u8; SEED_BYTES] {
    let mut rng = [0; SEED_BYTES];
    let mut have_seeded = false;
    #[cfg(target_arch = "x86_64")]
    {
        if CpuId::new().get_feature_info().unwrap().has_rdrand() {
            for i in 0..SEED_BYTES / 8 {
                // We get 8 bytes at a time from rdrand instruction
                let rand: u64;
                unsafe {
                    llvm_asm!("rdrand rax"
                    : "={rax}"(rand)
                    :
                    :
                    : "intel", "volatile");
                }
                rng[i * 8..(i * 8 + 8)].copy_from_slice(&rand.to_le_bytes());
            }
            have_seeded = true;
        }
    } // TODO integrate alternative entropy sources
    if !have_seeded {
        println!("randd: Seeding failed, no entropy source.  Random numbers on this platform are NOT SECURE");
    }
    rng
}
fn create_rdrand_seed ( ) -> [ u8 ; SEED_BYTES ] { let mut rng = [ 0 ; SEED_BYTES ] ; let mut have_seeded = false ; # [ cfg ( target_arch " " ) ] { if CpuId :: new ( ) . get_feature_info ( ) . unwrap ( ) . has_rdrand ( ) { for i in 0 .. SEED_BYTES / 8 { // We get 8 bytes at a time from rdrand instruction let rand : u64 ; unsafe { llvm_asm ! ( " " " " ( rand ) " " " " ) ; } rng [ i * 8 .. ( i * 8 + 8 ) ] . copy_from_slice ( & rand . to_le_bytes ( ) ) ; } have_seeded = true ; } } // TODO integrate alternative entropy sources if ! have_seeded { println ! ( " " ) ; } rng }
Create a true random seed for the RNG from the Intel x64 rdrand instruction if present.
Create a true random seed for the RNG from the Intel x64 rdrand instruction if present .