Skip to main content

SymmetricCipher

Trait SymmetricCipher 

Source
pub trait SymmetricCipher<const KEY_LEN: usize, const INIT_DATA_LEN: usize>: Algorithm {
    // Required methods
    fn encrypt(
        key: &KeyMaterial<KEY_LEN>,
        plaintext: &[u8],
    ) -> Result<([u8; INIT_DATA_LEN], Vec<u8>), SymmetricCipherError>;
    fn encrypt_out(
        key: &KeyMaterial<KEY_LEN>,
        plaintext: &[u8],
        ciphertext: &mut [u8],
    ) -> Result<([u8; INIT_DATA_LEN], usize), SymmetricCipherError>;
    fn decrypt(
        key: &KeyMaterial<KEY_LEN>,
        init_data: [u8; INIT_DATA_LEN],
        ciphertext: &[u8],
    ) -> Result<Vec<u8>, SymmetricCipherError>;
    fn decrypt_out(
        key: &KeyMaterial<KEY_LEN>,
        init_data: [u8; INIT_DATA_LEN],
        ciphertext: &[u8],
        plaintext: &mut [u8],
    ) -> Result<usize, SymmetricCipherError>;
}
Expand description

The basic one-shot encrypt and decrypt that all types of symmetric ciphers must implement. These are meant to be simple, easy to use, secure, and fool-proof APIs, but they may result in ciphertexts that are incompatible with other implementations as ciphers in more complex modes, such as AEADs or stream ciphers may need to stick extra data either at the beginning or end of the ciphertext. See the documentation of the underlying implementation for more details.

Required Methods§

Source

fn encrypt( key: &KeyMaterial<KEY_LEN>, plaintext: &[u8], ) -> Result<([u8; INIT_DATA_LEN], Vec<u8>), SymmetricCipherError>

A one-shot API to encrypt some plaintext with the given key. This function returns the ciphertext as a Vec<u8>, and therefore is only available when compiling with std. Returns a tuple containing the initialization data and the ciphertext. This is not available if building for no_std.

Source

fn encrypt_out( key: &KeyMaterial<KEY_LEN>, plaintext: &[u8], ciphertext: &mut [u8], ) -> Result<([u8; INIT_DATA_LEN], usize), SymmetricCipherError>

A one-shot API to encrypt some plaintext with the given key. This function takes a reference to the output buffer for the ciphertext, and is therefore available in no_std. See the documentation for the underlying implementation for details on providing a ciphertext 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 a tuple containing the initialization data and the number of bytes written to the ciphertext buffer.

Source

fn decrypt( key: &KeyMaterial<KEY_LEN>, init_data: [u8; INIT_DATA_LEN], ciphertext: &[u8], ) -> 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. This is not available if building for no_std.

Source

fn decrypt_out( key: &KeyMaterial<KEY_LEN>, init_data: [u8; INIT_DATA_LEN], ciphertext: &[u8], 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 a tuple containing the initialization data and the number of bytes written to the plaintext buffer.

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§