#block #cbc #cipher

nightly no-std speck-cbc

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

3 releases

Uses old Rust 2015

0.1.2 Sep 5, 2017
0.1.1 Aug 5, 2017
0.1.0 Aug 5, 2017

#7 in #cbc

MIT license

7KB

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);

Dependencies

~120KB