block_modes

Trait BlockMode

Source
pub trait BlockMode<C: BlockCipher, P: Padding>: Sized {
    type IvSize: ArrayLength<u8>;

    // Required methods
    fn new(cipher: C, iv: &GenericArray<u8, Self::IvSize>) -> Self;
    fn encrypt_blocks(
        &mut self,
        blocks: &mut [GenericArray<u8, <C as BlockCipher>::BlockSize>],
    );
    fn decrypt_blocks(
        &mut self,
        blocks: &mut [GenericArray<u8, <C as BlockCipher>::BlockSize>],
    );

    // Provided methods
    fn new_fix(
        key: &GenericArray<u8, <C as NewBlockCipher>::KeySize>,
        iv: &GenericArray<u8, Self::IvSize>,
    ) -> Self
       where C: NewBlockCipher { ... }
    fn new_from_slices(
        key: &[u8],
        iv: &[u8],
    ) -> Result<Self, InvalidKeyIvLength>
       where C: NewBlockCipher { ... }
    fn encrypt(
        self,
        buffer: &mut [u8],
        pos: usize,
    ) -> Result<&[u8], BlockModeError> { ... }
    fn decrypt(self, buffer: &mut [u8]) -> Result<&[u8], BlockModeError> { ... }
    fn encrypt_vec(self, plaintext: &[u8]) -> Vec<u8>  { ... }
    fn decrypt_vec(self, ciphertext: &[u8]) -> Result<Vec<u8>, BlockModeError> { ... }
}
Expand description

Trait for a block cipher mode of operation that is used to apply a block cipher operation to input data to transform it into a variable-length output message.

Required Associated Types§

Source

type IvSize: ArrayLength<u8>

Initialization Vector size.

Required Methods§

Source

fn new(cipher: C, iv: &GenericArray<u8, Self::IvSize>) -> Self

Create a new block mode instance from initialized block cipher and IV.

Source

fn encrypt_blocks( &mut self, blocks: &mut [GenericArray<u8, <C as BlockCipher>::BlockSize>], )

Encrypt blocks of data

Source

fn decrypt_blocks( &mut self, blocks: &mut [GenericArray<u8, <C as BlockCipher>::BlockSize>], )

Decrypt blocks of data

Provided Methods§

Source

fn new_fix( key: &GenericArray<u8, <C as NewBlockCipher>::KeySize>, iv: &GenericArray<u8, Self::IvSize>, ) -> Self
where C: NewBlockCipher,

Create a new block mode instance from fixed sized key and IV.

Source

fn new_from_slices(key: &[u8], iv: &[u8]) -> Result<Self, InvalidKeyIvLength>
where C: NewBlockCipher,

Create a new block mode instance from variable size key and IV.

Returns an error if key or IV have unsupported length.

Source

fn encrypt(self, buffer: &mut [u8], pos: usize) -> Result<&[u8], BlockModeError>

Encrypt message in-place.

&buffer[..pos] is used as a message and &buffer[pos..] as a reserved space for padding. The padding space should be big enough for padding, otherwise method will return Err(BlockModeError).

Source

fn decrypt(self, buffer: &mut [u8]) -> Result<&[u8], BlockModeError>

Decrypt message in-place.

Returns an error if buffer length is not multiple of block size and if after decoding message has malformed padding.

Source

fn encrypt_vec(self, plaintext: &[u8]) -> Vec<u8>

Encrypt message and store result in vector.

Source

fn decrypt_vec(self, ciphertext: &[u8]) -> Result<Vec<u8>, BlockModeError>

Encrypt message and store result in vector.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<C, P> BlockMode<C, P> for Cbc<C, P>

Source§

impl<C, P> BlockMode<C, P> for Cfb8<C, P>

Source§

impl<C, P> BlockMode<C, P> for Cfb<C, P>

Source§

impl<C, P> BlockMode<C, P> for Ecb<C, P>

Source§

impl<C, P> BlockMode<C, P> for Ige<C, P>
where C: BlockCipher + BlockEncrypt + BlockDecrypt, P: Padding, C::BlockSize: Add, Sum<<C as BlockCipher>::BlockSize, <C as BlockCipher>::BlockSize>: ArrayLength<u8>,

Source§

impl<C, P> BlockMode<C, P> for Ofb<C, P>

Source§

impl<C, P> BlockMode<C, P> for Pcbc<C, P>