Skip to content

Commit

Permalink
Auto merge of #59879 - ebarnard:patch-1, r=alexcrichton
Browse files Browse the repository at this point in the history
Add a comment explaining why SecRandomCopyBytes is not used on MacOS

SecRandomCopyBytes is [available since MacOS 10.7](https://developer.apple.com/documentation/security/1399291-secrandomcopybytes?language=objc) which is the minimum supported version and which was suggested in #58901 (comment) is the earliest version currently in use.

This matches the behaviour of other platforms which have a random number generator syscall available.
  • Loading branch information
bors committed Apr 16, 2019
2 parents 3b27b4f + f1da89a commit 70f1309
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libstd/sys/unix/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ mod imp {
}
}

// On iOS and MacOS `SecRandomCopyBytes` calls `CCRandomCopyBytes` with
// `kCCRandomDefault`. `CCRandomCopyBytes` manages a CSPRNG which is seeded
// from `/dev/random` and which runs on its own thread accessed via GCD.
// This seems needlessly heavyweight for the purposes of generating two u64s
// once per thread in `hashmap_random_keys`. Therefore `SecRandomCopyBytes` is
// only used on iOS where direct access to `/dev/urandom` is blocked by the
// sandbox.
#[cfg(target_os = "ios")]
mod imp {
use crate::io;
Expand Down

0 comments on commit 70f1309

Please sign in to comment.