pub trait Cipher {
    type Key: U8Array;

    // Required methods
    fn name() -> &'static str;
    fn encrypt(
        k: &Self::Key,
        nonce: u64,
        ad: &[u8],
        plaintext: &[u8],
        out: &mut [u8]
    );
    fn encrypt_in_place(
        k: &Self::Key,
        nonce: u64,
        ad: &[u8],
        in_out: &mut [u8],
        plaintext_len: usize
    ) -> usize;
    fn decrypt(
        k: &Self::Key,
        nonce: u64,
        ad: &[u8],
        ciphertext: &[u8],
        out: &mut [u8]
    ) -> Result<(), ()>;
    fn decrypt_in_place(
        k: &Self::Key,
        nonce: u64,
        ad: &[u8],
        in_out: &mut [u8],
        ciphertext_len: usize
    ) -> Result<usize, ()>;

    // Provided methods
    fn key_len() -> usize { ... }
    fn tag_len() -> usize { ... }
    fn rekey(k: &Self::Key) -> Self::Key { ... }
}
Expand description

An AEAD.

Required Associated Types§

source

type Key: U8Array

Type of key.

Required Methods§

source

fn name() -> &'static str

Name of this cipher function.

source

fn encrypt( k: &Self::Key, nonce: u64, ad: &[u8], plaintext: &[u8], out: &mut [u8] )

AEAD encryption.

Panics

If out.len() != plaintext.len() + Self::tag_len()

source

fn encrypt_in_place( k: &Self::Key, nonce: u64, ad: &[u8], in_out: &mut [u8], plaintext_len: usize ) -> usize

AEAD encryption, but encrypt on one buffer. return the length of ciphertext.

Panics

If in_out.len() < plaintext_len + Self::tag_len()

source

fn decrypt( k: &Self::Key, nonce: u64, ad: &[u8], ciphertext: &[u8], out: &mut [u8] ) -> Result<(), ()>

AEAD decryption.

Panics

If out.len() != ciphertext.len() - Self::tag_len()

source

fn decrypt_in_place( k: &Self::Key, nonce: u64, ad: &[u8], in_out: &mut [u8], ciphertext_len: usize ) -> Result<usize, ()>

AEAD decryption, but decrypt on one buffer. return the length of plaintext.

Panics

If in_out.len() < ciphertext_len or ciphertext_len < Self::tag_len()

Provided Methods§

source

fn key_len() -> usize

Length of key.

source

fn tag_len() -> usize

Length of auth tag.

All ciphers specified in the spec has tag length 16.

source

fn rekey(k: &Self::Key) -> Self::Key

Rekey. Returns a new cipher key as a pseudorandom function of k.

Object Safety§

This trait is not object safe.

Implementors§