Skip to content

Conversation

@pabuhler
Copy link
Member

This backports cryptex support added in #551 (76f23aa). The tests are nearly unchanged but the code was slightly simplified as non-in-place io is not supported in the v2 branch.

#777

This backports cryptex support added in  cisco#551 (76f23aa).
The tests are nearly unchanged but the code was slightly simplified
as non-in-place io is not supported in the v2 branch.

cisco#777
@pabuhler
Copy link
Member Author

Unfortunately this adds a new "use_cryptex" member to the srtp_policy_t struct, breaking binary compatibility.
This should maybe be changed to a setter function like srtp_set_cryptex_enabled() that should called after srtp_create() but before any data has been handled.

@pabuhler pabuhler requested a review from bifurcation November 26, 2025 10:33
Copy link
Contributor

@bifurcation bifurcation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor / aesthetic comments, which would probably have been better on the original Cryptex PR. If you agree, maybe let's implement them here, and then forward-port to main.

Also, looks like fuzzing CI is reliably failing (Copilot says it's due to an extra -- argument). Filed #780

srtp_err_status_pkt_idx_adv = 27 /**< packet index advanced, reset */
srtp_err_status_pkt_idx_adv = 27, /**< packet index advanced, reset */
/**< needed */
srtp_err_status_cryptex_err = 28 /**< cryptex error */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only used in once place, let's document more clearly.

Suggested change
srtp_err_status_cryptex_err = 28 /**< cryptex error */
srtp_err_status_cryptex_err = 28 /**< cryptex with CSRC and no header */

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it main it can be returned for different reasons but I am ok with this

/**
* @brief srtp_set_stream_use_cryptex(session, ssrc)
*
* Enable cryptex processing for the stream identified by the given SSRC. For
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would reference RFC 9335 somewhere in this doc comment.

return ntohs(xtn_hdr->profile_specific);
}

static void srtp_cryptex_adjust_buffer(const srtp_hdr_t *hdr, uint8_t *rtp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a more descriptive name, but I can't think of something better. Maybe srtp_cryptex_join? And split instead of restore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is back port from main ... would prefer to keep it the same

Comment on lines +153 to +159
uint8_t tmp[4];
uint8_t *ptr = rtp + srtp_get_rtp_hdr_len(hdr);
size_t cc_list_size = hdr->cc * 4;
memcpy(tmp, ptr, 4);
ptr -= cc_list_size;
memmove(ptr + 4, ptr, cc_list_size);
memcpy(ptr, tmp, 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would read a little more clearly to me not to interleave the pointer operations and the memory operations. (Also note that the field being moved is csrc, not cc_list.)

Suggested change
uint8_t tmp[4];
uint8_t *ptr = rtp + srtp_get_rtp_hdr_len(hdr);
size_t cc_list_size = hdr->cc * 4;
memcpy(tmp, ptr, 4);
ptr -= cc_list_size;
memmove(ptr + 4, ptr, cc_list_size);
memcpy(ptr, tmp, 4);
uint8_t tmp[4];
uint8_t *xtn_hdr = rtp + srtp_get_rtp_hdr_len(hdr);
uint8_t *csrc = rtp + octets_in_rtp_header;
size_t csrc_size = hdr->cc * 4;
memcpy(tmp, xtn_hdr, 4);
memmove(csrc + 4, csrc, csrc_size);
memcpy(csrc, tmp, 4);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is is list of csrc's not a single one.

Comment on lines +166 to +172
uint8_t tmp[4];
uint8_t *ptr = rtp + octets_in_rtp_header;
size_t cc_list_size = hdr->cc * 4;
memcpy(tmp, ptr, 4);
memmove(ptr, ptr + 4, cc_list_size);
ptr += cc_list_size;
memcpy(ptr, tmp, 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Suggested change
uint8_t tmp[4];
uint8_t *ptr = rtp + octets_in_rtp_header;
size_t cc_list_size = hdr->cc * 4;
memcpy(tmp, ptr, 4);
memmove(ptr, ptr + 4, cc_list_size);
ptr += cc_list_size;
memcpy(ptr, tmp, 4);
uint8_t tmp[4];
uint8_t *xtn_hdr = rtp + srtp_get_rtp_hdr_len(hdr);
uint8_t *csrc = rtp + octets_in_rtp_header;
size_t csrc_size = hdr->cc * 4;
memcpy(tmp, csrc, 4);
memmove(csrc, csrc + 4, csrc_size);
memcpy(xtn_hdr, tmp, 4);

return srtp_err_status_ok;
}

static srtp_err_status_t srtp_cryptex_protect(srtp_hdr_t *hdr, uint8_t *rtp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
static srtp_err_status_t srtp_cryptex_protect(srtp_hdr_t *hdr, uint8_t *rtp)
static srtp_err_status_t srtp_cryptex_protect_init(srtp_hdr_t *hdr, uint8_t *rtp)

The pattern with unprotect is better, since this isn't doing any actual protection.

Comment on lines +193 to +196
srtp_hdr_xtnd_t *xtn_hdr = srtp_get_rtp_xtn_hdr(hdr);
*enc_start -=
(srtp_get_rtp_xtn_hdr_len(xtn_hdr) - octets_in_rtp_xtn_hdr);
*enc_start -= (hdr->cc * 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than walking back, wouldn't it be simpler just to say "fixed header plus four"?

Suggested change
srtp_hdr_xtnd_t *xtn_hdr = srtp_get_rtp_xtn_hdr(hdr);
*enc_start -=
(srtp_get_rtp_xtn_hdr_len(xtn_hdr) - octets_in_rtp_xtn_hdr);
*enc_start -= (hdr->cc * 4);
*enc_start = hdr + octets_in_rtp_xtn_hdr;

Comment on lines +240 to +243
srtp_hdr_xtnd_t *xtn_hdr = srtp_get_rtp_xtn_hdr(hdr);
*enc_start -=
(srtp_get_rtp_xtn_hdr_len(xtn_hdr) - octets_in_rtp_xtn_hdr);
*enc_start -= (hdr->cc * 4);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
srtp_hdr_xtnd_t *xtn_hdr = srtp_get_rtp_xtn_hdr(hdr);
*enc_start -=
(srtp_get_rtp_xtn_hdr_len(xtn_hdr) - octets_in_rtp_xtn_hdr);
*enc_start -= (hdr->cc * 4);
*enc_start = hdr + octets_in_rtp_xtn_hdr;

@bifurcation bifurcation mentioned this pull request Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants