mod aegis;
mod aes;
#[cfg(feature = "aez")]
mod aez;
pub(crate) mod blowfish;
mod cbc;
mod ccm;
mod cfb;
mod chacha20;
mod chacha20poly1305;
#[cfg(all(feature = "std", any(target_arch = "x86_64", target_arch = "aarch64")))]
mod clmul;
mod cmac;
mod ctr;
mod des;
mod gcm;
mod gcm_siv;
mod gmac;
mod kw;
mod ofb;
mod poly1305;
pub(crate) mod salsa20;
mod sm4;
#[cfg(feature = "alloc")]
mod siv;
mod xchacha20poly1305;
mod xts;
pub use aegis::{Aegis128L, Aegis256};
pub use aes::{Aes128, Aes192, Aes256};
#[cfg(feature = "aez")]
pub use aez::Aez;
pub use cbc::Cbc;
pub use ccm::{Aes128Ccm, Aes128Ccm8, Aes192Ccm, Aes256Ccm, Aes256Ccm8, Ccm};
pub use cfb::Cfb;
pub use chacha20::ChaCha20;
pub use chacha20poly1305::ChaCha20Poly1305;
pub use cmac::{AesCmac128, AesCmac256, Cmac};
pub use ctr::Ctr;
pub use des::{Cbc64, Des, TdesEde2, TdesEde3};
pub use gcm::{Aes128Gcm, Aes256Gcm, Gcm};
pub use gcm_siv::{Aes128GcmSiv, Aes256GcmSiv, AesGcmSiv};
pub use gmac::{AesGmac128, AesGmac256, Gmac};
pub use kw::{
Aes128Kw, Aes128Kwp, Aes192Kw, Aes192Kwp, Aes256Kw, Aes256Kwp, AesKw, AesKwp, KwError,
kw_ciphertext_len, kwp_ciphertext_len,
};
pub use ofb::Ofb;
pub use poly1305::Poly1305;
#[cfg(feature = "alloc")]
pub use siv::AesSiv;
pub use sm4::Sm4;
pub use xchacha20poly1305::XChaCha20Poly1305;
pub use xts::{Aes128Xts, Aes256Xts, Xts};
pub trait BlockCipher {
const BLOCK_SIZE: usize;
const KEY_SIZE: usize;
fn encrypt_block(&self, block: &mut [u8; 16]);
fn decrypt_block(&self, block: &mut [u8; 16]);
fn encrypt_blocks(&self, blocks: &mut [u8]) {
debug_assert_eq!(blocks.len() % 16, 0, "encrypt_blocks needs whole blocks");
for chunk in blocks.chunks_exact_mut(16) {
let block: &mut [u8; 16] = chunk.try_into().expect("16-byte chunk");
self.encrypt_block(block);
}
}
fn decrypt_blocks(&self, blocks: &mut [u8]) {
debug_assert_eq!(blocks.len() % 16, 0, "decrypt_blocks needs whole blocks");
for chunk in blocks.chunks_exact_mut(16) {
let block: &mut [u8; 16] = chunk.try_into().expect("16-byte chunk");
self.decrypt_block(block);
}
}
}
pub trait BlockCipher64 {
const KEY_SIZE: usize;
fn encrypt_block(&self, block: &mut [u8; 8]);
fn decrypt_block(&self, block: &mut [u8; 8]);
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct InvalidLength;
impl core::fmt::Display for InvalidLength {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("input length is not a multiple of the block size")
}
}
impl core::error::Error for InvalidLength {}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TagMismatch;
impl core::fmt::Display for TagMismatch {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str("AEAD authentication tag mismatch")
}
}
impl core::error::Error for TagMismatch {}