Skip to content

Commit

Permalink
add Aes128CmHmacSha1_32 support
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Jun 29, 2024
1 parent ffaee7f commit 4fbad4a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion srtp/src/cipher/cipher_aead_aes_gcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ impl Cipher for CipherAeadAesGcm {

impl CipherAeadAesGcm {
/// Create a new AEAD instance.
pub(crate) fn new(profile: ProtectionProfile, master_key: &[u8], master_salt: &[u8]) -> Result<CipherAeadAesGcm> {
pub(crate) fn new(
profile: ProtectionProfile,
master_key: &[u8],
master_salt: &[u8],
) -> Result<CipherAeadAesGcm> {
let srtp_session_key = aes_cm_key_derivation(
LABEL_SRTP_ENCRYPTION,
master_key,
Expand Down
3 changes: 2 additions & 1 deletion srtp/src/cipher/cipher_aes_cm_hmac_sha1/ctrcipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ impl Cipher for CipherAesCmHmacSha1 {
let cipher_text = &encrypted[..encrypted_len - self.rtcp_auth_tag_len()];

// Generate the auth tag we expect to see from the ciphertext.
let expected_tag = &self.inner.generate_srtcp_auth_tag(cipher_text)[..self.rtcp_auth_tag_len()];
let expected_tag =
&self.inner.generate_srtcp_auth_tag(cipher_text)[..self.rtcp_auth_tag_len()];

// See if the auth tag actually matches.
// We use a constant time comparison to prevent timing attacks.
Expand Down
8 changes: 5 additions & 3 deletions srtp/src/cipher/cipher_aes_cm_hmac_sha1/opensslcipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use subtle::ConstantTimeEq;
use util::marshal::*;

use super::{Cipher, CipherInner};
use crate::protection_profile::ProtectionProfile;
use crate::{
error::{Error, Result},
key_derivation::*,
};
use crate::protection_profile::ProtectionProfile;

pub(crate) struct CipherAesCmHmacSha1 {
inner: CipherInner,
Expand Down Expand Up @@ -167,7 +167,8 @@ impl Cipher for CipherAesCmHmacSha1 {
fn encrypt_rtcp(&mut self, decrypted: &[u8], srtcp_index: usize, ssrc: u32) -> Result<Bytes> {
let decrypted_len = decrypted.len();

let mut writer = Vec::with_capacity(decrypted_len + SRTCP_INDEX_SIZE + self.rtcp_auth_tag_len());
let mut writer =
Vec::with_capacity(decrypted_len + SRTCP_INDEX_SIZE + self.rtcp_auth_tag_len());

// Write the decrypted to the destination buffer.
writer.extend_from_slice(&decrypted[..HEADER_LENGTH + SSRC_LENGTH]);
Expand Down Expand Up @@ -238,7 +239,8 @@ impl Cipher for CipherAesCmHmacSha1 {
let cipher_text = &encrypted[..encrypted_len - self.rtcp_auth_tag_len()];

// Generate the auth tag we expect to see from the ciphertext.
let expected_tag = &self.inner.generate_srtcp_auth_tag(cipher_text)[..self.rtcp_auth_tag_len()];
let expected_tag =
&self.inner.generate_srtcp_auth_tag(cipher_text)[..self.rtcp_auth_tag_len()];

// See if the auth tag actually matches.
// We use a constant time comparison to prevent timing attacks.
Expand Down
4 changes: 4 additions & 0 deletions webrtc/src/dtls_transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) fn default_srtp_protection_profiles() -> Vec<SrtpProtectionProfile> {
SrtpProtectionProfile::Srtp_Aead_Aes_128_Gcm,
SrtpProtectionProfile::Srtp_Aead_Aes_256_Gcm,
SrtpProtectionProfile::Srtp_Aes128_Cm_Hmac_Sha1_80,
SrtpProtectionProfile::Srtp_Aes128_Cm_Hmac_Sha1_32,
]
}

Expand Down Expand Up @@ -421,6 +422,9 @@ impl RTCDtlsTransport {
dtls::extension::extension_use_srtp::SrtpProtectionProfile::Srtp_Aes128_Cm_Hmac_Sha1_80 => {
srtp::protection_profile::ProtectionProfile::Aes128CmHmacSha1_80
}
dtls::extension::extension_use_srtp::SrtpProtectionProfile::Srtp_Aes128_Cm_Hmac_Sha1_32 => {
srtp::protection_profile::ProtectionProfile::Aes128CmHmacSha1_32
}
_ => {
if let Err(err) = dtls_conn.close().await {
log::error!("{}", err);
Expand Down

0 comments on commit 4fbad4a

Please sign in to comment.