pub fn ige_decrypt(ciphertext: &[u8], key: &[u8; 32], iv: &[u8; 32]) -> Vec<u8> {
    let size = ciphertext.len();
    assert!(size % 16 == 0);
    let mut plaintext = vec![0; size];

    let key = GenericArray::from_slice(key);
    let cipher = aes::Aes256::new(&key);
    let mut iv = *iv;
    let (iv1, iv2) = iv.split_at_mut(16);

    for (ciphertext_block, plaintext_block) in ciphertext.chunks(16).zip(plaintext.chunks_mut(16)) {
        // block = block XOR iv2
        plaintext_block
            .iter_mut()
            .zip(ciphertext_block)
            .zip(iv2.as_ref())
            .for_each(|((a, x), b)| *a = x ^ b);

        // block = decrypt(block);
        let plaintext_block = GenericArray::from_mut_slice(plaintext_block);
        cipher.decrypt_block(plaintext_block);

        // block = block XOR iv1
        plaintext_block
            .iter_mut()
            .zip(iv1.as_ref())
            .for_each(|(a, b)| *a ^= b);

        // save plaintext and adjust iv
        iv1.copy_from_slice(ciphertext_block);
        iv2.copy_from_slice(plaintext_block);
    }

    plaintext
}
/// Decrypt the input ciphertext using the AES-IGE mode.
Decrypt the input ciphertext using the AES-IGE mode.
Decrypt the input ciphertext using the AES - IGE mode .
pub fn ige_decrypt(ciphertext: &[u8], key: &[u8; 32], iv: &[u8; 32]) -> Vec<u8> {
    let size = ciphertext.len();
    assert!(size % 16 == 0);
    let mut plaintext = vec![0; size];
    let key = GenericArray::from_slice(key);
    let cipher = aes::Aes256::new(&key);
    let mut iv = *iv;
    let (iv1, iv2) = iv.split_at_mut(16);
    for (ciphertext_block, plaintext_block) in ciphertext.chunks(16).zip(plaintext.chunks_mut(16)) {
        // block = block XOR iv2
        plaintext_block
            .iter_mut()
            .zip(ciphertext_block)
            .zip(iv2.as_ref())
            .for_each(|((a, x), b)| *a = x ^ b);
        // block = decrypt(block);
        let plaintext_block = GenericArray::from_mut_slice(plaintext_block);
        cipher.decrypt_block(plaintext_block);
        // block = block XOR iv1
        plaintext_block
            .iter_mut()
            .zip(iv1.as_ref())
            .for_each(|(a, b)| *a ^= b);
        // save plaintext and adjust iv
        iv1.copy_from_slice(ciphertext_block);
        iv2.copy_from_slice(plaintext_block);
    }
    plaintext
}
pub fn ige_decrypt ( ciphertext : & [ u8 ] , key : & [ u8 ; 32 ] , iv : & [ u8 ; 32 ] ) -> Vec < u8 > { let size = ciphertext . len ( ) ; assert ! ( size 16 0 ) ; let mut plaintext = vec ! [ 0 size ] ; let key = GenericArray :: from_slice ( key ) ; let cipher = aes :: Aes256 :: new ( & key ) ; let mut iv = * iv ; let ( iv1 , iv2 ) = iv . split_at_mut ( 16 ) ; for ( ciphertext_block , plaintext_block ) in ciphertext . chunks ( 16 ) . zip ( plaintext . chunks_mut ( 16 ) ) { // block = block XOR iv2 plaintext_block . iter_mut ( ) . zip ( ciphertext_block ) . zip ( iv2 . as_ref ( ) ) . for_each ( | ( ( a , x ) , b ) | * a = x ^ b ) ; // block = decrypt(block); let plaintext_block = GenericArray :: from_mut_slice ( plaintext_block ) ; cipher . decrypt_block ( plaintext_block ) ; // block = block XOR iv1 plaintext_block . iter_mut ( ) . zip ( iv1 . as_ref ( ) ) . for_each ( | ( a , b ) | * a ^= b ) ; // save plaintext and adjust iv iv1 . copy_from_slice ( ciphertext_block ) ; iv2 . copy_from_slice ( plaintext_block ) ; } plaintext }
Decrypt the input ciphertext using the AES-IGE mode.
Decrypt the input ciphertext using the AES - IGE mode .
ciphertext
&[u8]
key
&[u8; 32]
iv
&[u8; 32]
ciphertext
&[u8]
key
&[u8; 32]
iv
&[u8; 32]