Skip to content

Commit

Permalink
Add valida backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
thealmarty committed Feb 26, 2025
1 parent 7ed0836 commit ceff50a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
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(())
}

0 comments on commit ceff50a

Please sign in to comment.