pub trait Cipher: Sized {
const BLOCK_SIZE: usize;
const KEY_SIZE: usize;
// Required methods
fn with_decrypt_key(key: &[u8]) -> Result<Self>;
fn with_encrypt_key(key: &[u8]) -> Result<Self>;
fn decrypt(&mut self, dst: &mut [u8], src: &[u8]);
fn encrypt(&mut self, dst: &mut [u8], src: &[u8]);
fn context(&mut self) -> *mut c_void;
fn raw_decrypt_function() -> RawCipherFunctionPointer;
fn raw_encrypt_function() -> RawCipherFunctionPointer;
}
Expand description
Symmetric block or stream cipher.
Symmetric cipher encrypt and decrypt data using the same key.
Required Associated Constants§
sourceconst BLOCK_SIZE: usize
const BLOCK_SIZE: usize
Block size in bytes.
Required Methods§
sourcefn with_decrypt_key(key: &[u8]) -> Result<Self>
fn with_decrypt_key(key: &[u8]) -> Result<Self>
Creates a new cipher instance for decryption.
The key
parameter must have size KEY_SIZE
.
sourcefn with_encrypt_key(key: &[u8]) -> Result<Self>
fn with_encrypt_key(key: &[u8]) -> Result<Self>
Creates a new cipher instance for encryption.
The key
parameter must have size KEY_SIZE
.
sourcefn decrypt(&mut self, dst: &mut [u8], src: &[u8])
fn decrypt(&mut self, dst: &mut [u8], src: &[u8])
Decrypt src
into dst
.
Both must have the same length. That length must be a multiple
of BLOCK_SIZE
. Blocks are processed in ECB mode.
sourcefn encrypt(&mut self, dst: &mut [u8], src: &[u8])
fn encrypt(&mut self, dst: &mut [u8], src: &[u8])
Encrypt src
into dst
.
Both must have the same length. That length must be a multiple
of BLOCK_SIZE
. Blocks are processed in ECB mode.
sourcefn context(&mut self) -> *mut c_void
fn context(&mut self) -> *mut c_void
Returns a pointer to the C context struct of the cipher instance.
Used internally by block modi.
sourcefn raw_decrypt_function() -> RawCipherFunctionPointer
fn raw_decrypt_function() -> RawCipherFunctionPointer
Pointer to the *_decrypt C function.
Used internally for block modi.
sourcefn raw_encrypt_function() -> RawCipherFunctionPointer
fn raw_encrypt_function() -> RawCipherFunctionPointer
Pointer to the *_encrypt C function.
Used internally for block modi.