[][src]Struct miscreant::siv::Siv

pub struct Siv<C, M> where
    C: NewStreamCipher<NonceSize = U16> + SyncStreamCipher,
    M: Mac<OutputSize = U16>, 
{ /* fields omitted */ }

Synthetic Initialization Vector (SIV) mode, providing misuse-resistant authenticated encryption (MRAE).

Methods

impl<C, M> Siv<C, M> where
    C: NewStreamCipher<NonceSize = U16> + SyncStreamCipher,
    M: Mac<OutputSize = U16>, 
[src]

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

Create a new AES-SIV instance

Panics if the key is the wrong length

pub fn seal_in_place<I, T>(&mut self, headers: I, plaintext: &mut [u8]) where
    I: IntoIterator<Item = T>,
    T: AsRef<[u8]>, 
[src]

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

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 headers.len() is greater than MAX_ASSOCIATED_DATA.

pub fn open_in_place<'a, I, T>(
    &mut self,
    headers: I,
    ciphertext: &'a mut [u8]
) -> Result<&'a [u8], Error> where
    I: IntoIterator<Item = T>,
    T: AsRef<[u8]>, 
[src]

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

Returns a slice containing a decrypted message on success.

Important traits for Vec<u8>
pub fn seal<I, T>(&mut self, associated_data: I, plaintext: &[u8]) -> Vec<u8> where
    I: IntoIterator<Item = T>,
    T: AsRef<[u8]>, 
[src]

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

pub fn open<I, T>(
    &mut self,
    associated_data: I,
    ciphertext: &[u8]
) -> Result<Vec<u8>, Error> where
    I: IntoIterator<Item = T>,
    T: AsRef<[u8]>, 
[src]

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

Trait Implementations

impl<C, M> Drop for Siv<C, M> where
    C: NewStreamCipher<NonceSize = U16> + SyncStreamCipher,
    M: Mac<OutputSize = U16>, 
[src]

Auto Trait Implementations

impl<C, M> Send for Siv<C, M> where
    M: Send,
    <C as NewStreamCipher>::KeySize: ArrayLength<u8>, 

impl<C, M> Sync for Siv<C, M> where
    M: Sync,
    <C as NewStreamCipher>::KeySize: ArrayLength<u8>, 

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same for T

type Output = T

Should always be Self