From 0d768a6eefe0f5fcd9d25717edbf10da50dcc100 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 16 Aug 2023 06:40:17 -0500 Subject: [PATCH] keyfork-mnemonic-generate: add correct amount of bits to bitvec --- keyfork-mnemonic-generate/src/main.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/keyfork-mnemonic-generate/src/main.rs b/keyfork-mnemonic-generate/src/main.rs index c410820..94d1a21 100644 --- a/keyfork-mnemonic-generate/src/main.rs +++ b/keyfork-mnemonic-generate/src/main.rs @@ -130,10 +130,17 @@ fn main() -> Result<(), Box> { let mut hasher = Sha256::new(); hasher.update(&entropy); let hash = hasher.finalize(); - let checksum = &hash[..bit_size / 32 / 8]; + let checksum = u8_to_bitslice(&hash[1]); - let seed = [&entropy[..bit_size / 8], checksum].concat(); - let seed_bits = seed.iter().flat_map(u8_to_bitslice).collect::>(); + let mut seed_bits = entropy[..bit_size / 8] + .iter() + .flat_map(u8_to_bitslice) + .collect::>(); + seed_bits.extend(if bit_size == 256 { + &checksum[..8] + } else { + &checksum[..4] + }); let words = seed_bits .chunks_exact(11) .map(|chunk| wordlist[bitslice_to_usize(chunk.try_into().expect("11 bit chunks"))].clone())