Crates.io | rc5-block |
lib.rs | rc5-block |
version | 0.1.0 |
created_at | 2025-07-03 17:25:17.672033+00 |
updated_at | 2025-07-03 17:25:17.672033+00 |
description | Rust implementation of RC5 Block cipher with ECB, CBC and CTR operation modes. |
homepage | |
repository | https://github.com/SyedAnees21/RC5-Rust |
max_upload_size | |
id | 1736603 |
size | 50,180 |
A pure‑Rust implementation of the RC5 block cipher, supporting variable word‑sizes (u16
, u32
, u64
, u128
),
PKCS#7 padding and the three classic modes of operation: ECB, CBC, and CTR.
This implementation is inspired by the original paper on RC5-Block-Cipher by Ronald L. Rivest.
This library is generic over word-size per block and suppoerts multiple operation modes.
Supported Word sizes:
Modes
Helpers
Add to your Cargo.toml
:
[dependencies]
rc5-block = "0.1"
And start using it in your application
use rc5_block::{
rc5_cipher, // builder
OperationMode, // enum for mode
random_iv, // for CBC
random_nonce_and_counter, // for CTR
utils::pkcs7, // padding helper
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1) Build an RC5 cipher: 32‑bit words, 12 rounds
let cipher = rc5_cipher::<u32>("my secret key", 12)?;
let plaintext = b"The quick brown fox jumps over the lazy dog";
// --- ECB ---
let ct_ecb = cipher.encrypt(plaintext, OperationMode::ECB)?;
let pt_ecb = cipher.decrypt(&ct_ecb, OperationMode::ECB)?;
assert_eq!(pt_ecb, plaintext);
// --- CBC ---
let iv = random_iv::<u32, 2>();
let ct_cbc = cipher.encrypt(plaintext, OperationMode::CBC { iv })?;
let pt_cbc = cipher.decrypt(&ct_cbc, OperationMode::CBC { iv })?;
assert_eq!(pt_cbc, plaintext);
// --- CTR ---
let nc = random_nonce_and_counter::<u32, 2>();
let ct_ctr = cipher.encrypt(plaintext, OperationMode::CTR { nonce_and_counter: nc })?;
// CTR decryption is same call:
let pt_ctr = cipher.decrypt(&ct_ctr, OperationMode::CTR { nonce_and_counter: nc })?;
assert_eq!(pt_ctr, plaintext);
Ok(())
}
This library is tested against some of the standard test vectors and round trip tests. These tests are define here. Standard test vector are picked from here.
This is a command-line application developed using this library, see it readme for more.