Function tindercrypt::aead::seal_in_place[][src]

pub fn seal_in_place(
    algo: &'static Algorithm,
    nonce: [u8; 12],
    aad: &[u8],
    key: &[u8],
    in_out: &mut [u8]
) -> Result<usize, Error>
Expand description

Seal the contents of a data buffer in place.

This function is a wrapper around the seal_in_place() function of the ring library. Its purpose is to simplify what needs to be passed to the underlying function and perform some early checks. The produced ciphertext will be stored in the same buffer as the plaintext, effectively erasing it.

This function accepts the following parameters:

  • A ring AEAD algorithm, e.g., AES-256-GCM,
  • A nonce buffer with a specific size. This nonce must NEVER be reused for the same key.
  • A reference to some data (additional authenticated data), which won’t be stored with the ciphertext, but will be used for the encryption and will be required for the decryption as well.
  • A reference to a symmetric key, whose size must match the size required by the AEAD algorithm.
  • A data buffer that holds the plaintext. The ciphertext will be stored in this buffer, so it must be large enough to contain the encrypted data and the tag as well. In practice, the user must craft a buffer that starts with the plaintext and add an empty space at the end, as large as the tag size expected by the algorithm.

This function returns an error if the key/buffer sizes are not the expected ones. If the encryption fails, which should never happen in practice, this function panics. If the encryption succeeds, it returns the length of the plaintext.