INNER CODE UNIT · Rust

pack_indices

TheMaxMur/RS-Key · crates/rsk-bip39/src/lib.rs:36

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;
        let mut j = 0;
        while j < 11 {
            v = (v << 1) | bit(i * 11 + j);
            j += 1;
        }
        idx[i] = v;
        i += 1;

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…