Crate speck_cbc [−] [src]
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
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);
Constants
BLOCK_SIZE |
The size of SPECK's blocks and keys. |
Functions
decrypt |
Decrypt data with SPECK-CBC. |
encrypt |
Encrypt data with SPECK-CBC. |