From a113d231a68ff910bf24d08a9b8337d9e93ccbc0 Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Mon, 22 Feb 2021 15:01:42 +0100 Subject: [PATCH] srtp: use srtp_crypto_policy_set_from_profile_for_* from libsrtp use the helper functions srtp_crypto_policy_set_from_profile_for_rtp and srtp_crypto_policy_set_from_profile_for_rtcp provided by libsrtp to initialize the rtp and rtcp policies. BUG=None Change-Id: Ib1560c0fc1c06d9e79c1f871b028555b3b4d66d4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/208480 Reviewed-by: Harald Alvestrand Commit-Queue: Philipp Hancke Cr-Commit-Position: refs/heads/master@{#33399} --- pc/srtp_session.cc | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/pc/srtp_session.cc b/pc/srtp_session.cc index dd3b7519af..8e89fdfa68 100644 --- a/pc/srtp_session.cc +++ b/pc/srtp_session.cc @@ -269,22 +269,12 @@ bool SrtpSession::DoSetKey(int type, srtp_policy_t policy; memset(&policy, 0, sizeof(policy)); - if (cs == rtc::SRTP_AES128_CM_SHA1_80) { - srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp); - srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); - } else if (cs == rtc::SRTP_AES128_CM_SHA1_32) { - // RTP HMAC is shortened to 32 bits, but RTCP remains 80 bits. - srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp); - srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); - } else if (cs == rtc::SRTP_AEAD_AES_128_GCM) { - srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp); - srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtcp); - } else if (cs == rtc::SRTP_AEAD_AES_256_GCM) { - srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtp); - srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtcp); - } else { - RTC_LOG(LS_WARNING) << "Failed to " << (session_ ? "update" : "create") - << " SRTP session: unsupported cipher_suite " << cs; + if (!(srtp_crypto_policy_set_from_profile_for_rtp( + &policy.rtp, (srtp_profile_t)cs) == srtp_err_status_ok && + srtp_crypto_policy_set_from_profile_for_rtcp( + &policy.rtcp, (srtp_profile_t)cs) == srtp_err_status_ok)) { + RTC_LOG(LS_ERROR) << "Failed to " << (session_ ? "update" : "create") + << " SRTP session: unsupported cipher_suite " << cs; return false; }