Skip to content

Commit

Permalink
Update protocols/v2/noise-sv2/src/aed_cipher.rs
Browse files Browse the repository at this point in the history
Co-authored-by: RJ Rybarczyk <[email protected]>
  • Loading branch information
Shourya742 and rrybarczyk authored Oct 11, 2024
1 parent f54c09c commit 10af50b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions protocols/v2/noise-sv2/src/aed_cipher.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// # AEAD Cipher
//
// Defines the [`AeadCipher`] trait which standardizes the interface for Authenticated Encryption
// with Associated Data (AEAD) ciphers used within the Noise protocol implementation. The trait is
// implemented for two common ciphers, [`ChaCha20Poly1305`] and [`Aes256Gcm`], providing encryption
// and decryption functionality with authenticated data.
// Abstracts the encryption and decryption operations for authenticated encryption with associated
// data (AEAD) ciphers used in the Noise protocol.
//
// ## Overview
// The [`AeadCipher`] trait provides a unified interface for AEAD ciphers, including
// [`ChaCha20Poly1305`] and [`Aes256Gcm`], allowing flexible cryptographic operations in different
// contexts.
//
// AEAD ciphers provide both confidentiality and integrity by encrypting data and creating an
// authentication tag in a single step. The integrity of additional associated data (AAD) can also
// be verified without including it in the encrypted output.
// The trait supports core AEAD operations, including:
//
// - Key initialization via the `from_key` method to derive a cipher instance from a 32-byte key.
// - Authenticated encryption via the `encrypt` method to securely encrypt data with a nonce and
// additional associated data (AAD).
// - Authenticated decryption via the `decrypt` method to securely decrypt data using the provided
// nonce and AAD.
//
// ## Usage
//
// The [`AeadCipher`] trait is used by the [`crate::handshake::HandshakeOp`] trait to perform
// cryptographic operations during the Noise protocol handshake, ensuring secure communication
// between parties.
// The `AeadCipher` trait can be implemented for any AEAD cipher, enabling encryption and decryption
// of Noise protocol messages. Two default implementations are provided for the
// [`ChaCha20Poly1305`] and [`Aes256Gcm`] ciphers.

use aes_gcm::Aes256Gcm;
use chacha20poly1305::{aead::Buffer, AeadInPlace, ChaCha20Poly1305, ChaChaPoly1305, KeyInit};
Expand Down

0 comments on commit 10af50b

Please sign in to comment.