Struct botan::BlockCipher[][src]

pub struct BlockCipher { /* fields omitted */ }

A raw block cipher interface (ie ECB mode)

Warning: you almost certainly want an AEAD cipher mode instead

Methods

impl BlockCipher
[src]

Create a new block cipher instance, failing if the cipher is unknown

Examples

let cipher = botan::BlockCipher::new("AES-128");
assert!(cipher.is_ok());
let no_such_cipher = botan::BlockCipher::new("SuperCipher9000");
assert!(no_such_cipher.is_err());

Return the block size of the cipher, in bytes

Examples

let cipher = botan::BlockCipher::new("AES-128").unwrap();
assert_eq!(cipher.block_size().unwrap(), 16);

Return the name of this algorithm which may or may not exactly match what was provided to new()

Examples

let cipher = botan::BlockCipher::new("AES-128").unwrap();
assert_eq!(cipher.algo_name().unwrap(), "AES-128");

Return information about the key lengths supported by this object

Set the key for the cipher.

Errors

Fails if the key is not a valid length for the cipher

Examples

let cipher = botan::BlockCipher::new("AES-128").unwrap();
assert!(cipher.set_key(&vec![0; 32]).is_err());
assert!(cipher.set_key(&vec![0; 16]).is_ok());

Encrypt some blocks of data

Errors

Fails if the input is not a multiple of the block size, or if the key was not set on the object.

Examples

let cipher = botan::BlockCipher::new("AES-128").unwrap();
// Key is not set
assert!(cipher.encrypt_blocks(&vec![0; 16]).is_err());
assert!(cipher.set_key(&vec![0; 16]).is_ok());
// Not a multiple of block size
assert!(cipher.encrypt_blocks(&vec![0; 17]).is_err());
// Key is set and multiple of block size - ok
assert!(cipher.encrypt_blocks(&vec![0; 16]).is_ok());

Decrypt some blocks of data

Errors

Fails if the input is not a multiple of the block size, or if the key was not set on the object.

Examples

let cipher = botan::BlockCipher::new("AES-128").unwrap();
// Key is not set
assert!(cipher.decrypt_blocks(&vec![0; 16]).is_err());
assert!(cipher.set_key(&vec![0; 16]).is_ok());
// Not a multiple of block size
assert!(cipher.decrypt_blocks(&vec![0; 17]).is_err());
// Key is set and multiple of block size - ok
assert!(cipher.decrypt_blocks(&vec![0; 16]).is_ok());

Clear the key set on the cipher from memory. After this, the object is un-keyed and must be re-keyed before use.

Examples

let cipher = botan::BlockCipher::new("AES-128").unwrap();
assert!(cipher.set_key(&vec![0; 16]).is_ok());
assert!(cipher.encrypt_blocks(&vec![0; 16]).is_ok());
assert!(cipher.clear().is_ok());
assert!(cipher.encrypt_blocks(&vec![0; 16]).is_err());

Trait Implementations

impl Debug for BlockCipher
[src]

Formats the value using the given formatter. Read more

impl Drop for BlockCipher
[src]

Executes the destructor for this type. Read more

Auto Trait Implementations

impl !Send for BlockCipher

impl !Sync for BlockCipher