Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve random number generation on Mac OS X and iOS #149

Closed
briansmith opened this issue Mar 12, 2016 · 5 comments
Closed

Improve random number generation on Mac OS X and iOS #149

briansmith opened this issue Mar 12, 2016 · 5 comments

Comments

@briansmith
Copy link
Owner

Avoid using dev/urandom on Mac OS X and instead do whatever is most like using the getrandom syscall on Linux (See #148).

References:

Note, in particular, that SecRandomCopyBytes was added in OS X 10.7 (Lion). According to this Rust issue, 10.7 is the lowest version supported by Rust anyway, although we should verify that hasn't changed since then.

@briansmith
Copy link
Owner Author

http://stackoverflow.com/questions/21734909/is-os-xs-secrandomcopybytes-fork-safe
http://opensource.apple.com//source/Security/Security-55471/libsecurity_keychain/lib/SecRandom.c
http://opensource.apple.com//source/CommonCrypto/CommonCrypto-60049/lib/CommonRandom.c

http://opensource.apple.com/source/Security/Security-55179.11/sec/Security/SecFramework.c

So, basically, it's just reading from /dev/random like we already do on Mac OS X. So, really nothing useful there. But, on iOS it seems to be required to use the provided API since (direct) access to /dev/random is blocked by the sandbox.

@briansmith
Copy link
Owner Author

I thought about this some more, and I think it would be good to do this on both Mac OS X and iOS. The main advantage for doing it on Mac OS X is that it would share the same file handle with the toolkit-provided function and hopefully then have less overhead in cases where Rust and non-Rust code are mixed, e.g. when a Rust lib is being included in an ObjC or C project.

@briansmith
Copy link
Owner Author

BTW, this can be implemented very easily by extending the definition of sysrand in ring/src/rand.rs. Can be done with 100% Rust code, I think.

@frewsxcv
Copy link
Contributor

frewsxcv commented Jan 4, 2017

A pull request was opened for this: #398.

@briansmith
Copy link
Owner Author

This was done in #398 by @dirk. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants