Skip to main content

BlockCipher

Trait BlockCipher 

Source
pub trait BlockCipher: Algorithm {
    const BLOCK_LEN: usize;
    const KEY_LEN: usize;

    // Required methods
    fn new(key: &[u8]) -> Result<Self>
       where Self: Sized;
    fn encrypt_block(&self, block: &mut [u8]) -> Result<()>;
    fn decrypt_block(&self, block: &mut [u8]) -> Result<()>;

    // Provided method
    fn encrypt_blocks(&self, data: &mut [u8]) -> Result<()> { ... }
}
Expand description

A fixed-width block cipher primitive (raw ECB core, for use inside modes).

Required Associated Constants§

Source

const BLOCK_LEN: usize

Block size in bytes.

Source

const KEY_LEN: usize

Accepted key length in bytes.

Required Methods§

Source

fn new(key: &[u8]) -> Result<Self>
where Self: Sized,

Expand a key into a round-key schedule.

Source

fn encrypt_block(&self, block: &mut [u8]) -> Result<()>

Encrypt a single block in place.

Source

fn decrypt_block(&self, block: &mut [u8]) -> Result<()>

Decrypt a single block in place.

Provided Methods§

Source

fn encrypt_blocks(&self, data: &mut [u8]) -> Result<()>

Encrypt a whole number of blocks in place.

The default implementation loops over encrypt_block. Backends with instruction-level parallelism override it: AES-NI has a pipelined round instruction, so encrypting eight independent blocks at once is several times faster than eight sequential calls. Counter-based modes route through here for exactly that reason.

Returns crate::ErrorKind::InvalidLength if data is not a whole number of blocks.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§