@@ -112,6 +112,8 @@ srtp_err_status_t srtp_test_roc_mismatch(void);
112
112
113
113
srtp_err_status_t srtp_test_set_sender_roc (void );
114
114
115
+ srtp_err_status_t srtp_test_cryptex_csrc_but_no_extension_header (void );
116
+
115
117
double srtp_bits_per_second (size_t msg_len_octets , const srtp_policy_t * policy );
116
118
117
119
double srtp_rejections_per_second (size_t msg_len_octets ,
@@ -886,6 +888,15 @@ int main(int argc, char *argv[])
886
888
printf ("failed\n" );
887
889
exit (1 );
888
890
}
891
+
892
+ printf ("testing cryptex_csrc_but_no_extension_header()..." );
893
+ if (srtp_test_cryptex_csrc_but_no_extension_header () ==
894
+ srtp_err_status_ok ) {
895
+ printf ("passed\n" );
896
+ } else {
897
+ printf ("failed\n" );
898
+ exit (1 );
899
+ }
889
900
}
890
901
891
902
if (do_stream_list ) {
@@ -2152,30 +2163,58 @@ char *srtp_packet_to_string(uint8_t *packet, size_t pkt_octet_len)
2152
2163
srtp_hdr_t * hdr = (srtp_hdr_t * )packet ;
2153
2164
size_t octets_in_rtp_header = 12 ;
2154
2165
uint8_t * data = packet + octets_in_rtp_header ;
2155
- size_t hex_len = pkt_octet_len - octets_in_rtp_header ;
2166
+ size_t data_len = pkt_octet_len - octets_in_rtp_header ;
2156
2167
2157
2168
/* sanity checking */
2158
2169
if ((hdr == NULL ) || (pkt_octet_len > MTU )) {
2159
2170
return NULL ;
2160
2171
}
2161
2172
2162
2173
/* write packet into string */
2163
- snprintf (packet_string , sizeof (packet_string ),
2164
- "(s)rtp packet: {\n"
2165
- " version:\t%d\n"
2166
- " p:\t\t%d\n"
2167
- " x:\t\t%d\n"
2168
- " cc:\t\t%d\n"
2169
- " m:\t\t%d\n"
2170
- " pt:\t\t%x\n"
2171
- " seq:\t\t%x\n"
2172
- " ts:\t\t%x\n"
2173
- " ssrc:\t%x\n"
2174
- " data:\t%s\n"
2174
+ int offset = snprintf (packet_string , sizeof (packet_string ),
2175
+ "(s)rtp packet: {\n"
2176
+ " version:\t%d\n"
2177
+ " p:\t\t%d\n"
2178
+ " x:\t\t%d\n"
2179
+ " cc:\t\t%d\n"
2180
+ " m:\t\t%d\n"
2181
+ " pt:\t\t%x\n"
2182
+ " seq:\t\t%x\n"
2183
+ " ts:\t\t%x\n"
2184
+ " ssrc:\t%x" ,
2185
+ hdr -> version , hdr -> p , hdr -> x , hdr -> cc , hdr -> m ,
2186
+ hdr -> pt , hdr -> seq , hdr -> ts , hdr -> ssrc );
2187
+
2188
+ if (hdr -> cc ) {
2189
+ offset += snprintf (packet_string + offset ,
2190
+ sizeof (packet_string ) - offset , "\n csrc:\t" );
2191
+ for (int i = 0 ; i < hdr -> cc ; i ++ ) {
2192
+ offset +=
2193
+ snprintf (packet_string + offset , sizeof (packet_string ) - offset ,
2194
+ "%x " , * ((& hdr -> ssrc ) + 1 + i ));
2195
+ }
2196
+ data += 4 * hdr -> cc ;
2197
+ data_len -= 4 * hdr -> cc ;
2198
+ }
2199
+
2200
+ if (hdr -> x ) {
2201
+ uint16_t profile = * ((uint16_t * )data );
2202
+ data += 2 ;
2203
+ data_len -= 2 ;
2204
+ uint16_t length = ntohs (* ((uint16_t * )data )) * 4 ;
2205
+ data += 2 ;
2206
+ data_len -= 2 ;
2207
+ offset += snprintf (packet_string + offset ,
2208
+ sizeof (packet_string ) - offset , "\n xtn:\t\t%x %s" ,
2209
+ profile , octet_string_hex_string (data , length ));
2210
+ data += length ;
2211
+ data_len -= length ;
2212
+ }
2213
+
2214
+ snprintf (packet_string + offset , sizeof (packet_string ) - offset ,
2215
+ "\n data:\t%s\n"
2175
2216
"} (%zu octets in total)\n" ,
2176
- hdr -> version , hdr -> p , hdr -> x , hdr -> cc , hdr -> m , hdr -> pt , hdr -> seq ,
2177
- hdr -> ts , hdr -> ssrc , octet_string_hex_string (data , hex_len ),
2178
- pkt_octet_len );
2217
+ octet_string_hex_string (data , data_len ), pkt_octet_len );
2179
2218
2180
2219
return packet_string ;
2181
2220
}
@@ -2913,7 +2952,7 @@ srtp_err_status_t srtp_validate_cryptex(void)
2913
2952
2914
2953
// clang-format on
2915
2954
2916
- struct test_vectors_t vectors [6 ] = {
2955
+ const struct test_vectors_t vectors [6 ] = {
2917
2956
{ "Plaintext packet with 1-byte header extension" , srtp_1bytehdrext_ref ,
2918
2957
srtp_1bytehdrext_cryptex },
2919
2958
{ "Plaintext packet with 2-byte header extension" , srtp_2bytehdrext_ref ,
@@ -2927,6 +2966,7 @@ srtp_err_status_t srtp_validate_cryptex(void)
2927
2966
{ "Plaintext packet with empty 2-byte header extension and CSRC fields" ,
2928
2967
srtp_2byte_empty_hdrext_cc_ref , srtp_2byte_empty_hdrext_cc_cryptex },
2929
2968
};
2969
+ const size_t num_vectors = sizeof (vectors ) / sizeof (vectors [0 ]);
2930
2970
2931
2971
srtp_t srtp_snd , srtp_recv ;
2932
2972
size_t len , ref_len , enc_len ;
@@ -2947,7 +2987,7 @@ srtp_err_status_t srtp_validate_cryptex(void)
2947
2987
policy .use_cryptex = true;
2948
2988
policy .next = NULL ;
2949
2989
2950
- for (size_t i = 0 ; i < 6 ; ++ i ) {
2990
+ for (size_t i = 0 ; i < num_vectors ; ++ i ) {
2951
2991
uint8_t packet [1400 ];
2952
2992
uint8_t reference [1400 ];
2953
2993
uint8_t ciphertext [1400 ];
@@ -2999,6 +3039,53 @@ srtp_err_status_t srtp_validate_cryptex(void)
2999
3039
return srtp_err_status_ok ;
3000
3040
}
3001
3041
3042
+ srtp_err_status_t srtp_test_cryptex_csrc_but_no_extension_header (void )
3043
+ {
3044
+ // clang-format off
3045
+ /* Plaintext packet with no header extension but CSRC fields. */
3046
+ const char * srtp_cc_ref =
3047
+ "820f1238"
3048
+ "decafbad"
3049
+ "cafebabe"
3050
+ "0001e240"
3051
+ "0000b26e"
3052
+ "abababab"
3053
+ "abababab"
3054
+ "abababab"
3055
+ "abababab" ;
3056
+ // clang-format on
3057
+
3058
+ /*
3059
+ * create a session with a single stream using the default srtp
3060
+ * policy and with the SSRC value 0xcafebabe
3061
+ */
3062
+ srtp_policy_t policy ;
3063
+ memset (& policy , 0 , sizeof (policy ));
3064
+ srtp_crypto_policy_set_rtp_default (& policy .rtp );
3065
+ srtp_crypto_policy_set_rtcp_default (& policy .rtcp );
3066
+ policy .ssrc .type = ssrc_specific ;
3067
+ policy .ssrc .value = 0xcafebabe ;
3068
+ policy .key = test_key ;
3069
+ policy .window_size = 128 ;
3070
+ policy .allow_repeat_tx = 0 ;
3071
+ policy .use_cryptex = true;
3072
+ policy .next = NULL ;
3073
+
3074
+ srtp_t srtp_snd ;
3075
+ CHECK_OK (srtp_create (& srtp_snd , & policy ));
3076
+
3077
+ uint8_t packet [1400 ];
3078
+ size_t packet_len =
3079
+ hex_string_to_octet_string (packet , srtp_cc_ref , sizeof (packet )) / 2 ;
3080
+
3081
+ CHECK_RETURN (call_srtp_protect (srtp_snd , packet , & packet_len , 0 ),
3082
+ srtp_err_status_cryptex_err );
3083
+
3084
+ CHECK_OK (srtp_dealloc (srtp_snd ));
3085
+
3086
+ return srtp_err_status_ok ;
3087
+ }
3088
+
3002
3089
#ifdef GCM
3003
3090
/*
3004
3091
* srtp_validate_gcm() verifies the correctness of libsrtp by comparing
@@ -3359,7 +3446,7 @@ srtp_err_status_t srtp_validate_gcm_cryptex(void)
3359
3446
"8b5207d8" ;
3360
3447
// clang-format on
3361
3448
3362
- struct test_vectors_t vectors [6 ] = {
3449
+ const struct test_vectors_t vectors [6 ] = {
3363
3450
{ "Plaintext packet with 1-byte header extension" , srtp_1bytehdrext_ref ,
3364
3451
srtp_1bytehdrext_cryptex_gcm },
3365
3452
{ "Plaintext packet with 2-byte header extension" , srtp_2bytehdrext_ref ,
@@ -3375,6 +3462,7 @@ srtp_err_status_t srtp_validate_gcm_cryptex(void)
3375
3462
srtp_2byte_empty_hdrext_cc_ref ,
3376
3463
srtp_2byte_empty_hdrext_cc_cryptex_gcm },
3377
3464
};
3465
+ const size_t num_vectors = sizeof (vectors ) / sizeof (vectors [0 ]);
3378
3466
3379
3467
srtp_t srtp_snd , srtp_recv ;
3380
3468
size_t len , ref_len , enc_len ;
@@ -3397,7 +3485,7 @@ srtp_err_status_t srtp_validate_gcm_cryptex(void)
3397
3485
3398
3486
CHECK_OK (srtp_create (& srtp_snd , & policy ));
3399
3487
3400
- for (int i = 0 ; i < 6 ; ++ i ) {
3488
+ for (size_t i = 0 ; i < num_vectors ; ++ i ) {
3401
3489
uint8_t packet [1400 ];
3402
3490
uint8_t reference [1400 ];
3403
3491
uint8_t ciphertext [1400 ];
@@ -3424,7 +3512,7 @@ srtp_err_status_t srtp_validate_gcm_cryptex(void)
3424
3512
// the combination of cryptex, cc, GCM & not inplace is not
3425
3513
// supported
3426
3514
CHECK_RETURN (call_srtp_protect (srtp_snd , packet , & len , 0 ),
3427
- srtp_err_status_bad_param );
3515
+ srtp_err_status_cryptex_err );
3428
3516
continue ;
3429
3517
}
3430
3518
CHECK_OK (call_srtp_protect (srtp_snd , packet , & len , 0 ));
0 commit comments