Skip to content

Remove Apple RNG fallbacks and simplify implementation#116319

Merged
bors merged 1 commit intorust-lang:masterfrom
BlackHoleFox:apple-rand-take-2
Oct 24, 2023
Merged

Remove Apple RNG fallbacks and simplify implementation#116319
bors merged 1 commit intorust-lang:masterfrom
BlackHoleFox:apple-rand-take-2

Conversation

@BlackHoleFox
Copy link
Contributor

Now that we have higher Apple platform requirements, the RNG code can be simplified a lot. Since getentropy still doesn't look to be usable outside macOS this implementation:

  • Removes any macOS fallback paths and unconditionally links to getentropy
  • Minimizes the implementation for everything else (iOS, watchOS, etc).

CCRandomGenerateBytes was added in iOS 8 which means that we can use it now. It and SecRandomCopyBytes have the exact same functionality, but the former has a simpler API and no longer requires libstd to link to Security.framework for one function. Its also available in all the other target's SDKs.

Why care about getentropy then though on macOS? Well, its still much more performant. Benchmarking shows it runs at ~2x the speed of CCRandomGenerateBytes, which makes sense since it directly pulls from the kernel vs going through its own generator etc.

Semi-related to a previous, but reverted, attempt at improving this logic in #101011

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. O-unix Operating system: Unix-like S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants