Skip to content

Use OsRng when generating a new Mnemonic - #105

Merged
tnull merged 2 commits into
rust-bitcoin:masterfrom
tankyleo:2026-08-use-osrng
Aug 10, 2026
Merged

Use OsRng when generating a new Mnemonic#105
tnull merged 2 commits into
rust-bitcoin:masterfrom
tankyleo:2026-08-use-osrng

Conversation

@tankyleo

@tankyleo tankyleo commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

ThreadRng should be fine, but we are paranoid, and we do not need mnemonic generation to be fast, so we prioritize security and use OsRng by default to generate a new Mnemonic.

Raise the minimum supported rand version to 0.7, the earliest release with unit-style OsRng construction, while preserving Rust 1.41.1 compatibility through the MSRV dependency pins.

@tankyleo
tankyleo force-pushed the 2026-08-use-osrng branch from 19d4160 to f464135 Compare August 6, 2026 01:23
@tankyleo

tankyleo commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

I regenerated Cargo-minimal.lock using cargo +nightly update -Z direct-minimal-versions let me know if I should use something else thank you.

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but can we do the dependency bump and the switch to OsRng in two separate commits?

@tnull
tnull requested a review from elsirion August 6, 2026 07:05
In the following commit, we will switch the default RNG used to generate
the `Mnemonic` from `rand::rngs::ThreadRng` to `rand::rngs::OsRng`.
The rand 0.7 release shipped `OsRng` with a new constructor, so instead
of handling the different constructors across versions 0.6 and 0.7+, we
choose to bump the minimum rand version supported to 0.7.

To reproduce the new `Cargo-minimal.lock`:
```
mv Cargo-minimal.lock Cargo.lock
cargo +1.41.1 update --package "rand" --precise "0.7.0"
cargo +1.41.1 update --package "rand" --precise "0.7.0"
cargo +1.41.1 update --package "libc" --precise "0.2.151"
cargo +1.41.1 update --package "ppv-lite86" --precise "0.2.17"
mv Cargo.lock Cargo-minimal.lock
```
`ThreadRng` *should* be fine, but we are paranoid, and we do not need
mnemonic generation to be fast, so we prioritize security and use
`OsRng` by default to generate a new `Mnemonic`.
@tankyleo
tankyleo force-pushed the 2026-08-use-osrng branch from f464135 to 87bd59d Compare August 8, 2026 15:56
@tankyleo
tankyleo requested a review from tnull August 8, 2026 15:58
@tankyleo

tankyleo commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

@tnull I've addressed your comment thank you. I also revisited how I create the new Cargo-minimal.lock, please find instructions to reproduce in the commit message of the first commit.

@tnull tnull left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM!

Talked to other maintainers in the meantime, and we might be good to bump rand/MSRV even further, but that doesn't need to happen in this PR.

@tnull
tnull merged commit 42f0fc5 into rust-bitcoin:master Aug 10, 2026
8 checks passed
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