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 valida backend so that crates can compile without a custom entry point. #611

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ libc = { version = "0.2.154", default-features = false }
# netbsd
[target.'cfg(target_os = "netbsd")'.dependencies]
libc = { version = "0.2.154", default-features = false }
# valida
[target.'cfg(target_os = "valida")'.dependencies]

# solaris
[target.'cfg(target_os = "solaris")'.dependencies]
Expand All @@ -73,15 +75,21 @@ windows-targets = "0.53"
# wasm_js
[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dependencies]
wasm-bindgen = { version = "0.2.98", default-features = false, optional = true }

# valida
[target.'cfg(getrandom_backend = "valida")'.dependencies]
atomic = { version = "0.5", default-features = false }

[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none"), target_feature = "atomics"))'.dependencies]
js-sys = { version = "0.3.77", default-features = false, optional = true }

[target.'cfg(all(target_arch = "wasm32", any(target_os = "unknown", target_os = "none")))'.dev-dependencies]
wasm-bindgen-test = "0.3"

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(getrandom_backend, values("custom", "rdrand", "rndr", "linux_getrandom", "wasm_js"))',
'cfg(getrandom_backend, values("custom", "rdrand", "rndr", "linux_getrandom", "wasm_js", "valida"))',
'cfg(getrandom_msan)',
'cfg(getrandom_test_linux_fallback)',
'cfg(getrandom_test_linux_without_fallback)',
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ of randomness based on their specific needs:
| `linux_getrandom` | Linux, Android | `*‑linux‑*` | [`getrandom`][1] system call (without `/dev/urandom` fallback). Bumps minimum supported Linux kernel version to 3.17 and Android API level to 23 (Marshmallow).
| `rdrand` | x86, x86-64 | `x86_64-*`, `i686-*` | [`RDRAND`] instruction
| `rndr` | AArch64 | `aarch64-*` | [`RNDR`] register
| `valida` | Valida | `*-valida` | Deterministic counter-based RNG for reproducible builds
| `wasm_js` | Web Browser, Node.js | `wasm32‑unknown‑unknown`, `wasm32v1-none` | [`Crypto.getRandomValues`]. Requires feature `wasm_js` ([see below](#webassembly-support)).
| `custom` | All targets | `*` | User-provided custom implementation (see [custom backend])

Expand Down
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ fn main() {
if santizers.contains("memory") {
println!("cargo:rustc-cfg=getrandom_msan");
}

// Declare valida as a valid value for getrandom_backend cfg
println!("cargo:rustc-check-cfg=cfg(getrandom_backend, values(\"valida\"))");
}
3 changes: 3 additions & 0 deletions src/backends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ cfg_if! {
if #[cfg(getrandom_backend = "custom")] {
mod custom;
pub use custom::*;
} else if #[cfg(getrandom_backend = "valida")] {
mod valida;
pub use valida::*;
} else if #[cfg(getrandom_backend = "linux_getrandom")] {
mod getrandom;
pub use getrandom::*;
Expand Down
12 changes: 12 additions & 0 deletions src/backends/valida.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::Error;
use core::mem::MaybeUninit;

pub use crate::util::{inner_u32, inner_u64};

#[inline]
pub fn fill_inner(_dest: &mut [MaybeUninit<u8>]) -> Result<(), Error> {
// Just a fixed value for determinism
0u32;

Ok(())
}
Loading