blob: 44bd502c1d21131b65612be5fe1125893f34206d [file] [log] [blame]
Cullen Jennings235513a2005-09-21 22:51:36 +00001/*
2 * srtp_driver.c
jfigus67b9c732014-11-20 10:17:21 -05003 *
Cullen Jennings235513a2005-09-21 22:51:36 +00004 * a test driver for libSRTP
5 *
6 * David A. McGrew
7 * Cisco Systems, Inc.
8 */
9/*
jfigus67b9c732014-11-20 10:17:21 -050010 *
David McGrew7629bf22006-06-08 17:00:25 +000011 * Copyright (c) 2001-2006, Cisco Systems, Inc.
Cullen Jennings235513a2005-09-21 22:51:36 +000012 * All rights reserved.
jfigus67b9c732014-11-20 10:17:21 -050013 *
Cullen Jennings235513a2005-09-21 22:51:36 +000014 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
jfigus67b9c732014-11-20 10:17:21 -050017 *
Cullen Jennings235513a2005-09-21 22:51:36 +000018 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
jfigus67b9c732014-11-20 10:17:21 -050020 *
Cullen Jennings235513a2005-09-21 22:51:36 +000021 * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution.
jfigus67b9c732014-11-20 10:17:21 -050025 *
Cullen Jennings235513a2005-09-21 22:51:36 +000026 * Neither the name of the Cisco Systems, Inc. nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
jfigus67b9c732014-11-20 10:17:21 -050029 *
Cullen Jennings235513a2005-09-21 22:51:36 +000030 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41 * OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 */
44
45
46#include <string.h> /* for memcpy() */
47#include <time.h> /* for clock() */
48#include <stdlib.h> /* for malloc(), free() */
49#include <stdio.h> /* for print(), fflush() */
David McGrew79bd3012006-07-17 20:41:21 +000050#include "getopt_s.h" /* for local getopt() */
jfigus46d6b472014-11-14 16:42:01 -050051#include "util.h"
Cullen Jennings235513a2005-09-21 22:51:36 +000052
David McGrew3c45e0c2006-07-12 00:50:56 +000053#include "srtp_priv.h"
Cullen Jennings235513a2005-09-21 22:51:36 +000054
Marcus Sundberg1cbca882005-10-02 20:50:06 +000055#ifdef HAVE_NETINET_IN_H
56# include <netinet/in.h>
57#elif defined HAVE_WINSOCK2_H
58# include <winsock2.h>
59#endif
60
Cullen Jennings235513a2005-09-21 22:51:36 +000061#define PRINT_REFERENCE_PACKET 1
62
jfigus857009c2014-11-05 11:17:43 -050063srtp_err_status_t
Marcus Sundberga3f95fe2005-09-29 12:48:41 +000064srtp_validate(void);
Cullen Jennings235513a2005-09-21 22:51:36 +000065
jfigus857009c2014-11-05 11:17:43 -050066srtp_err_status_t
Joachim Bauch99a74822015-11-17 00:08:19 +010067srtp_validate_encrypted_extensions_headers(void);
68
Joachim Bauch80a45b52015-12-06 22:57:58 +010069#ifdef OPENSSL
Joachim Bauch99a74822015-11-17 00:08:19 +010070srtp_err_status_t
Joachim Bauchfa1e8c22015-11-24 23:38:48 +010071srtp_validate_encrypted_extensions_headers_gcm(void);
Joachim Bauch80a45b52015-12-06 22:57:58 +010072#endif
Joachim Bauchfa1e8c22015-11-24 23:38:48 +010073
74srtp_err_status_t
Jonathan Lennox5df951a2010-05-20 20:55:54 +000075srtp_validate_aes_256(void);
76
jfigus857009c2014-11-05 11:17:43 -050077srtp_err_status_t
Cullen Jennings235513a2005-09-21 22:51:36 +000078srtp_create_big_policy(srtp_policy_t **list);
79
jfigus857009c2014-11-05 11:17:43 -050080srtp_err_status_t
Jonathan Lennox80c4c832010-05-17 19:30:28 +000081srtp_dealloc_big_policy(srtp_policy_t *list);
82
jfigus857009c2014-11-05 11:17:43 -050083srtp_err_status_t
Joachim Bauchc8a19ae2015-12-14 22:50:36 +010084srtp_test_empty_payload(void);
85
86#ifdef OPENSSL
87srtp_err_status_t
88srtp_test_empty_payload_gcm(void);
89#endif
90
91srtp_err_status_t
Marcus Sundberga3f95fe2005-09-29 12:48:41 +000092srtp_test_remove_stream(void);
Cullen Jennings235513a2005-09-21 22:51:36 +000093
Pascal Bühlerbd3112a2015-11-06 20:29:15 +010094srtp_err_status_t
95srtp_test_update(void);
96
Cullen Jennings235513a2005-09-21 22:51:36 +000097double
98srtp_bits_per_second(int msg_len_octets, const srtp_policy_t *policy);
99
100double
101srtp_rejections_per_second(int msg_len_octets, const srtp_policy_t *policy);
102
103void
104srtp_do_timing(const srtp_policy_t *policy);
105
106void
107srtp_do_rejection_timing(const srtp_policy_t *policy);
108
jfigus857009c2014-11-05 11:17:43 -0500109srtp_err_status_t
Joachim Bauch99a74822015-11-17 00:08:19 +0100110srtp_test(const srtp_policy_t *policy, int extension_header);
Cullen Jennings235513a2005-09-21 22:51:36 +0000111
jfigus857009c2014-11-05 11:17:43 -0500112srtp_err_status_t
David McGrew9c70f292006-05-03 19:38:38 +0000113srtcp_test(const srtp_policy_t *policy);
114
jfigus857009c2014-11-05 11:17:43 -0500115srtp_err_status_t
Cullen Jennings235513a2005-09-21 22:51:36 +0000116srtp_session_print_policy(srtp_t srtp);
117
jfigus857009c2014-11-05 11:17:43 -0500118srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -0500119srtp_print_policy(const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000120
121char *
122srtp_packet_to_string(srtp_hdr_t *hdr, int packet_len);
123
124double
125mips_estimate(int num_trials, int *ignore);
126
jfigus8c36da22013-10-01 16:41:19 -0400127extern uint8_t test_key[46];
Cullen Jennings235513a2005-09-21 22:51:36 +0000128
129void
jfigus67b9c732014-11-20 10:17:21 -0500130usage (char *prog_name)
131{
132 printf("usage: %s [ -t ][ -c ][ -v ][-d <debug_module> ]* [ -l ]\n"
133 " -t run timing test\n"
134 " -r run rejection timing test\n"
135 " -c run codec timing test\n"
136 " -v run validation tests\n"
137 " -d <mod> turn on debugging module <mod>\n"
138 " -l list debugging modules\n", prog_name);
139 exit(1);
Cullen Jennings235513a2005-09-21 22:51:36 +0000140}
141
142/*
143 * The policy_array is a null-terminated array of policy structs. it
144 * is declared at the end of this file
145 */
146
147extern const srtp_policy_t *policy_array[];
148
149
150/* the wildcard_policy is declared below; it has a wildcard ssrc */
151
152extern const srtp_policy_t wildcard_policy;
153
154/*
155 * mod_driver debug module - debugging module for this test driver
156 *
jfigus67b9c732014-11-20 10:17:21 -0500157 * we use the crypto_kernel debugging system in this driver, which
Cullen Jennings235513a2005-09-21 22:51:36 +0000158 * makes the interface uniform and increases portability
jfigus67b9c732014-11-20 10:17:21 -0500159 */
Cullen Jennings235513a2005-09-21 22:51:36 +0000160
jfigus02d6f032014-11-21 10:56:42 -0500161srtp_debug_module_t mod_driver = {
jfigus67b9c732014-11-20 10:17:21 -0500162 0, /* debugging is off by default */
163 "driver" /* printable name for module */
Cullen Jennings235513a2005-09-21 22:51:36 +0000164};
165
166int
jfigus67b9c732014-11-20 10:17:21 -0500167main (int argc, char *argv[])
168{
169 int q;
170 unsigned do_timing_test = 0;
171 unsigned do_rejection_test = 0;
172 unsigned do_codec_timing = 0;
173 unsigned do_validation = 0;
174 unsigned do_list_mods = 0;
175 srtp_err_status_t status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000176
177 /*
jfigus67b9c732014-11-20 10:17:21 -0500178 * verify that the compiler has interpreted the header data
179 * structure srtp_hdr_t correctly
Cullen Jennings235513a2005-09-21 22:51:36 +0000180 */
jfigus67b9c732014-11-20 10:17:21 -0500181 if (sizeof(srtp_hdr_t) != 12) {
182 printf("error: srtp_hdr_t has incorrect size"
183 "(size is %ld bytes, expected 12)\n",
184 (long)sizeof(srtp_hdr_t));
185 exit(1);
Cullen Jennings235513a2005-09-21 22:51:36 +0000186 }
187
jfigus67b9c732014-11-20 10:17:21 -0500188 /* initialize srtp library */
189 status = srtp_init();
190 if (status) {
191 printf("error: srtp init failed with error code %d\n", status);
192 exit(1);
193 }
194
195 /* load srtp_driver debug module */
jfigus92736bc2014-11-21 10:30:54 -0500196 status = srtp_crypto_kernel_load_debug_module(&mod_driver);
jfigus67b9c732014-11-20 10:17:21 -0500197 if (status) {
198 printf("error: load of srtp_driver debug module failed "
199 "with error code %d\n", status);
200 exit(1);
201 }
202
203 /* process input arguments */
204 while (1) {
205 q = getopt_s(argc, argv, "trcvld:");
206 if (q == -1) {
207 break;
208 }
209 switch (q) {
210 case 't':
211 do_timing_test = 1;
212 break;
213 case 'r':
214 do_rejection_test = 1;
215 break;
216 case 'c':
217 do_codec_timing = 1;
218 break;
219 case 'v':
220 do_validation = 1;
221 break;
222 case 'l':
223 do_list_mods = 1;
224 break;
225 case 'd':
jfigus92736bc2014-11-21 10:30:54 -0500226 status = srtp_crypto_kernel_set_debug_module(optarg_s, 1);
jfigus67b9c732014-11-20 10:17:21 -0500227 if (status) {
228 printf("error: set debug module (%s) failed\n", optarg_s);
229 exit(1);
230 }
231 break;
232 default:
233 usage(argv[0]);
234 }
235 }
236
237 if (!do_validation && !do_timing_test && !do_codec_timing
238 && !do_list_mods && !do_rejection_test) {
239 usage(argv[0]);
240 }
241
242 if (do_list_mods) {
jfigus92736bc2014-11-21 10:30:54 -0500243 status = srtp_crypto_kernel_list_debug_modules();
jfigus67b9c732014-11-20 10:17:21 -0500244 if (status) {
245 printf("error: list of debug modules failed\n");
246 exit(1);
247 }
248 }
249
250 if (do_validation) {
251 const srtp_policy_t **policy = policy_array;
252 srtp_policy_t *big_policy;
253
254 /* loop over policy array, testing srtp and srtcp for each policy */
255 while (*policy != NULL) {
256 printf("testing srtp_protect and srtp_unprotect\n");
Joachim Bauch99a74822015-11-17 00:08:19 +0100257 if (srtp_test(*policy, 0) == srtp_err_status_ok) {
258 printf("passed\n\n");
259 } else{
260 printf("failed\n");
261 exit(1);
262 }
263 printf("testing srtp_protect and srtp_unprotect with encrypted extensions headers\n");
264 if (srtp_test(*policy, 1) == srtp_err_status_ok) {
jfigus67b9c732014-11-20 10:17:21 -0500265 printf("passed\n\n");
266 } else{
267 printf("failed\n");
268 exit(1);
269 }
270 printf("testing srtp_protect_rtcp and srtp_unprotect_rtcp\n");
271 if (srtcp_test(*policy) == srtp_err_status_ok) {
272 printf("passed\n\n");
273 } else{
274 printf("failed\n");
275 exit(1);
276 }
277 policy++;
278 }
279
280 /* create a big policy list and run tests on it */
281 status = srtp_create_big_policy(&big_policy);
282 if (status) {
283 printf("unexpected failure with error code %d\n", status);
284 exit(1);
285 }
286 printf("testing srtp_protect and srtp_unprotect with big policy\n");
Joachim Bauch99a74822015-11-17 00:08:19 +0100287 if (srtp_test(big_policy, 0) == srtp_err_status_ok) {
288 printf("passed\n\n");
289 } else{
290 printf("failed\n");
291 exit(1);
292 }
293 printf("testing srtp_protect and srtp_unprotect with big policy and encrypted extensions headers\n");
294 if (srtp_test(big_policy, 1) == srtp_err_status_ok) {
jfigus67b9c732014-11-20 10:17:21 -0500295 printf("passed\n\n");
296 } else{
297 printf("failed\n");
298 exit(1);
299 }
300 status = srtp_dealloc_big_policy(big_policy);
301 if (status) {
302 printf("unexpected failure with error code %d\n", status);
303 exit(1);
304 }
305
306 /* run test on wildcard policy */
307 printf("testing srtp_protect and srtp_unprotect on "
308 "wildcard ssrc policy\n");
Joachim Bauch99a74822015-11-17 00:08:19 +0100309 if (srtp_test(&wildcard_policy, 0) == srtp_err_status_ok) {
310 printf("passed\n\n");
311 } else{
312 printf("failed\n");
313 exit(1);
314 }
315 printf("testing srtp_protect and srtp_unprotect on "
316 "wildcard ssrc policy and encrypted extensions headers\n");
317 if (srtp_test(&wildcard_policy, 1) == srtp_err_status_ok) {
jfigus67b9c732014-11-20 10:17:21 -0500318 printf("passed\n\n");
319 } else{
320 printf("failed\n");
321 exit(1);
322 }
323
324 /*
325 * run validation test against the reference packets - note
326 * that this test only covers the default policy
327 */
328 printf("testing srtp_protect and srtp_unprotect against "
329 "reference packets\n");
330 if (srtp_validate() == srtp_err_status_ok) {
331 printf("passed\n\n");
332 } else{
333 printf("failed\n");
334 exit(1);
335 }
Joachim Bauch99a74822015-11-17 00:08:19 +0100336 printf("testing srtp_protect and srtp_unprotect against "
337 "reference packets with encrypted extensions headers\n");
338 if (srtp_validate_encrypted_extensions_headers() == srtp_err_status_ok)
339 printf("passed\n\n");
340 else {
341 printf("failed\n");
342 exit(1);
343 }
jfigus67b9c732014-11-20 10:17:21 -0500344
Joachim Bauchb8cb5772015-11-24 21:46:25 +0100345#ifdef OPENSSL
Joachim Bauchfa1e8c22015-11-24 23:38:48 +0100346 printf("testing srtp_protect and srtp_unprotect against "
347 "reference packets with encrypted extension headers (GCM)\n");
348 if (srtp_validate_encrypted_extensions_headers_gcm() == srtp_err_status_ok) {
349 printf("passed\n\n");
350 } else{
351 printf("failed\n");
352 exit(1);
353 }
Joachim Bauch80a45b52015-12-06 22:57:58 +0100354#endif
Joachim Bauchfa1e8c22015-11-24 23:38:48 +0100355
jfigus67b9c732014-11-20 10:17:21 -0500356 /*
357 * run validation test against the reference packets for
358 * AES-256
359 */
360 printf("testing srtp_protect and srtp_unprotect against "
361 "reference packets (AES-256)\n");
362 if (srtp_validate_aes_256() == srtp_err_status_ok) {
363 printf("passed\n\n");
364 } else{
365 printf("failed\n");
366 exit(1);
367 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000368
jfigus67b9c732014-11-20 10:17:21 -0500369 /*
Joachim Bauchc8a19ae2015-12-14 22:50:36 +0100370 * test packets with empty payload
371 */
372 printf("testing srtp_protect and srtp_unprotect against "
373 "packets with empty payload\n");
374 if (srtp_test_empty_payload() == srtp_err_status_ok) {
375 printf("passed\n");
376 } else{
377 printf("failed\n");
378 exit(1);
379 }
380#ifdef OPENSSL
381 printf("testing srtp_protect and srtp_unprotect against "
382 "packets with empty payload (GCM)\n");
383 if (srtp_test_empty_payload_gcm() == srtp_err_status_ok) {
384 printf("passed\n");
385 } else{
386 printf("failed\n");
387 exit(1);
388 }
389#endif
390
391 /*
jfigus67b9c732014-11-20 10:17:21 -0500392 * test the function srtp_remove_stream()
393 */
394 printf("testing srtp_remove_stream()...");
395 if (srtp_test_remove_stream() == srtp_err_status_ok) {
396 printf("passed\n");
397 } else{
398 printf("failed\n");
399 exit(1);
400 }
Pascal Bühlerbd3112a2015-11-06 20:29:15 +0100401
402 /*
403 * test the function srtp_update()
404 */
405 printf("testing srtp_update()...");
406 if (srtp_test_update() == srtp_err_status_ok) {
407 printf("passed\n");
408 } else {
409 printf("failed\n");
410 exit(1);
411 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000412 }
jfigus67b9c732014-11-20 10:17:21 -0500413
414 if (do_timing_test) {
415 const srtp_policy_t **policy = policy_array;
416
417 /* loop over policies, run timing test for each */
418 while (*policy != NULL) {
419 srtp_print_policy(*policy);
420 srtp_do_timing(*policy);
421 policy++;
422 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000423 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000424
jfigus67b9c732014-11-20 10:17:21 -0500425 if (do_rejection_test) {
426 const srtp_policy_t **policy = policy_array;
427
428 /* loop over policies, run rejection timing test for each */
429 while (*policy != NULL) {
430 srtp_print_policy(*policy);
431 srtp_do_rejection_timing(*policy);
432 policy++;
433 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000434 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000435
jfigus67b9c732014-11-20 10:17:21 -0500436 if (do_codec_timing) {
437 srtp_policy_t policy;
438 int ignore;
439 double mips = mips_estimate(1000000000, &ignore);
Cullen Jennings235513a2005-09-21 22:51:36 +0000440
Joachim Bauch99a74822015-11-17 00:08:19 +0100441 memset(&policy, 0, sizeof(policy));
jfigus67b9c732014-11-20 10:17:21 -0500442 srtp_crypto_policy_set_rtp_default(&policy.rtp);
443 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
444 policy.ssrc.type = ssrc_specific;
445 policy.ssrc.value = 0xdecafbad;
446 policy.key = test_key;
447 policy.ekt = NULL;
448 policy.window_size = 128;
449 policy.allow_repeat_tx = 0;
450 policy.next = NULL;
Cullen Jennings235513a2005-09-21 22:51:36 +0000451
jfigus67b9c732014-11-20 10:17:21 -0500452 printf("mips estimate: %e\n", mips);
Cullen Jennings235513a2005-09-21 22:51:36 +0000453
jfigus67b9c732014-11-20 10:17:21 -0500454 printf("testing srtp processing time for voice codecs:\n");
455 printf("codec\t\tlength (octets)\t\tsrtp instructions/second\n");
456 printf("G.711\t\t%d\t\t\t%e\n", 80,
457 (double)mips * (80 * 8) /
458 srtp_bits_per_second(80, &policy) / .01 );
459 printf("G.711\t\t%d\t\t\t%e\n", 160,
460 (double)mips * (160 * 8) /
461 srtp_bits_per_second(160, &policy) / .02);
462 printf("G.726-32\t%d\t\t\t%e\n", 40,
463 (double)mips * (40 * 8) /
464 srtp_bits_per_second(40, &policy) / .01 );
465 printf("G.726-32\t%d\t\t\t%e\n", 80,
466 (double)mips * (80 * 8) /
467 srtp_bits_per_second(80, &policy) / .02);
468 printf("G.729\t\t%d\t\t\t%e\n", 10,
469 (double)mips * (10 * 8) /
470 srtp_bits_per_second(10, &policy) / .01 );
471 printf("G.729\t\t%d\t\t\t%e\n", 20,
472 (double)mips * (20 * 8) /
473 srtp_bits_per_second(20, &policy) / .02 );
474 printf("Wideband\t%d\t\t\t%e\n", 320,
475 (double)mips * (320 * 8) /
476 srtp_bits_per_second(320, &policy) / .01 );
477 printf("Wideband\t%d\t\t\t%e\n", 640,
478 (double)mips * (640 * 8) /
479 srtp_bits_per_second(640, &policy) / .02 );
480 }
Jonathan Lennoxdfb30842010-05-15 04:52:01 +0000481
jfigus67b9c732014-11-20 10:17:21 -0500482 status = srtp_shutdown();
483 if (status) {
484 printf("error: srtp shutdown failed with error code %d\n", status);
485 exit(1);
486 }
487
488 return 0;
Cullen Jennings235513a2005-09-21 22:51:36 +0000489}
490
491
492
493/*
494 * srtp_create_test_packet(len, ssrc) returns a pointer to a
495 * (malloced) example RTP packet whose data field has the length given
496 * by pkt_octet_len and the SSRC value ssrc. The total length of the
497 * packet is twelve octets longer, since the header is at the
498 * beginning. There is room at the end of the packet for a trailer,
499 * and the four octets following the packet are filled with 0xff
500 * values to enable testing for overwrites.
501 *
502 * note that the location of the test packet can (and should) be
503 * deallocated with the free() call once it is no longer needed.
504 */
505
506srtp_hdr_t *
jfigus67b9c732014-11-20 10:17:21 -0500507srtp_create_test_packet (int pkt_octet_len, uint32_t ssrc)
508{
509 int i;
510 uint8_t *buffer;
511 srtp_hdr_t *hdr;
512 int bytes_in_hdr = 12;
Cullen Jennings235513a2005-09-21 22:51:36 +0000513
jfigus67b9c732014-11-20 10:17:21 -0500514 /* allocate memory for test packet */
515 hdr = (srtp_hdr_t*)malloc(pkt_octet_len + bytes_in_hdr
516 + SRTP_MAX_TRAILER_LEN + 4);
517 if (!hdr) {
518 return NULL;
519 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000520
jfigus67b9c732014-11-20 10:17:21 -0500521 hdr->version = 2; /* RTP version two */
522 hdr->p = 0; /* no padding needed */
523 hdr->x = 0; /* no header extension */
524 hdr->cc = 0; /* no CSRCs */
525 hdr->m = 0; /* marker bit */
526 hdr->pt = 0xf; /* payload type */
527 hdr->seq = htons(0x1234); /* sequence number */
528 hdr->ts = htonl(0xdecafbad); /* timestamp */
529 hdr->ssrc = htonl(ssrc); /* synch. source */
Cullen Jennings235513a2005-09-21 22:51:36 +0000530
jfigus67b9c732014-11-20 10:17:21 -0500531 buffer = (uint8_t*)hdr;
532 buffer += bytes_in_hdr;
Cullen Jennings235513a2005-09-21 22:51:36 +0000533
jfigus67b9c732014-11-20 10:17:21 -0500534 /* set RTP data to 0xab */
535 for (i = 0; i < pkt_octet_len; i++) {
536 *buffer++ = 0xab;
537 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000538
jfigus67b9c732014-11-20 10:17:21 -0500539 /* set post-data value to 0xffff to enable overrun checking */
540 for (i = 0; i < SRTP_MAX_TRAILER_LEN + 4; i++) {
541 *buffer++ = 0xff;
542 }
543
544 return hdr;
Cullen Jennings235513a2005-09-21 22:51:36 +0000545}
546
Joachim Bauch99a74822015-11-17 00:08:19 +0100547srtp_hdr_t *
548srtp_create_test_packet_ext_hdr(int pkt_octet_len, uint32_t ssrc) {
549 int i;
550 uint8_t *buffer;
551 srtp_hdr_t *hdr;
552 int bytes_in_hdr = 12;
553 uint8_t extension_header[12] = {
554 /* one-byte header */
555 0xbe, 0xde,
556 /* size */
557 0x00, 0x02,
558 /* id 1, length 1 (i.e. 2 bytes) */
559 0x11,
560 /* payload */
561 0xca,
562 0xfe,
563 /* padding */
564 0x00,
565 /* id 2, length 0 (i.e. 1 byte) */
566 0x20,
567 /* payload */
568 0xba,
569 /* padding */
570 0x00,
571 0x00
572 };
573
574 /* allocate memory for test packet */
575 hdr = (srtp_hdr_t*) malloc(pkt_octet_len + bytes_in_hdr
576 + sizeof(extension_header) + SRTP_MAX_TRAILER_LEN + 4);
577 if (!hdr)
578 return NULL;
579
580 hdr->version = 2; /* RTP version two */
581 hdr->p = 0; /* no padding needed */
582 hdr->x = 1; /* no header extension */
583 hdr->cc = 0; /* no CSRCs */
584 hdr->m = 0; /* marker bit */
585 hdr->pt = 0xf; /* payload type */
586 hdr->seq = htons(0x1234); /* sequence number */
587 hdr->ts = htonl(0xdecafbad); /* timestamp */
588 hdr->ssrc = htonl(ssrc); /* synch. source */
589
590 buffer = (uint8_t *)hdr;
591 buffer += bytes_in_hdr;
592
593 memcpy(buffer, extension_header, sizeof(extension_header));
594 buffer += sizeof(extension_header);
595
596 /* set RTP data to 0xab */
597 for (i=0; i < pkt_octet_len; i++)
598 *buffer++ = 0xab;
599
600 /* set post-data value to 0xffff to enable overrun checking */
601 for (i=0; i < SRTP_MAX_TRAILER_LEN+4; i++)
602 *buffer++ = 0xff;
603
604 return hdr;
605}
606
Cullen Jennings235513a2005-09-21 22:51:36 +0000607void
jfigus67b9c732014-11-20 10:17:21 -0500608srtp_do_timing (const srtp_policy_t *policy)
609{
610 int len;
Cullen Jennings235513a2005-09-21 22:51:36 +0000611
jfigus67b9c732014-11-20 10:17:21 -0500612 /*
613 * note: the output of this function is formatted so that it
614 * can be used in gnuplot. '#' indicates a comment, and "\r\n"
615 * terminates a record
616 */
617
618 printf("# testing srtp throughput:\r\n");
619 printf("# mesg length (octets)\tthroughput (megabits per second)\r\n");
620
621 for (len = 16; len <= 2048; len *= 2) {
622 printf("%d\t\t\t%f\r\n", len,
623 srtp_bits_per_second(len, policy) / 1.0E6);
624 }
625
626 /* these extra linefeeds let gnuplot know that a dataset is done */
627 printf("\r\n\r\n");
Cullen Jennings235513a2005-09-21 22:51:36 +0000628
629}
630
631void
jfigus67b9c732014-11-20 10:17:21 -0500632srtp_do_rejection_timing (const srtp_policy_t *policy)
633{
634 int len;
Cullen Jennings235513a2005-09-21 22:51:36 +0000635
jfigus67b9c732014-11-20 10:17:21 -0500636 /*
637 * note: the output of this function is formatted so that it
638 * can be used in gnuplot. '#' indicates a comment, and "\r\n"
639 * terminates a record
640 */
641
642 printf("# testing srtp rejection throughput:\r\n");
643 printf("# mesg length (octets)\trejections per second\r\n");
644
645 for (len = 8; len <= 2048; len *= 2) {
646 printf("%d\t\t\t%e\r\n", len, srtp_rejections_per_second(len, policy));
647 }
648
649 /* these extra linefeeds let gnuplot know that a dataset is done */
650 printf("\r\n\r\n");
Cullen Jennings235513a2005-09-21 22:51:36 +0000651
652}
653
654
655#define MAX_MSG_LEN 1024
656
657double
jfigus67b9c732014-11-20 10:17:21 -0500658srtp_bits_per_second (int msg_len_octets, const srtp_policy_t *policy)
659{
660 srtp_t srtp;
661 srtp_hdr_t *mesg;
662 int i;
663 clock_t timer;
664 int num_trials = 100000;
665 int len;
666 uint32_t ssrc;
667 srtp_err_status_t status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000668
jfigus67b9c732014-11-20 10:17:21 -0500669 /*
670 * allocate and initialize an srtp session
671 */
672 status = srtp_create(&srtp, policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000673 if (status) {
jfigus67b9c732014-11-20 10:17:21 -0500674 printf("error: srtp_create() failed with error code %d\n", status);
675 exit(1);
Cullen Jennings235513a2005-09-21 22:51:36 +0000676 }
677
jfigus67b9c732014-11-20 10:17:21 -0500678 /*
679 * if the ssrc is unspecified, use a predetermined one
680 */
681 if (policy->ssrc.type != ssrc_specific) {
682 ssrc = 0xdeadbeef;
683 } else {
684 ssrc = policy->ssrc.value;
Jonathan Lennox75b36872010-05-21 00:30:21 +0000685 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000686
jfigus67b9c732014-11-20 10:17:21 -0500687 /*
688 * create a test packet
689 */
690 mesg = srtp_create_test_packet(msg_len_octets, ssrc);
691 if (mesg == NULL) {
692 return 0.0; /* indicate failure by returning zero */
Jonathan Lennox80c4c832010-05-17 19:30:28 +0000693
jfigus67b9c732014-11-20 10:17:21 -0500694 }
695 timer = clock();
696 for (i = 0; i < num_trials; i++) {
697 len = msg_len_octets + 12; /* add in rtp header length */
698
699 /* srtp protect message */
700 status = srtp_protect(srtp, mesg, &len);
701 if (status) {
702 printf("error: srtp_protect() failed with error code %d\n", status);
703 exit(1);
704 }
705
706 /* increment message number */
707 {
708 /* hack sequence to avoid problems with macros for htons/ntohs on some systems */
709 short new_seq = ntohs(mesg->seq) + 1;
710 mesg->seq = htons(new_seq);
711 }
712 }
713 timer = clock() - timer;
714
715 free(mesg);
716
717 status = srtp_dealloc(srtp);
718 if (status) {
719 printf("error: srtp_dealloc() failed with error code %d\n", status);
720 exit(1);
721 }
722
723 return (double)(msg_len_octets) * 8 *
724 num_trials * CLOCKS_PER_SEC / timer;
Cullen Jennings235513a2005-09-21 22:51:36 +0000725}
726
727double
jfigus67b9c732014-11-20 10:17:21 -0500728srtp_rejections_per_second (int msg_len_octets, const srtp_policy_t *policy)
729{
730 srtp_ctx_t *srtp;
731 srtp_hdr_t *mesg;
732 int i;
733 int len;
734 clock_t timer;
735 int num_trials = 1000000;
736 uint32_t ssrc = policy->ssrc.value;
737 srtp_err_status_t status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000738
jfigus67b9c732014-11-20 10:17:21 -0500739 /*
740 * allocate and initialize an srtp session
741 */
742 status = srtp_create(&srtp, policy);
743 if (status) {
744 printf("error: srtp_create() failed with error code %d\n", status);
745 exit(1);
746 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000747
jfigus67b9c732014-11-20 10:17:21 -0500748 mesg = srtp_create_test_packet(msg_len_octets, ssrc);
749 if (mesg == NULL) {
750 return 0.0; /* indicate failure by returning zero */
751
752 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000753 len = msg_len_octets;
jfigus67b9c732014-11-20 10:17:21 -0500754 srtp_protect(srtp, (srtp_hdr_t*)mesg, &len);
Cullen Jennings235513a2005-09-21 22:51:36 +0000755
jfigus67b9c732014-11-20 10:17:21 -0500756 timer = clock();
757 for (i = 0; i < num_trials; i++) {
758 len = msg_len_octets;
759 srtp_unprotect(srtp, (srtp_hdr_t*)mesg, &len);
760 }
761 timer = clock() - timer;
Jonathan Lennox80c4c832010-05-17 19:30:28 +0000762
jfigus67b9c732014-11-20 10:17:21 -0500763 free(mesg);
Jonathan Lennox80c4c832010-05-17 19:30:28 +0000764
jfigus67b9c732014-11-20 10:17:21 -0500765 status = srtp_dealloc(srtp);
766 if (status) {
767 printf("error: srtp_dealloc() failed with error code %d\n", status);
768 exit(1);
769 }
770
771 return (double)num_trials * CLOCKS_PER_SEC / timer;
Cullen Jennings235513a2005-09-21 22:51:36 +0000772}
773
774
775void
jfigus67b9c732014-11-20 10:17:21 -0500776err_check (srtp_err_status_t s)
777{
778 if (s == srtp_err_status_ok) {
779 return;
780 } else{
781 fprintf(stderr, "error: unexpected srtp failure (code %d)\n", s);
782 }
783 exit(1);
Cullen Jennings235513a2005-09-21 22:51:36 +0000784}
785
jfigus857009c2014-11-05 11:17:43 -0500786srtp_err_status_t
Joachim Bauch99a74822015-11-17 00:08:19 +0100787srtp_test (const srtp_policy_t *policy, int extension_header)
jfigus67b9c732014-11-20 10:17:21 -0500788{
789 int i;
790 srtp_t srtp_sender;
791 srtp_t srtp_rcvr;
792 srtp_err_status_t status = srtp_err_status_ok;
793 srtp_hdr_t *hdr, *hdr2;
794 uint8_t hdr_enc[64];
795 uint8_t *pkt_end;
796 int msg_len_octets, msg_len_enc;
797 int len;
798 int tag_length = policy->rtp.auth_tag_len;
799 uint32_t ssrc;
800 srtp_policy_t *rcvr_policy;
Joachim Bauch99a74822015-11-17 00:08:19 +0100801 srtp_policy_t tmp_policy;
802 int header = 1;
Cullen Jennings235513a2005-09-21 22:51:36 +0000803
Joachim Bauch99a74822015-11-17 00:08:19 +0100804 if (extension_header) {
805 memcpy(&tmp_policy, policy, sizeof(srtp_policy_t));
806 tmp_policy.enc_xtn_hdr = &header;
807 tmp_policy.enc_xtn_hdr_count = 1;
808 err_check(srtp_create(&srtp_sender, &tmp_policy));
809 } else {
810 err_check(srtp_create(&srtp_sender, policy));
811 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000812
jfigus67b9c732014-11-20 10:17:21 -0500813 /* print out policy */
814 err_check(srtp_session_print_policy(srtp_sender));
Cullen Jennings235513a2005-09-21 22:51:36 +0000815
jfigus67b9c732014-11-20 10:17:21 -0500816 /*
817 * initialize data buffer, using the ssrc in the policy unless that
818 * value is a wildcard, in which case we'll just use an arbitrary
819 * one
820 */
821 if (policy->ssrc.type != ssrc_specific) {
822 ssrc = 0xdecafbad;
823 } else{
824 ssrc = policy->ssrc.value;
Cullen Jennings235513a2005-09-21 22:51:36 +0000825 }
jfigus67b9c732014-11-20 10:17:21 -0500826 msg_len_octets = 28;
Joachim Bauch99a74822015-11-17 00:08:19 +0100827 if (extension_header) {
828 hdr = srtp_create_test_packet_ext_hdr(msg_len_octets, ssrc);
829 hdr2 = srtp_create_test_packet_ext_hdr(msg_len_octets, ssrc);
830 } else {
831 hdr = srtp_create_test_packet(msg_len_octets, ssrc);
832 hdr2 = srtp_create_test_packet(msg_len_octets, ssrc);
833 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000834
jfigus67b9c732014-11-20 10:17:21 -0500835 if (hdr == NULL) {
Joachim Bauch99a74822015-11-17 00:08:19 +0100836 free(hdr2);
jfigus67b9c732014-11-20 10:17:21 -0500837 return srtp_err_status_alloc_fail;
Cullen Jennings235513a2005-09-21 22:51:36 +0000838 }
jfigus67b9c732014-11-20 10:17:21 -0500839 if (hdr2 == NULL) {
840 free(hdr);
841 return srtp_err_status_alloc_fail;
Cullen Jennings235513a2005-09-21 22:51:36 +0000842 }
843
Marcus Sundberg5c40da82005-10-08 18:15:00 +0000844 /* set message length */
845 len = msg_len_octets;
Joachim Bauch99a74822015-11-17 00:08:19 +0100846 if (extension_header) {
847 len += 12;
848 }
Marcus Sundberg5c40da82005-10-08 18:15:00 +0000849
jfigus67b9c732014-11-20 10:17:21 -0500850 debug_print(mod_driver, "before protection:\n%s",
851 srtp_packet_to_string(hdr, len));
852
853#if PRINT_REFERENCE_PACKET
854 debug_print(mod_driver, "reference packet before protection:\n%s",
855 octet_string_hex_string((uint8_t*)hdr, len));
856#endif
Cullen Jennings235513a2005-09-21 22:51:36 +0000857 err_check(srtp_protect(srtp_sender, hdr, &len));
Cullen Jennings235513a2005-09-21 22:51:36 +0000858
jfigus67b9c732014-11-20 10:17:21 -0500859 debug_print(mod_driver, "after protection:\n%s",
860 srtp_packet_to_string(hdr, len));
861#if PRINT_REFERENCE_PACKET
862 debug_print(mod_driver, "after protection:\n%s",
863 octet_string_hex_string((uint8_t*)hdr, len));
864#endif
865
866 /* save protected message and length */
867 memcpy(hdr_enc, hdr, len);
868 msg_len_enc = len;
869
870 /*
871 * check for overrun of the srtp_protect() function
872 *
873 * The packet is followed by a value of 0xfffff; if the value of the
874 * data following the packet is different, then we know that the
875 * protect function is overwriting the end of the packet.
876 */
877 pkt_end = (uint8_t*)hdr + sizeof(srtp_hdr_t)
878 + msg_len_octets + tag_length;
Joachim Bauch99a74822015-11-17 00:08:19 +0100879 if (extension_header) {
880 pkt_end += 12;
881 }
jfigus67b9c732014-11-20 10:17:21 -0500882 for (i = 0; i < 4; i++) {
883 if (pkt_end[i] != 0xff) {
884 fprintf(stdout, "overwrite in srtp_protect() function "
885 "(expected %x, found %x in trailing octet %d)\n",
886 0xff, ((uint8_t*)hdr)[i], i);
887 free(hdr);
888 free(hdr2);
889 return srtp_err_status_algo_fail;
890 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000891 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000892
jfigus67b9c732014-11-20 10:17:21 -0500893 /*
894 * if the policy includes confidentiality, check that ciphertext is
895 * different than plaintext
896 *
897 * Note that this check will give false negatives, with some small
898 * probability, especially if the packets are short. For that
899 * reason, we skip this check if the plaintext is less than four
900 * octets long.
901 */
902 if ((policy->rtp.sec_serv & sec_serv_conf) && (msg_len_octets >= 4)) {
903 printf("testing that ciphertext is distinct from plaintext...");
904 status = srtp_err_status_algo_fail;
905 for (i = 12; i < msg_len_octets + 12; i++) {
906 if (((uint8_t*)hdr)[i] != ((uint8_t*)hdr2)[i]) {
907 status = srtp_err_status_ok;
908 }
909 }
910 if (status) {
911 printf("failed\n");
912 free(hdr);
913 free(hdr2);
914 return status;
915 }
916 printf("passed\n");
917 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000918
jfigus67b9c732014-11-20 10:17:21 -0500919 /*
920 * if the policy uses a 'wildcard' ssrc, then we need to make a copy
921 * of the policy that changes the direction to inbound
922 *
923 * we always copy the policy into the rcvr_policy, since otherwise
924 * the compiler would fret about the constness of the policy
925 */
926 rcvr_policy = (srtp_policy_t*)malloc(sizeof(srtp_policy_t));
927 if (rcvr_policy == NULL) {
928 free(hdr);
929 free(hdr2);
930 return srtp_err_status_alloc_fail;
931 }
Joachim Bauch99a74822015-11-17 00:08:19 +0100932 if (extension_header) {
933 memcpy(rcvr_policy, &tmp_policy, sizeof(srtp_policy_t));
934 if (tmp_policy.ssrc.type == ssrc_any_outbound) {
935 rcvr_policy->ssrc.type = ssrc_any_inbound;
936 }
937 } else {
938 memcpy(rcvr_policy, policy, sizeof(srtp_policy_t));
939 if (policy->ssrc.type == ssrc_any_outbound) {
940 rcvr_policy->ssrc.type = ssrc_any_inbound;
941 }
jfigus67b9c732014-11-20 10:17:21 -0500942 }
943
944 err_check(srtp_create(&srtp_rcvr, rcvr_policy));
945
946 err_check(srtp_unprotect(srtp_rcvr, hdr, &len));
947
948 debug_print(mod_driver, "after unprotection:\n%s",
949 srtp_packet_to_string(hdr, len));
950
951 /* verify that the unprotected packet matches the origial one */
952 for (i = 0; i < msg_len_octets; i++) {
953 if (((uint8_t*)hdr)[i] != ((uint8_t*)hdr2)[i]) {
954 fprintf(stdout, "mismatch at octet %d\n", i);
955 status = srtp_err_status_algo_fail;
956 }
957 }
958 if (status) {
959 free(hdr);
960 free(hdr2);
961 free(rcvr_policy);
962 return status;
963 }
964
965 /*
966 * if the policy includes authentication, then test for false positives
967 */
968 if (policy->rtp.sec_serv & sec_serv_auth) {
969 char *data = ((char*)hdr) + 12;
970
971 printf("testing for false positives in replay check...");
972
973 /* set message length */
974 len = msg_len_enc;
975
976 /* unprotect a second time - should fail with a replay error */
977 status = srtp_unprotect(srtp_rcvr, hdr_enc, &len);
978 if (status != srtp_err_status_replay_fail) {
979 printf("failed with error code %d\n", status);
980 free(hdr);
981 free(hdr2);
982 free(rcvr_policy);
983 return status;
984 } else {
985 printf("passed\n");
986 }
987
988 printf("testing for false positives in auth check...");
989
990 /* increment sequence number in header */
991 hdr->seq++;
992
993 /* set message length */
994 len = msg_len_octets;
Joachim Bauch99a74822015-11-17 00:08:19 +0100995 if (extension_header) {
996 len += 12;
997 }
jfigus67b9c732014-11-20 10:17:21 -0500998
999 /* apply protection */
1000 err_check(srtp_protect(srtp_sender, hdr, &len));
1001
1002 /* flip bits in packet */
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01001003 data[extension_header ? 12 : 0] ^= 0xff;
jfigus67b9c732014-11-20 10:17:21 -05001004
1005 /* unprotect, and check for authentication failure */
1006 status = srtp_unprotect(srtp_rcvr, hdr, &len);
1007 if (status != srtp_err_status_auth_fail) {
1008 printf("failed\n");
1009 free(hdr);
1010 free(hdr2);
1011 free(rcvr_policy);
1012 return status;
1013 } else {
1014 printf("passed\n");
1015 }
1016
1017 }
1018
1019 err_check(srtp_dealloc(srtp_sender));
1020 err_check(srtp_dealloc(srtp_rcvr));
1021
1022 free(hdr);
1023 free(hdr2);
1024 free(rcvr_policy);
1025 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001026}
1027
1028
jfigus857009c2014-11-05 11:17:43 -05001029srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001030srtcp_test (const srtp_policy_t *policy)
1031{
1032 int i;
1033 srtp_t srtcp_sender;
1034 srtp_t srtcp_rcvr;
1035 srtp_err_status_t status = srtp_err_status_ok;
1036 srtp_hdr_t *hdr, *hdr2;
1037 uint8_t hdr_enc[64];
1038 uint8_t *pkt_end;
1039 int msg_len_octets, msg_len_enc;
1040 int len;
1041 int tag_length = policy->rtp.auth_tag_len;
1042 uint32_t ssrc;
1043 srtp_policy_t *rcvr_policy;
David McGrew9c70f292006-05-03 19:38:38 +00001044
jfigus67b9c732014-11-20 10:17:21 -05001045 err_check(srtp_create(&srtcp_sender, policy));
David McGrew9c70f292006-05-03 19:38:38 +00001046
jfigus67b9c732014-11-20 10:17:21 -05001047 /* print out policy */
1048 err_check(srtp_session_print_policy(srtcp_sender));
David McGrew9c70f292006-05-03 19:38:38 +00001049
jfigus67b9c732014-11-20 10:17:21 -05001050 /*
1051 * initialize data buffer, using the ssrc in the policy unless that
1052 * value is a wildcard, in which case we'll just use an arbitrary
1053 * one
1054 */
1055 if (policy->ssrc.type != ssrc_specific) {
1056 ssrc = 0xdecafbad;
1057 } else{
1058 ssrc = policy->ssrc.value;
David McGrew9c70f292006-05-03 19:38:38 +00001059 }
jfigus67b9c732014-11-20 10:17:21 -05001060 msg_len_octets = 28;
1061 hdr = srtp_create_test_packet(msg_len_octets, ssrc);
David McGrew9c70f292006-05-03 19:38:38 +00001062
jfigus67b9c732014-11-20 10:17:21 -05001063 if (hdr == NULL) {
1064 return srtp_err_status_alloc_fail;
David McGrew9c70f292006-05-03 19:38:38 +00001065 }
jfigus67b9c732014-11-20 10:17:21 -05001066 hdr2 = srtp_create_test_packet(msg_len_octets, ssrc);
1067 if (hdr2 == NULL) {
1068 free(hdr);
1069 return srtp_err_status_alloc_fail;
David McGrew9c70f292006-05-03 19:38:38 +00001070 }
1071
David McGrew9c70f292006-05-03 19:38:38 +00001072 /* set message length */
1073 len = msg_len_octets;
1074
jfigus67b9c732014-11-20 10:17:21 -05001075 debug_print(mod_driver, "before protection:\n%s",
1076 srtp_packet_to_string(hdr, len));
1077
1078#if PRINT_REFERENCE_PACKET
1079 debug_print(mod_driver, "reference packet before protection:\n%s",
1080 octet_string_hex_string((uint8_t*)hdr, len));
1081#endif
David McGrew9c70f292006-05-03 19:38:38 +00001082 err_check(srtp_protect_rtcp(srtcp_sender, hdr, &len));
David McGrew9c70f292006-05-03 19:38:38 +00001083
jfigus67b9c732014-11-20 10:17:21 -05001084 debug_print(mod_driver, "after protection:\n%s",
1085 srtp_packet_to_string(hdr, len));
1086#if PRINT_REFERENCE_PACKET
1087 debug_print(mod_driver, "after protection:\n%s",
1088 octet_string_hex_string((uint8_t*)hdr, len));
1089#endif
1090
1091 /* save protected message and length */
1092 memcpy(hdr_enc, hdr, len);
1093 msg_len_enc = len;
1094
1095 /*
1096 * check for overrun of the srtp_protect() function
1097 *
1098 * The packet is followed by a value of 0xfffff; if the value of the
1099 * data following the packet is different, then we know that the
1100 * protect function is overwriting the end of the packet.
1101 */
1102 pkt_end = (uint8_t*)hdr + sizeof(srtp_hdr_t)
1103 + msg_len_octets + tag_length;
1104 for (i = 0; i < 4; i++) {
1105 if (pkt_end[i] != 0xff) {
1106 fprintf(stdout, "overwrite in srtp_protect_rtcp() function "
1107 "(expected %x, found %x in trailing octet %d)\n",
1108 0xff, ((uint8_t*)hdr)[i], i);
1109 free(hdr);
1110 free(hdr2);
1111 return srtp_err_status_algo_fail;
1112 }
David McGrew9c70f292006-05-03 19:38:38 +00001113 }
David McGrew9c70f292006-05-03 19:38:38 +00001114
jfigus67b9c732014-11-20 10:17:21 -05001115 /*
1116 * if the policy includes confidentiality, check that ciphertext is
1117 * different than plaintext
1118 *
1119 * Note that this check will give false negatives, with some small
1120 * probability, especially if the packets are short. For that
1121 * reason, we skip this check if the plaintext is less than four
1122 * octets long.
1123 */
1124 if ((policy->rtp.sec_serv & sec_serv_conf) && (msg_len_octets >= 4)) {
1125 printf("testing that ciphertext is distinct from plaintext...");
1126 status = srtp_err_status_algo_fail;
1127 for (i = 12; i < msg_len_octets + 12; i++) {
1128 if (((uint8_t*)hdr)[i] != ((uint8_t*)hdr2)[i]) {
1129 status = srtp_err_status_ok;
1130 }
1131 }
1132 if (status) {
1133 printf("failed\n");
1134 free(hdr);
1135 free(hdr2);
1136 return status;
1137 }
1138 printf("passed\n");
1139 }
David McGrew9c70f292006-05-03 19:38:38 +00001140
jfigus67b9c732014-11-20 10:17:21 -05001141 /*
1142 * if the policy uses a 'wildcard' ssrc, then we need to make a copy
1143 * of the policy that changes the direction to inbound
1144 *
1145 * we always copy the policy into the rcvr_policy, since otherwise
1146 * the compiler would fret about the constness of the policy
1147 */
1148 rcvr_policy = (srtp_policy_t*)malloc(sizeof(srtp_policy_t));
1149 if (rcvr_policy == NULL) {
1150 return srtp_err_status_alloc_fail;
1151 }
1152 memcpy(rcvr_policy, policy, sizeof(srtp_policy_t));
1153 if (policy->ssrc.type == ssrc_any_outbound) {
1154 rcvr_policy->ssrc.type = ssrc_any_inbound;
1155 }
1156
1157 err_check(srtp_create(&srtcp_rcvr, rcvr_policy));
1158
1159 err_check(srtp_unprotect_rtcp(srtcp_rcvr, hdr, &len));
1160
1161 debug_print(mod_driver, "after unprotection:\n%s",
1162 srtp_packet_to_string(hdr, len));
1163
1164 /* verify that the unprotected packet matches the origial one */
1165 for (i = 0; i < msg_len_octets; i++) {
1166 if (((uint8_t*)hdr)[i] != ((uint8_t*)hdr2)[i]) {
1167 fprintf(stdout, "mismatch at octet %d\n", i);
1168 status = srtp_err_status_algo_fail;
1169 }
1170 }
1171 if (status) {
1172 free(hdr);
1173 free(hdr2);
1174 free(rcvr_policy);
1175 return status;
1176 }
1177
1178 /*
1179 * if the policy includes authentication, then test for false positives
1180 */
1181 if (policy->rtp.sec_serv & sec_serv_auth) {
1182 char *data = ((char*)hdr) + 12;
1183
1184 printf("testing for false positives in replay check...");
1185
1186 /* set message length */
1187 len = msg_len_enc;
1188
1189 /* unprotect a second time - should fail with a replay error */
1190 status = srtp_unprotect_rtcp(srtcp_rcvr, hdr_enc, &len);
1191 if (status != srtp_err_status_replay_fail) {
1192 printf("failed with error code %d\n", status);
1193 free(hdr);
1194 free(hdr2);
1195 free(rcvr_policy);
1196 return status;
1197 } else {
1198 printf("passed\n");
1199 }
1200
1201 printf("testing for false positives in auth check...");
1202
1203 /* increment sequence number in header */
1204 hdr->seq++;
1205
1206 /* set message length */
1207 len = msg_len_octets;
1208
1209 /* apply protection */
1210 err_check(srtp_protect_rtcp(srtcp_sender, hdr, &len));
1211
1212 /* flip bits in packet */
1213 data[0] ^= 0xff;
1214
1215 /* unprotect, and check for authentication failure */
1216 status = srtp_unprotect_rtcp(srtcp_rcvr, hdr, &len);
1217 if (status != srtp_err_status_auth_fail) {
1218 printf("failed\n");
1219 free(hdr);
1220 free(hdr2);
1221 free(rcvr_policy);
1222 return status;
1223 } else {
1224 printf("passed\n");
1225 }
1226
1227 }
1228
1229 err_check(srtp_dealloc(srtcp_sender));
1230 err_check(srtp_dealloc(srtcp_rcvr));
1231
1232 free(hdr);
1233 free(hdr2);
1234 free(rcvr_policy);
1235 return srtp_err_status_ok;
David McGrew9c70f292006-05-03 19:38:38 +00001236}
1237
1238
jfigus857009c2014-11-05 11:17:43 -05001239srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001240srtp_session_print_policy (srtp_t srtp)
1241{
1242 char *serv_descr[4] = {
1243 "none",
1244 "confidentiality",
1245 "authentication",
1246 "confidentiality and authentication"
1247 };
1248 char *direction[3] = {
1249 "unknown",
1250 "outbound",
1251 "inbound"
1252 };
1253 srtp_stream_t stream;
Cullen Jennings235513a2005-09-21 22:51:36 +00001254
jfigus67b9c732014-11-20 10:17:21 -05001255 /* sanity checking */
1256 if (srtp == NULL) {
1257 return srtp_err_status_fail;
1258 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001259
jfigus67b9c732014-11-20 10:17:21 -05001260 /* if there's a template stream, print it out */
1261 if (srtp->stream_template != NULL) {
1262 stream = srtp->stream_template;
1263 printf("# SSRC: any %s\r\n"
1264 "# rtp cipher: %s\r\n"
1265 "# rtp auth: %s\r\n"
1266 "# rtp services: %s\r\n"
1267 "# rtcp cipher: %s\r\n"
1268 "# rtcp auth: %s\r\n"
1269 "# rtcp services: %s\r\n"
1270 "# window size: %lu\r\n"
1271 "# tx rtx allowed:%s\r\n",
1272 direction[stream->direction],
1273 stream->rtp_cipher->type->description,
1274 stream->rtp_auth->type->description,
1275 serv_descr[stream->rtp_services],
1276 stream->rtcp_cipher->type->description,
1277 stream->rtcp_auth->type->description,
1278 serv_descr[stream->rtcp_services],
jfigusde8deb32014-11-25 12:58:11 -05001279 srtp_rdbx_get_window_size(&stream->rtp_rdbx),
jfigus67b9c732014-11-20 10:17:21 -05001280 stream->allow_repeat_tx ? "true" : "false");
Joachim Bauch99a74822015-11-17 00:08:19 +01001281
1282 printf("# Encrypted extension headers: ");
1283 if (stream->enc_xtn_hdr && stream->enc_xtn_hdr_count > 0) {
1284 int* enc_xtn_hdr = stream->enc_xtn_hdr;
1285 int count = stream->enc_xtn_hdr_count;
1286 while (count > 0) {
1287 printf("%d ", *enc_xtn_hdr);
1288 enc_xtn_hdr++;
1289 count--;
1290 }
1291 printf("\n");
1292 } else {
1293 printf("none\n");
1294 }
jfigus67b9c732014-11-20 10:17:21 -05001295 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001296
jfigus67b9c732014-11-20 10:17:21 -05001297 /* loop over streams in session, printing the policy of each */
1298 stream = srtp->stream_list;
1299 while (stream != NULL) {
1300 if (stream->rtp_services > sec_serv_conf_and_auth) {
1301 return srtp_err_status_bad_param;
1302 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001303
jfigus67b9c732014-11-20 10:17:21 -05001304 printf("# SSRC: 0x%08x\r\n"
1305 "# rtp cipher: %s\r\n"
1306 "# rtp auth: %s\r\n"
1307 "# rtp services: %s\r\n"
1308 "# rtcp cipher: %s\r\n"
1309 "# rtcp auth: %s\r\n"
1310 "# rtcp services: %s\r\n"
1311 "# window size: %lu\r\n"
1312 "# tx rtx allowed:%s\r\n",
1313 stream->ssrc,
1314 stream->rtp_cipher->type->description,
1315 stream->rtp_auth->type->description,
1316 serv_descr[stream->rtp_services],
1317 stream->rtcp_cipher->type->description,
1318 stream->rtcp_auth->type->description,
1319 serv_descr[stream->rtcp_services],
jfigusde8deb32014-11-25 12:58:11 -05001320 srtp_rdbx_get_window_size(&stream->rtp_rdbx),
jfigus67b9c732014-11-20 10:17:21 -05001321 stream->allow_repeat_tx ? "true" : "false");
1322
Joachim Bauch99a74822015-11-17 00:08:19 +01001323 printf("# Encrypted extension headers: ");
1324 if (stream->enc_xtn_hdr && stream->enc_xtn_hdr_count > 0) {
1325 int* enc_xtn_hdr = stream->enc_xtn_hdr;
1326 int count = stream->enc_xtn_hdr_count;
1327 while (count > 0) {
1328 printf("%d ", *enc_xtn_hdr);
1329 enc_xtn_hdr++;
1330 count--;
1331 }
1332 printf("\n");
1333 } else {
1334 printf("none\n");
1335 }
1336
jfigus67b9c732014-11-20 10:17:21 -05001337 /* advance to next stream in the list */
1338 stream = stream->next;
1339 }
1340 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001341}
1342
jfigus857009c2014-11-05 11:17:43 -05001343srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001344srtp_print_policy (const srtp_policy_t *policy)
1345{
1346 srtp_err_status_t status;
1347 srtp_t session;
Cullen Jennings235513a2005-09-21 22:51:36 +00001348
jfigus67b9c732014-11-20 10:17:21 -05001349 status = srtp_create(&session, policy);
1350 if (status) {
1351 return status;
1352 }
1353 status = srtp_session_print_policy(session);
1354 if (status) {
1355 return status;
1356 }
1357 status = srtp_dealloc(session);
1358 if (status) {
1359 return status;
1360 }
1361 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001362}
1363
jfigus67b9c732014-11-20 10:17:21 -05001364/*
1365 * srtp_print_packet(...) is for debugging only
Cullen Jennings235513a2005-09-21 22:51:36 +00001366 * it prints an RTP packet to the stdout
1367 *
1368 * note that this function is *not* threadsafe
1369 */
1370
1371#include <stdio.h>
1372
1373#define MTU 2048
1374
1375char packet_string[MTU];
1376
1377char *
jfigus67b9c732014-11-20 10:17:21 -05001378srtp_packet_to_string (srtp_hdr_t *hdr, int pkt_octet_len)
1379{
1380 int octets_in_rtp_header = 12;
1381 uint8_t *data = ((uint8_t*)hdr) + octets_in_rtp_header;
1382 int hex_len = pkt_octet_len - octets_in_rtp_header;
Cullen Jennings235513a2005-09-21 22:51:36 +00001383
jfigus67b9c732014-11-20 10:17:21 -05001384 /* sanity checking */
1385 if ((hdr == NULL) || (pkt_octet_len > MTU)) {
1386 return NULL;
1387 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001388
jfigus67b9c732014-11-20 10:17:21 -05001389 /* write packet into string */
1390 sprintf(packet_string,
1391 "(s)rtp packet: {\n"
1392 " version:\t%d\n"
1393 " p:\t\t%d\n"
1394 " x:\t\t%d\n"
1395 " cc:\t\t%d\n"
1396 " m:\t\t%d\n"
1397 " pt:\t\t%x\n"
1398 " seq:\t\t%x\n"
1399 " ts:\t\t%x\n"
1400 " ssrc:\t%x\n"
1401 " data:\t%s\n"
1402 "} (%d octets in total)\n",
1403 hdr->version,
1404 hdr->p,
1405 hdr->x,
1406 hdr->cc,
1407 hdr->m,
1408 hdr->pt,
1409 hdr->seq,
1410 hdr->ts,
1411 hdr->ssrc,
1412 octet_string_hex_string(data, hex_len),
1413 pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001414
jfigus67b9c732014-11-20 10:17:21 -05001415 return packet_string;
Cullen Jennings235513a2005-09-21 22:51:36 +00001416}
1417
1418/*
1419 * mips_estimate() is a simple function to estimate the number of
1420 * instructions per second that the host can perform. note that this
1421 * function can be grossly wrong; you may want to have a manual sanity
1422 * check of its output!
1423 *
1424 * the 'ignore' pointer is there to convince the compiler to not just
1425 * optimize away the function
1426 */
1427
1428double
jfigus67b9c732014-11-20 10:17:21 -05001429mips_estimate (int num_trials, int *ignore)
1430{
1431 clock_t t;
1432 volatile int i, sum;
Cullen Jennings235513a2005-09-21 22:51:36 +00001433
jfigus67b9c732014-11-20 10:17:21 -05001434 sum = 0;
1435 t = clock();
1436 for (i = 0; i < num_trials; i++) {
1437 sum += i;
1438 }
1439 t = clock() - t;
Cullen Jennings235513a2005-09-21 22:51:36 +00001440
1441/* printf("%d\n", sum); */
jfigus67b9c732014-11-20 10:17:21 -05001442 *ignore = sum;
Cullen Jennings235513a2005-09-21 22:51:36 +00001443
jfigus67b9c732014-11-20 10:17:21 -05001444 return (double)num_trials * CLOCKS_PER_SEC / t;
Cullen Jennings235513a2005-09-21 22:51:36 +00001445}
1446
1447
1448/*
1449 * srtp_validate() verifies the correctness of libsrtp by comparing
1450 * some computed packets against some pre-computed reference values.
1451 * These packets were made with the default SRTP policy.
1452 */
1453
1454
jfigus857009c2014-11-05 11:17:43 -05001455srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001456srtp_validate ()
1457{
1458 uint8_t srtp_plaintext_ref[28] = {
1459 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1460 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
1461 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1462 0xab, 0xab, 0xab, 0xab
1463 };
1464 uint8_t srtp_plaintext[38] = {
1465 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1466 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
1467 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1468 0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
1469 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1470 };
1471 uint8_t srtp_ciphertext[38] = {
1472 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1473 0xca, 0xfe, 0xba, 0xbe, 0x4e, 0x55, 0xdc, 0x4c,
1474 0xe7, 0x99, 0x78, 0xd8, 0x8c, 0xa4, 0xd2, 0x15,
1475 0x94, 0x9d, 0x24, 0x02, 0xb7, 0x8d, 0x6a, 0xcc,
1476 0x99, 0xea, 0x17, 0x9b, 0x8d, 0xbb
1477 };
1478 srtp_t srtp_snd, srtp_recv;
1479 srtp_err_status_t status;
1480 int len;
1481 srtp_policy_t policy;
Cullen Jennings235513a2005-09-21 22:51:36 +00001482
jfigus67b9c732014-11-20 10:17:21 -05001483 /*
1484 * create a session with a single stream using the default srtp
1485 * policy and with the SSRC value 0xcafebabe
1486 */
Joachim Bauch99a74822015-11-17 00:08:19 +01001487 memset(&policy, 0, sizeof(policy));
jfigus67b9c732014-11-20 10:17:21 -05001488 srtp_crypto_policy_set_rtp_default(&policy.rtp);
1489 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
1490 policy.ssrc.type = ssrc_specific;
1491 policy.ssrc.value = 0xcafebabe;
1492 policy.key = test_key;
1493 policy.ekt = NULL;
1494 policy.window_size = 128;
1495 policy.allow_repeat_tx = 0;
1496 policy.next = NULL;
Cullen Jennings235513a2005-09-21 22:51:36 +00001497
jfigus67b9c732014-11-20 10:17:21 -05001498 status = srtp_create(&srtp_snd, &policy);
1499 if (status) {
1500 return status;
1501 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001502
jfigus67b9c732014-11-20 10:17:21 -05001503 /*
1504 * protect plaintext, then compare with ciphertext
1505 */
1506 len = 28;
1507 status = srtp_protect(srtp_snd, srtp_plaintext, &len);
1508 if (status || (len != 38)) {
1509 return srtp_err_status_fail;
1510 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001511
jfigus67b9c732014-11-20 10:17:21 -05001512 debug_print(mod_driver, "ciphertext:\n %s",
1513 octet_string_hex_string(srtp_plaintext, len));
1514 debug_print(mod_driver, "ciphertext reference:\n %s",
1515 octet_string_hex_string(srtp_ciphertext, len));
Cullen Jennings235513a2005-09-21 22:51:36 +00001516
jfigus67b9c732014-11-20 10:17:21 -05001517 if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
1518 return srtp_err_status_fail;
1519 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00001520
jfigus67b9c732014-11-20 10:17:21 -05001521 /*
1522 * create a receiver session context comparable to the one created
1523 * above - we need to do this so that the replay checking doesn't
1524 * complain
1525 */
1526 status = srtp_create(&srtp_recv, &policy);
1527 if (status) {
1528 return status;
1529 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00001530
jfigus67b9c732014-11-20 10:17:21 -05001531 /*
1532 * unprotect ciphertext, then compare with plaintext
1533 */
1534 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
1535 if (status || (len != 28)) {
1536 return status;
1537 }
1538
1539 if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
1540 return srtp_err_status_fail;
1541 }
1542
1543 status = srtp_dealloc(srtp_snd);
1544 if (status) {
1545 return status;
1546 }
1547
1548 status = srtp_dealloc(srtp_recv);
1549 if (status) {
1550 return status;
1551 }
1552
1553 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001554}
1555
Joachim Bauch99a74822015-11-17 00:08:19 +01001556/*
1557 * Test vectors taken from RFC 6904, Appendix A
1558 */
1559srtp_err_status_t
1560srtp_validate_encrypted_extensions_headers() {
1561 unsigned char test_key_ext_headers[30] = {
1562 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0,
1563 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde, 0x41, 0x39,
1564 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb,
1565 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
1566 };
1567 uint8_t srtp_plaintext_ref[56] = {
1568 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1569 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1570 0x17, 0x41, 0x42, 0x73, 0xA4, 0x75, 0x26, 0x27,
1571 0x48, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x8E, 0x46,
1572 0x55, 0x99, 0x63, 0x86, 0xB3, 0x95, 0xFB, 0x00,
1573 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1574 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab
1575 };
1576 uint8_t srtp_plaintext[66] = {
1577 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1578 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1579 0x17, 0x41, 0x42, 0x73, 0xA4, 0x75, 0x26, 0x27,
1580 0x48, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x8E, 0x46,
1581 0x55, 0x99, 0x63, 0x86, 0xB3, 0x95, 0xFB, 0x00,
1582 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1583 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1584 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1585 0x00, 0x00
1586 };
1587 uint8_t srtp_ciphertext[66] = {
1588 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1589 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1590 0x17, 0x58, 0x8A, 0x92, 0x70, 0xF4, 0xE1, 0x5E,
1591 0x1C, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x95, 0x46,
1592 0xA9, 0x94, 0xF0, 0xBC, 0x54, 0x78, 0x97, 0x00,
1593 0x4e, 0x55, 0xdc, 0x4c, 0xe7, 0x99, 0x78, 0xd8,
1594 0x8c, 0xa4, 0xd2, 0x15, 0x94, 0x9d, 0x24, 0x02,
1595 0x5a, 0x46, 0xb3, 0xca, 0x35, 0xc5, 0x35, 0xa8,
1596 0x91, 0xc7
1597 };
1598 srtp_t srtp_snd, srtp_recv;
1599 srtp_err_status_t status;
1600 int len;
1601 srtp_policy_t policy;
1602 int headers[3] = {1, 3, 4};
1603
1604 /*
1605 * create a session with a single stream using the default srtp
1606 * policy and with the SSRC value 0xcafebabe
1607 */
1608 memset(&policy, 0, sizeof(policy));
1609 srtp_crypto_policy_set_rtp_default(&policy.rtp);
1610 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
1611 policy.ssrc.type = ssrc_specific;
1612 policy.ssrc.value = 0xcafebabe;
1613 policy.key = test_key_ext_headers;
1614 policy.ekt = NULL;
1615 policy.window_size = 128;
1616 policy.allow_repeat_tx = 0;
1617 policy.enc_xtn_hdr = headers;
1618 policy.enc_xtn_hdr_count = sizeof(headers) / sizeof(headers[0]);
1619 policy.next = NULL;
1620
1621 status = srtp_create(&srtp_snd, &policy);
1622 if (status)
1623 return status;
1624
1625 /*
1626 * protect plaintext, then compare with ciphertext
1627 */
1628 len = sizeof(srtp_plaintext_ref);
1629 status = srtp_protect(srtp_snd, srtp_plaintext, &len);
1630 if (status || (len != sizeof(srtp_plaintext)))
1631 return srtp_err_status_fail;
1632
1633 debug_print(mod_driver, "ciphertext:\n %s",
1634 srtp_octet_string_hex_string(srtp_plaintext, len));
1635 debug_print(mod_driver, "ciphertext reference:\n %s",
1636 srtp_octet_string_hex_string(srtp_ciphertext, len));
1637
1638 if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
1639 return srtp_err_status_fail;
1640
1641 /*
1642 * create a receiver session context comparable to the one created
1643 * above - we need to do this so that the replay checking doesn't
1644 * complain
1645 */
1646 status = srtp_create(&srtp_recv, &policy);
1647 if (status)
1648 return status;
1649
1650 /*
1651 * unprotect ciphertext, then compare with plaintext
1652 */
1653 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
1654 if (status || (len != 28))
1655 return status;
1656
1657 if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
1658 return srtp_err_status_fail;
1659
1660 status = srtp_dealloc(srtp_snd);
1661 if (status)
1662 return status;
1663
1664 status = srtp_dealloc(srtp_recv);
1665 if (status)
1666 return status;
1667
1668 return srtp_err_status_ok;
1669}
1670
Cullen Jennings235513a2005-09-21 22:51:36 +00001671
Joachim Bauch80a45b52015-12-06 22:57:58 +01001672#ifdef OPENSSL
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001673/*
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01001674 * Headers of test vectors taken from RFC 6904, Appendix A
1675 */
1676srtp_err_status_t
1677srtp_validate_encrypted_extensions_headers_gcm() {
1678 unsigned char test_key_ext_headers[30] = {
1679 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0,
1680 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde, 0x41, 0x39,
1681 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb,
1682 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
1683 };
1684 uint8_t srtp_plaintext_ref[56] = {
1685 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1686 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1687 0x17, 0x41, 0x42, 0x73, 0xA4, 0x75, 0x26, 0x27,
1688 0x48, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x8E, 0x46,
1689 0x55, 0x99, 0x63, 0x86, 0xB3, 0x95, 0xFB, 0x00,
1690 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1691 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab
1692 };
1693 uint8_t srtp_plaintext[64] = {
1694 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1695 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1696 0x17, 0x41, 0x42, 0x73, 0xA4, 0x75, 0x26, 0x27,
1697 0x48, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x8E, 0x46,
1698 0x55, 0x99, 0x63, 0x86, 0xB3, 0x95, 0xFB, 0x00,
1699 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1700 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1701 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1702 };
1703 uint8_t srtp_ciphertext[64] = {
1704 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1705 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1706 0x17, 0x58, 0x8A, 0x92, 0x70, 0xF4, 0xE1, 0x5E,
1707 0x1C, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x95, 0x46,
1708 0xA9, 0x94, 0xF0, 0xBC, 0x54, 0x78, 0x97, 0x00,
1709 0x0e, 0xca, 0x0c, 0xf9, 0x5e, 0xe9, 0x55, 0xb2,
1710 0x6c, 0xd3, 0xd2, 0x88, 0xb4, 0x9f, 0x6c, 0xa9,
1711 0xbb, 0x4e, 0x15, 0xc2, 0xe9, 0xf2, 0x66, 0x78
1712 };
1713 srtp_t srtp_snd, srtp_recv;
1714 srtp_err_status_t status;
1715 int len;
1716 srtp_policy_t policy;
1717 int headers[3] = {1, 3, 4};
1718
1719 /*
1720 * create a session with a single stream using the default srtp
1721 * policy and with the SSRC value 0xcafebabe
1722 */
1723 memset(&policy, 0, sizeof(policy));
1724 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtp);
1725 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtcp);
1726 policy.ssrc.type = ssrc_specific;
1727 policy.ssrc.value = 0xcafebabe;
1728 policy.key = test_key_ext_headers;
1729 policy.ekt = NULL;
1730 policy.window_size = 128;
1731 policy.allow_repeat_tx = 0;
1732 policy.enc_xtn_hdr = headers;
1733 policy.enc_xtn_hdr_count = sizeof(headers) / sizeof(headers[0]);
1734 policy.next = NULL;
1735
1736 status = srtp_create(&srtp_snd, &policy);
1737 if (status)
1738 return status;
1739
1740 /*
1741 * protect plaintext, then compare with ciphertext
1742 */
1743 len = sizeof(srtp_plaintext_ref);
1744 status = srtp_protect(srtp_snd, srtp_plaintext, &len);
1745 if (status || (len != sizeof(srtp_plaintext)))
1746 return srtp_err_status_fail;
1747
1748 debug_print(mod_driver, "ciphertext:\n %s",
1749 srtp_octet_string_hex_string(srtp_plaintext, len));
1750 debug_print(mod_driver, "ciphertext reference:\n %s",
1751 srtp_octet_string_hex_string(srtp_ciphertext, len));
1752
1753 if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
1754 return srtp_err_status_fail;
1755
1756 /*
1757 * create a receiver session context comparable to the one created
1758 * above - we need to do this so that the replay checking doesn't
1759 * complain
1760 */
1761 status = srtp_create(&srtp_recv, &policy);
1762 if (status)
1763 return status;
1764
1765 /*
1766 * unprotect ciphertext, then compare with plaintext
1767 */
1768 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
1769 if (status || (len != 28))
1770 return status;
1771
1772 if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
1773 return srtp_err_status_fail;
1774
1775 status = srtp_dealloc(srtp_snd);
1776 if (status)
1777 return status;
1778
1779 status = srtp_dealloc(srtp_recv);
1780 if (status)
1781 return status;
1782
1783 return srtp_err_status_ok;
1784}
Joachim Bauch80a45b52015-12-06 22:57:58 +01001785#endif
Cullen Jennings235513a2005-09-21 22:51:36 +00001786
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001787/*
1788 * srtp_validate_aes_256() verifies the correctness of libsrtp by comparing
1789 * some computed packets against some pre-computed reference values.
1790 * These packets were made with the AES-CM-256/HMAC-SHA-1-80 policy.
1791 */
1792
1793
jfigus857009c2014-11-05 11:17:43 -05001794srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001795srtp_validate_aes_256 ()
1796{
1797 unsigned char aes_256_test_key[46] = {
1798 0xf0, 0xf0, 0x49, 0x14, 0xb5, 0x13, 0xf2, 0x76,
1799 0x3a, 0x1b, 0x1f, 0xa1, 0x30, 0xf1, 0x0e, 0x29,
1800 0x98, 0xf6, 0xf6, 0xe4, 0x3e, 0x43, 0x09, 0xd1,
1801 0xe6, 0x22, 0xa0, 0xe3, 0x32, 0xb9, 0xf1, 0xb6,
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001802
jfigus67b9c732014-11-20 10:17:21 -05001803 0x3b, 0x04, 0x80, 0x3d, 0xe5, 0x1e, 0xe7, 0xc9,
1804 0x64, 0x23, 0xab, 0x5b, 0x78, 0xd2
1805 };
1806 uint8_t srtp_plaintext_ref[28] = {
1807 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1808 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
1809 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1810 0xab, 0xab, 0xab, 0xab
1811 };
1812 uint8_t srtp_plaintext[38] = {
1813 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1814 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
1815 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1816 0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
1817 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1818 };
1819 uint8_t srtp_ciphertext[38] = {
1820 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1821 0xca, 0xfe, 0xba, 0xbe, 0xf1, 0xd9, 0xde, 0x17,
1822 0xff, 0x25, 0x1f, 0xf1, 0xaa, 0x00, 0x77, 0x74,
1823 0xb0, 0xb4, 0xb4, 0x0d, 0xa0, 0x8d, 0x9d, 0x9a,
1824 0x5b, 0x3a, 0x55, 0xd8, 0x87, 0x3b
1825 };
1826 srtp_t srtp_snd, srtp_recv;
1827 srtp_err_status_t status;
1828 int len;
1829 srtp_policy_t policy;
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001830
jfigus67b9c732014-11-20 10:17:21 -05001831 /*
1832 * create a session with a single stream using the default srtp
1833 * policy and with the SSRC value 0xcafebabe
1834 */
Joachim Bauch99a74822015-11-17 00:08:19 +01001835 memset(&policy, 0, sizeof(policy));
jfigus67b9c732014-11-20 10:17:21 -05001836 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtp);
1837 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtcp);
1838 policy.ssrc.type = ssrc_specific;
1839 policy.ssrc.value = 0xcafebabe;
1840 policy.key = aes_256_test_key;
1841 policy.ekt = NULL;
1842 policy.window_size = 128;
1843 policy.allow_repeat_tx = 0;
1844 policy.next = NULL;
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001845
jfigus67b9c732014-11-20 10:17:21 -05001846 status = srtp_create(&srtp_snd, &policy);
1847 if (status) {
1848 return status;
1849 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001850
jfigus67b9c732014-11-20 10:17:21 -05001851 /*
1852 * protect plaintext, then compare with ciphertext
1853 */
1854 len = 28;
1855 status = srtp_protect(srtp_snd, srtp_plaintext, &len);
1856 if (status || (len != 38)) {
1857 return srtp_err_status_fail;
1858 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001859
jfigus67b9c732014-11-20 10:17:21 -05001860 debug_print(mod_driver, "ciphertext:\n %s",
1861 octet_string_hex_string(srtp_plaintext, len));
1862 debug_print(mod_driver, "ciphertext reference:\n %s",
1863 octet_string_hex_string(srtp_ciphertext, len));
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001864
jfigus67b9c732014-11-20 10:17:21 -05001865 if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
1866 return srtp_err_status_fail;
1867 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001868
jfigus67b9c732014-11-20 10:17:21 -05001869 /*
1870 * create a receiver session context comparable to the one created
1871 * above - we need to do this so that the replay checking doesn't
1872 * complain
1873 */
1874 status = srtp_create(&srtp_recv, &policy);
1875 if (status) {
1876 return status;
1877 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001878
jfigus67b9c732014-11-20 10:17:21 -05001879 /*
1880 * unprotect ciphertext, then compare with plaintext
1881 */
1882 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
1883 if (status || (len != 28)) {
1884 return status;
1885 }
1886
1887 if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
1888 return srtp_err_status_fail;
1889 }
1890
1891 status = srtp_dealloc(srtp_snd);
1892 if (status) {
1893 return status;
1894 }
1895
1896 status = srtp_dealloc(srtp_recv);
1897 if (status) {
1898 return status;
1899 }
1900
1901 return srtp_err_status_ok;
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001902}
1903
1904
jfigus857009c2014-11-05 11:17:43 -05001905srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001906srtp_create_big_policy (srtp_policy_t **list)
1907{
1908 extern const srtp_policy_t *policy_array[];
1909 srtp_policy_t *p, *tmp;
1910 int i = 0;
1911 uint32_t ssrc = 0;
Cullen Jennings235513a2005-09-21 22:51:36 +00001912
jfigus67b9c732014-11-20 10:17:21 -05001913 /* sanity checking */
1914 if ((list == NULL) || (policy_array[0] == NULL)) {
1915 return srtp_err_status_bad_param;
1916 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001917
jfigus67b9c732014-11-20 10:17:21 -05001918 /*
1919 * loop over policy list, mallocing a new list and copying values
1920 * into it (and incrementing the SSRC value as we go along)
1921 */
1922 tmp = NULL;
1923 while (policy_array[i] != NULL) {
1924 p = (srtp_policy_t*)malloc(sizeof(srtp_policy_t));
1925 if (p == NULL) {
1926 return srtp_err_status_bad_param;
1927 }
1928 memcpy(p, policy_array[i], sizeof(srtp_policy_t));
1929 p->ssrc.type = ssrc_specific;
1930 p->ssrc.value = ssrc++;
1931 p->next = tmp;
1932 tmp = p;
1933 i++;
1934 }
1935 *list = p;
1936
1937 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001938}
1939
jfigus857009c2014-11-05 11:17:43 -05001940srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001941srtp_dealloc_big_policy (srtp_policy_t *list)
1942{
1943 srtp_policy_t *p, *next;
Jonathan Lennox80c4c832010-05-17 19:30:28 +00001944
jfigus67b9c732014-11-20 10:17:21 -05001945 for (p = list; p != NULL; p = next) {
1946 next = p->next;
1947 free(p);
1948 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00001949
jfigus67b9c732014-11-20 10:17:21 -05001950 return srtp_err_status_ok;
Jonathan Lennox80c4c832010-05-17 19:30:28 +00001951}
1952
Joachim Bauchc8a19ae2015-12-14 22:50:36 +01001953srtp_err_status_t
1954srtp_test_empty_payload()
1955{
1956 srtp_t srtp_snd, srtp_recv;
1957 srtp_err_status_t status;
1958 int len;
1959 srtp_policy_t policy;
1960 srtp_hdr_t *mesg;
1961
1962 /*
1963 * create a session with a single stream using the default srtp
1964 * policy and with the SSRC value 0xcafebabe
1965 */
1966 memset(&policy, 0, sizeof(policy));
1967 srtp_crypto_policy_set_rtp_default(&policy.rtp);
1968 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
1969 policy.ssrc.type = ssrc_specific;
1970 policy.ssrc.value = 0xcafebabe;
1971 policy.key = test_key;
1972 policy.ekt = NULL;
1973 policy.window_size = 128;
1974 policy.allow_repeat_tx = 0;
1975 policy.next = NULL;
1976
1977 status = srtp_create(&srtp_snd, &policy);
1978 if (status) {
1979 return status;
1980 }
1981
1982 mesg = srtp_create_test_packet(0, policy.ssrc.value);
1983 if (mesg == NULL) {
1984 return srtp_err_status_fail;
1985 }
1986
1987 len = 12; /* only the header */
1988 status = srtp_protect(srtp_snd, mesg, &len);
1989 if (status) {
1990 return status;
1991 } else if (len != 12 + 10) {
1992 return srtp_err_status_fail;
1993 }
1994
1995 /*
1996 * create a receiver session context comparable to the one created
1997 * above - we need to do this so that the replay checking doesn't
1998 * complain
1999 */
2000 status = srtp_create(&srtp_recv, &policy);
2001 if (status) {
2002 return status;
2003 }
2004
2005 /*
2006 * unprotect ciphertext, then compare with plaintext
2007 */
2008 status = srtp_unprotect(srtp_recv, mesg, &len);
2009 if (status) {
2010 return status;
2011 } else if (len != 12) {
2012 return srtp_err_status_fail;
2013 }
2014
2015 status = srtp_dealloc(srtp_snd);
2016 if (status) {
2017 return status;
2018 }
2019
2020 status = srtp_dealloc(srtp_recv);
2021 if (status) {
2022 return status;
2023 }
2024
2025 free(mesg);
2026
2027 return srtp_err_status_ok;
2028}
2029
2030#ifdef OPENSSL
2031srtp_err_status_t
2032srtp_test_empty_payload_gcm()
2033{
2034 srtp_t srtp_snd, srtp_recv;
2035 srtp_err_status_t status;
2036 int len;
2037 srtp_policy_t policy;
2038 srtp_hdr_t *mesg;
2039
2040 /*
2041 * create a session with a single stream using the default srtp
2042 * policy and with the SSRC value 0xcafebabe
2043 */
2044 memset(&policy, 0, sizeof(policy));
2045 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtp);
2046 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtcp);
2047 policy.ssrc.type = ssrc_specific;
2048 policy.ssrc.value = 0xcafebabe;
2049 policy.key = test_key;
2050 policy.ekt = NULL;
2051 policy.window_size = 128;
2052 policy.allow_repeat_tx = 0;
2053 policy.next = NULL;
2054
2055 status = srtp_create(&srtp_snd, &policy);
2056 if (status) {
2057 return status;
2058 }
2059
2060 mesg = srtp_create_test_packet(0, policy.ssrc.value);
2061 if (mesg == NULL) {
2062 return srtp_err_status_fail;
2063 }
2064
2065 len = 12; /* only the header */
2066 status = srtp_protect(srtp_snd, mesg, &len);
2067 if (status) {
2068 return status;
2069 } else if (len != 12 + 8) {
2070 return srtp_err_status_fail;
2071 }
2072
2073 /*
2074 * create a receiver session context comparable to the one created
2075 * above - we need to do this so that the replay checking doesn't
2076 * complain
2077 */
2078 status = srtp_create(&srtp_recv, &policy);
2079 if (status) {
2080 return status;
2081 }
2082
2083 /*
2084 * unprotect ciphertext, then compare with plaintext
2085 */
2086 status = srtp_unprotect(srtp_recv, mesg, &len);
2087 if (status) {
2088 return status;
2089 } else if (len != 12) {
2090 return srtp_err_status_fail;
2091 }
2092
2093 status = srtp_dealloc(srtp_snd);
2094 if (status) {
2095 return status;
2096 }
2097
2098 status = srtp_dealloc(srtp_recv);
2099 if (status) {
2100 return status;
2101 }
2102
2103 free(mesg);
2104
2105 return srtp_err_status_ok;
2106}
2107#endif // OPENSSL
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002108
jfigus857009c2014-11-05 11:17:43 -05002109srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05002110srtp_test_remove_stream ()
2111{
2112 srtp_err_status_t status;
2113 srtp_policy_t *policy_list, policy;
2114 srtp_t session;
2115 srtp_stream_t stream;
Cullen Jennings235513a2005-09-21 22:51:36 +00002116
jfigus67b9c732014-11-20 10:17:21 -05002117 /*
2118 * srtp_get_stream() is a libSRTP internal function that we declare
2119 * here so that we can use it to verify the correct operation of the
2120 * library
2121 */
2122 extern srtp_stream_t srtp_get_stream(srtp_t srtp, uint32_t ssrc);
Cullen Jennings235513a2005-09-21 22:51:36 +00002123
Cullen Jennings235513a2005-09-21 22:51:36 +00002124
jfigus67b9c732014-11-20 10:17:21 -05002125 status = srtp_create_big_policy(&policy_list);
2126 if (status) {
2127 return status;
2128 }
Cullen Jennings235513a2005-09-21 22:51:36 +00002129
jfigus67b9c732014-11-20 10:17:21 -05002130 status = srtp_create(&session, policy_list);
2131 if (status) {
2132 return status;
2133 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002134
jfigus67b9c732014-11-20 10:17:21 -05002135 /*
2136 * check for false positives by trying to remove a stream that's not
2137 * in the session
2138 */
2139 status = srtp_remove_stream(session, htonl(0xaaaaaaaa));
2140 if (status != srtp_err_status_no_ctx) {
2141 return srtp_err_status_fail;
2142 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002143
jfigus67b9c732014-11-20 10:17:21 -05002144 /*
2145 * check for false negatives by removing stream 0x1, then
2146 * searching for streams 0x0 and 0x2
2147 */
2148 status = srtp_remove_stream(session, htonl(0x1));
2149 if (status != srtp_err_status_ok) {
2150 return srtp_err_status_fail;
2151 }
2152 stream = srtp_get_stream(session, htonl(0x0));
2153 if (stream == NULL) {
2154 return srtp_err_status_fail;
2155 }
2156 stream = srtp_get_stream(session, htonl(0x2));
2157 if (stream == NULL) {
2158 return srtp_err_status_fail;
2159 }
Jonathan Lennoxad741b22010-05-27 19:23:05 +00002160
jfigus67b9c732014-11-20 10:17:21 -05002161 status = srtp_dealloc(session);
2162 if (status != srtp_err_status_ok) {
2163 return status;
2164 }
Jonathan Lennoxad741b22010-05-27 19:23:05 +00002165
jfigus67b9c732014-11-20 10:17:21 -05002166 status = srtp_dealloc_big_policy(policy_list);
2167 if (status != srtp_err_status_ok) {
2168 return status;
2169 }
Jonathan Lennoxad741b22010-05-27 19:23:05 +00002170
jfigus67b9c732014-11-20 10:17:21 -05002171 /* Now test adding and removing a single stream */
Joachim Bauch99a74822015-11-17 00:08:19 +01002172 memset(&policy, 0, sizeof(policy));
jfigus67b9c732014-11-20 10:17:21 -05002173 srtp_crypto_policy_set_rtp_default(&policy.rtp);
2174 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
2175 policy.ssrc.type = ssrc_specific;
2176 policy.ssrc.value = 0xcafebabe;
2177 policy.key = test_key;
2178 policy.ekt = NULL;
2179 policy.window_size = 128;
2180 policy.allow_repeat_tx = 0;
2181 policy.next = NULL;
Jonathan Lennoxad741b22010-05-27 19:23:05 +00002182
jfigus67b9c732014-11-20 10:17:21 -05002183 status = srtp_create(&session, NULL);
2184 if (status != srtp_err_status_ok) {
2185 return status;
2186 }
2187
2188 status = srtp_add_stream(session, &policy);
2189 if (status != srtp_err_status_ok) {
2190 return status;
2191 }
2192
2193 status = srtp_remove_stream(session, htonl(0xcafebabe));
2194 if (status != srtp_err_status_ok) {
2195 return status;
2196 }
2197
2198 status = srtp_dealloc(session);
2199 if (status != srtp_err_status_ok) {
2200 return status;
2201 }
2202
2203 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00002204}
2205
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002206
2207unsigned char test_alt_key[46] = {
2208 0xe5, 0x19, 0x6f, 0x01, 0x5e, 0xf1, 0x9b, 0xe1,
2209 0xd7, 0x47, 0xa7, 0x27, 0x07, 0xd7, 0x47, 0x33,
2210 0x01, 0xc2, 0x35, 0x4d, 0x59, 0x6a, 0xf7, 0x84,
2211 0x96, 0x98, 0xeb, 0xaa, 0xac, 0xf6, 0xa1, 0x45,
2212 0xc7, 0x15, 0xe2, 0xea, 0xfe, 0x55, 0x67, 0x96,
2213 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
2214};
2215
2216/*
2217 * srtp_test_update() verifies updating/rekeying exsisting streams.
2218 * As stated in https://tools.ietf.org/html/rfc3711#section-3.3.1
2219 * the value of the ROC must not be reset after a rekey, this test
2220 * atempts to prove that srtp_update does not reset the ROC.
2221 */
2222
2223srtp_err_status_t
2224srtp_test_update() {
2225
2226 srtp_err_status_t status;
2227 uint32_t ssrc = 0x12121212;
2228 int msg_len_octets = 32;
2229 int protected_msg_len_octets;
2230 srtp_hdr_t * msg;
2231 srtp_t srtp_snd, srtp_recv;
2232 srtp_policy_t policy;
2233
2234 srtp_crypto_policy_set_rtp_default(&policy.rtp);
2235 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
2236 policy.ekt = NULL;
2237 policy.window_size = 128;
2238 policy.allow_repeat_tx = 0;
2239 policy.next = NULL;
2240 policy.ssrc.type = ssrc_any_outbound;
2241 policy.key = test_key;
2242
2243 /* create a send and recive ctx with defualt profile and test_key */
2244 status = srtp_create(&srtp_recv, &policy);
2245 if (status)
2246 return status;
2247
2248 policy.ssrc.type = ssrc_any_inbound;
2249 status = srtp_create(&srtp_snd, &policy);
2250 if (status)
2251 return status;
2252
2253 /* protect and unprotect two msg's that will cause the ROC to be equal to 1 */
2254 msg = srtp_create_test_packet(msg_len_octets, ssrc);
2255 if (msg == NULL)
2256 return srtp_err_status_alloc_fail;
2257 msg->seq = htons(65535);
2258
2259 protected_msg_len_octets = msg_len_octets;
2260 status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets);
2261 if (status)
2262 return srtp_err_status_fail;
2263
2264 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2265 if (status)
2266 return status;
2267
2268 free(msg);
2269
2270 msg = srtp_create_test_packet(msg_len_octets, ssrc);
2271 if (msg == NULL)
2272 return srtp_err_status_alloc_fail;
2273 msg->seq = htons(1);
2274
2275 protected_msg_len_octets = msg_len_octets;
2276 status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets);
2277 if (status)
2278 return srtp_err_status_fail;
2279
2280 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2281 if (status)
2282 return status;
2283
2284 free(msg);
2285
2286 /* update send ctx to use test_alt_key */
2287 policy.ssrc.type = ssrc_any_outbound;
2288 policy.key = test_alt_key;
2289 status = srtp_update(srtp_snd, &policy);
2290 if (status)
2291 return status;
2292
2293 /* create and protect msg with new key and ROC still equal to 1 */
2294 msg = srtp_create_test_packet(msg_len_octets, ssrc);
2295 if (msg == NULL)
2296 return srtp_err_status_alloc_fail;
2297 msg->seq = htons(2);
2298
2299 protected_msg_len_octets = msg_len_octets;
2300 status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets);
2301 if (status)
2302 return srtp_err_status_fail;
2303
2304 /* verify that recive ctx will fail to unprotect as it still uses test_key */
2305 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2306 if (status == srtp_err_status_ok)
2307 return srtp_err_status_fail;
2308
2309 /* create a new recvieve ctx with test_alt_key but since it is new it will have ROC equal to 1
2310 * and therefore should fail to unprotected */
2311 {
2312 srtp_t srtp_recv_roc_0;
2313
2314 policy.ssrc.type = ssrc_any_inbound;
2315 policy.key = test_alt_key;
2316 status = srtp_create(&srtp_recv_roc_0, &policy);
2317 if (status)
2318 return status;
2319
2320 status = srtp_unprotect(srtp_recv_roc_0, msg, &protected_msg_len_octets);
2321 if (status == srtp_err_status_ok)
2322 return srtp_err_status_fail;
2323
2324 status = srtp_dealloc(srtp_recv_roc_0);
2325 if (status)
2326 return status;
2327 }
2328
2329 /* update recive ctx to use test_alt_key */
2330 policy.ssrc.type = ssrc_any_inbound;
2331 policy.key = test_alt_key;
2332 status = srtp_update(srtp_recv, &policy);
2333 if (status)
2334 return status;
2335
2336 /* verify that can still unprotect, therfore key is updated and ROC value is preserved */
2337 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2338 if (status)
2339 return status;
2340
2341 free(msg);
2342
2343 status = srtp_dealloc(srtp_snd);
2344 if (status)
2345 return status;
2346
2347 status = srtp_dealloc(srtp_recv);
2348 if (status)
2349 return status;
2350
2351 return srtp_err_status_ok;
2352}
2353
Cullen Jennings235513a2005-09-21 22:51:36 +00002354/*
2355 * srtp policy definitions - these definitions are used above
2356 */
2357
jfigus8c36da22013-10-01 16:41:19 -04002358unsigned char test_key[46] = {
Cullen Jennings235513a2005-09-21 22:51:36 +00002359 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0,
2360 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde, 0x41, 0x39,
2361 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb,
jfigus8c36da22013-10-01 16:41:19 -04002362 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6, 0xc1, 0x73,
2363 0xc3, 0x17, 0xf2, 0xda, 0xbe, 0x35, 0x77, 0x93,
Cullen Jennings235513a2005-09-21 22:51:36 +00002364 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
2365};
2366
2367
2368const srtp_policy_t default_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002369 { ssrc_any_outbound, 0 }, /* SSRC */
2370 { /* SRTP policy */
2371 SRTP_AES_128_ICM, /* cipher type */
2372 30, /* cipher key length in octets */
2373 SRTP_HMAC_SHA1, /* authentication func type */
2374 16, /* auth key length in octets */
2375 10, /* auth tag length in octets */
2376 sec_serv_conf_and_auth /* security services flag */
2377 },
2378 { /* SRTCP policy */
2379 SRTP_AES_128_ICM, /* cipher type */
2380 30, /* cipher key length in octets */
2381 SRTP_HMAC_SHA1, /* authentication func type */
2382 16, /* auth key length in octets */
2383 10, /* auth tag length in octets */
2384 sec_serv_conf_and_auth /* security services flag */
2385 },
2386 test_key,
2387 NULL, /* indicates that EKT is not in use */
2388 128, /* replay window size */
2389 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002390 NULL, /* no encrypted extension headers */
2391 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05002392 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00002393};
2394
2395const srtp_policy_t aes_only_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002396 { ssrc_any_outbound, 0 }, /* SSRC */
2397 {
2398 SRTP_AES_128_ICM, /* cipher type */
2399 30, /* cipher key length in octets */
2400 SRTP_NULL_AUTH, /* authentication func type */
2401 0, /* auth key length in octets */
2402 0, /* auth tag length in octets */
2403 sec_serv_conf /* security services flag */
2404 },
2405 {
2406 SRTP_AES_128_ICM, /* cipher type */
2407 30, /* cipher key length in octets */
2408 SRTP_NULL_AUTH, /* authentication func type */
2409 0, /* auth key length in octets */
2410 0, /* auth tag length in octets */
2411 sec_serv_conf /* security services flag */
2412 },
2413 test_key,
2414 NULL, /* indicates that EKT is not in use */
2415 128, /* replay window size */
2416 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002417 NULL, /* no encrypted extension headers */
2418 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05002419 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00002420};
2421
2422const srtp_policy_t hmac_only_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002423 { ssrc_any_outbound, 0 }, /* SSRC */
2424 {
2425 SRTP_NULL_CIPHER, /* cipher type */
2426 0, /* cipher key length in octets */
2427 SRTP_HMAC_SHA1, /* authentication func type */
2428 20, /* auth key length in octets */
2429 4, /* auth tag length in octets */
2430 sec_serv_auth /* security services flag */
2431 },
2432 {
2433 SRTP_NULL_CIPHER, /* cipher type */
2434 0, /* cipher key length in octets */
2435 SRTP_HMAC_SHA1, /* authentication func type */
2436 20, /* auth key length in octets */
2437 4, /* auth tag length in octets */
2438 sec_serv_auth /* security services flag */
2439 },
2440 test_key,
2441 NULL, /* indicates that EKT is not in use */
2442 128, /* replay window size */
2443 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002444 NULL, /* no encrypted extension headers */
2445 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05002446 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00002447};
2448
jfigus8c36da22013-10-01 16:41:19 -04002449#ifdef OPENSSL
2450const srtp_policy_t aes128_gcm_8_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002451 { ssrc_any_outbound, 0 }, /* SSRC */
2452 { /* SRTP policy */
2453 SRTP_AES_128_GCM, /* cipher type */
2454 SRTP_AES_128_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
2455 SRTP_NULL_AUTH, /* authentication func type */
2456 0, /* auth key length in octets */
2457 8, /* auth tag length in octets */
2458 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04002459 },
jfigus67b9c732014-11-20 10:17:21 -05002460 { /* SRTCP policy */
2461 SRTP_AES_128_GCM, /* cipher type */
2462 SRTP_AES_128_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
2463 SRTP_NULL_AUTH, /* authentication func type */
2464 0, /* auth key length in octets */
2465 8, /* auth tag length in octets */
2466 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04002467 },
2468 test_key,
2469 NULL, /* indicates that EKT is not in use */
2470 128, /* replay window size */
2471 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002472 NULL, /* no encrypted extension headers */
2473 0, /* list of encrypted extension headers is empty */
jfigus8c36da22013-10-01 16:41:19 -04002474 NULL
2475};
2476
2477const srtp_policy_t aes128_gcm_8_cauth_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002478 { ssrc_any_outbound, 0 }, /* SSRC */
2479 { /* SRTP policy */
2480 SRTP_AES_128_GCM, /* cipher type */
2481 SRTP_AES_128_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
2482 SRTP_NULL_AUTH, /* authentication func type */
2483 0, /* auth key length in octets */
2484 8, /* auth tag length in octets */
2485 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04002486 },
jfigus67b9c732014-11-20 10:17:21 -05002487 { /* SRTCP policy */
2488 SRTP_AES_128_GCM, /* cipher type */
2489 SRTP_AES_128_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
2490 SRTP_NULL_AUTH, /* authentication func type */
2491 0, /* auth key length in octets */
2492 8, /* auth tag length in octets */
2493 sec_serv_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04002494 },
2495 test_key,
2496 NULL, /* indicates that EKT is not in use */
2497 128, /* replay window size */
2498 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002499 NULL, /* no encrypted extension headers */
2500 0, /* list of encrypted extension headers is empty */
jfigus8c36da22013-10-01 16:41:19 -04002501 NULL
2502};
jfigus67b9c732014-11-20 10:17:21 -05002503
jfigus8c36da22013-10-01 16:41:19 -04002504const srtp_policy_t aes256_gcm_8_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002505 { ssrc_any_outbound, 0 }, /* SSRC */
2506 { /* SRTP policy */
2507 SRTP_AES_256_GCM, /* cipher type */
2508 SRTP_AES_256_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
2509 SRTP_NULL_AUTH, /* authentication func type */
2510 0, /* auth key length in octets */
2511 8, /* auth tag length in octets */
2512 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04002513 },
jfigus67b9c732014-11-20 10:17:21 -05002514 { /* SRTCP policy */
2515 SRTP_AES_256_GCM, /* cipher type */
2516 SRTP_AES_256_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
2517 SRTP_NULL_AUTH, /* authentication func type */
2518 0, /* auth key length in octets */
2519 8, /* auth tag length in octets */
2520 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04002521 },
2522 test_key,
2523 NULL, /* indicates that EKT is not in use */
2524 128, /* replay window size */
2525 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002526 NULL, /* no encrypted extension headers */
2527 0, /* list of encrypted extension headers is empty */
jfigus8c36da22013-10-01 16:41:19 -04002528 NULL
2529};
jfigus67b9c732014-11-20 10:17:21 -05002530
jfigus8c36da22013-10-01 16:41:19 -04002531const srtp_policy_t aes256_gcm_8_cauth_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002532 { ssrc_any_outbound, 0 }, /* SSRC */
2533 { /* SRTP policy */
2534 SRTP_AES_256_GCM, /* cipher type */
2535 SRTP_AES_256_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
2536 SRTP_NULL_AUTH, /* authentication func type */
2537 0, /* auth key length in octets */
2538 8, /* auth tag length in octets */
2539 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04002540 },
jfigus67b9c732014-11-20 10:17:21 -05002541 { /* SRTCP policy */
2542 SRTP_AES_256_GCM, /* cipher type */
2543 SRTP_AES_256_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
2544 SRTP_NULL_AUTH, /* authentication func type */
2545 0, /* auth key length in octets */
2546 8, /* auth tag length in octets */
2547 sec_serv_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04002548 },
2549 test_key,
2550 NULL, /* indicates that EKT is not in use */
2551 128, /* replay window size */
2552 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002553 NULL, /* no encrypted extension headers */
2554 0, /* list of encrypted extension headers is empty */
jfigus8c36da22013-10-01 16:41:19 -04002555 NULL
2556};
2557#endif
2558
Cullen Jennings235513a2005-09-21 22:51:36 +00002559const srtp_policy_t null_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002560 { ssrc_any_outbound, 0 }, /* SSRC */
2561 {
2562 SRTP_NULL_CIPHER, /* cipher type */
2563 0, /* cipher key length in octets */
2564 SRTP_NULL_AUTH, /* authentication func type */
2565 0, /* auth key length in octets */
2566 0, /* auth tag length in octets */
2567 sec_serv_none /* security services flag */
2568 },
2569 {
2570 SRTP_NULL_CIPHER, /* cipher type */
2571 0, /* cipher key length in octets */
2572 SRTP_NULL_AUTH, /* authentication func type */
2573 0, /* auth key length in octets */
2574 0, /* auth tag length in octets */
2575 sec_serv_none /* security services flag */
2576 },
2577 test_key,
2578 NULL, /* indicates that EKT is not in use */
2579 128, /* replay window size */
2580 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002581 NULL, /* no encrypted extension headers */
2582 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05002583 NULL
David McGrew79870d62007-06-15 18:17:39 +00002584};
2585
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002586unsigned char test_256_key[46] = {
jfigus67b9c732014-11-20 10:17:21 -05002587 0xf0, 0xf0, 0x49, 0x14, 0xb5, 0x13, 0xf2, 0x76,
2588 0x3a, 0x1b, 0x1f, 0xa1, 0x30, 0xf1, 0x0e, 0x29,
2589 0x98, 0xf6, 0xf6, 0xe4, 0x3e, 0x43, 0x09, 0xd1,
2590 0xe6, 0x22, 0xa0, 0xe3, 0x32, 0xb9, 0xf1, 0xb6,
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002591
jfigus67b9c732014-11-20 10:17:21 -05002592 0x3b, 0x04, 0x80, 0x3d, 0xe5, 0x1e, 0xe7, 0xc9,
2593 0x64, 0x23, 0xab, 0x5b, 0x78, 0xd2
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002594};
2595
2596const srtp_policy_t aes_256_hmac_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002597 { ssrc_any_outbound, 0 }, /* SSRC */
2598 { /* SRTP policy */
2599 SRTP_AES_ICM, /* cipher type */
2600 46, /* cipher key length in octets */
2601 SRTP_HMAC_SHA1, /* authentication func type */
2602 20, /* auth key length in octets */
2603 10, /* auth tag length in octets */
2604 sec_serv_conf_and_auth /* security services flag */
2605 },
2606 { /* SRTCP policy */
2607 SRTP_AES_ICM, /* cipher type */
2608 46, /* cipher key length in octets */
2609 SRTP_HMAC_SHA1, /* authentication func type */
2610 20, /* auth key length in octets */
2611 10, /* auth tag length in octets */
2612 sec_serv_conf_and_auth /* security services flag */
2613 },
2614 test_256_key,
2615 NULL, /* indicates that EKT is not in use */
2616 128, /* replay window size */
2617 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002618 NULL, /* no encrypted extension headers */
2619 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05002620 NULL
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002621};
2622
David McGrew79870d62007-06-15 18:17:39 +00002623uint8_t ekt_test_key[16] = {
jfigus67b9c732014-11-20 10:17:21 -05002624 0x77, 0x26, 0x9d, 0xac, 0x16, 0xa3, 0x28, 0xca,
2625 0x8e, 0xc9, 0x68, 0x4b, 0xcc, 0xc4, 0xd2, 0x1b
David McGrew79870d62007-06-15 18:17:39 +00002626};
2627
2628#include "ekt.h"
2629
jfigusc5887e72014-11-06 09:46:18 -05002630srtp_ekt_policy_ctx_t ekt_test_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002631 0xa5a5, /* SPI */
2632 SRTP_EKT_CIPHER_AES_128_ECB,
2633 ekt_test_key,
2634 NULL
David McGrew79870d62007-06-15 18:17:39 +00002635};
2636
2637const srtp_policy_t hmac_only_with_ekt_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002638 { ssrc_any_outbound, 0 }, /* SSRC */
2639 {
2640 SRTP_NULL_CIPHER, /* cipher type */
2641 0, /* cipher key length in octets */
2642 SRTP_HMAC_SHA1, /* authentication func type */
2643 20, /* auth key length in octets */
2644 4, /* auth tag length in octets */
2645 sec_serv_auth /* security services flag */
2646 },
2647 {
2648 SRTP_NULL_CIPHER, /* cipher type */
2649 0, /* cipher key length in octets */
2650 SRTP_HMAC_SHA1, /* authentication func type */
2651 20, /* auth key length in octets */
2652 4, /* auth tag length in octets */
2653 sec_serv_auth /* security services flag */
2654 },
2655 test_key,
2656 &ekt_test_policy, /* indicates that EKT is not in use */
2657 128, /* replay window size */
2658 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002659 NULL, /* no encrypted extension headers */
2660 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05002661 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00002662};
2663
2664
2665/*
2666 * an array of pointers to the policies listed above
2667 *
2668 * This array is used to test various aspects of libSRTP for
2669 * different cryptographic policies. The order of the elements
2670 * matters - the timing test generates output that can be used
jfigus67b9c732014-11-20 10:17:21 -05002671 * in a plot (see the gnuplot script file 'timing'). If you
Cullen Jennings235513a2005-09-21 22:51:36 +00002672 * add to this list, you should do it at the end.
2673 */
2674
Cullen Jennings235513a2005-09-21 22:51:36 +00002675const srtp_policy_t *
2676policy_array[] = {
jfigus67b9c732014-11-20 10:17:21 -05002677 &hmac_only_policy,
2678 &aes_only_policy,
2679 &default_policy,
jfigus8c36da22013-10-01 16:41:19 -04002680#ifdef OPENSSL
jfigus67b9c732014-11-20 10:17:21 -05002681 &aes128_gcm_8_policy,
2682 &aes128_gcm_8_cauth_policy,
2683 &aes256_gcm_8_policy,
2684 &aes256_gcm_8_cauth_policy,
jfigus8c36da22013-10-01 16:41:19 -04002685#endif
jfigus67b9c732014-11-20 10:17:21 -05002686 &null_policy,
2687 &aes_256_hmac_policy,
2688 &hmac_only_with_ekt_policy,
2689 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00002690};
2691
2692const srtp_policy_t wildcard_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002693 { ssrc_any_outbound, 0 }, /* SSRC */
2694 { /* SRTP policy */
2695 SRTP_AES_128_ICM, /* cipher type */
2696 30, /* cipher key length in octets */
2697 SRTP_HMAC_SHA1, /* authentication func type */
2698 16, /* auth key length in octets */
2699 10, /* auth tag length in octets */
2700 sec_serv_conf_and_auth /* security services flag */
2701 },
2702 { /* SRTCP policy */
2703 SRTP_AES_128_ICM, /* cipher type */
2704 30, /* cipher key length in octets */
2705 SRTP_HMAC_SHA1, /* authentication func type */
2706 16, /* auth key length in octets */
2707 10, /* auth tag length in octets */
2708 sec_serv_conf_and_auth /* security services flag */
2709 },
2710 test_key,
2711 NULL,
2712 128, /* replay window size */
2713 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01002714 NULL, /* no encrypted extension headers */
2715 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05002716 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00002717};