From f2f5fc6faf65fd181ac01e86cffab53cc913d342 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 19 Apr 2018 11:43:34 +0200 Subject: [PATCH] Add PacketKey::decrypt() method --- src/crypto.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 {