Skip to content

Commit f139d39

Browse files
committed
Use os_rng for seed/mnemonic generation
The previously-used `thread_rng` should be fine, but `os_rng` is guaranteed to block until there is sufficient entropy available (e.g., after startup), which might slightly improve security here.
1 parent 59208e1 commit f139d39

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/io/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use lightning::util::persist::{
3535
};
3636
use lightning::util::ser::{Readable, ReadableArgs, Writeable};
3737
use lightning_types::string::PrintableString;
38-
use rand::{thread_rng, RngCore};
38+
use rand::{os_rng, RngCore};
3939

4040
use super::*;
4141
use crate::chain::ChainSource;
@@ -63,7 +63,7 @@ pub const EXTERNAL_PATHFINDING_SCORES_CACHE_KEY: &str = "external_pathfinding_sc
6363
pub fn generate_entropy_mnemonic() -> Mnemonic {
6464
// bip39::Mnemonic supports 256 bit entropy max
6565
let mut entropy = [0; 32];
66-
thread_rng().fill_bytes(&mut entropy);
66+
os_rng().fill_bytes(&mut entropy);
6767
Mnemonic::from_entropy(&entropy).unwrap()
6868
}
6969

@@ -96,7 +96,7 @@ where
9696
Ok(key)
9797
} else {
9898
let mut key = [0; WALLET_KEYS_SEED_LEN];
99-
thread_rng().fill_bytes(&mut key);
99+
os_rng().fill_bytes(&mut key);
100100

101101
if let Some(parent_dir) = Path::new(&keys_seed_path).parent() {
102102
fs::create_dir_all(parent_dir).map_err(|e| {

0 commit comments

Comments
 (0)