srtp: document rationale for srtp overhead calculation
documents why it is safe to not follow libsrtp's advice to ensure additional SRTP_MAX_TRAILER_LEN bytes are available when calling srtp_protect (and similar srtcp functions). BUG=None Change-Id: I504645d21553160f06133fd8bb3ee79e178247da Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/209064 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Philipp Hancke <philipp.hancke@googlemail.com> Cr-Commit-Position: refs/heads/master@{#33396}
This commit is contained in:

committed by
Commit Bot

parent
456a2642d3
commit
be66d95ab7
@ -80,6 +80,10 @@ bool SrtpSession::ProtectRtp(void* p, int in_len, int max_len, int* out_len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note: the need_len differs from the libsrtp recommendatіon to ensure
|
||||
// SRTP_MAX_TRAILER_LEN bytes of free space after the data. WebRTC
|
||||
// never includes a MKI, therefore the amount of bytes added by the
|
||||
// srtp_protect call is known in advance and depends on the cipher suite.
|
||||
int need_len = in_len + rtp_auth_tag_len_; // NOLINT
|
||||
if (max_len < need_len) {
|
||||
RTC_LOG(LS_WARNING) << "Failed to protect SRTP packet: The buffer length "
|
||||
@ -122,6 +126,10 @@ bool SrtpSession::ProtectRtcp(void* p, int in_len, int max_len, int* out_len) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note: the need_len differs from the libsrtp recommendatіon to ensure
|
||||
// SRTP_MAX_TRAILER_LEN bytes of free space after the data. WebRTC
|
||||
// never includes a MKI, therefore the amount of bytes added by the
|
||||
// srtp_protect_rtp call is known in advance and depends on the cipher suite.
|
||||
int need_len = in_len + sizeof(uint32_t) + rtcp_auth_tag_len_; // NOLINT
|
||||
if (max_len < need_len) {
|
||||
RTC_LOG(LS_WARNING) << "Failed to protect SRTCP packet: The buffer length "
|
||||
|
@ -126,8 +126,14 @@ class SrtpSession {
|
||||
|
||||
webrtc::SequenceChecker thread_checker_;
|
||||
srtp_ctx_t_* session_ = nullptr;
|
||||
|
||||
// Overhead of the SRTP auth tag for RTP and RTCP in bytes.
|
||||
// Depends on the cipher suite used and is usually the same with the exception
|
||||
// of the CS_AES_CM_128_HMAC_SHA1_32 cipher suite. The additional four bytes
|
||||
// required for RTCP protection are not included.
|
||||
int rtp_auth_tag_len_ = 0;
|
||||
int rtcp_auth_tag_len_ = 0;
|
||||
|
||||
bool inited_ = false;
|
||||
static webrtc::GlobalMutex lock_;
|
||||
int last_send_seq_num_ = -1;
|
||||
|
Reference in New Issue
Block a user