From 10af50b47d7fdbe072688e2df0da872ea2a274a1 Mon Sep 17 00:00:00 2001 From: bit-aloo <84662239+Shourya742@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:35:11 +0530 Subject: [PATCH] Update protocols/v2/noise-sv2/src/aed_cipher.rs Co-authored-by: RJ Rybarczyk --- protocols/v2/noise-sv2/src/aed_cipher.rs | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/protocols/v2/noise-sv2/src/aed_cipher.rs b/protocols/v2/noise-sv2/src/aed_cipher.rs index 86ec83ad2c..4ce0dc70f9 100644 --- a/protocols/v2/noise-sv2/src/aed_cipher.rs +++ b/protocols/v2/noise-sv2/src/aed_cipher.rs @@ -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};