[][src]Trait miscreant::aead::Aead

pub trait Aead {
    type KeySize: ArrayLength<u8>;
    type TagSize: ArrayLength<u8>;
    fn new(key: &[u8]) -> Self;
fn seal_in_place(
        &mut self,
        nonce: &[u8],
        associated_data: &[u8],
        buffer: &mut [u8]
    );
fn open_in_place<'a>(
        &mut self,
        nonce: &[u8],
        associated_data: &[u8],
        buffer: &'a mut [u8]
    ) -> Result<&'a [u8], Error>; fn seal(
        &mut self,
        nonce: &[u8],
        associated_data: &[u8],
        plaintext: &[u8]
    ) -> Vec<u8> { ... }
fn open(
        &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 seal_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 open_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

Important traits for Vec<u8>

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

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

fn open(
    &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>, 
[src]

type KeySize = <C as NewStreamCipher>::KeySize

type TagSize = U16

Important traits for Vec<u8>
fn seal(
    &mut self,
    nonce: &[u8],
    associated_data: &[u8],
    plaintext: &[u8]
) -> Vec<u8>
[src]

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

Loading content...