Skip to content

Commit 7af219a

Browse files
committed
Added support for set and get the roll-over-counter
1 parent e5531e8 commit 7af219a

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

crypto/include/rdbx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ typedef uint64_t srtp_xtd_seq_num_t;
8585
typedef struct {
8686
srtp_xtd_seq_num_t index;
8787
bitvector_t bitmask;
88+
int is_roc_set;
8889
} srtp_rdbx_t;
8990

9091

crypto/replay/rdbx.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ srtp_err_status_t srtp_rdbx_init (srtp_rdbx_t *rdbx, unsigned long ws)
194194
}
195195

196196
srtp_index_init(&rdbx->index);
197+
rdbx->is_roc_set = 0;
197198

198199
return srtp_err_status_ok;
199200
}
@@ -232,6 +233,8 @@ srtp_err_status_t srtp_rdbx_set_roc (srtp_rdbx_t *rdbx, uint32_t roc)
232233
rdbx->index |= ((uint64_t)roc) << 16; /* set ROC */
233234
#endif
234235

236+
rdbx->is_roc_set = 1;
237+
235238
return srtp_err_status_ok;
236239
}
237240

include/srtp.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,29 @@ srtp_err_status_t srtp_get_protect_rtcp_trailer_length(srtp_t session, uint32_t
18541854
uint32_t mki_index, uint32_t *length);
18551855

18561856

1857+
/**
1858+
* @brief srtp_set_stream_roc(session, ssrc, roc)
1859+
*
1860+
* Set the roll-over-counter on a session for a given SSRC
1861+
*
1862+
* returns err_status_ok on success, srtp_err_status_bad_param if there is no
1863+
* stream found
1864+
*
1865+
*/
1866+
srtp_err_status_t srtp_set_stream_roc(srtp_t session, uint32_t ssrc, uint32_t roc);
1867+
1868+
/**
1869+
* @brief srtp_get_stream_roc(session, ssrc, roc)
1870+
*
1871+
* Get the roll-over-counter on a session for a given SSRC
1872+
*
1873+
* returns err_status_ok on success, srtp_err_status_bad_param if there is no
1874+
* stream found
1875+
*
1876+
*/
1877+
srtp_err_status_t srtp_get_stream_roc(srtp_t session, uint32_t ssrc, uint32_t *roc);
1878+
1879+
18571880
/**
18581881
* @}
18591882
*/

srtp/srtp.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,8 +2251,14 @@ srtp_unprotect_mki(srtp_ctx_t *ctx, void *srtp_hdr, int *pkt_octet_len,
22512251
}
22522252
} else {
22532253

2254-
/* estimate packet index from seq. num. in header */
2255-
delta = srtp_rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs(hdr->seq));
2254+
if (stream->rtp_rdbx.is_roc_set) {
2255+
est = (srtp_xtd_seq_num_t) ntohs(hdr->seq) + stream->rtp_rdbx.index;
2256+
delta = (int)est;
2257+
stream->rtp_rdbx.is_roc_set = 0;
2258+
} else {
2259+
/* estimate packet index from seq. num. in header */
2260+
delta = srtp_rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs(hdr->seq));
2261+
}
22562262

22572263
/* check replay database */
22582264
status = srtp_rdbx_check(&stream->rtp_rdbx, delta);
@@ -4461,3 +4467,27 @@ srtp_err_status_t srtp_install_log_handler(srtp_log_handler_func_t func, void *
44614467
}
44624468
return srtp_err_status_ok;
44634469
}
4470+
4471+
srtp_err_status_t
4472+
srtp_set_stream_roc(srtp_t session, uint32_t ssrc, uint32_t roc) {
4473+
srtp_stream_t stream;
4474+
4475+
stream = srtp_get_stream(session, htonl(ssrc));
4476+
if (stream == NULL)
4477+
return srtp_err_status_bad_param;
4478+
4479+
return srtp_rdbx_set_roc(&stream->rtp_rdbx, roc);
4480+
}
4481+
4482+
srtp_err_status_t
4483+
srtp_get_stream_roc(srtp_t session, uint32_t ssrc, uint32_t *roc) {
4484+
srtp_stream_t stream;
4485+
4486+
stream = srtp_get_stream(session, htonl(ssrc));
4487+
if (stream == NULL)
4488+
return srtp_err_status_bad_param;
4489+
4490+
*roc = stream->rtp_rdbx.index >> 16;
4491+
4492+
return srtp_err_status_ok;
4493+
}

0 commit comments

Comments
 (0)