Skip to content

Make mnemonic RNG selection explicit - #1013

Open
benthecarman wants to merge 1 commit into
lightningdevkit:mainfrom
benthecarman:osrng
Open

Make mnemonic RNG selection explicit#1013
benthecarman wants to merge 1 commit into
lightningdevkit:mainfrom
benthecarman:osrng

Conversation

@benthecarman

Copy link
Copy Markdown
Contributor

Mnemonic generation is infrequent, so source randomness directly from OS entropy instead of initializing a thread-local generator. Also given recent events, better have this more explicitly defined than in a dep.

Mnemonic generation is infrequent, so source randomness directly from
OS entropy instead of initializing a thread-local generator. Also given
recent events, better have this more explicitly defined than in a dep.

Generated with assistance from OpenAI Codex.
@benthecarman
benthecarman requested a review from tankyleo August 4, 2026 05:17
@ldk-reviews-bot

ldk-reviews-bot commented Aug 4, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @tnull as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@tankyleo tankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@tnull let us know what you think, this gets us back to our choice of RNG following this PR #683

I'm also thinking we should apply this patch on rust-bip39 too:

diff --git a/src/lib.rs b/src/lib.rs
index ea56c05..69f4def 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -263,7 +263,7 @@ impl Mnemonic {
 	/// ```
 	/// use bip39::{Mnemonic, Language};
 	///
-	/// let mut rng = bip39::rand::thread_rng();
+	/// let mut rng = bip39::rand::rngs::OsRng;
 	/// let m = Mnemonic::generate_in_with(&mut rng, Language::English, 24).unwrap();
 	/// ```
 	#[cfg(feature = "rand_core")]
@@ -297,7 +297,7 @@ impl Mnemonic {
 	/// ```
 	#[cfg(feature = "rand")]
 	pub fn generate_in(language: Language, word_count: usize) -> Result<Mnemonic, Error> {
-		Mnemonic::generate_in_with(&mut rand::thread_rng(), language, word_count)
+		Mnemonic::generate_in_with(&mut rand::rngs::OsRng, language, word_count)
 	}

 	/// Generate a new [Mnemonic] in English.
@@ -727,7 +727,7 @@ mod tests {
 	fn test_generate() {
 		let _ = Mnemonic::generate(24).unwrap();
 		let _ = Mnemonic::generate_in(Language::English, 24).unwrap();
-		let _ = Mnemonic::generate_in_with(&mut rand::thread_rng(), Language::English, 24).unwrap();
+		let _ = Mnemonic::generate_in_with(&mut rand::rngs::OsRng, Language::English, 24).unwrap();
 	}

 	#[cfg(feature = "rand")]

@tankyleo
tankyleo requested a review from tnull August 5, 2026 04:58
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.

3 participants