Module block

Module block 

Source
Expand description

Block cipher implementations with advanced type-level guarantees

This module contains implementations of various block ciphers and related algorithms with improved type-safety through compile-time constraints.

§Example usage

use dcrypt_algorithms::block::{TypedAes128, TypedCbc, BlockCipher, BlockCipherMode, CipherAlgorithm};
use rand::rngs::OsRng;

// Generate a random key and nonce
let key = TypedAes128::generate_key(&mut OsRng);
let nonce = TypedCbc::<TypedAes128>::generate_nonce(&mut OsRng);

// Create cipher and mode instances
let cipher = TypedAes128::new(&key);
let mode = TypedCbc::new(cipher, &nonce).unwrap();

// Encrypt and decrypt
let plaintext = b"secret message with padding...!!"; // Exactly 32 bytes (multiple of 16)
let ciphertext = mode.encrypt(plaintext).unwrap();
let decrypted = mode.decrypt(&ciphertext).unwrap();

assert_eq!(plaintext, &decrypted[..]);

Re-exports§

pub use aes::Aes128;
pub use aes::Aes192;
pub use aes::Aes256;
pub use modes::cbc::Cbc;
pub use modes::ctr::Ctr;

Modules§

aes
AES block cipher implementations
modes
Block cipher modes of operation

Structs§

TypedAes128
Enhanced AES-128 implementation with type-level guarantees
TypedCbc
Enhanced CBC mode implementation with type parameters

Enums§

Aes128Algorithm
Type-level constants for AES-128
CbcMode
Type-level constants for CBC mode

Traits§

AesVariant
Marker trait for specific AES key sizes
AuthenticatedCipherMode
Trait for authenticated block cipher modes
BlockCipher
Trait for block ciphers with type-level constraints
BlockCipherMode
Trait for block cipher modes with type parameters
CipherAlgorithm
Marker trait for cipher algorithms with compile-time properties
CipherMode
Marker trait for block cipher operating modes