Trait nettle::cipher::Cipher

source ·
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§

source

const BLOCK_SIZE: usize

Block size in bytes.

source

const KEY_SIZE: usize

Maximal key size in bytes.

Required Methods§

source

fn with_decrypt_key(key: &[u8]) -> Result<Self>

Creates a new cipher instance for decryption.

The key parameter must have size KEY_SIZE.

source

fn with_encrypt_key(key: &[u8]) -> Result<Self>

Creates a new cipher instance for encryption.

The key parameter must have size KEY_SIZE.

source

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.

source

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.

source

fn context(&mut self) -> *mut c_void

Returns a pointer to the C context struct of the cipher instance.

Used internally by block modi.

source

fn raw_decrypt_function() -> RawCipherFunctionPointer

Pointer to the *_decrypt C function.

Used internally for block modi.

source

fn raw_encrypt_function() -> RawCipherFunctionPointer

Pointer to the *_encrypt C function.

Used internally for block modi.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl Cipher for ArcFour

source§

const BLOCK_SIZE: usize = 1usize

source§

const KEY_SIZE: usize = 256usize

source§

impl Cipher for ArcTwo

source§

const BLOCK_SIZE: usize = 8usize

source§

const KEY_SIZE: usize = 128usize

source§

impl Cipher for Des

source§

const BLOCK_SIZE: usize = 8usize

source§

const KEY_SIZE: usize = 8usize

source§

impl Cipher for Aes128

source§

const BLOCK_SIZE: usize = 16usize

source§

const KEY_SIZE: usize = 16usize

source§

impl Cipher for Aes192

source§

const BLOCK_SIZE: usize = 16usize

source§

const KEY_SIZE: usize = 24usize

source§

impl Cipher for Aes256

source§

const BLOCK_SIZE: usize = 16usize

source§

const KEY_SIZE: usize = 32usize

source§

impl Cipher for Blowfish

source§

const BLOCK_SIZE: usize = 8usize

source§

const KEY_SIZE: usize = 56usize

source§

impl Cipher for Camellia128

source§

const BLOCK_SIZE: usize = 16usize

source§

const KEY_SIZE: usize = 16usize

source§

impl Cipher for Camellia192

source§

const BLOCK_SIZE: usize = 16usize

source§

const KEY_SIZE: usize = 24usize

source§

impl Cipher for Camellia256

source§

const BLOCK_SIZE: usize = 16usize

source§

const KEY_SIZE: usize = 32usize

source§

impl Cipher for Cast128

source§

const BLOCK_SIZE: usize = 8usize

source§

const KEY_SIZE: usize = 16usize

source§

impl Cipher for Des3

source§

const BLOCK_SIZE: usize = 8usize

source§

const KEY_SIZE: usize = 24usize

source§

impl Cipher for Serpent

source§

const BLOCK_SIZE: usize = 16usize

source§

const KEY_SIZE: usize = 32usize

source§

impl Cipher for Twofish

source§

const BLOCK_SIZE: usize = 16usize

source§

const KEY_SIZE: usize = 32usize