Skip to content
Snippets Groups Projects
whitener.rs 632 B
Newer Older
Stephen D's avatar
Stephen D committed
const WHITE: [u8; 16] = [
    0xe9, 0xcf, 0x67, 0x20, 0x19, 0x1a, 0x07, 0xdc, 0xc0, 0x72, 0x79, 0x97, 0x51, 0xf7, 0xdd, 0x93,
];

Stephen D's avatar
Stephen D committed
pub(crate) fn whiten(data: &mut [u8]) {
Stephen D's avatar
Stephen D committed
    for (i, d) in data.iter_mut().enumerate() {
        *d ^= WHITE[i % 15];
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn basic() {
        let mut data = [0; 64];
        data[0..57]
            .clone_from_slice(&b"Hello world! The quick brown fox jumped over the lazy dog"[..]);
Stephen D's avatar
Stephen D committed
        let orig = data;
Stephen D's avatar
Stephen D committed

        whiten(&mut data);
        assert_ne!(orig, data);

        whiten(&mut data);
        assert_eq!(orig, data);
    }
}