about summary refs log tree commit diff
path: root/library/std/src/sys/windows/rand.rs
diff options
context:
space:
mode:
authormark <markm@cs.wisc.edu>2020-06-11 21:31:49 -0500
committermark <markm@cs.wisc.edu>2020-07-27 19:51:13 -0500
commit2c31b45ae878b821975c4ebd94cc1e49f6073fd0 (patch)
tree14f64e683e3f64dcbcfb8c2c7cb45ac7592e6e09 /library/std/src/sys/windows/rand.rs
parent9be8ffcb0206fc1558069a7b4766090df7877659 (diff)
downloadrust-2c31b45ae878b821975c4ebd94cc1e49f6073fd0.tar.gz
rust-2c31b45ae878b821975c4ebd94cc1e49f6073fd0.zip
mv std libs to library/
Diffstat (limited to 'library/std/src/sys/windows/rand.rs')
-rw-r--r--library/std/src/sys/windows/rand.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/library/std/src/sys/windows/rand.rs b/library/std/src/sys/windows/rand.rs
new file mode 100644
index 00000000000..87ea416bf67
--- /dev/null
+++ b/library/std/src/sys/windows/rand.rs
@@ -0,0 +1,33 @@
+use crate::io;
+use crate::mem;
+use crate::sys::c;
+
+#[cfg(not(target_vendor = "uwp"))]
+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());
+    }
+    v
+}
+
+#[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;
+}