A small, pure Rust implementation of the RC5 block cipher using 32-bit words and 64-bit blocks.
RC5 is a symmetric block cipher designed by Ronald Rivest. Its design is parameterized by word size, number of rounds, and key length. This crate focuses on the common RC5-32 variant and exposes a minimal API for encrypting and decrypting a single 8-byte block.
Educational project: this crate is useful for learning and experiments. It has not been independently audited and should not be used to protect production data.
- Pure Rust implementation
#![forbid(unsafe_code)]- 32-bit word operations
- Configurable number of rounds
- In-place encryption and decryption of 8-byte blocks
[dependencies]
rc5-block-cipher = "0.1.0"use rc5_block_cipher::RC5;
let key = b"example key";
let rounds = 12;
let rc5 = RC5::new(key, rounds);
let mut block = *b"message!";
let original = block;
rc5.encrypt_block(&mut block);
assert_ne!(block, original);
rc5.decrypt_block(&mut block);
assert_eq!(block, original);Run the included example:
cargo run --example basicRC5::new(key, rounds) creates a cipher instance by expanding the provided key.
encrypt_block(&mut block) encrypts one 8-byte block in place.
decrypt_block(&mut block) decrypts one 8-byte block in place.
This implementation uses the RC5-32 block layout:
- each block is 8 bytes
- each block is interpreted as two little-endian
u32words - the key is packed into little-endian
u32words before expansion - the expanded subkey table has
2 * (rounds + 1)words
Encryption mutates the caller-provided block in place. Decryption applies the rounds in reverse order and should recover the original block when the same key and round count are used.
The crate does not include padding or a block mode. Callers should treat it as a single-block primitive for studying RC5 internals, not as a complete encryption scheme.
cargo fmt
cargo test
cargo clippy --all-targets -- -D warningsThis repository is intentionally compact. Good follow-up contributions include:
- adding externally verified RC5 test vectors
- adding block mode examples for educational use
- benchmarking round counts and key sizes
MIT