pub struct Encryptor { /* private fields */ }Expand description
An encryptor utilizing XChaCha20Poly1305 authenticated encryption with a Kyber shared secret
This struct provides an interface for encrypting and decrypting data using a post-quantum shared secret established via ML-KEM (formerly Kyber). It uses XChaCha20Poly1305 for authenticated encryption with associated data (AEAD).
Implementations§
Source§impl Encryptor
impl Encryptor
Sourcepub fn new(shared_secret: SharedSecret) -> Self
pub fn new(shared_secret: SharedSecret) -> Self
Sourcepub fn encrypt(
&self,
plaintext: &[u8],
nonce: &[u8; 24],
) -> Result<Vec<u8>, CryptoError>
pub fn encrypt( &self, plaintext: &[u8], nonce: &[u8; 24], ) -> Result<Vec<u8>, CryptoError>
Encrypts plaintext using XChaCha20Poly1305 with the stored shared secret
§Arguments
plaintext- The data to encryptnonce- A 24-byte nonce (must be unique for each encryption with the same key)
§Returns
Result<Vec<u8>, CryptoError>: The encrypted ciphertext or an error
§Security Notes
- The nonce must never be reused with the same key
- The ciphertext includes an authentication tag to verify integrity
Sourcepub fn decrypt(
&self,
ciphertext: &[u8],
nonce: &[u8; 24],
) -> Result<Vec<u8>, CryptoError>
pub fn decrypt( &self, ciphertext: &[u8], nonce: &[u8; 24], ) -> Result<Vec<u8>, CryptoError>
Decrypts ciphertext using XChaCha20Poly1305 with the stored shared secret
§Arguments
ciphertext- The encrypted data to decryptnonce- The 24-byte nonce used during encryption
§Returns
Result<Vec<u8>, CryptoError>: The decrypted plaintext or an error
§Security Notes
- This function will return an error if the ciphertext has been tampered with
- The same nonce used for encryption must be provided for decryption
Auto Trait Implementations§
impl Freeze for Encryptor
impl RefUnwindSafe for Encryptor
impl Send for Encryptor
impl Sync for Encryptor
impl Unpin for Encryptor
impl UnwindSafe for Encryptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more