Trait Cipher

Source
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.

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§