Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AEAD decryption-in-place traits with additional tag processing, created for committing AEAD wrappers #1372

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions aead/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,63 @@ pub trait AeadMutInPlace: AeadCore {
) -> Result<()>;
}

/// In-place stateless AEADs that support additional processing on the expected
/// tag before comparing the result to the received tag.
///
/// # ⚠️Hazmat Trait
///
/// This trait was added to allow implementation of committing AEAD wrappers
/// like CTX which require access to the expected tag at decryption time.
/// **Incorrect usage of this trait can destroy the integrity guarantees that
/// an AEAD otherwise provides. Unless you know exactly what you're doing and
/// have a good reason to need the expected tag's value beyond checking the
/// received tag's correctness, do not use this trait's function.**
pub trait DelegatedAuthenticityAeadInPlace: AeadInPlace {
/// Decrypt the data in-place, returning an error in the event the provided
/// authentication tag does not match the given ciphertext (i.e. ciphertext
/// is modified/unauthentic), with additional tag processing
///
/// The `tag_closure` argument is a function that receives the expected tag
/// and performs a computation on it to produce a new value that can then be
/// directly compared to the received tag.
fn decrypt_in_place_detached_with_tag_processing<N: ArrayLength<u8>>(
&self,
nonce: &Nonce<Self>,
associated_data: &[u8],
buffer: &mut [u8],
received_tag: GenericArray<u8, N>,
tag_closure: impl Fn(&Tag<Self>) -> GenericArray<u8, N>,
) -> Result<()>;
}
/// In-place stateful AEADs that support additional processing on the expected
/// tag before comparing the result to the received tag.
///
/// # ⚠️Hazmat Trait
///
/// This trait was added to allow implementation of committing AEAD wrappers
/// like CTX which require access to the expected tag at decryption time.
/// **Incorrect usage of this trait can destroy the integrity guarantees that
/// an AEAD otherwise provides. Unless you know exactly what you're doing and
/// have a good reason to need the expected tag's value beyond checking the
/// received tag's correctness, do not use this trait's function.**
pub trait DelegatedAuthenticityAeadMutInPlace: AeadMutInPlace {
/// Decrypt the data in-place, returning an error in the event the provided
/// authentication tag does not match the given ciphertext (i.e. ciphertext
/// is modified/unauthentic), with additional tag processing
///
/// The `tag_closure` argument is a function that receives the expected tag
/// and performs a computation on it to produce a new value that can then be
/// directly compared to the received tag.
fn decrypt_in_place_detached_with_tag_processing<N: ArrayLength<u8>>(
&mut self,
nonce: &Nonce<Self>,
associated_data: &[u8],
buffer: &mut [u8],
received_tag: GenericArray<u8, N>,
tag_closure: impl Fn(&Tag<Self>) -> GenericArray<u8, N>,
) -> Result<()>;
}

#[cfg(feature = "alloc")]
impl<Alg: AeadInPlace> Aead for Alg {
fn encrypt<'msg, 'aad>(
Expand Down