jjyr / hdwallet

HD wallet BIP-32 related key derivation utilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`random_with_seed_size` is producing an empty seed

maciejhirsz opened this issue · comments

seed in:

hdwallet/src/key.rs

Lines 46 to 55 in c86ed6a

/// Generate an ExtendedPrivKey which use 128 or 256 or 512 size random seed.
pub fn random_with_seed_size(seed_size: KeySeed) -> Result<ExtendedPrivKey, Error> {
let seed = {
let mut seed = Vec::with_capacity(seed_size as usize);
let mut rng = rand::thread_rng();
rng.fill(seed.as_mut_slice());
seed
};
Self::with_seed(&seed)
}

is a 0-lenght Vec, rng.fill(seed.as_mut_slice()); is a noop (you get a mutable 0-size slice).

Proper approach is to use a zero-ed vector (vec![0; len]) or after creating a Vec with capacity to use the unsafe set_len (although you have to make sure the bytes aren't being read, as it opens you up to potential memory exploits if they are).

commented

Good catch! Thanks for pointing it out.