Skip to main content

BlockCipher

Trait BlockCipher 

Source
pub trait BlockCipher<W: Word, const N: usize> {
    // Required methods
    fn control_block_version(&self) -> String;
    fn block_size(&self) -> usize;
    fn word_size(&self) -> usize;
    fn generate_blocks(&self, pt: Vec<u8>) -> Vec<[W; N]>;
    fn generate_bytes_stream(&self, blocks: Vec<[W; N]>) -> Vec<u8> ;
    fn encrypt(&self, pt: [W; N]) -> [W; N];
    fn decrypt(&self, ct: [W; N]) -> [W; N];
}
Expand description

A core trait that any block-cipher must implement to work with Cipher.

Generics in this trait defines:

  • W: A variable length unit type which implements Word trait.
  • N: A generic constand for number of words per block.

This trait coerces some of the necessary functionalities for block-cipher.

Required Methods§

Source

fn control_block_version(&self) -> String

Human‐readable version tag, mostly a parametric version. e.g. in RC5-block-cipher “RC5-32/12/16”.

Source

fn block_size(&self) -> usize

Base block-size in bytes for a block-cipher.

Source

fn word_size(&self) -> usize

Word-szie in bytes per block for a block-cipher.

Source

fn generate_blocks(&self, pt: Vec<u8>) -> Vec<[W; N]>

Split a byte‐vector into a Vec of length-N word blocks. More generally, it creates a list of blocks from a stream of plain bytes.

Source

fn generate_bytes_stream(&self, blocks: Vec<[W; N]>) -> Vec<u8>

Generates a stream of bytes from a list of blocks. More specefically from N word blocks list generates byte-vector. Its counterfiet of generate_blocks method.

Source

fn encrypt(&self, pt: [W; N]) -> [W; N]

Raw encryption, encrypt a single [W;N] block.

Returns a cipher [W;N] block

Source

fn decrypt(&self, ct: [W; N]) -> [W; N]

Raw decryption, decrypt a single [W;N] block.

Returns a plain-text [W;N] block

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§