Skip to main content

coin_to_entropy

Function coin_to_entropy 

Source
pub fn coin_to_entropy<const N: usize>(
    flips: &[u8],
) -> Result<CoinEntropy<N>, EntropyError>
Expand description

Fold a sequence of coin flips into an N-byte entropy buffer.

Flips are formatted as a concatenated string of "0" / "1" ASCII digits, SHA-256 hashed, then the first N bytes of the digest are taken. Mirrors Krux’s dice-string approach for FACES < 10.

§Example

use kdk_entropy::{coin_to_entropy, CoinEntropy};
use kdk_zeroize::prelude::*;

// SHA-256("0" * 128)[:16].
let flips = [0u8; 128];
let e: CoinEntropy<16> = coin_to_entropy(&flips).unwrap();
assert_eq!(
    e.expose_secret(),
    &[
        0x45, 0x72, 0x57, 0x91, 0xc4, 0x7b, 0x32, 0x61,
        0x8c, 0xc5, 0x7b, 0x88, 0x34, 0x3e, 0x2b, 0xce,
    ]
);