Crate ctr[][src]

Expand description

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::{NewCipher, StreamCipher, StreamCipherSeek};

// `aes` crate provides AES block cipher implementation
type Aes128Ctr = ctr::Ctr128BE<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.seek(0);
cipher.apply_keystream(&mut data);
assert_eq!(data, [1, 2, 3, 4, 5, 6, 7]);

Re-exports

pub use cipher;

Modules

CTR mode flavors

Structs

Generic CTR block mode isntance.

Type Definitions

CTR mode with 32-bit big endian counter.

CTR mode with 32-bit little endian counter.

CTR mode with 64-bit big endian counter.

CTR mode with 64-bit little endian counter.

CTR mode with 128-bit big endian counter.

CTR mode with 128-bit little endian counter.