[][src]Crate ctr

Generic implementations of CTR mode for block ciphers.

Mode functionality is accessed using traits from re-exported cipher crate.

⚠️ Security Warning: Hazmat!

This crate does not ensure ciphertexts are authentic! Thus ciphertext integrity is not verified, which can lead to serious vulnerabilities!

Ctr128 Usage Example

use ctr::cipher::stream::{NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek};

// `aes` crate provides AES block cipher implementation
type Aes128Ctr = ctr::Ctr128<aes::Aes128>;

let mut data = [1, 2, 3, 4, 5, 6, 7];

let key = b"very secret key.";
let nonce = b"and secret nonce";

// create cipher instance
let mut cipher = Aes128Ctr::new(key.into(), nonce.into());

// apply keystream (encrypt)
cipher.apply_keystream(&mut data);
assert_eq!(data, [6, 245, 126, 124, 180, 146, 37]);

// seek to the keystream beginning and apply it again to the `data` (decrypt)
cipher.apply_keystream(&mut data);
assert_eq!(data, [1, 2, 3, 4, 5, 6, 7]);


pub use cipher;



CTR mode with a 32-bit big endian counter.


CTR mode with a 32-bit little endian counter.


CTR mode of operation for 128-bit block ciphers