diff --git a/src/crypto.rs b/src/crypto.rs index 0989f595a..d84ff4908 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -1,7 +1,7 @@ use bytes::{BigEndian, BufMut}; use ring::{ - aead::{self, AES_128_GCM, SealingKey}, + aead::{self, AES_128_GCM, OpeningKey, SealingKey}, digest::SHA256, hkdf, hmac::SigningKey, @@ -39,6 +39,12 @@ impl PacketKey { let nonce = &self.data[self.split..]; aead::seal_in_place(&key, nonce, ad, in_out, out_suffix_capacity).unwrap() } + + pub fn decrypt<'a>(&self, ad: &[u8], input: &'a mut [u8]) -> &'a [u8] { + let key = OpeningKey::new(self.alg, &self.data[..self.split]).unwrap(); + let nonce = &self.data[self.split..]; + aead::open_in_place(&key, nonce, ad, 0, input).unwrap() + } } fn client_handshake_secret(conn_id: u64) -> Vec {