From b5fefd05a88ce382f530b8455a51083c73694d0b Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Fri, 7 May 2021 12:00:18 -0600 Subject: [PATCH] upgrade aes (#99) --- srt-protocol/Cargo.toml | 9 ++++----- srt-protocol/src/crypto.rs | 8 +++----- srt-protocol/src/crypto/wrap.rs | 17 +++++++++-------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/srt-protocol/Cargo.toml b/srt-protocol/Cargo.toml index 732b71f5..422f0ab7 100644 --- a/srt-protocol/Cargo.toml +++ b/srt-protocol/Cargo.toml @@ -15,11 +15,10 @@ log = { version = "0.4", default-features = false } bytes = "1" streaming-stats = "0.2.3" rand = "0.8" -aes-ctr = "0.6" -aes-soft = "0.6" -cipher = "0.2" -pbkdf2 = { version = "0.7", default-features = false } -hmac = "0.10" +aes = { version = "0.7", features = ["ctr"] } +cipher = "0.3" +pbkdf2 = { version = "0.8", default-features = false } +hmac = "0.11" sha-1 = "0.9" bitflags = "1" diff --git a/srt-protocol/src/crypto.rs b/srt-protocol/src/crypto.rs index 5d54cded..6998d1d1 100644 --- a/srt-protocol/src/crypto.rs +++ b/srt-protocol/src/crypto.rs @@ -1,8 +1,6 @@ -use aes_ctr::{ - cipher::{NewBlockCipher, NewStreamCipher, SyncStreamCipher}, - Aes128Ctr, Aes192Ctr, Aes256Ctr, -}; -use aes_soft::{Aes128, Aes192, Aes256}; +use aes::NewBlockCipher; +use aes::{Aes128, Aes128Ctr, Aes192, Aes192Ctr, Aes256, Aes256Ctr}; +use cipher::{NewCipher, StreamCipher}; use hmac::Hmac; use pbkdf2::pbkdf2; use sha1::Sha1; diff --git a/srt-protocol/src/crypto/wrap.rs b/srt-protocol/src/crypto/wrap.rs index 2ca8fa56..0d40e7e1 100644 --- a/srt-protocol/src/crypto/wrap.rs +++ b/srt-protocol/src/crypto/wrap.rs @@ -1,6 +1,7 @@ //! Aes key wrapping is availble in OpenSSL rust, but it's the only thing we need from openssl...so I just ported OpenSSL's code to Rust //! If a third-party library offers, this it would be better... +use aes::{BlockDecrypt, BlockEncrypt}; use cipher::generic_array::typenum::consts::U16; use cipher::generic_array::{ArrayLength, GenericArray}; use cipher::BlockCipher; @@ -44,7 +45,7 @@ pub const DEFAULT_IV: [u8; 8] = [0xA6; 8]; // } pub fn aes_wrap(key: &K, iv: Option<&[u8; 8]>, out: &mut [u8], input: &[u8]) where - K: BlockCipher, + K: BlockEncrypt, ::ParBlocks: ArrayLength>, { assert_eq!(input.len() & 0x7, 0); @@ -116,7 +117,7 @@ where // } pub fn aes_unwrap(key: &K, iv: &mut [u8; 8], out: &mut [u8], input: &[u8]) where - K: BlockCipher, + K: BlockDecrypt, ::ParBlocks: ArrayLength>, { assert_eq!(input.len(), out.len() + 8); @@ -157,14 +158,14 @@ where mod test { use super::*; - use aes_soft::cipher::NewBlockCipher; - use aes_soft::*; + use aes::cipher::NewBlockCipher; + use aes::*; // these are from https://tools.ietf.org/html/rfc3394#page-8 #[test] fn example_4_1() { - let kek = - Aes128::new_varkey(&hex::decode("000102030405060708090A0B0C0D0E0F").unwrap()).unwrap(); + let kek = Aes128::new_from_slice(&hex::decode("000102030405060708090A0B0C0D0E0F").unwrap()) + .unwrap(); let to_wrap = hex::decode("00112233445566778899AABBCCDDEEFF").unwrap(); let mut out = [0; 24]; @@ -183,7 +184,7 @@ mod test { #[test] fn example_4_2() { - let kek = Aes192::new_varkey( + let kek = Aes192::new_from_slice( &hex::decode("000102030405060708090A0B0C0D0E0F1011121314151617").unwrap(), ) .unwrap(); @@ -205,7 +206,7 @@ mod test { #[test] fn example_4_3() { - let kek = Aes256::new_varkey( + let kek = Aes256::new_from_slice( &hex::decode("000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F") .unwrap(), )