Skip to content

Commit 70f1309

Browse files
committed
Auto merge of #59879 - ebarnard:patch-1, r=alexcrichton
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.
2 parents 3b27b4f + f1da89a commit 70f1309

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/libstd/sys/unix/rand.rs

+7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ mod imp {
9999
}
100100
}
101101

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

0 commit comments

Comments
 (0)