| Crates.io | lwbc |
| lib.rs | lwbc |
| version | 0.9.0 |
| created_at | 2026-01-08 09:08:49.122721+00 |
| updated_at | 2026-01-08 09:08:49.122721+00 |
| description | Compact implementations of small block ciphers (SPECK, SIMON, SIMECK) |
| homepage | https://github.com/jedisct1/rust-lwbc |
| repository | https://github.com/jedisct1/rust-lwbc |
| max_upload_size | |
| id | 2029789 |
| size | 50,309 |
Rust implementations of the SPECK, SIMON, and SIMECK block cipher families.
These are small block ciphers (32-bit and 64-bit blocks) designed by the NSA and academic researchers. While often marketed for constrained environments, small block ciphers have broader applications:
Add to your Cargo.toml:
[dependencies]
lwbc = { git = "https://github.com/jedisct1/rust-lwbc" }
use lwbc::Speck32;
// Initialize with a 64-bit key (4 x u16)
let cipher = Speck32::new([0x0100, 0x0908, 0x1110, 0x1918]);
// Encrypt a 32-bit block (2 x u16)
let plaintext = [0x6574u16, 0x694c];
let ciphertext = cipher.encrypt(plaintext);
let decrypted = cipher.decrypt(ciphertext);
assert_eq!(plaintext, decrypted);
use lwbc::Speck64;
// Initialize from raw bytes (little-endian)
let cipher = Speck64::from_bytes([
0x00, 0x01, 0x02, 0x03,
0x08, 0x09, 0x0a, 0x0b,
0x10, 0x11, 0x12, 0x13,
0x18, 0x19, 0x1a, 0x1b,
]);
// Encrypt/decrypt byte arrays directly
let plaintext = [0x74, 0x65, 0x72, 0x3b, 0x2d, 0x43, 0x75, 0x74];
let ciphertext = cipher.encrypt_block(plaintext);
let decrypted = cipher.decrypt_block(ciphertext);
Whitened variants XOR additional key material before and after encryption, providing extra security margin with minimal overhead:
use lwbc::Speck32Whitened;
// Extended key: 4 words for cipher + 2 pre-whitening + 2 post-whitening
let cipher = Speck32Whitened::new([
0x0100, 0x0908, 0x1110, 0x1918, // cipher key
0xdead, 0xbeef, // pre-whitening
0xcafe, 0xbabe, // post-whitening
]);
let ciphertext = cipher.encrypt([0x6574, 0x694c]);
Available whitened types: Speck32Whitened, Speck64Whitened, Simon32Whitened, Simon64Whitened, Simeck32Whitened, Simeck64Whitened.
| Cipher | Block | Key | Rounds | Design |
|---|---|---|---|---|
| SPECK32/64 | 32-bit | 64-bit | 22 | ARX (add-rotate-xor) |
| SPECK64/128 | 64-bit | 128-bit | 27 | ARX |
| SIMON32/64 | 32-bit | 64-bit | 32 | Feistel + bitwise ops |
| SIMON64/128 | 64-bit | 128-bit | 44 | Feistel + bitwise ops |
| SIMECK32/64 | 32-bit | 64-bit | 32 | Hybrid SIMON/SPECK |
| SIMECK64/128 | 64-bit | 128-bit | 44 | Hybrid SIMON/SPECK |
Word sizes: 32-bit variants use u16 words, 64-bit variants use u32 words.
Byte order: All byte-level operations use little-endian encoding.
SPECK is the fastest due to its simple ARX structure. SIMON trades speed for smaller hardware implementation. SIMECK aims to balance both.
Run benchmarks with:
cargo run --release
These ciphers provide strong encryption for their block sizes, but small blocks have inherent limitations:
SPECK and SIMON were designed by the NSA and have undergone significant public cryptanalysis. SIMECK was designed by academic researchers at the University of Waterloo.
MIT