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 <hta@webrtc.org>
Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com>
Cr-Commit-Position: refs/heads/master@{#33399}
This commit is contained in:
Philipp Hancke
2021-02-22 15:01:42 +01:00
committed by Commit Bot
parent c81665cf9d
commit a113d231a6

View File

@ -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;
}