Skip to content

Commit

Permalink
upgrade aes (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
russelltg authored May 7, 2021
1 parent 8640676 commit b5fefd0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
9 changes: 4 additions & 5 deletions srt-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 3 additions & 5 deletions srt-protocol/src/crypto.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
17 changes: 9 additions & 8 deletions srt-protocol/src/crypto/wrap.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,7 +45,7 @@ pub const DEFAULT_IV: [u8; 8] = [0xA6; 8];
// }
pub fn aes_wrap<K>(key: &K, iv: Option<&[u8; 8]>, out: &mut [u8], input: &[u8])
where
K: BlockCipher<BlockSize = U16>,
K: BlockEncrypt,
<K as BlockCipher>::ParBlocks: ArrayLength<GenericArray<u8, U16>>,
{
assert_eq!(input.len() & 0x7, 0);
Expand Down Expand Up @@ -116,7 +117,7 @@ where
// }
pub fn aes_unwrap<K>(key: &K, iv: &mut [u8; 8], out: &mut [u8], input: &[u8])
where
K: BlockCipher<BlockSize = U16>,
K: BlockDecrypt,
<K as BlockCipher>::ParBlocks: ArrayLength<GenericArray<u8, U16>>,
{
assert_eq!(input.len(), out.len() + 8);
Expand Down Expand Up @@ -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];
Expand All @@ -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();
Expand All @@ -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(),
)
Expand Down

0 comments on commit b5fefd0

Please sign in to comment.