Repository navigation
Use CCRandomGenerateBytes on macOS - #879
Conversation
josephlr
left a comment
There was a problem hiding this comment.
Originally, we had different implementations on macOS and iOS/tvOS/etc... due to the cost of linking in the Security Framework for SecRandomCopyBytes. However, #388 (correctly) switched all our iOS/etc... implementations to use CCRandomGenerateBytes.
As that PR notes, CCRandomGenerateBytes is part of libSystem, it's always linked in (it contains the libc symbols for example), so that cost no longer exists.
I think changing the macOS implementation is reasonable, it will simplify things w.r.t. Common Criteria and it aligns us with what Python does.
Note that BoringSSL still uses getentropy on macOS, I'm not sure why, but my guess is keeping the implementation similar between macOS and OpenBSD.
|
Thanks! Renamed the backend to |
160080f to
7db5218
Compare
josephlr
left a comment
There was a problem hiding this comment.
Rebased this onto master, and made a few minor changes (renamed error constant to APPLE_RANDOM_GEN and fixed some links in the docs and names in the CI). Looks good to merge.
I'll let @newpavlov confirm that my changes are good.
Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
7db5218 to
4e9980f
Compare
|
Huh... What a lucky timing for Nightly to introduce |
On macOS we call
getentropy, which is a syscall per call and capped at 256 bytes. This switches macOS toCCRandomGenerateBytes, which the iOS/tvOS/watchOS backend already uses and which std uses on all Apple targets (library/std/src/sys/random/apple.rs). It's available since macOS 10.10, so the 10.12 minimum is fine.cargo +nightly benchon an M5 MacBook, master vs this branch:u32u64#823 discussed
getentropyvs. the CommonCrypto API from the entropy-quality side. This one is just about speed, and even seed-sized requests get ~4x faster.I also dropped macOS from the
__errorarm inget_errno.rssince nothing on macOS uses it anymore, and updated the README table and the nopanic step names.