[−][src]Trait miscreant::aead::Aead
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
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]
)
&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>
&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.
Provided methods
fn seal(
&mut self,
nonce: &[u8],
associated_data: &[u8],
plaintext: &[u8]
) -> Vec<u8>
&mut self,
nonce: &[u8],
associated_data: &[u8],
plaintext: &[u8]
) -> Vec<u8>
Encrypt the given plaintext, allocating and returning a Vec
fn open(
&mut self,
nonce: &[u8],
associated_data: &[u8],
ciphertext: &[u8]
) -> Result<Vec<u8>, Error>
&mut self,
nonce: &[u8],
associated_data: &[u8],
ciphertext: &[u8]
) -> Result<Vec<u8>, Error>
Decrypt the given ciphertext, allocating and returning a Vec
Implementors
impl<C, M> Aead for SivAead<C, M> where
C: NewStreamCipher<NonceSize = U16> + SyncStreamCipher,
M: Mac<OutputSize = U16>,
[src]
impl<C, M> Aead for SivAead<C, M> where
C: NewStreamCipher<NonceSize = U16> + SyncStreamCipher,
M: Mac<OutputSize = U16>,
type KeySize = <C as NewStreamCipher>::KeySize
type TagSize = U16
fn new(key: &[u8]) -> Self | [src] |
fn seal_in_place( | [src] |
fn open_in_place<'a>( | [src] |
fn seal( | [src] |
fn open( | [src] |