Expand description

ECB-Mix-ECB (EME) block cipher mode implementation.

Usage example

use aes::Aes128;
use eme_mode::{
  cipher::{block_padding::Pkcs7, consts::U16, BlockDecryptMut, BlockEncryptMut, KeyIvInit},
  Eme,
};

type Aes128Eme = Eme<Aes128, U16>;

let key = [0; 16];
let iv = [1; 16];
let plaintext = b"Hello world!";
let mut cipher = Aes128Eme::new_from_slices(&key, &iv).unwrap();

// buffer must have enough space for message+padding
let mut buffer = [0u8; 16];
// copy message to the buffer
let pos = plaintext.len();
buffer[..pos].copy_from_slice(plaintext);
cipher.encrypt_padded_mut::<Pkcs7>(buffer.as_mut_slice().into(), pos);

assert_eq!(
  buffer,
  [147, 227, 119, 228, 187, 150, 249, 88, 176, 145, 53, 209, 217, 99, 70, 245]
);

// re-create cipher mode instance
let mut cipher = Aes128Eme::new_from_slices(&key, &iv).unwrap();
let decrypted = cipher
  .decrypt_padded_mut::<Pkcs7>(buffer.as_mut_slice().into())
  .unwrap();

assert_eq!(decrypted, plaintext);

Re-exports

pub use cipher;

Structs

EME block mode instance with dynamic block size.

ECB-Mix-ECB (EME) block mode instance.