Skip to main content

AEADCipher

Trait AEADCipher 

Source
pub trait AEADCipher<const KEY_LEN: usize, const NONCE_LEN: usize, const TAG_LEN: usize>: SymmetricCipher<KEY_LEN, NONCE_LEN> + Sized {
    // Required methods
    fn aead_encrypt(
        key: &KeyMaterial<KEY_LEN>,
        aad: &[u8],
        plaintext: &[u8],
    ) -> Result<([u8; NONCE_LEN], Vec<u8>, [u8; TAG_LEN]), SymmetricCipherError>;
    fn aead_encrypt_out(
        key: &KeyMaterial<KEY_LEN>,
        aad: &[u8],
        plaintext: &[u8],
        ciphertext: &mut [u8],
    ) -> Result<([u8; NONCE_LEN], usize, [u8; TAG_LEN]), SymmetricCipherError>;
    fn do_aead_encrypt_final(
        self,
    ) -> Result<[u8; TAG_LEN], SymmetricCipherError>;
    fn aead_decrypt(
        key: &KeyMaterial<KEY_LEN>,
        nonce: &[u8; NONCE_LEN],
        aad: &[u8],
        ciphertext: &[u8],
        tag: &[u8; TAG_LEN],
    ) -> Result<Vec<u8>, SymmetricCipherError>;
    fn aead_decrypt_out(
        key: &KeyMaterial<KEY_LEN>,
        nonce: &[u8; NONCE_LEN],
        aad: &[u8],
        ciphertext: &[u8],
        tag: &[u8; TAG_LEN],
        plaintext: &mut [u8],
    ) -> Result<usize, SymmetricCipherError>;
    fn do_aead_decrypt_final(
        self,
        tag: &[u8; TAG_LEN],
    ) -> Result<(), SymmetricCipherError>;
}
Expand description

The basic functions of an Authenticated Encryption with Addititional Data cipher.

Required Methods§

Source

fn aead_encrypt( key: &KeyMaterial<KEY_LEN>, aad: &[u8], plaintext: &[u8], ) -> Result<([u8; NONCE_LEN], Vec<u8>, [u8; TAG_LEN]), SymmetricCipherError>

A one-shot API to encrypt some plaintext with the given key. A distinguishing feature of AEAD ciphers is the ability to provide additional authenticated data (AAD) that is not encrypted but is protected by the authentication tag; ie it can be sent along with the ciphertext and any tampering with it will result in the decryption operation failing the tag check. This function returns the ciphertext as a Vec<u8>, and therefore is only available when compiling with std. Returns a tuple containing a generated nonce, the ciphertext and the tag.

Source

fn aead_encrypt_out( key: &KeyMaterial<KEY_LEN>, aad: &[u8], plaintext: &[u8], ciphertext: &mut [u8], ) -> Result<([u8; NONCE_LEN], usize, [u8; TAG_LEN]), SymmetricCipherError>

A one-shot API to encrypt some plaintext with the given key. A distinguishing feature of AEAD ciphers is the ability to provide additional authenticated data (AAD) that is not encrypted but is protected by the authentication tag; ie it can be sent along with the ciphertext and any tampering with it will result in the decryption operation failing the tag check. Returns a tuple containing the randomly-generated nonce, number of bytes written to the ciphertext buffer, and the tag. If you need a deterministic mode where you feed in the nonce, use the streaming API of BlockCipher or StreamCipher as appropriate and feed the nonce into the IV field.

Source

fn do_aead_encrypt_final(self) -> Result<[u8; TAG_LEN], SymmetricCipherError>

All AEAD ciphers will also be either a BlockCipher or a StreamCipher, and so will already have a streaming API. This allows you to finish either style of streaming API flow with AEAD specific do_final() that computes and returns the authentication tag.

Source

fn aead_decrypt( key: &KeyMaterial<KEY_LEN>, nonce: &[u8; NONCE_LEN], aad: &[u8], ciphertext: &[u8], tag: &[u8; TAG_LEN], ) -> Result<Vec<u8>, SymmetricCipherError>

A one-shot API to decrypt some ciphertext with the given key. This function returns the ciphertext as a Vec<u8>, and therefore is only available when compiling with std.

Source

fn aead_decrypt_out( key: &KeyMaterial<KEY_LEN>, nonce: &[u8; NONCE_LEN], aad: &[u8], ciphertext: &[u8], tag: &[u8; TAG_LEN], plaintext: &mut [u8], ) -> Result<usize, SymmetricCipherError>

A one-shot API to decrypt some ciphertext with the given key. This function takes a reference to the output buffer for the plaintext, and is therefore available in no_std. See the documentation for the underlying implementation for details on providing a plaintext buffer of sufficient size; typically the ciphertext is the same length as the plaintext, but some ciphers may have an expansion factor or require extra space for a nonce or tag. Returns the number of bytes written to the plaintext buffer.

Source

fn do_aead_decrypt_final( self, tag: &[u8; TAG_LEN], ) -> Result<(), SymmetricCipherError>

All AEAD ciphers will also be either a BlockCipher or a StreamCipher, and so will already have a streaming API. This allows you to finish either style of streaming API flow with AEAD specific do_final() that computes and returns the authentication tag.

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§