Skip to content

Commit

Permalink
Added support for set and get the roll-over-counter
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfolsson committed Apr 3, 2017
1 parent e5531e8 commit 7af219a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
1 change: 1 addition & 0 deletions crypto/include/rdbx.h
Expand Up @@ -85,6 +85,7 @@ typedef uint64_t srtp_xtd_seq_num_t;
typedef struct {
srtp_xtd_seq_num_t index;
bitvector_t bitmask;
int is_roc_set;
} srtp_rdbx_t;


Expand Down
3 changes: 3 additions & 0 deletions crypto/replay/rdbx.c
Expand Up @@ -194,6 +194,7 @@ srtp_err_status_t srtp_rdbx_init (srtp_rdbx_t *rdbx, unsigned long ws)
}

srtp_index_init(&rdbx->index);
rdbx->is_roc_set = 0;

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

rdbx->is_roc_set = 1;

return srtp_err_status_ok;
}

Expand Down
23 changes: 23 additions & 0 deletions include/srtp.h
Expand Up @@ -1854,6 +1854,29 @@ srtp_err_status_t srtp_get_protect_rtcp_trailer_length(srtp_t session, uint32_t
uint32_t mki_index, uint32_t *length);


/**
* @brief srtp_set_stream_roc(session, ssrc, roc)
*
* Set the roll-over-counter on a session for a given SSRC
*
* returns err_status_ok on success, srtp_err_status_bad_param if there is no
* stream found
*
*/
srtp_err_status_t srtp_set_stream_roc(srtp_t session, uint32_t ssrc, uint32_t roc);

/**
* @brief srtp_get_stream_roc(session, ssrc, roc)
*
* Get the roll-over-counter on a session for a given SSRC
*
* returns err_status_ok on success, srtp_err_status_bad_param if there is no
* stream found
*
*/
srtp_err_status_t srtp_get_stream_roc(srtp_t session, uint32_t ssrc, uint32_t *roc);


/**
* @}
*/
Expand Down
34 changes: 32 additions & 2 deletions srtp/srtp.c
Expand Up @@ -2251,8 +2251,14 @@ srtp_unprotect_mki(srtp_ctx_t *ctx, void *srtp_hdr, int *pkt_octet_len,
}
} else {

/* estimate packet index from seq. num. in header */
delta = srtp_rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs(hdr->seq));
if (stream->rtp_rdbx.is_roc_set) {
est = (srtp_xtd_seq_num_t) ntohs(hdr->seq) + stream->rtp_rdbx.index;
delta = (int)est;
stream->rtp_rdbx.is_roc_set = 0;
} else {
/* estimate packet index from seq. num. in header */
delta = srtp_rdbx_estimate_index(&stream->rtp_rdbx, &est, ntohs(hdr->seq));
}

/* check replay database */
status = srtp_rdbx_check(&stream->rtp_rdbx, delta);
Expand Down Expand Up @@ -4461,3 +4467,27 @@ srtp_err_status_t srtp_install_log_handler(srtp_log_handler_func_t func, void *
}
return srtp_err_status_ok;
}

srtp_err_status_t
srtp_set_stream_roc(srtp_t session, uint32_t ssrc, uint32_t roc) {
srtp_stream_t stream;

stream = srtp_get_stream(session, htonl(ssrc));
if (stream == NULL)
return srtp_err_status_bad_param;

return srtp_rdbx_set_roc(&stream->rtp_rdbx, roc);
}

srtp_err_status_t
srtp_get_stream_roc(srtp_t session, uint32_t ssrc, uint32_t *roc) {
srtp_stream_t stream;

stream = srtp_get_stream(session, htonl(ssrc));
if (stream == NULL)
return srtp_err_status_bad_param;

*roc = stream->rtp_rdbx.index >> 16;

return srtp_err_status_ok;
}

0 comments on commit 7af219a

Please sign in to comment.