-
Notifications
You must be signed in to change notification settings - Fork 501
backport cryptex to v2 branch #778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 2_x_dev
Are you sure you want to change the base?
Conversation
|
Unfortunately this adds a new "use_cryptex" member to the srtp_policy_t struct, breaking binary compatibility. |
There was a problem hiding this 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 */ |
There was a problem hiding this comment.
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.
| srtp_err_status_cryptex_err = 28 /**< cryptex error */ | |
| srtp_err_status_cryptex_err = 28 /**< cryptex with CSRC and no header */ |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| 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); |
There was a problem hiding this comment.
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.)
| 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); |
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
| 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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.
| 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); |
There was a problem hiding this comment.
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"?
| 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; |
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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; |
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