speck-cbc 0.1.2

The Cipher Block Chaining (CBC) mode of the SPECK cipher, for Rust.
Documentation

A Rust implementation of the Cipher Block Chaining (CBC) mode of the SPECK cipher.

Don't use this unless you know what you are doing, as practical attacks exist against CBC mode in certain cases.

Example

# extern crate rand;
# extern crate pkcs7;
# extern crate speck_cbc;
# extern crate byteorder;
#
# fn example() -> std::io::Result<()> {
use rand::{Rng, OsRng};
use byteorder::NetworkEndian;

// This should probably be derived from an exchanged key or a password.
let key = [0u8; speck_cbc::BLOCK_SIZE];

let input = b"This is a test.";
let mut buffer: Vec<u8> = input.to_vec();

// Sender.
let mut iv = [0u8; speck_cbc::BLOCK_SIZE];
OsRng::new()?.fill_bytes(&mut iv);
pkcs7::pad(&mut buffer, speck_cbc::BLOCK_SIZE as u8);
speck_cbc::encrypt::<NetworkEndian>(&mut buffer, &key, &iv);

// Message authenticity needs to be provided between `encrypt` and `decrypt`.

// Receiver.
speck_cbc::decrypt::<NetworkEndian>(&mut buffer, &key, &iv);
pkcs7::un_pad(&mut buffer);

assert_eq!(buffer.as_slice(), input);
# Ok(())
# }
# fn main() { example().unwrap() }