Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RC5 Block Cipher

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.

Features

  • Pure Rust implementation
  • #![forbid(unsafe_code)]
  • 32-bit word operations
  • Configurable number of rounds
  • In-place encryption and decryption of 8-byte blocks

Installation

[dependencies]
rc5-block-cipher = "0.1.0"

Usage

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 basic

API

RC5::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.

Implementation Notes

This implementation uses the RC5-32 block layout:

  • each block is 8 bytes
  • each block is interpreted as two little-endian u32 words
  • the key is packed into little-endian u32 words 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.

Development

cargo fmt
cargo test
cargo clippy --all-targets -- -D warnings

Repository Status

This 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

License

MIT

About

Pure Rust RC5 block cipher implementation for learning and experiments

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages