Trait block_cipher_trait::BlockCipher
source · pub trait BlockCipher: Sized {
type KeySize: ArrayLength<u8>;
type BlockSize: ArrayLength<u8>;
type ParBlocks: ArrayLength<GenericArray<u8, Self::BlockSize>>;
fn new(key: &GenericArray<u8, Self::KeySize>) -> Self;
fn encrypt_block(&self, block: &mut GenericArray<u8, Self::BlockSize>);
fn decrypt_block(&self, block: &mut GenericArray<u8, Self::BlockSize>);
fn new_varkey(key: &[u8]) -> Result<Self, InvalidKeyLength> { ... }
fn encrypt_blocks(
&self,
blocks: &mut GenericArray<GenericArray<u8, Self::BlockSize>, Self::ParBlocks>
) { ... }
fn decrypt_blocks(
&self,
blocks: &mut GenericArray<GenericArray<u8, Self::BlockSize>, Self::ParBlocks>
) { ... }
}
Expand description
The trait which defines in-place encryption and decryption over single block or several blocks in parallel.
Required Associated Types§
sourcetype KeySize: ArrayLength<u8>
type KeySize: ArrayLength<u8>
Key size in bytes with which cipher guaranteed to be initialized
sourcetype BlockSize: ArrayLength<u8>
type BlockSize: ArrayLength<u8>
Size of the block in bytes
sourcetype ParBlocks: ArrayLength<GenericArray<u8, Self::BlockSize>>
type ParBlocks: ArrayLength<GenericArray<u8, Self::BlockSize>>
Number of blocks which can be processed in parallel by cipher implementation
Required Methods§
sourcefn new(key: &GenericArray<u8, Self::KeySize>) -> Self
fn new(key: &GenericArray<u8, Self::KeySize>) -> Self
Create new block cipher instance from key with fixed size.
sourcefn encrypt_block(&self, block: &mut GenericArray<u8, Self::BlockSize>)
fn encrypt_block(&self, block: &mut GenericArray<u8, Self::BlockSize>)
Encrypt block in-place
sourcefn decrypt_block(&self, block: &mut GenericArray<u8, Self::BlockSize>)
fn decrypt_block(&self, block: &mut GenericArray<u8, Self::BlockSize>)
Decrypt block in-place
Provided Methods§
sourcefn new_varkey(key: &[u8]) -> Result<Self, InvalidKeyLength>
fn new_varkey(key: &[u8]) -> Result<Self, InvalidKeyLength>
Create new block cipher instance from key with variable size.
Default implementation will accept only keys with length equal to
KeySize
, but some ciphers can accept range of key lengths.
sourcefn encrypt_blocks(
&self,
blocks: &mut GenericArray<GenericArray<u8, Self::BlockSize>, Self::ParBlocks>
)
fn encrypt_blocks(
&self,
blocks: &mut GenericArray<GenericArray<u8, Self::BlockSize>, Self::ParBlocks>
)
Encrypt several blocks in parallel using instruction level parallelism if possible.
If ParBlocks
equals to 1 it’s equivalent to encrypt_block
.
sourcefn decrypt_blocks(
&self,
blocks: &mut GenericArray<GenericArray<u8, Self::BlockSize>, Self::ParBlocks>
)
fn decrypt_blocks(
&self,
blocks: &mut GenericArray<GenericArray<u8, Self::BlockSize>, Self::ParBlocks>
)
Decrypt several blocks in parallel using instruction level parallelism if possible.
If ParBlocks
equals to 1 it’s equivalent to decrypt_block
.