1 unstable release

new 0.1.0 Dec 11, 2024

#1139 in Cryptography

Download history 139/week @ 2024-12-09

139 downloads per month

MIT/Apache

16KB
311 lines

Generic implementation of a Feistel Cipher

let network = key
    .chunks_exact(4)
    .map(|chunk| {
        move |half: &XorArray<u8, ConstArrayLength<32>>| {
            let mut hasher = Sha256::new();
            hasher.update(half);
            hasher.update(chunk);
            let value: [u8; 32] = hasher.finalize().into();
            XorArray(value.into())
        }
    })
    .feistel_symmetric();
let original = [0; 64].into();
let encrypted = network.clone().array_encrypt(original);
assert_ne!(original, encrypted);
let decrypted = network.clone().array_decrypt(encrypted);
assert_eq!(original, decrypted);

lib.rs:

Generic implementation of a Feistel Cipher.

Warning: this crate for now values ease of use and genericity over having perfect timing-attack-resistent implementations.

let network = key
    .chunks_exact(4)
    .map(|chunk| {
        move |half: &XorArray<u8, ConstArrayLength<32>>| {
            let mut hasher = Sha256::new();
            hasher.update(half);
            hasher.update(chunk);
            let value: [u8; 32] = hasher.finalize().into();
            XorArray(value.into())
        }
    })
    .feistel_symmetric();
let original = [0; 64].into();
let encrypted = network.clone().array_encrypt(original);
assert_ne!(original, encrypted);
let decrypted = network.clone().array_decrypt(encrypted);
assert_eq!(original, decrypted);

Dependencies

~51KB