2019-02-11 04:23:21 +09:00
|
|
|
use crate::io;
|
|
|
|
|
use crate::mem;
|
|
|
|
|
use crate::sys::c;
|
2016-02-17 13:56:16 -08:00
|
|
|
|
2019-05-27 16:41:52 +02:00
|
|
|
#[cfg(not(target_vendor = "uwp"))]
|
2017-11-01 12:32:13 -07:00
|
|
|
pub fn hashmap_random_keys() -> (u64, u64) {
|
|
|
|
|
let mut v = (0, 0);
|
|
|
|
|
let ret = unsafe {
|
|
|
|
|
c::RtlGenRandom(&mut v as *mut _ as *mut u8,
|
|
|
|
|
mem::size_of_val(&v) as c::ULONG)
|
|
|
|
|
};
|
|
|
|
|
if ret == 0 {
|
|
|
|
|
panic!("couldn't generate random bytes: {}",
|
|
|
|
|
io::Error::last_os_error());
|
2016-02-17 13:56:16 -08:00
|
|
|
}
|
2019-09-05 13:30:30 +02:00
|
|
|
v
|
2016-02-17 13:56:16 -08:00
|
|
|
}
|
2019-05-27 16:41:52 +02:00
|
|
|
|
|
|
|
|
#[cfg(target_vendor = "uwp")]
|
|
|
|
|
pub fn hashmap_random_keys() -> (u64, u64) {
|
|
|
|
|
use crate::ptr;
|
|
|
|
|
|
|
|
|
|
let mut v = (0, 0);
|
|
|
|
|
let ret = unsafe {
|
|
|
|
|
c::BCryptGenRandom(ptr::null_mut(), &mut v as *mut _ as *mut u8,
|
|
|
|
|
mem::size_of_val(&v) as c::ULONG,
|
|
|
|
|
c::BCRYPT_USE_SYSTEM_PREFERRED_RNG)
|
|
|
|
|
};
|
|
|
|
|
if ret != 0 {
|
|
|
|
|
panic!("couldn't generate random bytes: {}",
|
|
|
|
|
io::Error::last_os_error());
|
|
|
|
|
}
|
|
|
|
|
return v
|
|
|
|
|
}
|