[][src]Trait miscreant::Aead

pub trait Aead {
    type KeySize: ArrayLength<u8>;
    type TagSize: ArrayLength<u8>;
    fn new(key: &[u8]) -> Self;
fn encrypt_in_place(
        &mut self,
        nonce: &[u8],
        associated_data: &[u8],
        buffer: &mut [u8]
    );
fn decrypt_in_place<'a>(
        &mut self,
        nonce: &[u8],
        associated_data: &[u8],
        buffer: &'a mut [u8]
    ) -> Result<&'a [u8], Error>; fn encrypt(
        &mut self,
        nonce: &[u8],
        associated_data: &[u8],
        plaintext: &[u8]
    ) -> Vec<u8> { ... }
fn decrypt(
        &mut self,
        nonce: &[u8],
        associated_data: &[u8],
        ciphertext: &[u8]
    ) -> Result<Vec<u8>, Error> { ... } }

An Authenticated Encryption with Associated Data (AEAD) algorithm.

Associated Types

type KeySize: ArrayLength<u8>

Size of a key associated with this AEAD algorithm

type TagSize: ArrayLength<u8>

Size of a MAC tag

Loading content...

Required methods

fn new(key: &[u8]) -> Self

Create a new AEAD instance

Panics if the key is the wrong length

fn encrypt_in_place(
    &mut self,
    nonce: &[u8],
    associated_data: &[u8],
    buffer: &mut [u8]
)

Encrypt the given plaintext in-place, replacing it with the SIV tag and ciphertext. Requires a buffer with 16-bytes additional space.

To encrypt data, it is recommended to use this API instead of the lower-level Siv API.

Usage

It's important to note that only the end of the buffer will be treated as the input plaintext:

let buffer = [0u8; 21];
let plaintext = &buffer[..buffer.len() - 16];

In this case, only the last 5 bytes are treated as the plaintext, since 21 - 16 = 5 (the AES block size is 16-bytes).

The buffer must include an additional 16-bytes of space in which to write the SIV tag (at the beginning of the buffer). Failure to account for this will leave you with plaintext messages that are missing their first 16-bytes!

Panics

Panics if plaintext.len() is less than M::OutputSize. Panics if nonce.len() is greater than MAX_ASSOCIATED_DATA. Panics if associated_data.len() is greater than MAX_ASSOCIATED_DATA.

fn decrypt_in_place<'a>(
    &mut self,
    nonce: &[u8],
    associated_data: &[u8],
    buffer: &'a mut [u8]
) -> Result<&'a [u8], Error>

Decrypt the given ciphertext in-place, authenticating it against the synthetic IV included in the message.

To decrypt data, it is recommended to use this API instead of the lower-level Siv API.

Returns a slice containing a decrypted message on success.

Loading content...

Provided methods

fn encrypt(
    &mut self,
    nonce: &[u8],
    associated_data: &[u8],
    plaintext: &[u8]
) -> Vec<u8>

Encrypt the given plaintext, allocating and returning a Vec for the ciphertext

fn decrypt(
    &mut self,
    nonce: &[u8],
    associated_data: &[u8],
    ciphertext: &[u8]
) -> Result<Vec<u8>, Error>

Decrypt the given ciphertext, allocating and returning a Vec for the plaintext

Loading content...

Implementors

impl<C, M> Aead for SivAead<C, M> where
    C: NewStreamCipher<NonceSize = U16> + SyncStreamCipher,
    M: Mac<OutputSize = U16>,
    C::KeySize: Add,
    <C::KeySize as Add>::Output: ArrayLength<u8>, 
[src]

type KeySize = <C as NewStreamCipher>::KeySize

type TagSize = U16

Loading content...