Skip to content

Use OS randomness directly for bitbox seeds - #961

Open
citizen-stig wants to merge 1 commit into
thrumdev:masterfrom
citizen-stig:os-randomness
Open

citizen-stig wants to merge 1 commit into
thrumdev:masterfrom
citizen-stig:os-randomness

Conversation

@citizen-stig

@citizen-stig citizen-stig commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Options::new() was the only place nomt used rand outside tests and benchmarks: it called rand::random() once to pick a 16-byte bitbox seed. This PR fills the seed with getrandom::fill() instead, which reads from the OS random source directly.

With that call gone, rand is no longer a normal dependency of nomt:

  • rand is now a dev-dependency (tests still use it) and an optional dependency enabled by the benchmarks feature (benches.rs uses it).
  • getrandom = { version = "0.4.2", default-features = false } is added as a direct dependency. It was already in the tree through rand, so no new crate comes in.

Non-dev dependency tree of nomt

Measured with cargo tree -p nomt -e normal --prefix none --locked, counting unique crates, with default features. The base is master at 6e4aab2.

unique crates
master 55
this PR 51

Four crates are removed from the tree that downstream users of nomt compile:

crate why it was there
rand v0.10.1 direct dependency of nomt
rand_core v0.10.1 via rand / chacha20
chacha20 v0.10.0 via rand (the ThreadRng CSPRNG)
cpufeatures v0.3.0 via chacha20

The subtree that goes away on master:

nomt v1.0.5
├── rand v0.10.1
│   ├── chacha20 v0.10.0
│   │   ├── cfg-if v1.0.5
│   │   ├── cpufeatures v0.3.0
│   │   └── rand_core v0.10.1
│   ├── getrandom v0.4.2
│   │   ├── cfg-if v1.0.5
│   │   ├── libc v0.2.191
│   │   └── rand_core v0.10.1

getrandom, cfg-if and libc stay, because other dependencies still need them.

The workspace Cargo.lock still lists all four crates. torture, trickfs, nomt-test-utils, quickcheck and rand_distr need rand too, but those are dev-only or workspace-internal, so they don't reach crates that depend on nomt.

Testing

All of these pass:

  • cargo check -p nomt --locked
  • cargo check -p nomt --features benchmarks --locked
  • cargo check -p nomt --tests --locked
  • cargo metadata --locked in benchtop/ (its lockfile is up to date)

🤖 Generated with Claude Code

@rphmeier

Copy link
Copy Markdown
Contributor

why?

@citizen-stig

Copy link
Copy Markdown
Contributor Author

why?

I think originally rand went away for main dep, but after merging master something got wrong. Let me double check the history

@citizen-stig

Copy link
Copy Markdown
Contributor Author

With that call gone, rand is no longer a normal dependency of nom

updated PR description

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.

2 participants