Skip to content

Commit e15a877

Browse files
alexlaparainliu
authored andcommitted
corrections
1 parent 82fd074 commit e15a877

File tree

8 files changed

+51
-54
lines changed

8 files changed

+51
-54
lines changed

.github/workflows/cargo.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ jobs:
4747
- name: 🏭 Cache dependencies
4848
uses: Swatinem/rust-cache@v2
4949
- name: Test
50-
run: cargo test --features metrics
50+
run: cargo test
51+
- name: Test with all features enabled
52+
run: cargo test --all-features
5153

5254
test_windows:
5355
name: Test (windows)

srtp/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ rust-version = "1.63.0"
1212

1313
[features]
1414
openssl = ["dep:openssl"]
15+
vendored-openssl = ["openssl/vendored"]
1516

1617
[dependencies]
1718
util = { version = "0.7.0", path = "../util", package = "webrtc-util", default-features = false, features = [
@@ -34,7 +35,7 @@ tokio = { version = "1.19", features = ["full"] }
3435
log = "0.4.16"
3536
aead = { version = "0.4.3", features = ["std"] }
3637
aes-gcm = { version = "0.10.1", features = ["std"] }
37-
openssl = { version = "0.10.45", features = ["vendored"], optional = true }
38+
openssl = { version = "0.10", optional = true }
3839

3940
[dev-dependencies]
4041
criterion = { version = "0.4.0", features = ["async_futures"] }

srtp/benches/srtp_bench.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
use bytes::{Bytes, BytesMut};
1+
use bytes::BytesMut;
22
use criterion::{criterion_group, criterion_main, Criterion};
33
use util::Marshal;
44
use webrtc_srtp::{context::Context, protection_profile::ProtectionProfile};
55

6-
const RAW_RTCP: Bytes = Bytes::from_static(&[
6+
const RAW_RTCP: &[u8] = &[
77
0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
88
0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
9-
]);
9+
];
1010

1111
fn benchmark_encrypt_rtp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
1212
let mut ctx = Context::new(
13-
&vec![
13+
&[
1414
96, 180, 31, 4, 119, 137, 128, 252, 75, 194, 252, 44, 63, 56, 61, 55,
1515
],
16-
&vec![247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
16+
&[247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
1717
ProtectionProfile::Aes128CmHmacSha1_80,
1818
None,
1919
None,
@@ -55,21 +55,21 @@ fn benchmark_encrypt_rtp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
5555

5656
fn benchmark_decrypt_rtp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
5757
let mut setup_ctx = Context::new(
58-
&vec![
58+
&[
5959
96, 180, 31, 4, 119, 137, 128, 252, 75, 194, 252, 44, 63, 56, 61, 55,
6060
],
61-
&vec![247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
61+
&[247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
6262
ProtectionProfile::Aes128CmHmacSha1_80,
6363
None,
6464
None,
6565
)
6666
.unwrap();
6767

6868
let mut ctx = Context::new(
69-
&vec![
69+
&[
7070
96, 180, 31, 4, 119, 137, 128, 252, 75, 194, 252, 44, 63, 56, 61, 55,
7171
],
72-
&vec![247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
72+
&[247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
7373
ProtectionProfile::Aes128CmHmacSha1_80,
7474
None,
7575
None,
@@ -109,10 +109,10 @@ fn benchmark_decrypt_rtp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
109109

110110
fn benchmark_encrypt_rtcp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
111111
let mut ctx = Context::new(
112-
&vec![
112+
&[
113113
96, 180, 31, 4, 119, 137, 128, 252, 75, 194, 252, 44, 63, 56, 61, 55,
114114
],
115-
&vec![247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
115+
&[247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
116116
ProtectionProfile::Aes128CmHmacSha1_80,
117117
None,
118118
None,
@@ -121,30 +121,30 @@ fn benchmark_encrypt_rtcp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
121121

122122
c.bench_function("Benchmark RTCP encrypt", |b| {
123123
b.iter(|| {
124-
ctx.encrypt_rtcp(&RAW_RTCP).unwrap();
124+
ctx.encrypt_rtcp(RAW_RTCP).unwrap();
125125
});
126126
});
127127
}
128128

129129
fn benchmark_decrypt_rtcp_aes_128_cm_hmac_sha1(c: &mut Criterion) {
130130
let encrypted = Context::new(
131-
&vec![
131+
&[
132132
96, 180, 31, 4, 119, 137, 128, 252, 75, 194, 252, 44, 63, 56, 61, 55,
133133
],
134-
&vec![247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
134+
&[247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
135135
ProtectionProfile::Aes128CmHmacSha1_80,
136136
None,
137137
None,
138138
)
139139
.unwrap()
140-
.encrypt_rtcp(&RAW_RTCP)
140+
.encrypt_rtcp(RAW_RTCP)
141141
.unwrap();
142142

143143
let mut ctx = Context::new(
144-
&vec![
144+
&[
145145
96, 180, 31, 4, 119, 137, 128, 252, 75, 194, 252, 44, 63, 56, 61, 55,
146146
],
147-
&vec![247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
147+
&[247, 26, 49, 94, 99, 29, 79, 94, 5, 111, 252, 216, 62, 195],
148148
ProtectionProfile::Aes128CmHmacSha1_80,
149149
None,
150150
None,

srtp/src/cipher/cipher_aes_cm_hmac_sha1/ctrcipher.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ use crate::key_derivation::*;
1111

1212
type Aes128Ctr = ctr::Ctr128BE<aes::Aes128>;
1313

14-
pub(crate) struct CtrCipher {
14+
pub(crate) struct CipherAesCmHmacSha1 {
1515
inner: CipherInner,
1616
srtp_session_key: Vec<u8>,
1717
srtcp_session_key: Vec<u8>,
1818
}
1919

20-
impl CtrCipher {
21-
pub fn new(inner: CipherInner, master_key: &[u8], master_salt: &[u8]) -> Result<Self> {
20+
impl CipherAesCmHmacSha1 {
21+
pub fn new(master_key: &[u8], master_salt: &[u8]) -> Result<Self> {
22+
let inner = CipherInner::new(master_key, master_salt)?;
23+
2224
let srtp_session_key = aes_cm_key_derivation(
2325
LABEL_SRTP_ENCRYPTION,
2426
master_key,
@@ -34,15 +36,15 @@ impl CtrCipher {
3436
master_key.len(),
3537
)?;
3638

37-
Ok(CtrCipher {
39+
Ok(CipherAesCmHmacSha1 {
3840
inner,
3941
srtp_session_key,
4042
srtcp_session_key,
4143
})
4244
}
4345
}
4446

45-
impl Cipher for CtrCipher {
47+
impl Cipher for CipherAesCmHmacSha1 {
4648
fn auth_tag_len(&self) -> usize {
4749
self.inner.auth_tag_len()
4850
}

srtp/src/cipher/cipher_aes_cm_hmac_sha1/mod.rs

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ use crate::error::{Error, Result};
77
use crate::key_derivation::*;
88
use crate::protection_profile::*;
99

10+
#[cfg(not(feature = "openssl"))]
1011
mod ctrcipher;
12+
1113
#[cfg(feature = "openssl")]
1214
mod opensslcipher;
1315

16+
#[cfg(not(feature = "openssl"))]
17+
pub(crate) use ctrcipher::CipherAesCmHmacSha1;
18+
19+
#[cfg(feature = "openssl")]
20+
pub(crate) use opensslcipher::CipherAesCmHmacSha1;
21+
1422
type HmacSha1 = Hmac<Sha1>;
1523

1624
pub const CIPHER_AES_CM_HMAC_SHA1AUTH_TAG_LEN: usize = 10;
@@ -123,24 +131,3 @@ impl CipherInner {
123131
as usize
124132
}
125133
}
126-
127-
pub(crate) struct CipherAesCmHmacSha1 {}
128-
129-
impl CipherAesCmHmacSha1 {
130-
pub fn new(master_key: &[u8], master_salt: &[u8]) -> Result<Box<dyn Cipher + Send>> {
131-
let inner = CipherInner::new(master_key, master_salt)?;
132-
133-
#[cfg(feature = "openssl")]
134-
return Ok(Box::new(opensslcipher::OpenSslCipher::new(
135-
inner,
136-
master_key,
137-
master_salt,
138-
)?));
139-
140-
Ok(Box::new(ctrcipher::CtrCipher::new(
141-
inner,
142-
master_key,
143-
master_salt,
144-
)?))
145-
}
146-
}

srtp/src/cipher/cipher_aes_cm_hmac_sha1/opensslcipher.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,22 @@ use rtcp::header::{HEADER_LENGTH, SSRC_LENGTH};
44
use subtle::ConstantTimeEq;
55
use util::marshal::*;
66

7-
use super::CipherInner;
8-
use crate::cipher::Cipher;
9-
use crate::error::{Error, Result};
10-
use crate::key_derivation::*;
7+
use super::{Cipher, CipherInner};
8+
use crate::{
9+
error::{Error, Result},
10+
key_derivation::*,
11+
};
1112

12-
pub(crate) struct OpenSslCipher {
13+
pub(crate) struct CipherAesCmHmacSha1 {
1314
inner: CipherInner,
1415
rtp_ctx: CipherCtx,
1516
rtcp_ctx: CipherCtx,
1617
}
1718

18-
impl OpenSslCipher {
19-
pub fn new(inner: CipherInner, master_key: &[u8], master_salt: &[u8]) -> Result<Self> {
19+
impl CipherAesCmHmacSha1 {
20+
pub fn new(master_key: &[u8], master_salt: &[u8]) -> Result<Self> {
21+
let inner = CipherInner::new(master_key, master_salt)?;
22+
2023
let srtp_session_key = aes_cm_key_derivation(
2124
LABEL_SRTP_ENCRYPTION,
2225
master_key,
@@ -52,7 +55,7 @@ impl OpenSslCipher {
5255
}
5356
}
5457

55-
impl Cipher for OpenSslCipher {
58+
impl Cipher for CipherAesCmHmacSha1 {
5659
fn auth_tag_len(&self) -> usize {
5760
self.inner.auth_tag_len()
5861
}

srtp/src/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl Context {
131131

132132
let cipher: Box<dyn Cipher + Send> = match profile {
133133
ProtectionProfile::Aes128CmHmacSha1_80 => {
134-
CipherAesCmHmacSha1::new(master_key, master_salt)?
134+
Box::new(CipherAesCmHmacSha1::new(master_key, master_salt)?)
135135
}
136136

137137
ProtectionProfile::AeadAes128Gcm => {

webrtc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,5 @@ env_logger = "0.9.0"
6565

6666
[features]
6767
pem = ["dep:pem", "dtls/pem"]
68+
openssl = ["srtp/openssl"]
69+
vendored-openssl = ["srtp/vendored-openssl"]

0 commit comments

Comments
 (0)