Function aes_cbc

Source
pub fn aes_cbc(key: &[u8], data: &mut [u8], iv: u128, is_encrypt: bool)
Expand description

This function applies AES-128-CBC encryption or decryption in place to each block in the input data using the specified key. The operation is determined by the is_encrypt parameter.

For encrpytion in AES-CBC mode each block of plaintext is XORed with the previous ciphertext block before being encrypted. The first block is the only execption where, the initialization vector (IV) is used to XOR’d with the plaintext instead. For decryption in AES-CBC mode each block of ciphertext is decrypted and then XOR’d with the previous ciphertext block to produce the plaintext. Again the IV is used for the first block instead.

§Arguments

  • key - The AES key to use for encryption or decryption. Given as a slice of bytes. Must be either 16, 24, or 32 bytes long (128, 192, or 256 bits).
  • data - An immutable reference to a slice of bytes to process. Length must be a multiple of 16 bytes.
  • iv - The initialization vector (IV) used for the first block in CBC mode. Can only be a 128-bit value.
  • is_encrypt - A boolean indicating whether to encrypt (true) or decrypt (false).

§Returns

A vector of processed blocks after applying AES in CBC mode.