Skip to content

Commit

Permalink
introduce xx2 api and add layer to test
Browse files Browse the repository at this point in the history
 to be able change which api
is used with out copy duplicating
  • Loading branch information
pabuhler committed Jan 23, 2024
1 parent 08673a1 commit f37e0ef
Show file tree
Hide file tree
Showing 4 changed files with 317 additions and 83 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ if(LIBSRTP_TEST_APPS)
${ENABLE_WARNINGS_AS_ERRORS})
target_link_libraries(srtp_driver srtp2)
add_test(srtp_driver srtp_driver -v)
add_test(srtp_driver_x2 srtp_driver -v -n)

if(NOT (BUILD_SHARED_LIBS AND WIN32))
add_executable(test_srtp test/test_srtp.c)
Expand Down
30 changes: 30 additions & 0 deletions include/srtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx,
bool use_mki,
size_t mki_index);

srtp_err_status_t srtp_protect2(srtp_t ctx,
const uint8_t *rtp,
size_t rtp_len,
uint8_t *srtp,
size_t *srtp_len,
bool use_mki,
size_t mki_index);

/**
* @brief srtp_unprotect() is the Secure RTP receiver-side packet
* processing function.
Expand Down Expand Up @@ -574,6 +582,13 @@ srtp_err_status_t srtp_unprotect_mki(srtp_t ctx,
size_t *len_ptr,
bool use_mki);

srtp_err_status_t srtp_unprotect2(srtp_t ctx,
const uint8_t *srtp,
size_t srtp_len,
uint8_t *rtp,
size_t *rtp_len,
bool use_mki);

/**
* @brief srtp_create() allocates and initializes an SRTP session.
Expand Down Expand Up @@ -1297,6 +1312,14 @@ srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx,
bool use_mki,
size_t mki_index);

srtp_err_status_t srtp_protect_rtcp2(srtp_t ctx,
const uint8_t *rtcp,
size_t rtcp_len,
uint8_t *srtcp,
size_t *srtcp_len,
bool use_mki,
size_t mki_index);

/**
* @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
* processing function.
Expand Down Expand Up @@ -1389,6 +1412,13 @@ srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx,
size_t *pkt_octet_len,
bool use_mki);

srtp_err_status_t srtp_unprotect_rtcp2(srtp_t ctx,
const uint8_t *srtcp,
size_t srtcp_len,
uint8_t *rtcp,
size_t *rtcp_len,
bool use_mki);

/**
* @}
*/
Expand Down
64 changes: 64 additions & 0 deletions srtp/srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2083,6 +2083,22 @@ srtp_err_status_t srtp_protect(srtp_ctx_t *ctx,
return srtp_protect_mki(ctx, rtp_hdr, pkt_octet_len, false, 0);
}

srtp_err_status_t srtp_protect2(srtp_t ctx,
const uint8_t *rtp,
size_t rtp_len,
uint8_t *srtp,
size_t *srtp_len,
bool use_mki,
size_t mki_index)
{
if (*srtp_len < rtp_len) {
return srtp_err_status_bad_param;
}
memcpy(srtp, rtp, rtp_len);
*srtp_len = rtp_len;
return srtp_protect_mki(ctx, srtp, srtp_len, use_mki, mki_index);
}

srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx,
uint8_t *rtp_hdr,
size_t *pkt_octet_len,
Expand Down Expand Up @@ -2397,6 +2413,22 @@ srtp_err_status_t srtp_unprotect(srtp_ctx_t *ctx,
return srtp_unprotect_mki(ctx, srtp_hdr, pkt_octet_len, false);
}

srtp_err_status_t srtp_unprotect2(srtp_t ctx,
const uint8_t *srtp,
size_t srtp_len,
uint8_t *rtp,
size_t *rtp_len,
bool use_mki)
{
if (*rtp_len < srtp_len) {
// this is actually expected but for the tests this should not happen
return srtp_err_status_bad_param;
}
memcpy(rtp, srtp, srtp_len);
*rtp_len = srtp_len;
return srtp_unprotect_mki(ctx, rtp, rtp_len, use_mki);
}

srtp_err_status_t srtp_unprotect_mki(srtp_ctx_t *ctx,
uint8_t *srtp_hdr,
size_t *pkt_octet_len,
Expand Down Expand Up @@ -3855,6 +3887,22 @@ srtp_err_status_t srtp_protect_rtcp(srtp_t ctx,
return srtp_protect_rtcp_mki(ctx, rtcp_hdr, pkt_octet_len, false, 0);
}

srtp_err_status_t srtp_protect_rtcp2(srtp_t ctx,
const uint8_t *rtcp,
size_t rtcp_len,
uint8_t *srtcp,
size_t *srtcp_len,
bool use_mki,
size_t mki_index)
{
if (*srtcp_len < rtcp_len) {
return srtp_err_status_bad_param;
}
memcpy(srtcp, rtcp, rtcp_len);
*srtcp_len = rtcp_len;
return srtp_protect_rtcp_mki(ctx, srtcp, srtcp_len, use_mki, mki_index);
}

srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx,
uint8_t *rtcp_hdr,
size_t *pkt_octet_len,
Expand Down Expand Up @@ -4092,6 +4140,22 @@ srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx,
return srtp_unprotect_rtcp_mki(ctx, srtcp_hdr, pkt_octet_len, false);
}

srtp_err_status_t srtp_unprotect_rtcp2(srtp_t ctx,
const uint8_t *srtcp,
size_t srtcp_len,
uint8_t *rtcp,
size_t *rtcp_len,
bool use_mki)
{
if (*rtcp_len < srtcp_len) {
// this is actually expected but for the tests this should not happen
return srtp_err_status_bad_param;
}
memcpy(rtcp, srtcp, srtcp_len);
*rtcp_len = srtcp_len;
return srtp_unprotect_rtcp_mki(ctx, rtcp, rtcp_len, use_mki);
}

srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx,
uint8_t *srtcp_hdr,
size_t *pkt_octet_len,
Expand Down
Loading

0 comments on commit f37e0ef

Please sign in to comment.