INNER CODE UNIT · Rust
entropy_to_indices
TheMaxMur/RS-Key · crates/rsk-bip39/src/lib.rs:29
pub fn entropy_to_indices(entropy: &[u8; 32]) -> [u16; WORD_COUNT] {
pack_indices(entropy, rsk_crypto::sha256(entropy)[0])
}
/// The packing half of [`entropy_to_indices`], with the checksum byte passed in.
/// Split out so `indices_in_range` proves the real loop over a symbolic checksum
/// instead of dragging SHA-256 into the solver for no added assurance.
fn pack_indices(entropy: &[u8; 32], checksum: u8) -> [u16; WORD_COUNT] {
// Bit `b` of the 264-bit string: the first 256 come from `entropy` (MSB-first per
// byte), the last 8 from `checksum`. No copy of the seed is made.
let bit = |b: usize| -> u16 {
let byte = if b < 256 { entropy[b / 8] } else { checksum };
((byte >> (7 - (b % 8))) & 1) as u16
};
let mut idx = [0u16; WORD_COUNT];
let mut i = 0;
while i < WORD_COUNT {
let mut v = 0u16;