@@ -63,6 +63,8 @@ size_t num_trials = 1 << 16;
6363
6464srtp_err_status_t test_rdb_db (void );
6565
66+ srtp_err_status_t test_rdb_boundaries (void );
67+
6668double rdb_check_adds_per_second (void );
6769
6870int main (void )
@@ -247,6 +249,75 @@ srtp_err_status_t test_rdb_db(void)
247249 return srtp_err_status_fail ;
248250 }
249251
252+ err = test_rdb_boundaries ();
253+ if (err ) {
254+ return err ;
255+ }
256+
257+ return srtp_err_status_ok ;
258+ }
259+
260+ srtp_err_status_t test_rdb_boundaries (void )
261+ {
262+ srtp_rdb_t rdb ;
263+
264+ if (srtp_rdb_init (& rdb ) != srtp_err_status_ok ) {
265+ printf ("rdb_init failed\n" );
266+ return srtp_err_status_fail ;
267+ }
268+
269+ if (srtp_rdb_add_index (& rdb , 0 ) != srtp_err_status_ok ) {
270+ printf ("rdb_add_index failed at index 0\n" );
271+ return srtp_err_status_fail ;
272+ }
273+ if (srtp_rdb_check (& rdb , 127 ) != srtp_err_status_ok ) {
274+ printf ("rdb_check failed at index 127\n" );
275+ return srtp_err_status_fail ;
276+ }
277+ if (srtp_rdb_add_index (& rdb , 127 ) != srtp_err_status_ok ) {
278+ printf ("rdb_add_index failed at index 127\n" );
279+ return srtp_err_status_fail ;
280+ }
281+ if (srtp_rdb_check (& rdb , 127 ) != srtp_err_status_replay_fail ) {
282+ printf ("rdb_check failed to reject index 127\n" );
283+ return srtp_err_status_fail ;
284+ }
285+ if (srtp_rdb_check (& rdb , 128 ) != srtp_err_status_ok ) {
286+ printf ("rdb_check failed at index 128\n" );
287+ return srtp_err_status_fail ;
288+ }
289+ if (srtp_rdb_add_index (& rdb , 128 ) != srtp_err_status_ok ) {
290+ printf ("rdb_add_index failed at index 128\n" );
291+ return srtp_err_status_fail ;
292+ }
293+ if (rdb .window_start != 1 ) {
294+ printf ("rdb window_start was %u, expected 1\n" , rdb .window_start );
295+ return srtp_err_status_fail ;
296+ }
297+ if (srtp_rdb_check (& rdb , 0 ) != srtp_err_status_replay_old ) {
298+ printf ("rdb_check failed to age out index 0\n" );
299+ return srtp_err_status_fail ;
300+ }
301+
302+ if (srtp_rdb_init (& rdb ) != srtp_err_status_ok ) {
303+ printf ("rdb_init failed\n" );
304+ return srtp_err_status_fail ;
305+ }
306+
307+ rdb .window_start = 0x7fffffff - 127 ;
308+ if (srtp_rdb_add_index (& rdb , 0x7fffffff ) != srtp_err_status_ok ) {
309+ printf ("rdb_add_index failed at 31-bit boundary\n" );
310+ return srtp_err_status_fail ;
311+ }
312+ if (srtp_rdb_check (& rdb , 0x7fffffff ) != srtp_err_status_replay_fail ) {
313+ printf ("rdb_check failed to retain 31-bit boundary packet\n" );
314+ return srtp_err_status_fail ;
315+ }
316+ if (srtp_rdb_check (& rdb , 0x7fffffff - 128 ) != srtp_err_status_replay_old ) {
317+ printf ("rdb_check failed to age packets before 31-bit boundary\n" );
318+ return srtp_err_status_fail ;
319+ }
320+
250321 return srtp_err_status_ok ;
251322}
252323
0 commit comments