Skip to content

Commit

Permalink
introduce not-in-place io api
Browse files Browse the repository at this point in the history
A layer to the srtp driver test is added to be able to run the tests both in-place & not-in-place without duplicating the test.

The not-in-place functions are currently a minimal implementation using a memcpy.
  • Loading branch information
pabuhler committed Apr 30, 2024
1 parent c8f77bb commit a15e63d
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 90 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,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_not_in_place_io srtp_driver -v -n)

if(NOT (BUILD_SHARED_LIBS AND WIN32))
add_executable(test_srtp test/test_srtp.c)
Expand Down
30 changes: 26 additions & 4 deletions include/srtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,13 @@ srtp_err_status_t srtp_protect(srtp_ctx_t *ctx,
size_t *pkt_octet_len,
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,
size_t mki_index);

/**
* @brief srtp_unprotect() is the Secure RTP receiver-side packet
* processing function.
Expand Down Expand Up @@ -476,9 +483,15 @@ srtp_err_status_t srtp_unprotect(srtp_t ctx,
uint8_t *srtp_hdr,
size_t *len_ptr);

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

/**
* @brief srtp_create() allocates and initializes an SRTP session.
*
* The function call srtp_create(session, policy) allocates and
* initializes an SRTP session context, applying the given policy.
*
Expand Down Expand Up @@ -1152,6 +1165,13 @@ srtp_err_status_t srtp_protect_rtcp(srtp_t ctx,
size_t *pkt_octet_len,
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,
size_t mki_index);

/**
* @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
* processing function.
Expand Down Expand Up @@ -1196,9 +1216,11 @@ srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx,
uint8_t *srtcp_hdr,
size_t *pkt_octet_len);

/**
* @}
*/
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);

/**
* @defgroup User data associated to a SRTP session.
Expand Down
60 changes: 60 additions & 0 deletions srtp/srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,21 @@ static srtp_err_status_t srtp_unprotect_aead(srtp_ctx_t *ctx,
return srtp_err_status_ok;
}

srtp_err_status_t srtp_protect2(srtp_t ctx,
const uint8_t *rtp,
size_t rtp_len,
uint8_t *srtp,
size_t *srtp_len,
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(ctx, srtp, srtp_len, mki_index);
}

srtp_err_status_t srtp_protect(srtp_ctx_t *ctx,
uint8_t *rtp_hdr,
size_t *pkt_octet_len,
Expand Down Expand Up @@ -2484,6 +2499,21 @@ srtp_err_status_t srtp_protect(srtp_ctx_t *ctx,
return srtp_err_status_ok;
}

srtp_err_status_t srtp_unprotect2(srtp_t ctx,
const uint8_t *srtp,
size_t srtp_len,
uint8_t *rtp,
size_t *rtp_len)
{
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(ctx, rtp, rtp_len);
}

srtp_err_status_t srtp_unprotect(srtp_ctx_t *ctx,
uint8_t *srtp_hdr,
size_t *pkt_octet_len)
Expand Down Expand Up @@ -3950,6 +3980,21 @@ static srtp_err_status_t srtp_unprotect_rtcp_aead(
return srtp_err_status_ok;
}

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,
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(ctx, srtcp, srtcp_len, mki_index);
}

srtp_err_status_t srtp_protect_rtcp(srtp_t ctx,
uint8_t *rtcp_hdr,
size_t *pkt_octet_len,
Expand Down Expand Up @@ -4178,6 +4223,21 @@ srtp_err_status_t srtp_protect_rtcp(srtp_t ctx,
return srtp_err_status_ok;
}

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)
{
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(ctx, rtcp, rtcp_len);
}

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

0 comments on commit a15e63d

Please sign in to comment.