This crate contains generic implementation of block cipher modes of operation.
Note that this crate implements only modes which require padding. For CTR, CFB and OFB modes (i.e. modes which transsform block ciphers into stream ciphers) see crates in the RustCrypto/stream-ciphers repository.
Usage example
extern crate hex_literal;
extern crate aes_soft as aes;
extern crate block_modes;
use ;
use Pkcs7;
use Aes128;
// create an alias for convinience
type Aes128Cbc = ;
let key = hex!;
let iv = hex!;
let plaintext = b"Hello world!";
let cipher = new_var.unwrap;
// buffer must have enough space for message+padding
let mut buffer = ;
// copy message to the buffer
let pos = plaintext.len;
buffer.copy_from_slice;
let ciphertext = cipher.encrypt.unwrap;
assert_eq!;
// re-create cipher mode instance
let cipher = new_var.unwrap;
let mut buf = ciphertext.to_vec;
let decrypted_ciphertext = cipher.decrypt.unwrap;
assert_eq!;
With an enabled std
feature (which is enabled by default) you can use
encrypt_vec
and descrypt_vec
methods:
# extern crate hex_literal;
# extern crate aes_soft as aes;
# extern crate block_modes;
#
# use ;
# use Pkcs7;
# use Aes128;
#
# // create an alias for convinience
# type Aes128Cbc = ;
#
# let key = hex!;
# let iv = hex!;
# let plaintext = b"Hello world!";
let cipher = new_var.unwrap;
let ciphertext = cipher.encrypt_vec;
assert_eq!;
let cipher = new_var.unwrap;
let decrypted_ciphertext = cipher.decrypt_vec.unwrap;
assert_eq!;