From c685c4e7358ec1fe235b05d64cdcbdd626543de6 Mon Sep 17 00:00:00 2001 From: bit-aloo Date: Mon, 1 Sep 2025 16:16:41 +0530 Subject: [PATCH] Add AeadCipher trait abstraction - Define a common trait `AeadCipher` for encryption/decryption. - Provide methods for both "combined" and "detached" encryption modes: - encrypt / decrypt - encrypt_detached / decrypt_detached --- core/storage/encryption.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/storage/encryption.rs b/core/storage/encryption.rs index 5211f1b38..a37c2eaaf 100644 --- a/core/storage/encryption.rs +++ b/core/storage/encryption.rs @@ -72,6 +72,21 @@ impl Drop for EncryptionKey { } } +pub trait AeadCipher { + fn encrypt(&self, plaintext: &[u8], ad: &[u8]) -> Result<(Vec, Vec)>; + fn decrypt(&self, ciphertext: &[u8], nonce: &[u8], ad: &[u8]) -> Result>; + + fn encrypt_detached(&self, plaintext: &[u8], ad: &[u8]) -> Result<(Vec, Vec, Vec)>; + + fn decrypt_detached( + &self, + ciphertext: &[u8], + nonce: &[u8], + tag: &[u8], + ad: &[u8], + ) -> Result>; +} + // wrapper struct for AEGIS-256 cipher, because the crate we use is a bit low-level and we add // some nice abstractions here // note, the AEGIS has many variants and support for hardware acceleration. Here we just use the