]> git.lizzy.rs Git - rust.git/commitdiff
implement SecRandomCopyBytes for macOS RNG
authorRalf Jung <post@ralfj.de>
Sun, 21 Apr 2019 19:37:06 +0000 (21:37 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 22 Apr 2019 09:08:23 +0000 (11:08 +0200)
src/fn_call.rs
test-cargo-miri/tests/test.rs

index 9789a76c6393eabbd4959f748abe4d8d3bb09718..fa0373ec54ec8a170ede230a6b82ac03419779be 100644 (file)
@@ -712,6 +712,18 @@ fn emulate_foreign_item(
             "_NSGetArgv" => {
                 this.write_scalar(Scalar::Ptr(this.machine.argv.unwrap()), dest)?;
             },
+            "SecRandomCopyBytes" => {
+                let len = this.read_scalar(args[1])?.to_usize(this)?;
+                let ptr = this.read_scalar(args[2])?.to_ptr()?;
+
+                if len > 0 {
+                    let data = gen_random(this, len as usize)?;
+                    this.memory_mut().get_mut(ptr.alloc_id)?
+                        .write_bytes(tcx, ptr, &data)?;
+                }
+
+                this.write_null(dest)?;
+            }
 
             // Windows API stubs.
             // HANDLE = isize
index 69a31c42a75c1b8f69b797ae57d2fa77bae14395..1f2f792148074ae96c60c9d427d27090326e1945 100644 (file)
@@ -21,17 +21,13 @@ fn fixed_rng() {
 
 #[test]
 fn entropy_rng() {
-    #[cfg(not(target_os="macos"))] // FIXME entropy does not work on macOS
-    // (Not disabling the entire test as that would change the output.)
-    {
-        // Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite)
-        let mut rng = SmallRng::from_entropy();
-        let _val = rng.gen::<i32>();
+    // Use this opportunity to test querying the RNG (needs an external crate, hence tested here and not in the compiletest suite)
+    let mut rng = SmallRng::from_entropy();
+    let _val = rng.gen::<i32>();
 
-        // Also try per-thread RNG.
-        let mut rng = rand::thread_rng();
-        let _val = rng.gen::<i32>();
-    }
+    // Also try per-thread RNG.
+    let mut rng = rand::thread_rng();
+    let _val = rng.gen::<i32>();
 }
 
 // A test that won't work on miri