@@ -115,6 +115,8 @@ srtp_err_status_t srtp_test_cryptex_csrc_but_no_extension_header(void);
115115
116116srtp_err_status_t srtp_test_cryptex_disable (void );
117117
118+ srtp_err_status_t srtp_test_require_cryptex (void );
119+
118120double srtp_bits_per_second (int msg_len_octets , const srtp_policy_t * policy );
119121
120122double srtp_rejections_per_second (int msg_len_octets ,
@@ -684,6 +686,14 @@ int main(int argc, char *argv[])
684686 printf ("failed\n" );
685687 exit (1 );
686688 }
689+
690+ printf ("testing require_cryptex()..." );
691+ if (srtp_test_require_cryptex () == srtp_err_status_ok ) {
692+ printf ("passed\n" );
693+ } else {
694+ printf ("failed\n" );
695+ exit (1 );
696+ }
687697 }
688698
689699 if (do_stream_list ) {
@@ -2707,6 +2717,47 @@ srtp_err_status_t srtp_test_cryptex_disable(void)
27072717 return srtp_err_status_ok ;
27082718}
27092719
2720+ srtp_err_status_t srtp_test_require_cryptex (void )
2721+ {
2722+ srtp_policy_t policy ;
2723+ memset (& policy , 0 , sizeof (policy ));
2724+ srtp_crypto_policy_set_rtp_default (& policy .rtp );
2725+ srtp_crypto_policy_set_rtcp_default (& policy .rtcp );
2726+ policy .ssrc .type = ssrc_any_outbound ;
2727+ policy .ssrc .value = 0xcafebabe ;
2728+ policy .key = test_key ;
2729+ policy .window_size = 128 ;
2730+ policy .allow_repeat_tx = 0 ;
2731+ policy .next = NULL ;
2732+
2733+ srtp_t srtp_snd , srtp_recv ;
2734+ CHECK_OK (srtp_create (& srtp_snd , & policy ));
2735+ CHECK_OK (srtp_set_stream_use_cryptex (srtp_snd , & policy .ssrc , 0 ));
2736+ /*
2737+ * requiring cryptex is not defined for the outbound wildcard ssrc.
2738+ */
2739+ CHECK_RETURN (srtp_set_stream_require_cryptex (srtp_snd , & policy .ssrc , 1 ),
2740+ srtp_err_status_bad_param );
2741+ policy .ssrc .type = ssrc_any_inbound ;
2742+ CHECK_OK (srtp_create (& srtp_recv , & policy ));
2743+ CHECK_OK (srtp_set_stream_require_cryptex (srtp_recv , & policy .ssrc , 1 ));
2744+
2745+ int packet_len ;
2746+ srtp_hdr_t * packet =
2747+ srtp_create_test_packet_ext_hdr (100 , policy .ssrc .value , & packet_len );
2748+
2749+ CHECK_OK (srtp_protect (srtp_snd , packet , & packet_len ));
2750+
2751+ CHECK_RETURN (srtp_unprotect (srtp_recv , packet , & packet_len ),
2752+ srtp_err_status_cryptex_err );
2753+
2754+ CHECK_OK (srtp_dealloc (srtp_snd ));
2755+ CHECK_OK (srtp_dealloc (srtp_recv ));
2756+ free (packet );
2757+
2758+ return srtp_err_status_ok ;
2759+ }
2760+
27102761#ifdef GCM
27112762/*
27122763 * srtp_validate_gcm() verifies the correctness of libsrtp by comparing
0 commit comments