Function aes_ctr

Source
pub fn aes_ctr(key: &[u8], data: &mut [u8], nonce: u128)
Expand description

Encrypts or decrypts data using AES in CTR mode.

Counter mode (CTR) encrypts a nonce value (the counter) and XORs the result with the plaintext to produce ciphertext, or vice versa. For the last block, which may be a partial block of u bits, the most significant u bits of the last output block are used for the exclusive-OR operation; the remaining block length-u bits of the last output block are discarded.

§Parameters

  • key: The AES key (128-bit, 192-bit, or 256-bit).
  • nonce: A unique nonce to start at(128-bit). The counter increments this nonce value for each block.
  • data: The input data to be encrypted or decrypted given as a slice of bytes. Can be of any length. There is no functional difference between encryption and decryption in CTR mode, so no input is given to distinguish the two.

§Returns

The resulting encrypted or decrypted data.