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

    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 (plaintext_block, ciphertext_block) in plaintext.chunks(16).zip(ciphertext.chunks_mut(16)) {
        // block = block XOR iv1
        ciphertext_block
            .iter_mut()
            .zip(plaintext_block)
            .zip(iv1.as_ref())
            .for_each(|((x, a), b)| *x = a ^ b);

        // block = encrypt(block);
        let ciphertext_block = GenericArray::from_mut_slice(ciphertext_block);
        cipher.encrypt_block(ciphertext_block);

        // block = block XOR iv2
        ciphertext_block
            .iter_mut()
            .zip(iv2.as_ref())
            .for_each(|(x, a)| *x ^= a);

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

    ciphertext
}
/// Encrypt the input plaintext using the AES-IGE mode.
Encrypt the input plaintext using the AES-IGE mode.
Encrypt the input plaintext using the AES - IGE mode .
pub fn ige_encrypt(plaintext: &[u8], key: &[u8; 32], iv: &[u8; 32]) -> Vec<u8> {
    assert!(plaintext.len() % 16 == 0);
    let mut ciphertext = vec![0; plaintext.len()];
    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 (plaintext_block, ciphertext_block) in plaintext.chunks(16).zip(ciphertext.chunks_mut(16)) {
        // block = block XOR iv1
        ciphertext_block
            .iter_mut()
            .zip(plaintext_block)
            .zip(iv1.as_ref())
            .for_each(|((x, a), b)| *x = a ^ b);
        // block = encrypt(block);
        let ciphertext_block = GenericArray::from_mut_slice(ciphertext_block);
        cipher.encrypt_block(ciphertext_block);
        // block = block XOR iv2
        ciphertext_block
            .iter_mut()
            .zip(iv2.as_ref())
            .for_each(|(x, a)| *x ^= a);
        // save ciphertext and adjust iv
        iv1.copy_from_slice(ciphertext_block);
        iv2.copy_from_slice(plaintext_block);
    }
    ciphertext
}
pub fn ige_encrypt ( plaintext : & [ u8 ] , key : & [ u8 ; 32 ] , iv : & [ u8 ; 32 ] ) -> Vec < u8 > { assert ! ( plaintext len ( ) 16 0 ) ; let mut ciphertext = vec ! [ 0 plaintext len ( ) ] ; 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 ( plaintext_block , ciphertext_block ) in plaintext . chunks ( 16 ) . zip ( ciphertext . chunks_mut ( 16 ) ) { // block = block XOR iv1 ciphertext_block . iter_mut ( ) . zip ( plaintext_block ) . zip ( iv1 . as_ref ( ) ) . for_each ( | ( ( x , a ) , b ) | * x = a ^ b ) ; // block = encrypt(block); let ciphertext_block = GenericArray :: from_mut_slice ( ciphertext_block ) ; cipher . encrypt_block ( ciphertext_block ) ; // block = block XOR iv2 ciphertext_block . iter_mut ( ) . zip ( iv2 . as_ref ( ) ) . for_each ( | ( x , a ) | * x ^= a ) ; // save ciphertext and adjust iv iv1 . copy_from_slice ( ciphertext_block ) ; iv2 . copy_from_slice ( plaintext_block ) ; } ciphertext }
Encrypt the input plaintext using the AES-IGE mode.
Encrypt the input plaintext using the AES - IGE mode .
plaintext
&[u8]
key
&[u8; 32]
iv
&[u8; 32]
plaintext
&[u8]
key
&[u8; 32]
iv
&[u8; 32]