rs-crypto-aes 0.1.0
AES-128/192/256 block cipher with CBC (PKCS#7 padding) and CTR modes, correctness first and not constant-time, std only
Install
cargo add rs-crypto-aes --registry rupm
In Ruststudio: Packages, search for rs-crypto-aes, Install.
Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-23.
Versions
- 0.1.0 2026-11-23
README
# rs-crypto-aes
AES-128/192/256 block cipher with CBC (PKCS#7 padding) and CTR modes, correctness first and not constant-time, std only
Add it with `rupm add rs-crypto-aes` (or `cargo add rs-crypto-aes --registry rupm`).
The cipher is checked against the FIPS 197 and NIST SP 800-38A test vectors. This is a plain table-based implementation that is NOT constant-time: its S-box lookups depend on secret data and can leak through cache timing. It is also unaudited and has no authentication (CBC and CTR do not detect tampering). Do not use it for security-critical work, use an audited crate there.
## Install
```
rupm add rs-crypto-aes
```
## Usage
```rust
use rs_crypto_aes::{cbc_decrypt, cbc_encrypt, ctr_apply, Aes};
let key = [0x2bu8; 16];
let iv = [0u8; 16];
// CBC with PKCS#7 padding.
let ct = cbc_encrypt(&key, &iv, b"attack at dawn").unwrap();
assert_eq!(cbc_decrypt(&key, &iv, &ct).unwrap(), b"attack at dawn");
// CTR is its own inverse.
let enc = ctr_apply(&key, &iv, b"stream me").unwrap();
assert_eq!(ctr_apply(&key, &iv, &enc).unwrap(), b"stream me");
// Single block.
let aes = Aes::new(&key).unwrap();
let block = aes.encrypt_block(&[0u8; 16]);
assert_eq!(aes.decrypt_block(&block), [0u8; 16]);
```
## API overview
- `Aes::new(key)`: 16, 24 or 32 byte key, otherwise `Error::BadKeyLength`. Methods `encrypt_block`, `decrypt_block`.
- `cbc_encrypt(key, iv, data)`: pads with PKCS#7 and chains blocks.
- `cbc_decrypt(key, iv, data)`: checks length and padding, returns `Error::BadLength` or `Error::BadPadding`.
- `ctr_apply(key, counter_block, data)`: CTR keystream XOR (encrypt and decrypt), with a 128-bit big-endian counter as in SP 800-38A.
- `Error`: the failure cases above.