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

Add FreeBSD support. #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ _Listed in order of priority_
* Linux and Android will attempt to use the [`getrandom`](https://man7.org/linux/man-pages/man2/getrandom.2.html) syscall.
* macOS and iOS (Darwin-based systems) will use Security.framework's [`SecRandomCopyBytes`](https://developer.apple.com/documentation/security/1399291-secrandomcopybytes).
* OpenBSD will attempt to use the [`arc4random_buf`](https://man.openbsd.org/arc4random.3) function.
* FreeBSD will attempt to use the [`arc4random_buf`](https://man.freebsd.org/cgi/man.cgi?query=arc4random_buf&sektion=3) function.
* Windows
* If we're targeting UWP, then the [`BCryptGenRandom`](https://docs.microsoft.com/en-us/windows/win32/api/bcrypt/nf-bcrypt-bcryptgenrandom) is used with system-preferred RNG (`BCRYPT_USE_SYSTEM_PREFERRED_RNG`).
* Otherwise, we'll use [`RtlGenRandom`](https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom).
Expand Down
17 changes: 12 additions & 5 deletions src/entropy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ pub use darwin::entropy as system;
not(feature = "getrandom")
))]
pub use linux::entropy as system;
#[cfg(all(target_os = "openbsd", not(feature = "getrandom")))]
pub use openbsd::entropy as system;
#[cfg(all(
any(target_os = "openbsd", target_os = "freebsd"),
not(feature = "getrandom")
))]
pub use bsd::entropy as system;
#[cfg(all(windows, not(target_vendor = "uwp"), not(feature = "getrandom")))]
pub use windows::entropy as system;
#[cfg(all(windows, target_vendor = "uwp", not(feature = "getrandom")))]
Expand All @@ -34,9 +37,12 @@ pub mod windows_uwp;
/// An entropy generator for Windows, using WinAPI's `RtlGenRandom` function.
pub mod windows;

#[cfg(all(target_os = "openbsd", not(feature = "getrandom")))]
/// An entropy generator for OpenBSD, using libc's `arc4random_buf` function.
pub mod openbsd;
#[cfg(all(
any(target_os = "openbsd", target_os = "freebsd"),
not(feature = "getrandom")
))]
/// An entropy generator for OpenBSD and FreeBSD, using libc's `arc4random_buf` function.
pub mod bsd;

#[cfg(feature = "getrandom")]
/// Pull in system entropy using the [`getrandom`](https://crates.io/crates/getrandom) crate.
Expand All @@ -54,6 +60,7 @@ pub fn system(out: &mut [u8]) {
target_os = "linux",
target_os = "android",
target_os = "openbsd",
target_os = "freebsd",
target_vendor = "apple",
windows
)))]
Expand Down
File renamed without changes.