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

Use arc4rand(9) on FreeBSD #112

Merged
merged 3 commits into from
Aug 23, 2016

Conversation

habnabit
Copy link
Contributor

@habnabit habnabit commented Aug 4, 2016

After reading through rust-lang/rust#30691 it seems that there's general agreement that using OS-provided facilities for seeding rust userland processes is fine as long as it doesn't use too much from libc. FreeBSD's arc4random_buf(3) is not only a whole lot of libc code, but also not even currently exposed in the libc crate. Fortunately, the mechanism arc4random_buf(3) et al. use for getting entropy from the kernel (arc4rand(9)) is exposed via sysctl(3) with constants that are already in the libc crate.

I haven't found too much documentation on KERN_ARND—it's missing or only briefly described in most of the places that cover sysctl mibs. But, from digging through the kernel source, it appears that the sysctl used in this PR is very close to just calling arc4rand(9) directly (with reseed set to 0 and no way to change it).

habnabit added 2 commits July 29, 2016 09:01
There were a bunch of more-of-less the same few lines for doing a
fill_bytes+transmute, and I didn't want to copy-paste it yet again.
This means that /dev/urandom doesn't have to be opened.
@habnabit
Copy link
Contributor Author

habnabit commented Aug 4, 2016

Oh oops I guess my refactor failed.

I thought I did this, but I guess not.
@habnabit
Copy link
Contributor Author

habnabit commented Aug 4, 2016

Looks good except for nightly rust, which failed for unrelated reasons?

@brson
Copy link
Contributor

brson commented Aug 22, 2016

cc @alexcrichton @brson

@alexcrichton
Copy link
Contributor

Oops sorry for the delay, thanks @habnabit!

@alexcrichton alexcrichton merged commit 47bf29d into rust-random:master Aug 23, 2016
eddyb added a commit to eddyb/rust that referenced this pull request Aug 23, 2016
…ichton

Use arc4rand(9) on FreeBSD

From rust-random/rand#112:

>After reading through rust-lang#30691 it seems that there's general agreement that using OS-provided facilities for seeding rust userland processes is fine as long as it doesn't use too much from libc. FreeBSD's `arc4random_buf(3)` is not only a whole lot of libc code, but also not even currently exposed in the libc crate. Fortunately, the mechanism `arc4random_buf(3)` et al. use for getting entropy from the kernel ([`arc4rand(9)`](https://www.freebsd.org/cgi/man.cgi?query=arc4random&apropos=0&sektion=9&manpath=FreeBSD+10.3-RELEASE&arch=default&format=html)) is exposed via `sysctl(3)` with constants that are already in the libc crate.

>I haven't found too much documentation on `KERN_ARND`—it's missing or only briefly described in most of the places that cover sysctl mibs. But, from digging through the kernel source, it appears that the sysctl used in this PR is very close to just calling `arc4rand(9)` directly (with `reseed` set to 0 and no way to change it).

I expected [rand](/rust-lang-nursery/rand) to reply quicker, so I tried submitting it there first. It's been a few weeks with no comment, so I don't know the state of it, but maybe someone will see it here and have an opinion. This is basically the same patch. It pains me to duplicate the code but I guess it hasn't been factored out into just one place yet.
eddyb added a commit to eddyb/rust that referenced this pull request Aug 23, 2016
…ichton

Use arc4rand(9) on FreeBSD

From rust-random/rand#112:

>After reading through rust-lang#30691 it seems that there's general agreement that using OS-provided facilities for seeding rust userland processes is fine as long as it doesn't use too much from libc. FreeBSD's `arc4random_buf(3)` is not only a whole lot of libc code, but also not even currently exposed in the libc crate. Fortunately, the mechanism `arc4random_buf(3)` et al. use for getting entropy from the kernel ([`arc4rand(9)`](https://www.freebsd.org/cgi/man.cgi?query=arc4random&apropos=0&sektion=9&manpath=FreeBSD+10.3-RELEASE&arch=default&format=html)) is exposed via `sysctl(3)` with constants that are already in the libc crate.

>I haven't found too much documentation on `KERN_ARND`—it's missing or only briefly described in most of the places that cover sysctl mibs. But, from digging through the kernel source, it appears that the sysctl used in this PR is very close to just calling `arc4rand(9)` directly (with `reseed` set to 0 and no way to change it).

I expected [rand](/rust-lang-nursery/rand) to reply quicker, so I tried submitting it there first. It's been a few weeks with no comment, so I don't know the state of it, but maybe someone will see it here and have an opinion. This is basically the same patch. It pains me to duplicate the code but I guess it hasn't been factored out into just one place yet.
@habnabit
Copy link
Contributor Author

Thank you!

@habnabit habnabit deleted the freebsd-kernel-osrng branch August 23, 2016 21:16
bors added a commit to rust-lang/rust that referenced this pull request Aug 25, 2016
Use arc4rand(9) on FreeBSD

From rust-random/rand#112:

>After reading through #30691 it seems that there's general agreement that using OS-provided facilities for seeding rust userland processes is fine as long as it doesn't use too much from libc. FreeBSD's `arc4random_buf(3)` is not only a whole lot of libc code, but also not even currently exposed in the libc crate. Fortunately, the mechanism `arc4random_buf(3)` et al. use for getting entropy from the kernel ([`arc4rand(9)`](https://www.freebsd.org/cgi/man.cgi?query=arc4random&apropos=0&sektion=9&manpath=FreeBSD+10.3-RELEASE&arch=default&format=html)) is exposed via `sysctl(3)` with constants that are already in the libc crate.

>I haven't found too much documentation on `KERN_ARND`—it's missing or only briefly described in most of the places that cover sysctl mibs. But, from digging through the kernel source, it appears that the sysctl used in this PR is very close to just calling `arc4rand(9)` directly (with `reseed` set to 0 and no way to change it).

I expected [rand](/rust-lang-nursery/rand) to reply quicker, so I tried submitting it there first. It's been a few weeks with no comment, so I don't know the state of it, but maybe someone will see it here and have an opinion. This is basically the same patch. It pains me to duplicate the code but I guess it hasn't been factored out into just one place yet.
pitdicker pushed a commit to pitdicker/rand that referenced this pull request Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants