blob: 287f1ceaee4a5b2371a3fcc92fd416705c48b068 [file] [log] [blame]
Ryan Hooper89a288b2016-12-22 16:22:47 -05001
Ryan Hooperab0345b2017-02-07 16:07:59 -05002
Cullen Jennings235513a2005-09-21 22:51:36 +00003/*
4 * srtp_driver.c
jfigus67b9c732014-11-20 10:17:21 -05005 *
Cullen Jennings235513a2005-09-21 22:51:36 +00006 * a test driver for libSRTP
7 *
8 * David A. McGrew
9 * Cisco Systems, Inc.
10 */
11/*
jfigus67b9c732014-11-20 10:17:21 -050012 *
Geir Istad445c1c92017-03-27 08:13:49 +020013 * Copyright (c) 2001-2017, Cisco Systems, Inc.
Cullen Jennings235513a2005-09-21 22:51:36 +000014 * All rights reserved.
jfigus67b9c732014-11-20 10:17:21 -050015 *
Cullen Jennings235513a2005-09-21 22:51:36 +000016 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
jfigus67b9c732014-11-20 10:17:21 -050019 *
Cullen Jennings235513a2005-09-21 22:51:36 +000020 * Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
jfigus67b9c732014-11-20 10:17:21 -050022 *
Cullen Jennings235513a2005-09-21 22:51:36 +000023 * Redistributions in binary form must reproduce the above
24 * copyright notice, this list of conditions and the following
25 * disclaimer in the documentation and/or other materials provided
26 * with the distribution.
jfigus67b9c732014-11-20 10:17:21 -050027 *
Cullen Jennings235513a2005-09-21 22:51:36 +000028 * Neither the name of the Cisco Systems, Inc. nor the names of its
29 * contributors may be used to endorse or promote products derived
30 * from this software without specific prior written permission.
jfigus67b9c732014-11-20 10:17:21 -050031 *
Cullen Jennings235513a2005-09-21 22:51:36 +000032 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
36 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
37 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
43 * OF THE POSSIBILITY OF SUCH DAMAGE.
44 *
45 */
46
47
48#include <string.h> /* for memcpy() */
49#include <time.h> /* for clock() */
50#include <stdlib.h> /* for malloc(), free() */
51#include <stdio.h> /* for print(), fflush() */
David McGrew79bd3012006-07-17 20:41:21 +000052#include "getopt_s.h" /* for local getopt() */
Cullen Jennings235513a2005-09-21 22:51:36 +000053
David McGrew3c45e0c2006-07-12 00:50:56 +000054#include "srtp_priv.h"
Ryan Hooperfe5d8b82016-12-15 14:53:58 -050055#include "util.h"
Cullen Jennings235513a2005-09-21 22:51:36 +000056
Marcus Sundberg1cbca882005-10-02 20:50:06 +000057#ifdef HAVE_NETINET_IN_H
58# include <netinet/in.h>
59#elif defined HAVE_WINSOCK2_H
60# include <winsock2.h>
61#endif
62
Cullen Jennings235513a2005-09-21 22:51:36 +000063#define PRINT_REFERENCE_PACKET 1
64
jfigus857009c2014-11-05 11:17:43 -050065srtp_err_status_t
Marcus Sundberga3f95fe2005-09-29 12:48:41 +000066srtp_validate(void);
Cullen Jennings235513a2005-09-21 22:51:36 +000067
Paul E. Jones9fc018c2016-06-03 02:56:56 -040068#ifdef OPENSSL
jfigus857009c2014-11-05 11:17:43 -050069srtp_err_status_t
Paul E. Jonese2ab5f22016-05-29 16:18:24 -040070srtp_validate_gcm(void);
Paul E. Jones9fc018c2016-06-03 02:56:56 -040071#endif
Paul E. Jonese2ab5f22016-05-29 16:18:24 -040072
73srtp_err_status_t
Joachim Bauch99a74822015-11-17 00:08:19 +010074srtp_validate_encrypted_extensions_headers(void);
75
Joachim Bauch80a45b52015-12-06 22:57:58 +010076#ifdef OPENSSL
Joachim Bauch99a74822015-11-17 00:08:19 +010077srtp_err_status_t
Joachim Bauchfa1e8c22015-11-24 23:38:48 +010078srtp_validate_encrypted_extensions_headers_gcm(void);
Joachim Bauch80a45b52015-12-06 22:57:58 +010079#endif
Joachim Bauchfa1e8c22015-11-24 23:38:48 +010080
81srtp_err_status_t
Jonathan Lennox5df951a2010-05-20 20:55:54 +000082srtp_validate_aes_256(void);
83
jfigus857009c2014-11-05 11:17:43 -050084srtp_err_status_t
Cullen Jennings235513a2005-09-21 22:51:36 +000085srtp_create_big_policy(srtp_policy_t **list);
86
jfigus857009c2014-11-05 11:17:43 -050087srtp_err_status_t
Jonathan Lennox80c4c832010-05-17 19:30:28 +000088srtp_dealloc_big_policy(srtp_policy_t *list);
89
jfigus857009c2014-11-05 11:17:43 -050090srtp_err_status_t
Joachim Bauchc8a19ae2015-12-14 22:50:36 +010091srtp_test_empty_payload(void);
92
93#ifdef OPENSSL
94srtp_err_status_t
95srtp_test_empty_payload_gcm(void);
96#endif
97
98srtp_err_status_t
Marcus Sundberga3f95fe2005-09-29 12:48:41 +000099srtp_test_remove_stream(void);
Cullen Jennings235513a2005-09-21 22:51:36 +0000100
Pascal Bühlerbd3112a2015-11-06 20:29:15 +0100101srtp_err_status_t
102srtp_test_update(void);
103
Ryan Hooperab0345b2017-02-07 16:07:59 -0500104srtp_err_status_t
105srtp_test_protect_trailer_length(void);
106
107srtp_err_status_t
108srtp_test_protect_rtcp_trailer_length(void);
109
Cullen Jennings235513a2005-09-21 22:51:36 +0000110double
111srtp_bits_per_second(int msg_len_octets, const srtp_policy_t *policy);
112
113double
114srtp_rejections_per_second(int msg_len_octets, const srtp_policy_t *policy);
115
116void
117srtp_do_timing(const srtp_policy_t *policy);
118
119void
120srtp_do_rejection_timing(const srtp_policy_t *policy);
121
jfigus857009c2014-11-05 11:17:43 -0500122srtp_err_status_t
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500123srtp_test(const srtp_policy_t *policy, int extension_header, int mki_index);
Cullen Jennings235513a2005-09-21 22:51:36 +0000124
jfigus857009c2014-11-05 11:17:43 -0500125srtp_err_status_t
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500126srtcp_test(const srtp_policy_t *policy, int mki_index);
David McGrew9c70f292006-05-03 19:38:38 +0000127
jfigus857009c2014-11-05 11:17:43 -0500128srtp_err_status_t
Cullen Jennings235513a2005-09-21 22:51:36 +0000129srtp_session_print_policy(srtp_t srtp);
130
jfigus857009c2014-11-05 11:17:43 -0500131srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -0500132srtp_print_policy(const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000133
134char *
135srtp_packet_to_string(srtp_hdr_t *hdr, int packet_len);
136
137double
138mips_estimate(int num_trials, int *ignore);
139
Ryan Hooper89a288b2016-12-22 16:22:47 -0500140#define TEST_MKI_ID_SIZE 4
141
jfigus8c36da22013-10-01 16:41:19 -0400142extern uint8_t test_key[46];
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500143extern uint8_t test_key_2[46];
Ryan Hooper89a288b2016-12-22 16:22:47 -0500144extern uint8_t test_mki_id[TEST_MKI_ID_SIZE];
145extern uint8_t test_mki_id_2[TEST_MKI_ID_SIZE];
146
147srtp_master_key_t master_key_1 = {
148 test_key,
149 test_mki_id,
150 TEST_MKI_ID_SIZE
151};
152
153srtp_master_key_t master_key_2 = {
154 test_key_2,
155 test_mki_id_2,
156 TEST_MKI_ID_SIZE
157};
158
159srtp_master_key_t *test_keys[2] = {
160 &master_key_1,
161 &master_key_2
162};
Cullen Jennings235513a2005-09-21 22:51:36 +0000163
164void
jfigus67b9c732014-11-20 10:17:21 -0500165usage (char *prog_name)
166{
Pascal Bühleraf151782017-02-24 10:51:52 +0100167 printf("usage: %s [ -t ][ -c ][ -v ][ -o ][-d <debug_module> ]* [ -l ]\n"
jfigus67b9c732014-11-20 10:17:21 -0500168 " -t run timing test\n"
169 " -r run rejection timing test\n"
170 " -c run codec timing test\n"
171 " -v run validation tests\n"
Pascal Bühleraf151782017-02-24 10:51:52 +0100172 " -o output logging to stdout\n"
jfigus67b9c732014-11-20 10:17:21 -0500173 " -d <mod> turn on debugging module <mod>\n"
174 " -l list debugging modules\n", prog_name);
175 exit(1);
Cullen Jennings235513a2005-09-21 22:51:36 +0000176}
177
Pascal Bühleraf151782017-02-24 10:51:52 +0100178void
Pascal Bühler98762312017-03-01 11:24:35 +0100179log_handler (srtp_log_level_t level, const char * msg, void * data)
Pascal Bühleraf151782017-02-24 10:51:52 +0100180{
181 char level_char = '?';
182 switch(level) {
183 case srtp_log_level_error: level_char = 'e'; break;
184 case srtp_log_level_warning: level_char = 'w'; break;
185 case srtp_log_level_info: level_char = 'i'; break;
186 case srtp_log_level_debug: level_char = 'd'; break;
187 }
188 printf("SRTP-LOG [%c]: %s\n", level_char, msg);
189}
190
Cullen Jennings235513a2005-09-21 22:51:36 +0000191/*
192 * The policy_array is a null-terminated array of policy structs. it
193 * is declared at the end of this file
194 */
195
196extern const srtp_policy_t *policy_array[];
197
198
199/* the wildcard_policy is declared below; it has a wildcard ssrc */
200
201extern const srtp_policy_t wildcard_policy;
202
203/*
204 * mod_driver debug module - debugging module for this test driver
205 *
jfigus67b9c732014-11-20 10:17:21 -0500206 * we use the crypto_kernel debugging system in this driver, which
Cullen Jennings235513a2005-09-21 22:51:36 +0000207 * makes the interface uniform and increases portability
jfigus67b9c732014-11-20 10:17:21 -0500208 */
Cullen Jennings235513a2005-09-21 22:51:36 +0000209
jfigus02d6f032014-11-21 10:56:42 -0500210srtp_debug_module_t mod_driver = {
jfigus67b9c732014-11-20 10:17:21 -0500211 0, /* debugging is off by default */
212 "driver" /* printable name for module */
Cullen Jennings235513a2005-09-21 22:51:36 +0000213};
214
215int
jfigus67b9c732014-11-20 10:17:21 -0500216main (int argc, char *argv[])
217{
218 int q;
219 unsigned do_timing_test = 0;
220 unsigned do_rejection_test = 0;
221 unsigned do_codec_timing = 0;
222 unsigned do_validation = 0;
223 unsigned do_list_mods = 0;
Pascal Bühleraf151782017-02-24 10:51:52 +0100224 unsigned do_log_stdout = 0;
jfigus67b9c732014-11-20 10:17:21 -0500225 srtp_err_status_t status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000226
227 /*
jfigus67b9c732014-11-20 10:17:21 -0500228 * verify that the compiler has interpreted the header data
229 * structure srtp_hdr_t correctly
Cullen Jennings235513a2005-09-21 22:51:36 +0000230 */
jfigus67b9c732014-11-20 10:17:21 -0500231 if (sizeof(srtp_hdr_t) != 12) {
232 printf("error: srtp_hdr_t has incorrect size"
233 "(size is %ld bytes, expected 12)\n",
234 (long)sizeof(srtp_hdr_t));
235 exit(1);
Cullen Jennings235513a2005-09-21 22:51:36 +0000236 }
237
jfigus67b9c732014-11-20 10:17:21 -0500238 /* initialize srtp library */
239 status = srtp_init();
240 if (status) {
241 printf("error: srtp init failed with error code %d\n", status);
242 exit(1);
243 }
244
245 /* load srtp_driver debug module */
jfigus92736bc2014-11-21 10:30:54 -0500246 status = srtp_crypto_kernel_load_debug_module(&mod_driver);
jfigus67b9c732014-11-20 10:17:21 -0500247 if (status) {
248 printf("error: load of srtp_driver debug module failed "
249 "with error code %d\n", status);
250 exit(1);
251 }
252
253 /* process input arguments */
254 while (1) {
Pascal Bühleraf151782017-02-24 10:51:52 +0100255 q = getopt_s(argc, argv, "trcvold:");
jfigus67b9c732014-11-20 10:17:21 -0500256 if (q == -1) {
257 break;
258 }
259 switch (q) {
260 case 't':
261 do_timing_test = 1;
262 break;
263 case 'r':
264 do_rejection_test = 1;
265 break;
266 case 'c':
267 do_codec_timing = 1;
268 break;
269 case 'v':
270 do_validation = 1;
271 break;
Pascal Bühleraf151782017-02-24 10:51:52 +0100272 case 'o':
273 do_log_stdout = 1;
274 break;
jfigus67b9c732014-11-20 10:17:21 -0500275 case 'l':
276 do_list_mods = 1;
277 break;
278 case 'd':
Pascal Bühleraf151782017-02-24 10:51:52 +0100279 status = srtp_set_debug_module(optarg_s, 1);
jfigus67b9c732014-11-20 10:17:21 -0500280 if (status) {
281 printf("error: set debug module (%s) failed\n", optarg_s);
282 exit(1);
283 }
284 break;
285 default:
286 usage(argv[0]);
287 }
288 }
289
290 if (!do_validation && !do_timing_test && !do_codec_timing
291 && !do_list_mods && !do_rejection_test) {
292 usage(argv[0]);
293 }
294
Pascal Bühleraf151782017-02-24 10:51:52 +0100295 if (do_log_stdout) {
Pascal Bühler98762312017-03-01 11:24:35 +0100296 status = srtp_install_log_handler(log_handler, NULL);
Pascal Bühleraf151782017-02-24 10:51:52 +0100297 if (status) {
298 printf("error: install log handler failed\n");
299 exit(1);
300 }
301 }
302
jfigus67b9c732014-11-20 10:17:21 -0500303 if (do_list_mods) {
Pascal Bühleraf151782017-02-24 10:51:52 +0100304 status = srtp_list_debug_modules();
jfigus67b9c732014-11-20 10:17:21 -0500305 if (status) {
306 printf("error: list of debug modules failed\n");
307 exit(1);
308 }
309 }
310
311 if (do_validation) {
312 const srtp_policy_t **policy = policy_array;
313 srtp_policy_t *big_policy;
314
315 /* loop over policy array, testing srtp and srtcp for each policy */
316 while (*policy != NULL) {
317 printf("testing srtp_protect and srtp_unprotect\n");
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500318 if (srtp_test(*policy, 0, -1) == srtp_err_status_ok) {
Joachim Bauch99a74822015-11-17 00:08:19 +0100319 printf("passed\n\n");
320 } else{
321 printf("failed\n");
322 exit(1);
323 }
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500324
Joachim Bauch99a74822015-11-17 00:08:19 +0100325 printf("testing srtp_protect and srtp_unprotect with encrypted extensions headers\n");
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500326 if (srtp_test(*policy, 1, -1) == srtp_err_status_ok) {
jfigus67b9c732014-11-20 10:17:21 -0500327 printf("passed\n\n");
328 } else{
329 printf("failed\n");
330 exit(1);
331 }
332 printf("testing srtp_protect_rtcp and srtp_unprotect_rtcp\n");
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500333 if (srtcp_test(*policy, -1) == srtp_err_status_ok) {
334 printf("passed\n\n");
335 } else{
336 printf("failed\n");
337 exit(1);
338 }
339 printf("testing srtp_protect_rtp and srtp_unprotect_rtp with MKI index set to 0\n");
340 if (srtp_test(*policy, 0, 0) == srtp_err_status_ok) {
341 printf("passed\n\n");
342 } else{
343 printf("failed\n");
344 exit(1);
345 }
346 printf("testing srtp_protect_rtp and srtp_unprotect_rtp with MKI index set to 1\n");
347 if (srtp_test(*policy, 0, 1) == srtp_err_status_ok) {
348 printf("passed\n\n");
349 } else{
350 printf("failed\n");
351 exit(1);
352 }
353
354 printf("testing srtp_protect_rtcp and srtp_unprotect_rtcp with MKI index set to 0\n");
355 if (srtcp_test(*policy, 0) == srtp_err_status_ok) {
356 printf("passed\n\n");
357 } else{
358 printf("failed\n");
359 exit(1);
360 }
361 printf("testing srtp_protect_rtcp and srtp_unprotect_rtcp with MKI index set to 1\n");
362 if (srtcp_test(*policy, 1) == srtp_err_status_ok) {
jfigus67b9c732014-11-20 10:17:21 -0500363 printf("passed\n\n");
364 } else{
365 printf("failed\n");
366 exit(1);
367 }
368 policy++;
369 }
370
371 /* create a big policy list and run tests on it */
372 status = srtp_create_big_policy(&big_policy);
373 if (status) {
374 printf("unexpected failure with error code %d\n", status);
375 exit(1);
376 }
377 printf("testing srtp_protect and srtp_unprotect with big policy\n");
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500378 if (srtp_test(big_policy, 0, -1) == srtp_err_status_ok) {
Joachim Bauch99a74822015-11-17 00:08:19 +0100379 printf("passed\n\n");
380 } else{
381 printf("failed\n");
382 exit(1);
383 }
384 printf("testing srtp_protect and srtp_unprotect with big policy and encrypted extensions headers\n");
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500385 if (srtp_test(big_policy, 1, -1) == srtp_err_status_ok) {
jfigus67b9c732014-11-20 10:17:21 -0500386 printf("passed\n\n");
387 } else{
388 printf("failed\n");
389 exit(1);
390 }
391 status = srtp_dealloc_big_policy(big_policy);
392 if (status) {
393 printf("unexpected failure with error code %d\n", status);
394 exit(1);
395 }
396
397 /* run test on wildcard policy */
398 printf("testing srtp_protect and srtp_unprotect on "
399 "wildcard ssrc policy\n");
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500400 if (srtp_test(&wildcard_policy, 0, -1) == srtp_err_status_ok) {
Joachim Bauch99a74822015-11-17 00:08:19 +0100401 printf("passed\n\n");
402 } else{
403 printf("failed\n");
404 exit(1);
405 }
406 printf("testing srtp_protect and srtp_unprotect on "
407 "wildcard ssrc policy and encrypted extensions headers\n");
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500408 if (srtp_test(&wildcard_policy, 1, -1) == srtp_err_status_ok) {
jfigus67b9c732014-11-20 10:17:21 -0500409 printf("passed\n\n");
410 } else{
411 printf("failed\n");
412 exit(1);
413 }
414
415 /*
416 * run validation test against the reference packets - note
417 * that this test only covers the default policy
418 */
419 printf("testing srtp_protect and srtp_unprotect against "
Paul E. Jonese2ab5f22016-05-29 16:18:24 -0400420 "reference packet\n");
jfigus67b9c732014-11-20 10:17:21 -0500421 if (srtp_validate() == srtp_err_status_ok) {
422 printf("passed\n\n");
423 } else{
424 printf("failed\n");
425 exit(1);
426 }
Paul E. Jonese2ab5f22016-05-29 16:18:24 -0400427
428#ifdef OPENSSL
Joachim Bauch99a74822015-11-17 00:08:19 +0100429 printf("testing srtp_protect and srtp_unprotect against "
Paul E. Jonese2ab5f22016-05-29 16:18:24 -0400430 "reference packet using GCM\n");
431 if (srtp_validate_gcm() == srtp_err_status_ok) {
432 printf("passed\n\n");
433 } else{
434 printf("failed\n");
435 exit(1);
436 }
437#endif
438
439 printf("testing srtp_protect and srtp_unprotect against "
440 "reference packet with encrypted extensions headers\n");
Joachim Bauch99a74822015-11-17 00:08:19 +0100441 if (srtp_validate_encrypted_extensions_headers() == srtp_err_status_ok)
442 printf("passed\n\n");
443 else {
444 printf("failed\n");
445 exit(1);
446 }
jfigus67b9c732014-11-20 10:17:21 -0500447
Joachim Bauchb8cb5772015-11-24 21:46:25 +0100448#ifdef OPENSSL
Joachim Bauchfa1e8c22015-11-24 23:38:48 +0100449 printf("testing srtp_protect and srtp_unprotect against "
Paul E. Jonese2ab5f22016-05-29 16:18:24 -0400450 "reference packet with encrypted extension headers (GCM)\n");
Joachim Bauchfa1e8c22015-11-24 23:38:48 +0100451 if (srtp_validate_encrypted_extensions_headers_gcm() == srtp_err_status_ok) {
452 printf("passed\n\n");
453 } else{
454 printf("failed\n");
455 exit(1);
456 }
Joachim Bauch80a45b52015-12-06 22:57:58 +0100457#endif
Joachim Bauchfa1e8c22015-11-24 23:38:48 +0100458
jfigus67b9c732014-11-20 10:17:21 -0500459 /*
460 * run validation test against the reference packets for
461 * AES-256
462 */
463 printf("testing srtp_protect and srtp_unprotect against "
Paul E. Jonese2ab5f22016-05-29 16:18:24 -0400464 "reference packet (AES-256)\n");
jfigus67b9c732014-11-20 10:17:21 -0500465 if (srtp_validate_aes_256() == srtp_err_status_ok) {
466 printf("passed\n\n");
467 } else{
468 printf("failed\n");
469 exit(1);
470 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000471
jfigus67b9c732014-11-20 10:17:21 -0500472 /*
Joachim Bauchc8a19ae2015-12-14 22:50:36 +0100473 * test packets with empty payload
474 */
475 printf("testing srtp_protect and srtp_unprotect against "
Paul E. Jonese2ab5f22016-05-29 16:18:24 -0400476 "packet with empty payload\n");
Joachim Bauchc8a19ae2015-12-14 22:50:36 +0100477 if (srtp_test_empty_payload() == srtp_err_status_ok) {
478 printf("passed\n");
479 } else{
480 printf("failed\n");
481 exit(1);
482 }
483#ifdef OPENSSL
484 printf("testing srtp_protect and srtp_unprotect against "
Paul E. Jonese2ab5f22016-05-29 16:18:24 -0400485 "packet with empty payload (GCM)\n");
Joachim Bauchc8a19ae2015-12-14 22:50:36 +0100486 if (srtp_test_empty_payload_gcm() == srtp_err_status_ok) {
487 printf("passed\n");
488 } else{
489 printf("failed\n");
490 exit(1);
491 }
492#endif
493
494 /*
jfigus67b9c732014-11-20 10:17:21 -0500495 * test the function srtp_remove_stream()
496 */
497 printf("testing srtp_remove_stream()...");
498 if (srtp_test_remove_stream() == srtp_err_status_ok) {
499 printf("passed\n");
500 } else{
501 printf("failed\n");
502 exit(1);
503 }
Pascal Bühlerbd3112a2015-11-06 20:29:15 +0100504
505 /*
506 * test the function srtp_update()
507 */
508 printf("testing srtp_update()...");
509 if (srtp_test_update() == srtp_err_status_ok) {
510 printf("passed\n");
511 } else {
512 printf("failed\n");
513 exit(1);
514 }
Ryan Hooperab0345b2017-02-07 16:07:59 -0500515
516 /*
517 * test the functions srtp_get_protect_trailer_length
518 * and srtp_get_protect_rtcp_trailer_length
519 */
520 printf("testing srtp_get_protect_trailer_length()...");
521 if (srtp_test_protect_trailer_length() == srtp_err_status_ok) {
522 printf("passed\n");
523 } else {
524 printf("failed\n");
525 exit(1);
526 }
527
528 printf("testing srtp_get_protect_rtcp_trailer_length()...");
529 if (srtp_test_protect_rtcp_trailer_length() == srtp_err_status_ok) {
530 printf("passed\n");
531 } else {
532 printf("failed\n");
533 exit(1);
534 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000535 }
jfigus67b9c732014-11-20 10:17:21 -0500536
537 if (do_timing_test) {
538 const srtp_policy_t **policy = policy_array;
539
540 /* loop over policies, run timing test for each */
541 while (*policy != NULL) {
542 srtp_print_policy(*policy);
543 srtp_do_timing(*policy);
544 policy++;
545 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000546 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000547
jfigus67b9c732014-11-20 10:17:21 -0500548 if (do_rejection_test) {
549 const srtp_policy_t **policy = policy_array;
550
551 /* loop over policies, run rejection timing test for each */
552 while (*policy != NULL) {
553 srtp_print_policy(*policy);
554 srtp_do_rejection_timing(*policy);
555 policy++;
556 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000557 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000558
jfigus67b9c732014-11-20 10:17:21 -0500559 if (do_codec_timing) {
560 srtp_policy_t policy;
561 int ignore;
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100562 double mips_value = mips_estimate(1000000000, &ignore);
Cullen Jennings235513a2005-09-21 22:51:36 +0000563
Joachim Bauch99a74822015-11-17 00:08:19 +0100564 memset(&policy, 0, sizeof(policy));
jfigus67b9c732014-11-20 10:17:21 -0500565 srtp_crypto_policy_set_rtp_default(&policy.rtp);
566 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
567 policy.ssrc.type = ssrc_specific;
568 policy.ssrc.value = 0xdecafbad;
Ryan Hooper89a288b2016-12-22 16:22:47 -0500569 policy.key = test_key;
jfigus67b9c732014-11-20 10:17:21 -0500570 policy.ekt = NULL;
571 policy.window_size = 128;
572 policy.allow_repeat_tx = 0;
573 policy.next = NULL;
Cullen Jennings235513a2005-09-21 22:51:36 +0000574
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100575 printf("mips estimate: %e\n", mips_value);
Cullen Jennings235513a2005-09-21 22:51:36 +0000576
jfigus67b9c732014-11-20 10:17:21 -0500577 printf("testing srtp processing time for voice codecs:\n");
578 printf("codec\t\tlength (octets)\t\tsrtp instructions/second\n");
579 printf("G.711\t\t%d\t\t\t%e\n", 80,
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100580 (double)mips_value * (80 * 8) /
jfigus67b9c732014-11-20 10:17:21 -0500581 srtp_bits_per_second(80, &policy) / .01 );
582 printf("G.711\t\t%d\t\t\t%e\n", 160,
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100583 (double)mips_value * (160 * 8) /
jfigus67b9c732014-11-20 10:17:21 -0500584 srtp_bits_per_second(160, &policy) / .02);
585 printf("G.726-32\t%d\t\t\t%e\n", 40,
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100586 (double)mips_value * (40 * 8) /
jfigus67b9c732014-11-20 10:17:21 -0500587 srtp_bits_per_second(40, &policy) / .01 );
588 printf("G.726-32\t%d\t\t\t%e\n", 80,
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100589 (double)mips_value * (80 * 8) /
jfigus67b9c732014-11-20 10:17:21 -0500590 srtp_bits_per_second(80, &policy) / .02);
591 printf("G.729\t\t%d\t\t\t%e\n", 10,
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100592 (double)mips_value * (10 * 8) /
jfigus67b9c732014-11-20 10:17:21 -0500593 srtp_bits_per_second(10, &policy) / .01 );
594 printf("G.729\t\t%d\t\t\t%e\n", 20,
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100595 (double)mips_value * (20 * 8) /
jfigus67b9c732014-11-20 10:17:21 -0500596 srtp_bits_per_second(20, &policy) / .02 );
597 printf("Wideband\t%d\t\t\t%e\n", 320,
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100598 (double)mips_value * (320 * 8) /
jfigus67b9c732014-11-20 10:17:21 -0500599 srtp_bits_per_second(320, &policy) / .01 );
600 printf("Wideband\t%d\t\t\t%e\n", 640,
Joachim Bauchdc53dcb2016-03-10 20:32:44 +0100601 (double)mips_value * (640 * 8) /
jfigus67b9c732014-11-20 10:17:21 -0500602 srtp_bits_per_second(640, &policy) / .02 );
603 }
Jonathan Lennoxdfb30842010-05-15 04:52:01 +0000604
jfigus67b9c732014-11-20 10:17:21 -0500605 status = srtp_shutdown();
606 if (status) {
607 printf("error: srtp shutdown failed with error code %d\n", status);
608 exit(1);
609 }
610
611 return 0;
Cullen Jennings235513a2005-09-21 22:51:36 +0000612}
613
614
615
616/*
617 * srtp_create_test_packet(len, ssrc) returns a pointer to a
618 * (malloced) example RTP packet whose data field has the length given
619 * by pkt_octet_len and the SSRC value ssrc. The total length of the
620 * packet is twelve octets longer, since the header is at the
621 * beginning. There is room at the end of the packet for a trailer,
622 * and the four octets following the packet are filled with 0xff
623 * values to enable testing for overwrites.
624 *
625 * note that the location of the test packet can (and should) be
626 * deallocated with the free() call once it is no longer needed.
627 */
628
629srtp_hdr_t *
jfigus67b9c732014-11-20 10:17:21 -0500630srtp_create_test_packet (int pkt_octet_len, uint32_t ssrc)
631{
632 int i;
633 uint8_t *buffer;
634 srtp_hdr_t *hdr;
635 int bytes_in_hdr = 12;
Cullen Jennings235513a2005-09-21 22:51:36 +0000636
jfigus67b9c732014-11-20 10:17:21 -0500637 /* allocate memory for test packet */
638 hdr = (srtp_hdr_t*)malloc(pkt_octet_len + bytes_in_hdr
639 + SRTP_MAX_TRAILER_LEN + 4);
640 if (!hdr) {
641 return NULL;
642 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000643
jfigus67b9c732014-11-20 10:17:21 -0500644 hdr->version = 2; /* RTP version two */
645 hdr->p = 0; /* no padding needed */
646 hdr->x = 0; /* no header extension */
647 hdr->cc = 0; /* no CSRCs */
648 hdr->m = 0; /* marker bit */
649 hdr->pt = 0xf; /* payload type */
650 hdr->seq = htons(0x1234); /* sequence number */
651 hdr->ts = htonl(0xdecafbad); /* timestamp */
652 hdr->ssrc = htonl(ssrc); /* synch. source */
Cullen Jennings235513a2005-09-21 22:51:36 +0000653
jfigus67b9c732014-11-20 10:17:21 -0500654 buffer = (uint8_t*)hdr;
655 buffer += bytes_in_hdr;
Cullen Jennings235513a2005-09-21 22:51:36 +0000656
jfigus67b9c732014-11-20 10:17:21 -0500657 /* set RTP data to 0xab */
658 for (i = 0; i < pkt_octet_len; i++) {
659 *buffer++ = 0xab;
660 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000661
jfigus67b9c732014-11-20 10:17:21 -0500662 /* set post-data value to 0xffff to enable overrun checking */
663 for (i = 0; i < SRTP_MAX_TRAILER_LEN + 4; i++) {
664 *buffer++ = 0xff;
665 }
666
667 return hdr;
Cullen Jennings235513a2005-09-21 22:51:36 +0000668}
669
Joachim Bauch99a74822015-11-17 00:08:19 +0100670srtp_hdr_t *
671srtp_create_test_packet_ext_hdr(int pkt_octet_len, uint32_t ssrc) {
672 int i;
673 uint8_t *buffer;
674 srtp_hdr_t *hdr;
675 int bytes_in_hdr = 12;
676 uint8_t extension_header[12] = {
677 /* one-byte header */
678 0xbe, 0xde,
679 /* size */
680 0x00, 0x02,
681 /* id 1, length 1 (i.e. 2 bytes) */
682 0x11,
683 /* payload */
684 0xca,
685 0xfe,
686 /* padding */
687 0x00,
688 /* id 2, length 0 (i.e. 1 byte) */
689 0x20,
690 /* payload */
691 0xba,
692 /* padding */
693 0x00,
694 0x00
695 };
696
697 /* allocate memory for test packet */
698 hdr = (srtp_hdr_t*) malloc(pkt_octet_len + bytes_in_hdr
699 + sizeof(extension_header) + SRTP_MAX_TRAILER_LEN + 4);
700 if (!hdr)
701 return NULL;
702
703 hdr->version = 2; /* RTP version two */
704 hdr->p = 0; /* no padding needed */
705 hdr->x = 1; /* no header extension */
706 hdr->cc = 0; /* no CSRCs */
707 hdr->m = 0; /* marker bit */
708 hdr->pt = 0xf; /* payload type */
709 hdr->seq = htons(0x1234); /* sequence number */
710 hdr->ts = htonl(0xdecafbad); /* timestamp */
711 hdr->ssrc = htonl(ssrc); /* synch. source */
712
713 buffer = (uint8_t *)hdr;
714 buffer += bytes_in_hdr;
715
716 memcpy(buffer, extension_header, sizeof(extension_header));
717 buffer += sizeof(extension_header);
718
719 /* set RTP data to 0xab */
720 for (i=0; i < pkt_octet_len; i++)
721 *buffer++ = 0xab;
722
723 /* set post-data value to 0xffff to enable overrun checking */
724 for (i=0; i < SRTP_MAX_TRAILER_LEN+4; i++)
725 *buffer++ = 0xff;
726
727 return hdr;
728}
729
Cullen Jennings235513a2005-09-21 22:51:36 +0000730void
jfigus67b9c732014-11-20 10:17:21 -0500731srtp_do_timing (const srtp_policy_t *policy)
732{
733 int len;
Cullen Jennings235513a2005-09-21 22:51:36 +0000734
jfigus67b9c732014-11-20 10:17:21 -0500735 /*
736 * note: the output of this function is formatted so that it
737 * can be used in gnuplot. '#' indicates a comment, and "\r\n"
738 * terminates a record
739 */
740
741 printf("# testing srtp throughput:\r\n");
742 printf("# mesg length (octets)\tthroughput (megabits per second)\r\n");
743
744 for (len = 16; len <= 2048; len *= 2) {
745 printf("%d\t\t\t%f\r\n", len,
746 srtp_bits_per_second(len, policy) / 1.0E6);
747 }
748
749 /* these extra linefeeds let gnuplot know that a dataset is done */
750 printf("\r\n\r\n");
Cullen Jennings235513a2005-09-21 22:51:36 +0000751
752}
753
754void
jfigus67b9c732014-11-20 10:17:21 -0500755srtp_do_rejection_timing (const srtp_policy_t *policy)
756{
757 int len;
Cullen Jennings235513a2005-09-21 22:51:36 +0000758
jfigus67b9c732014-11-20 10:17:21 -0500759 /*
760 * note: the output of this function is formatted so that it
761 * can be used in gnuplot. '#' indicates a comment, and "\r\n"
762 * terminates a record
763 */
764
765 printf("# testing srtp rejection throughput:\r\n");
766 printf("# mesg length (octets)\trejections per second\r\n");
767
768 for (len = 8; len <= 2048; len *= 2) {
769 printf("%d\t\t\t%e\r\n", len, srtp_rejections_per_second(len, policy));
770 }
771
772 /* these extra linefeeds let gnuplot know that a dataset is done */
773 printf("\r\n\r\n");
Cullen Jennings235513a2005-09-21 22:51:36 +0000774
775}
776
777
778#define MAX_MSG_LEN 1024
779
780double
jfigus67b9c732014-11-20 10:17:21 -0500781srtp_bits_per_second (int msg_len_octets, const srtp_policy_t *policy)
782{
783 srtp_t srtp;
784 srtp_hdr_t *mesg;
785 int i;
786 clock_t timer;
787 int num_trials = 100000;
788 int len;
789 uint32_t ssrc;
790 srtp_err_status_t status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000791
jfigus67b9c732014-11-20 10:17:21 -0500792 /*
793 * allocate and initialize an srtp session
794 */
795 status = srtp_create(&srtp, policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000796 if (status) {
jfigus67b9c732014-11-20 10:17:21 -0500797 printf("error: srtp_create() failed with error code %d\n", status);
798 exit(1);
Cullen Jennings235513a2005-09-21 22:51:36 +0000799 }
800
jfigus67b9c732014-11-20 10:17:21 -0500801 /*
802 * if the ssrc is unspecified, use a predetermined one
803 */
804 if (policy->ssrc.type != ssrc_specific) {
805 ssrc = 0xdeadbeef;
806 } else {
807 ssrc = policy->ssrc.value;
Jonathan Lennox75b36872010-05-21 00:30:21 +0000808 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000809
jfigus67b9c732014-11-20 10:17:21 -0500810 /*
811 * create a test packet
812 */
813 mesg = srtp_create_test_packet(msg_len_octets, ssrc);
814 if (mesg == NULL) {
815 return 0.0; /* indicate failure by returning zero */
Jonathan Lennox80c4c832010-05-17 19:30:28 +0000816
jfigus67b9c732014-11-20 10:17:21 -0500817 }
818 timer = clock();
819 for (i = 0; i < num_trials; i++) {
820 len = msg_len_octets + 12; /* add in rtp header length */
821
822 /* srtp protect message */
823 status = srtp_protect(srtp, mesg, &len);
824 if (status) {
825 printf("error: srtp_protect() failed with error code %d\n", status);
826 exit(1);
827 }
828
829 /* increment message number */
830 {
831 /* hack sequence to avoid problems with macros for htons/ntohs on some systems */
832 short new_seq = ntohs(mesg->seq) + 1;
833 mesg->seq = htons(new_seq);
834 }
835 }
836 timer = clock() - timer;
837
838 free(mesg);
839
840 status = srtp_dealloc(srtp);
841 if (status) {
842 printf("error: srtp_dealloc() failed with error code %d\n", status);
843 exit(1);
844 }
845
846 return (double)(msg_len_octets) * 8 *
847 num_trials * CLOCKS_PER_SEC / timer;
Cullen Jennings235513a2005-09-21 22:51:36 +0000848}
849
850double
jfigus67b9c732014-11-20 10:17:21 -0500851srtp_rejections_per_second (int msg_len_octets, const srtp_policy_t *policy)
852{
853 srtp_ctx_t *srtp;
854 srtp_hdr_t *mesg;
855 int i;
856 int len;
857 clock_t timer;
858 int num_trials = 1000000;
859 uint32_t ssrc = policy->ssrc.value;
860 srtp_err_status_t status;
Cullen Jennings235513a2005-09-21 22:51:36 +0000861
jfigus67b9c732014-11-20 10:17:21 -0500862 /*
863 * allocate and initialize an srtp session
864 */
865 status = srtp_create(&srtp, policy);
866 if (status) {
867 printf("error: srtp_create() failed with error code %d\n", status);
868 exit(1);
869 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000870
jfigus67b9c732014-11-20 10:17:21 -0500871 mesg = srtp_create_test_packet(msg_len_octets, ssrc);
872 if (mesg == NULL) {
873 return 0.0; /* indicate failure by returning zero */
874
875 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000876 len = msg_len_octets;
jfigus67b9c732014-11-20 10:17:21 -0500877 srtp_protect(srtp, (srtp_hdr_t*)mesg, &len);
Cullen Jennings235513a2005-09-21 22:51:36 +0000878
jfigus67b9c732014-11-20 10:17:21 -0500879 timer = clock();
880 for (i = 0; i < num_trials; i++) {
881 len = msg_len_octets;
882 srtp_unprotect(srtp, (srtp_hdr_t*)mesg, &len);
883 }
884 timer = clock() - timer;
Jonathan Lennox80c4c832010-05-17 19:30:28 +0000885
jfigus67b9c732014-11-20 10:17:21 -0500886 free(mesg);
Jonathan Lennox80c4c832010-05-17 19:30:28 +0000887
jfigus67b9c732014-11-20 10:17:21 -0500888 status = srtp_dealloc(srtp);
889 if (status) {
890 printf("error: srtp_dealloc() failed with error code %d\n", status);
891 exit(1);
892 }
893
894 return (double)num_trials * CLOCKS_PER_SEC / timer;
Cullen Jennings235513a2005-09-21 22:51:36 +0000895}
896
897
898void
jfigus67b9c732014-11-20 10:17:21 -0500899err_check (srtp_err_status_t s)
900{
901 if (s == srtp_err_status_ok) {
902 return;
903 } else{
904 fprintf(stderr, "error: unexpected srtp failure (code %d)\n", s);
905 }
906 exit(1);
Cullen Jennings235513a2005-09-21 22:51:36 +0000907}
908
jfigus857009c2014-11-05 11:17:43 -0500909srtp_err_status_t
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500910srtp_test_call_protect(srtp_t srtp_sender, srtp_hdr_t *hdr, int *len, int mki_index) {
911 if (mki_index == -1) {
912 return srtp_protect(srtp_sender, hdr, len);
913 } else {
914 return srtp_protect_mki(srtp_sender, hdr, len, 1, mki_index);
915 }
916}
917
918srtp_err_status_t
919srtp_test_call_protect_rtcp(srtp_t srtp_sender, srtp_hdr_t *hdr, int *len, int mki_index) {
920 if (mki_index == -1) {
921 return srtp_protect_rtcp(srtp_sender, hdr, len);
922 } else {
923 return srtp_protect_rtcp_mki(srtp_sender, hdr, len, 1, mki_index);
924 }
925}
926
927srtp_err_status_t
928srtp_test_call_unprotect(srtp_t srtp_sender, srtp_hdr_t *hdr, int *len, int use_mki) {
929 if (use_mki == -1) {
930 return srtp_unprotect(srtp_sender, hdr, len);
931 } else {
932 return srtp_unprotect_mki(srtp_sender, hdr, len, use_mki);
933 }
934}
935
936srtp_err_status_t
937srtp_test_call_unprotect_rtcp(srtp_t srtp_sender, srtp_hdr_t *hdr, int *len, int use_mki) {
938 if (use_mki == -1) {
939 return srtp_unprotect_rtcp(srtp_sender, hdr, len);
940 } else {
941 return srtp_unprotect_rtcp_mki(srtp_sender, hdr, len, use_mki);
942 }
943}
944
945srtp_err_status_t
946srtp_test (const srtp_policy_t *policy, int extension_header, int mki_index)
jfigus67b9c732014-11-20 10:17:21 -0500947{
948 int i;
949 srtp_t srtp_sender;
950 srtp_t srtp_rcvr;
951 srtp_err_status_t status = srtp_err_status_ok;
952 srtp_hdr_t *hdr, *hdr2;
953 uint8_t hdr_enc[64];
954 uint8_t *pkt_end;
955 int msg_len_octets, msg_len_enc;
956 int len;
957 int tag_length = policy->rtp.auth_tag_len;
958 uint32_t ssrc;
959 srtp_policy_t *rcvr_policy;
Joachim Bauch99a74822015-11-17 00:08:19 +0100960 srtp_policy_t tmp_policy;
961 int header = 1;
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500962 int use_mki = 0;
963
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500964 if (mki_index >= 0)
965 use_mki = 1;
Cullen Jennings235513a2005-09-21 22:51:36 +0000966
Joachim Bauch99a74822015-11-17 00:08:19 +0100967 if (extension_header) {
968 memcpy(&tmp_policy, policy, sizeof(srtp_policy_t));
969 tmp_policy.enc_xtn_hdr = &header;
970 tmp_policy.enc_xtn_hdr_count = 1;
971 err_check(srtp_create(&srtp_sender, &tmp_policy));
972 } else {
973 err_check(srtp_create(&srtp_sender, policy));
974 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000975
jfigus67b9c732014-11-20 10:17:21 -0500976 /* print out policy */
977 err_check(srtp_session_print_policy(srtp_sender));
Cullen Jennings235513a2005-09-21 22:51:36 +0000978
jfigus67b9c732014-11-20 10:17:21 -0500979 /*
980 * initialize data buffer, using the ssrc in the policy unless that
981 * value is a wildcard, in which case we'll just use an arbitrary
982 * one
983 */
984 if (policy->ssrc.type != ssrc_specific) {
985 ssrc = 0xdecafbad;
986 } else{
987 ssrc = policy->ssrc.value;
Cullen Jennings235513a2005-09-21 22:51:36 +0000988 }
jfigus67b9c732014-11-20 10:17:21 -0500989 msg_len_octets = 28;
Joachim Bauch99a74822015-11-17 00:08:19 +0100990 if (extension_header) {
991 hdr = srtp_create_test_packet_ext_hdr(msg_len_octets, ssrc);
992 hdr2 = srtp_create_test_packet_ext_hdr(msg_len_octets, ssrc);
993 } else {
994 hdr = srtp_create_test_packet(msg_len_octets, ssrc);
995 hdr2 = srtp_create_test_packet(msg_len_octets, ssrc);
996 }
Cullen Jennings235513a2005-09-21 22:51:36 +0000997
jfigus67b9c732014-11-20 10:17:21 -0500998 if (hdr == NULL) {
Joachim Bauch99a74822015-11-17 00:08:19 +0100999 free(hdr2);
jfigus67b9c732014-11-20 10:17:21 -05001000 return srtp_err_status_alloc_fail;
Cullen Jennings235513a2005-09-21 22:51:36 +00001001 }
jfigus67b9c732014-11-20 10:17:21 -05001002 if (hdr2 == NULL) {
1003 free(hdr);
1004 return srtp_err_status_alloc_fail;
Cullen Jennings235513a2005-09-21 22:51:36 +00001005 }
1006
Marcus Sundberg5c40da82005-10-08 18:15:00 +00001007 /* set message length */
1008 len = msg_len_octets;
Joachim Bauch99a74822015-11-17 00:08:19 +01001009 if (extension_header) {
1010 len += 12;
1011 }
Marcus Sundberg5c40da82005-10-08 18:15:00 +00001012
jfigus67b9c732014-11-20 10:17:21 -05001013 debug_print(mod_driver, "before protection:\n%s",
1014 srtp_packet_to_string(hdr, len));
1015
1016#if PRINT_REFERENCE_PACKET
1017 debug_print(mod_driver, "reference packet before protection:\n%s",
1018 octet_string_hex_string((uint8_t*)hdr, len));
1019#endif
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001020 err_check(srtp_test_call_protect(srtp_sender, hdr, &len, mki_index));
Cullen Jennings235513a2005-09-21 22:51:36 +00001021
jfigus67b9c732014-11-20 10:17:21 -05001022 debug_print(mod_driver, "after protection:\n%s",
1023 srtp_packet_to_string(hdr, len));
1024#if PRINT_REFERENCE_PACKET
1025 debug_print(mod_driver, "after protection:\n%s",
1026 octet_string_hex_string((uint8_t*)hdr, len));
1027#endif
1028
1029 /* save protected message and length */
1030 memcpy(hdr_enc, hdr, len);
1031 msg_len_enc = len;
1032
1033 /*
1034 * check for overrun of the srtp_protect() function
1035 *
1036 * The packet is followed by a value of 0xfffff; if the value of the
1037 * data following the packet is different, then we know that the
1038 * protect function is overwriting the end of the packet.
1039 */
1040 pkt_end = (uint8_t*)hdr + sizeof(srtp_hdr_t)
1041 + msg_len_octets + tag_length;
Joachim Bauch99a74822015-11-17 00:08:19 +01001042 if (extension_header) {
1043 pkt_end += 12;
1044 }
jfigus67b9c732014-11-20 10:17:21 -05001045 for (i = 0; i < 4; i++) {
1046 if (pkt_end[i] != 0xff) {
1047 fprintf(stdout, "overwrite in srtp_protect() function "
1048 "(expected %x, found %x in trailing octet %d)\n",
1049 0xff, ((uint8_t*)hdr)[i], i);
1050 free(hdr);
1051 free(hdr2);
1052 return srtp_err_status_algo_fail;
1053 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001054 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001055
jfigus67b9c732014-11-20 10:17:21 -05001056 /*
1057 * if the policy includes confidentiality, check that ciphertext is
1058 * different than plaintext
1059 *
1060 * Note that this check will give false negatives, with some small
1061 * probability, especially if the packets are short. For that
1062 * reason, we skip this check if the plaintext is less than four
1063 * octets long.
1064 */
1065 if ((policy->rtp.sec_serv & sec_serv_conf) && (msg_len_octets >= 4)) {
1066 printf("testing that ciphertext is distinct from plaintext...");
1067 status = srtp_err_status_algo_fail;
1068 for (i = 12; i < msg_len_octets + 12; i++) {
1069 if (((uint8_t*)hdr)[i] != ((uint8_t*)hdr2)[i]) {
1070 status = srtp_err_status_ok;
1071 }
1072 }
1073 if (status) {
1074 printf("failed\n");
1075 free(hdr);
1076 free(hdr2);
1077 return status;
1078 }
1079 printf("passed\n");
1080 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001081
jfigus67b9c732014-11-20 10:17:21 -05001082 /*
1083 * if the policy uses a 'wildcard' ssrc, then we need to make a copy
1084 * of the policy that changes the direction to inbound
1085 *
1086 * we always copy the policy into the rcvr_policy, since otherwise
1087 * the compiler would fret about the constness of the policy
1088 */
1089 rcvr_policy = (srtp_policy_t*)malloc(sizeof(srtp_policy_t));
1090 if (rcvr_policy == NULL) {
1091 free(hdr);
1092 free(hdr2);
1093 return srtp_err_status_alloc_fail;
1094 }
Joachim Bauch99a74822015-11-17 00:08:19 +01001095 if (extension_header) {
1096 memcpy(rcvr_policy, &tmp_policy, sizeof(srtp_policy_t));
1097 if (tmp_policy.ssrc.type == ssrc_any_outbound) {
1098 rcvr_policy->ssrc.type = ssrc_any_inbound;
1099 }
1100 } else {
1101 memcpy(rcvr_policy, policy, sizeof(srtp_policy_t));
1102 if (policy->ssrc.type == ssrc_any_outbound) {
1103 rcvr_policy->ssrc.type = ssrc_any_inbound;
1104 }
jfigus67b9c732014-11-20 10:17:21 -05001105 }
1106
1107 err_check(srtp_create(&srtp_rcvr, rcvr_policy));
1108
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001109 err_check(srtp_test_call_unprotect(srtp_rcvr, hdr, &len, use_mki));
jfigus67b9c732014-11-20 10:17:21 -05001110
1111 debug_print(mod_driver, "after unprotection:\n%s",
1112 srtp_packet_to_string(hdr, len));
1113
1114 /* verify that the unprotected packet matches the origial one */
1115 for (i = 0; i < msg_len_octets; i++) {
1116 if (((uint8_t*)hdr)[i] != ((uint8_t*)hdr2)[i]) {
1117 fprintf(stdout, "mismatch at octet %d\n", i);
1118 status = srtp_err_status_algo_fail;
1119 }
1120 }
1121 if (status) {
1122 free(hdr);
1123 free(hdr2);
1124 free(rcvr_policy);
1125 return status;
1126 }
1127
1128 /*
1129 * if the policy includes authentication, then test for false positives
1130 */
1131 if (policy->rtp.sec_serv & sec_serv_auth) {
1132 char *data = ((char*)hdr) + 12;
1133
1134 printf("testing for false positives in replay check...");
1135
1136 /* set message length */
1137 len = msg_len_enc;
1138
1139 /* unprotect a second time - should fail with a replay error */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001140 status = srtp_test_call_unprotect(srtp_rcvr, hdr, &len, use_mki);
jfigus67b9c732014-11-20 10:17:21 -05001141 if (status != srtp_err_status_replay_fail) {
1142 printf("failed with error code %d\n", status);
1143 free(hdr);
1144 free(hdr2);
1145 free(rcvr_policy);
1146 return status;
1147 } else {
1148 printf("passed\n");
1149 }
1150
1151 printf("testing for false positives in auth check...");
1152
1153 /* increment sequence number in header */
1154 hdr->seq++;
1155
1156 /* set message length */
1157 len = msg_len_octets;
Joachim Bauch99a74822015-11-17 00:08:19 +01001158 if (extension_header) {
1159 len += 12;
1160 }
jfigus67b9c732014-11-20 10:17:21 -05001161
1162 /* apply protection */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001163 err_check(srtp_test_call_protect(srtp_sender, hdr, &len, mki_index));
jfigus67b9c732014-11-20 10:17:21 -05001164
1165 /* flip bits in packet */
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01001166 data[extension_header ? 12 : 0] ^= 0xff;
jfigus67b9c732014-11-20 10:17:21 -05001167
1168 /* unprotect, and check for authentication failure */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001169 status = srtp_test_call_unprotect(srtp_rcvr, hdr, &len, use_mki);
jfigus67b9c732014-11-20 10:17:21 -05001170 if (status != srtp_err_status_auth_fail) {
1171 printf("failed\n");
1172 free(hdr);
1173 free(hdr2);
1174 free(rcvr_policy);
1175 return status;
1176 } else {
1177 printf("passed\n");
1178 }
1179
1180 }
1181
1182 err_check(srtp_dealloc(srtp_sender));
1183 err_check(srtp_dealloc(srtp_rcvr));
1184
1185 free(hdr);
1186 free(hdr2);
1187 free(rcvr_policy);
1188 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001189}
1190
1191
jfigus857009c2014-11-05 11:17:43 -05001192srtp_err_status_t
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001193srtcp_test (const srtp_policy_t *policy, int mki_index)
jfigus67b9c732014-11-20 10:17:21 -05001194{
1195 int i;
1196 srtp_t srtcp_sender;
1197 srtp_t srtcp_rcvr;
1198 srtp_err_status_t status = srtp_err_status_ok;
1199 srtp_hdr_t *hdr, *hdr2;
1200 uint8_t hdr_enc[64];
1201 uint8_t *pkt_end;
1202 int msg_len_octets, msg_len_enc;
1203 int len;
1204 int tag_length = policy->rtp.auth_tag_len;
1205 uint32_t ssrc;
1206 srtp_policy_t *rcvr_policy;
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001207 int use_mki = 0;
1208
1209 if (mki_index >= 0)
1210 use_mki = 1;
David McGrew9c70f292006-05-03 19:38:38 +00001211
jfigus67b9c732014-11-20 10:17:21 -05001212 err_check(srtp_create(&srtcp_sender, policy));
David McGrew9c70f292006-05-03 19:38:38 +00001213
jfigus67b9c732014-11-20 10:17:21 -05001214 /* print out policy */
1215 err_check(srtp_session_print_policy(srtcp_sender));
David McGrew9c70f292006-05-03 19:38:38 +00001216
jfigus67b9c732014-11-20 10:17:21 -05001217 /*
1218 * initialize data buffer, using the ssrc in the policy unless that
1219 * value is a wildcard, in which case we'll just use an arbitrary
1220 * one
1221 */
1222 if (policy->ssrc.type != ssrc_specific) {
1223 ssrc = 0xdecafbad;
1224 } else{
1225 ssrc = policy->ssrc.value;
David McGrew9c70f292006-05-03 19:38:38 +00001226 }
jfigus67b9c732014-11-20 10:17:21 -05001227 msg_len_octets = 28;
1228 hdr = srtp_create_test_packet(msg_len_octets, ssrc);
David McGrew9c70f292006-05-03 19:38:38 +00001229
jfigus67b9c732014-11-20 10:17:21 -05001230 if (hdr == NULL) {
1231 return srtp_err_status_alloc_fail;
David McGrew9c70f292006-05-03 19:38:38 +00001232 }
jfigus67b9c732014-11-20 10:17:21 -05001233 hdr2 = srtp_create_test_packet(msg_len_octets, ssrc);
1234 if (hdr2 == NULL) {
1235 free(hdr);
1236 return srtp_err_status_alloc_fail;
David McGrew9c70f292006-05-03 19:38:38 +00001237 }
1238
David McGrew9c70f292006-05-03 19:38:38 +00001239 /* set message length */
1240 len = msg_len_octets;
1241
jfigus67b9c732014-11-20 10:17:21 -05001242 debug_print(mod_driver, "before protection:\n%s",
1243 srtp_packet_to_string(hdr, len));
1244
1245#if PRINT_REFERENCE_PACKET
1246 debug_print(mod_driver, "reference packet before protection:\n%s",
1247 octet_string_hex_string((uint8_t*)hdr, len));
1248#endif
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001249 err_check(srtp_test_call_protect_rtcp(srtcp_sender, hdr, &len, mki_index));
David McGrew9c70f292006-05-03 19:38:38 +00001250
jfigus67b9c732014-11-20 10:17:21 -05001251 debug_print(mod_driver, "after protection:\n%s",
1252 srtp_packet_to_string(hdr, len));
1253#if PRINT_REFERENCE_PACKET
1254 debug_print(mod_driver, "after protection:\n%s",
1255 octet_string_hex_string((uint8_t*)hdr, len));
1256#endif
1257
1258 /* save protected message and length */
1259 memcpy(hdr_enc, hdr, len);
1260 msg_len_enc = len;
1261
1262 /*
1263 * check for overrun of the srtp_protect() function
1264 *
1265 * The packet is followed by a value of 0xfffff; if the value of the
1266 * data following the packet is different, then we know that the
1267 * protect function is overwriting the end of the packet.
1268 */
1269 pkt_end = (uint8_t*)hdr + sizeof(srtp_hdr_t)
1270 + msg_len_octets + tag_length;
1271 for (i = 0; i < 4; i++) {
1272 if (pkt_end[i] != 0xff) {
1273 fprintf(stdout, "overwrite in srtp_protect_rtcp() function "
1274 "(expected %x, found %x in trailing octet %d)\n",
1275 0xff, ((uint8_t*)hdr)[i], i);
1276 free(hdr);
1277 free(hdr2);
1278 return srtp_err_status_algo_fail;
1279 }
David McGrew9c70f292006-05-03 19:38:38 +00001280 }
David McGrew9c70f292006-05-03 19:38:38 +00001281
jfigus67b9c732014-11-20 10:17:21 -05001282 /*
1283 * if the policy includes confidentiality, check that ciphertext is
1284 * different than plaintext
1285 *
1286 * Note that this check will give false negatives, with some small
1287 * probability, especially if the packets are short. For that
1288 * reason, we skip this check if the plaintext is less than four
1289 * octets long.
1290 */
1291 if ((policy->rtp.sec_serv & sec_serv_conf) && (msg_len_octets >= 4)) {
1292 printf("testing that ciphertext is distinct from plaintext...");
1293 status = srtp_err_status_algo_fail;
1294 for (i = 12; i < msg_len_octets + 12; i++) {
1295 if (((uint8_t*)hdr)[i] != ((uint8_t*)hdr2)[i]) {
1296 status = srtp_err_status_ok;
1297 }
1298 }
1299 if (status) {
1300 printf("failed\n");
1301 free(hdr);
1302 free(hdr2);
1303 return status;
1304 }
1305 printf("passed\n");
1306 }
David McGrew9c70f292006-05-03 19:38:38 +00001307
jfigus67b9c732014-11-20 10:17:21 -05001308 /*
1309 * if the policy uses a 'wildcard' ssrc, then we need to make a copy
1310 * of the policy that changes the direction to inbound
1311 *
1312 * we always copy the policy into the rcvr_policy, since otherwise
1313 * the compiler would fret about the constness of the policy
1314 */
1315 rcvr_policy = (srtp_policy_t*)malloc(sizeof(srtp_policy_t));
1316 if (rcvr_policy == NULL) {
1317 return srtp_err_status_alloc_fail;
1318 }
1319 memcpy(rcvr_policy, policy, sizeof(srtp_policy_t));
1320 if (policy->ssrc.type == ssrc_any_outbound) {
1321 rcvr_policy->ssrc.type = ssrc_any_inbound;
1322 }
1323
1324 err_check(srtp_create(&srtcp_rcvr, rcvr_policy));
1325
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001326 err_check(srtp_test_call_unprotect_rtcp(srtcp_rcvr, hdr, &len, use_mki));
jfigus67b9c732014-11-20 10:17:21 -05001327
1328 debug_print(mod_driver, "after unprotection:\n%s",
1329 srtp_packet_to_string(hdr, len));
1330
1331 /* verify that the unprotected packet matches the origial one */
1332 for (i = 0; i < msg_len_octets; i++) {
1333 if (((uint8_t*)hdr)[i] != ((uint8_t*)hdr2)[i]) {
1334 fprintf(stdout, "mismatch at octet %d\n", i);
1335 status = srtp_err_status_algo_fail;
1336 }
1337 }
1338 if (status) {
1339 free(hdr);
1340 free(hdr2);
1341 free(rcvr_policy);
1342 return status;
1343 }
1344
1345 /*
1346 * if the policy includes authentication, then test for false positives
1347 */
1348 if (policy->rtp.sec_serv & sec_serv_auth) {
1349 char *data = ((char*)hdr) + 12;
1350
1351 printf("testing for false positives in replay check...");
1352
1353 /* set message length */
1354 len = msg_len_enc;
1355
1356 /* unprotect a second time - should fail with a replay error */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001357 status = srtp_test_call_unprotect_rtcp(srtcp_rcvr, hdr, &len, use_mki);
jfigus67b9c732014-11-20 10:17:21 -05001358 if (status != srtp_err_status_replay_fail) {
1359 printf("failed with error code %d\n", status);
1360 free(hdr);
1361 free(hdr2);
1362 free(rcvr_policy);
1363 return status;
1364 } else {
1365 printf("passed\n");
1366 }
1367
1368 printf("testing for false positives in auth check...");
1369
1370 /* increment sequence number in header */
1371 hdr->seq++;
1372
1373 /* set message length */
1374 len = msg_len_octets;
1375
1376 /* apply protection */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001377 err_check(srtp_test_call_protect_rtcp(srtcp_sender, hdr, &len, mki_index));
jfigus67b9c732014-11-20 10:17:21 -05001378
1379 /* flip bits in packet */
1380 data[0] ^= 0xff;
1381
1382 /* unprotect, and check for authentication failure */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001383 status = srtp_test_call_unprotect_rtcp(srtcp_rcvr, hdr, &len, use_mki);
jfigus67b9c732014-11-20 10:17:21 -05001384 if (status != srtp_err_status_auth_fail) {
1385 printf("failed\n");
1386 free(hdr);
1387 free(hdr2);
1388 free(rcvr_policy);
1389 return status;
1390 } else {
1391 printf("passed\n");
1392 }
1393
1394 }
1395
1396 err_check(srtp_dealloc(srtcp_sender));
1397 err_check(srtp_dealloc(srtcp_rcvr));
1398
1399 free(hdr);
1400 free(hdr2);
1401 free(rcvr_policy);
1402 return srtp_err_status_ok;
David McGrew9c70f292006-05-03 19:38:38 +00001403}
1404
1405
jfigus857009c2014-11-05 11:17:43 -05001406srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001407srtp_session_print_policy (srtp_t srtp)
1408{
1409 char *serv_descr[4] = {
1410 "none",
1411 "confidentiality",
1412 "authentication",
1413 "confidentiality and authentication"
1414 };
1415 char *direction[3] = {
1416 "unknown",
1417 "outbound",
1418 "inbound"
1419 };
1420 srtp_stream_t stream;
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001421 srtp_session_keys_t *session_keys = NULL;
Cullen Jennings235513a2005-09-21 22:51:36 +00001422
jfigus67b9c732014-11-20 10:17:21 -05001423 /* sanity checking */
1424 if (srtp == NULL) {
1425 return srtp_err_status_fail;
1426 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001427
jfigus67b9c732014-11-20 10:17:21 -05001428 /* if there's a template stream, print it out */
1429 if (srtp->stream_template != NULL) {
1430 stream = srtp->stream_template;
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001431 session_keys = &stream->session_keys[0];
jfigus67b9c732014-11-20 10:17:21 -05001432 printf("# SSRC: any %s\r\n"
1433 "# rtp cipher: %s\r\n"
1434 "# rtp auth: %s\r\n"
1435 "# rtp services: %s\r\n"
1436 "# rtcp cipher: %s\r\n"
1437 "# rtcp auth: %s\r\n"
1438 "# rtcp services: %s\r\n"
1439 "# window size: %lu\r\n"
1440 "# tx rtx allowed:%s\r\n",
1441 direction[stream->direction],
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001442 session_keys->rtp_cipher->type->description,
1443 session_keys->rtp_auth->type->description,
jfigus67b9c732014-11-20 10:17:21 -05001444 serv_descr[stream->rtp_services],
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001445 session_keys->rtcp_cipher->type->description,
1446 session_keys->rtcp_auth->type->description,
jfigus67b9c732014-11-20 10:17:21 -05001447 serv_descr[stream->rtcp_services],
jfigusde8deb32014-11-25 12:58:11 -05001448 srtp_rdbx_get_window_size(&stream->rtp_rdbx),
jfigus67b9c732014-11-20 10:17:21 -05001449 stream->allow_repeat_tx ? "true" : "false");
Joachim Bauch99a74822015-11-17 00:08:19 +01001450
1451 printf("# Encrypted extension headers: ");
1452 if (stream->enc_xtn_hdr && stream->enc_xtn_hdr_count > 0) {
1453 int* enc_xtn_hdr = stream->enc_xtn_hdr;
1454 int count = stream->enc_xtn_hdr_count;
1455 while (count > 0) {
1456 printf("%d ", *enc_xtn_hdr);
1457 enc_xtn_hdr++;
1458 count--;
1459 }
1460 printf("\n");
1461 } else {
1462 printf("none\n");
1463 }
jfigus67b9c732014-11-20 10:17:21 -05001464 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001465
jfigus67b9c732014-11-20 10:17:21 -05001466 /* loop over streams in session, printing the policy of each */
1467 stream = srtp->stream_list;
1468 while (stream != NULL) {
1469 if (stream->rtp_services > sec_serv_conf_and_auth) {
1470 return srtp_err_status_bad_param;
1471 }
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001472 session_keys = &stream->session_keys[0];
Cullen Jennings235513a2005-09-21 22:51:36 +00001473
jfigus67b9c732014-11-20 10:17:21 -05001474 printf("# SSRC: 0x%08x\r\n"
1475 "# rtp cipher: %s\r\n"
1476 "# rtp auth: %s\r\n"
1477 "# rtp services: %s\r\n"
1478 "# rtcp cipher: %s\r\n"
1479 "# rtcp auth: %s\r\n"
1480 "# rtcp services: %s\r\n"
1481 "# window size: %lu\r\n"
1482 "# tx rtx allowed:%s\r\n",
1483 stream->ssrc,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001484 session_keys->rtp_cipher->type->description,
1485 session_keys->rtp_auth->type->description,
jfigus67b9c732014-11-20 10:17:21 -05001486 serv_descr[stream->rtp_services],
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001487 session_keys->rtcp_cipher->type->description,
1488 session_keys->rtcp_auth->type->description,
jfigus67b9c732014-11-20 10:17:21 -05001489 serv_descr[stream->rtcp_services],
jfigusde8deb32014-11-25 12:58:11 -05001490 srtp_rdbx_get_window_size(&stream->rtp_rdbx),
jfigus67b9c732014-11-20 10:17:21 -05001491 stream->allow_repeat_tx ? "true" : "false");
1492
Joachim Bauch99a74822015-11-17 00:08:19 +01001493 printf("# Encrypted extension headers: ");
1494 if (stream->enc_xtn_hdr && stream->enc_xtn_hdr_count > 0) {
1495 int* enc_xtn_hdr = stream->enc_xtn_hdr;
1496 int count = stream->enc_xtn_hdr_count;
1497 while (count > 0) {
1498 printf("%d ", *enc_xtn_hdr);
1499 enc_xtn_hdr++;
1500 count--;
1501 }
1502 printf("\n");
1503 } else {
1504 printf("none\n");
1505 }
1506
jfigus67b9c732014-11-20 10:17:21 -05001507 /* advance to next stream in the list */
1508 stream = stream->next;
1509 }
1510 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001511}
1512
jfigus857009c2014-11-05 11:17:43 -05001513srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001514srtp_print_policy (const srtp_policy_t *policy)
1515{
1516 srtp_err_status_t status;
1517 srtp_t session;
Cullen Jennings235513a2005-09-21 22:51:36 +00001518
jfigus67b9c732014-11-20 10:17:21 -05001519 status = srtp_create(&session, policy);
1520 if (status) {
1521 return status;
1522 }
1523 status = srtp_session_print_policy(session);
1524 if (status) {
1525 return status;
1526 }
1527 status = srtp_dealloc(session);
1528 if (status) {
1529 return status;
1530 }
1531 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001532}
1533
jfigus67b9c732014-11-20 10:17:21 -05001534/*
1535 * srtp_print_packet(...) is for debugging only
Cullen Jennings235513a2005-09-21 22:51:36 +00001536 * it prints an RTP packet to the stdout
1537 *
1538 * note that this function is *not* threadsafe
1539 */
1540
1541#include <stdio.h>
1542
1543#define MTU 2048
1544
1545char packet_string[MTU];
1546
1547char *
jfigus67b9c732014-11-20 10:17:21 -05001548srtp_packet_to_string (srtp_hdr_t *hdr, int pkt_octet_len)
1549{
1550 int octets_in_rtp_header = 12;
1551 uint8_t *data = ((uint8_t*)hdr) + octets_in_rtp_header;
1552 int hex_len = pkt_octet_len - octets_in_rtp_header;
Cullen Jennings235513a2005-09-21 22:51:36 +00001553
jfigus67b9c732014-11-20 10:17:21 -05001554 /* sanity checking */
1555 if ((hdr == NULL) || (pkt_octet_len > MTU)) {
1556 return NULL;
1557 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001558
jfigus67b9c732014-11-20 10:17:21 -05001559 /* write packet into string */
1560 sprintf(packet_string,
1561 "(s)rtp packet: {\n"
1562 " version:\t%d\n"
1563 " p:\t\t%d\n"
1564 " x:\t\t%d\n"
1565 " cc:\t\t%d\n"
1566 " m:\t\t%d\n"
1567 " pt:\t\t%x\n"
1568 " seq:\t\t%x\n"
1569 " ts:\t\t%x\n"
1570 " ssrc:\t%x\n"
1571 " data:\t%s\n"
1572 "} (%d octets in total)\n",
1573 hdr->version,
1574 hdr->p,
1575 hdr->x,
1576 hdr->cc,
1577 hdr->m,
1578 hdr->pt,
1579 hdr->seq,
1580 hdr->ts,
1581 hdr->ssrc,
1582 octet_string_hex_string(data, hex_len),
1583 pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001584
jfigus67b9c732014-11-20 10:17:21 -05001585 return packet_string;
Cullen Jennings235513a2005-09-21 22:51:36 +00001586}
1587
1588/*
1589 * mips_estimate() is a simple function to estimate the number of
1590 * instructions per second that the host can perform. note that this
1591 * function can be grossly wrong; you may want to have a manual sanity
1592 * check of its output!
1593 *
1594 * the 'ignore' pointer is there to convince the compiler to not just
1595 * optimize away the function
1596 */
1597
1598double
jfigus67b9c732014-11-20 10:17:21 -05001599mips_estimate (int num_trials, int *ignore)
1600{
1601 clock_t t;
1602 volatile int i, sum;
Cullen Jennings235513a2005-09-21 22:51:36 +00001603
jfigus67b9c732014-11-20 10:17:21 -05001604 sum = 0;
1605 t = clock();
1606 for (i = 0; i < num_trials; i++) {
1607 sum += i;
1608 }
1609 t = clock() - t;
Cullen Jennings235513a2005-09-21 22:51:36 +00001610
1611/* printf("%d\n", sum); */
jfigus67b9c732014-11-20 10:17:21 -05001612 *ignore = sum;
Cullen Jennings235513a2005-09-21 22:51:36 +00001613
jfigus67b9c732014-11-20 10:17:21 -05001614 return (double)num_trials * CLOCKS_PER_SEC / t;
Cullen Jennings235513a2005-09-21 22:51:36 +00001615}
1616
1617
1618/*
1619 * srtp_validate() verifies the correctness of libsrtp by comparing
1620 * some computed packets against some pre-computed reference values.
1621 * These packets were made with the default SRTP policy.
1622 */
1623
1624
jfigus857009c2014-11-05 11:17:43 -05001625srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05001626srtp_validate ()
1627{
1628 uint8_t srtp_plaintext_ref[28] = {
1629 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1630 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
1631 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1632 0xab, 0xab, 0xab, 0xab
1633 };
1634 uint8_t srtp_plaintext[38] = {
1635 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1636 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
1637 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1638 0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
1639 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1640 };
1641 uint8_t srtp_ciphertext[38] = {
1642 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1643 0xca, 0xfe, 0xba, 0xbe, 0x4e, 0x55, 0xdc, 0x4c,
1644 0xe7, 0x99, 0x78, 0xd8, 0x8c, 0xa4, 0xd2, 0x15,
1645 0x94, 0x9d, 0x24, 0x02, 0xb7, 0x8d, 0x6a, 0xcc,
1646 0x99, 0xea, 0x17, 0x9b, 0x8d, 0xbb
1647 };
Pascal Bühler941cf122016-06-10 09:30:52 +02001648 uint8_t rtcp_plaintext_ref[24] = {
1649 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe,
1650 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1651 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1652 };
1653 uint8_t rtcp_plaintext[38] = {
1654 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe,
1655 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1656 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1657 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1658 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1659 };
1660 uint8_t srtcp_ciphertext[38] = {
1661 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe,
1662 0x71, 0x28, 0x03, 0x5b, 0xe4, 0x87, 0xb9, 0xbd,
1663 0xbe, 0xf8, 0x90, 0x41, 0xf9, 0x77, 0xa5, 0xa8,
1664 0x80, 0x00, 0x00, 0x01, 0x99, 0x3e, 0x08, 0xcd,
1665 0x54, 0xd6, 0xc1, 0x23, 0x07, 0x98
1666 };
jfigus67b9c732014-11-20 10:17:21 -05001667 srtp_t srtp_snd, srtp_recv;
1668 srtp_err_status_t status;
1669 int len;
1670 srtp_policy_t policy;
Cullen Jennings235513a2005-09-21 22:51:36 +00001671
jfigus67b9c732014-11-20 10:17:21 -05001672 /*
1673 * create a session with a single stream using the default srtp
1674 * policy and with the SSRC value 0xcafebabe
1675 */
Joachim Bauch99a74822015-11-17 00:08:19 +01001676 memset(&policy, 0, sizeof(policy));
jfigus67b9c732014-11-20 10:17:21 -05001677 srtp_crypto_policy_set_rtp_default(&policy.rtp);
1678 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
1679 policy.ssrc.type = ssrc_specific;
1680 policy.ssrc.value = 0xcafebabe;
Ryan Hooper89a288b2016-12-22 16:22:47 -05001681 policy.key = test_key;
jfigus67b9c732014-11-20 10:17:21 -05001682 policy.ekt = NULL;
1683 policy.window_size = 128;
1684 policy.allow_repeat_tx = 0;
1685 policy.next = NULL;
Cullen Jennings235513a2005-09-21 22:51:36 +00001686
jfigus67b9c732014-11-20 10:17:21 -05001687 status = srtp_create(&srtp_snd, &policy);
1688 if (status) {
1689 return status;
1690 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001691
jfigus67b9c732014-11-20 10:17:21 -05001692 /*
1693 * protect plaintext, then compare with ciphertext
1694 */
1695 len = 28;
1696 status = srtp_protect(srtp_snd, srtp_plaintext, &len);
1697 if (status || (len != 38)) {
1698 return srtp_err_status_fail;
1699 }
Cullen Jennings235513a2005-09-21 22:51:36 +00001700
jfigus67b9c732014-11-20 10:17:21 -05001701 debug_print(mod_driver, "ciphertext:\n %s",
1702 octet_string_hex_string(srtp_plaintext, len));
1703 debug_print(mod_driver, "ciphertext reference:\n %s",
1704 octet_string_hex_string(srtp_ciphertext, len));
Cullen Jennings235513a2005-09-21 22:51:36 +00001705
jfigus67b9c732014-11-20 10:17:21 -05001706 if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
1707 return srtp_err_status_fail;
1708 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00001709
jfigus67b9c732014-11-20 10:17:21 -05001710 /*
Pascal Bühler941cf122016-06-10 09:30:52 +02001711 * protect plaintext rtcp, then compare with srtcp ciphertext
1712 */
1713 len = 24;
1714 status = srtp_protect_rtcp(srtp_snd, rtcp_plaintext, &len);
1715 if (status || (len != 38)) {
1716 return srtp_err_status_fail;
1717 }
1718
1719 debug_print(mod_driver, "srtcp ciphertext:\n %s",
1720 octet_string_hex_string(rtcp_plaintext, len));
1721 debug_print(mod_driver, "srtcp ciphertext reference:\n %s",
1722 octet_string_hex_string(srtcp_ciphertext, len));
1723
1724 if (octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
1725 return srtp_err_status_fail;
1726 }
1727
1728 /*
jfigus67b9c732014-11-20 10:17:21 -05001729 * create a receiver session context comparable to the one created
1730 * above - we need to do this so that the replay checking doesn't
1731 * complain
1732 */
1733 status = srtp_create(&srtp_recv, &policy);
1734 if (status) {
1735 return status;
1736 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00001737
jfigus67b9c732014-11-20 10:17:21 -05001738 /*
1739 * unprotect ciphertext, then compare with plaintext
1740 */
1741 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
1742 if (status || (len != 28)) {
1743 return status;
1744 }
1745
1746 if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
1747 return srtp_err_status_fail;
1748 }
1749
Pascal Bühler941cf122016-06-10 09:30:52 +02001750 /*
1751 * unprotect srtcp ciphertext, then compare with rtcp plaintext
1752 */
1753 len = 38;
1754 status = srtp_unprotect_rtcp(srtp_recv, srtcp_ciphertext, &len);
1755 if (status || (len != 24)) {
1756 return status;
1757 }
1758
1759 if (octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
1760 return srtp_err_status_fail;
1761 }
1762
jfigus67b9c732014-11-20 10:17:21 -05001763 status = srtp_dealloc(srtp_snd);
1764 if (status) {
1765 return status;
1766 }
1767
1768 status = srtp_dealloc(srtp_recv);
1769 if (status) {
1770 return status;
1771 }
1772
1773 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00001774}
1775
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001776#ifdef OPENSSL
1777/*
1778 * srtp_validate_gcm() verifies the correctness of libsrtp by comparing
1779 * an computed packet against the known ciphertext for the plaintext.
1780 */
1781srtp_err_status_t
1782srtp_validate_gcm ()
1783{
1784 unsigned char test_key_gcm[28] = {
1785 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1786 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
1787 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
1788 0xa8, 0xa9, 0xaa, 0xab
1789 };
Pascal Bühler45019ae2016-06-10 08:35:12 +02001790 uint8_t rtp_plaintext_ref[28] = {
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001791 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1792 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
1793 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1794 0xab, 0xab, 0xab, 0xab
1795 };
Pascal Bühler45019ae2016-06-10 08:35:12 +02001796 uint8_t rtp_plaintext[44] = {
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001797 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1798 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
1799 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1800 0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
1801 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1802 0x00, 0x00, 0x00, 0x00
1803 };
1804 uint8_t srtp_ciphertext[44] = {
1805 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1806 0xca, 0xfe, 0xba, 0xbe, 0xc5, 0x00, 0x2e, 0xde,
1807 0x04, 0xcf, 0xdd, 0x2e, 0xb9, 0x11, 0x59, 0xe0,
1808 0x88, 0x0a, 0xa0, 0x6e, 0xd2, 0x97, 0x68, 0x26,
1809 0xf7, 0x96, 0xb2, 0x01, 0xdf, 0x31, 0x31, 0xa1,
1810 0x27, 0xe8, 0xa3, 0x92
1811 };
Pascal Bühler45019ae2016-06-10 08:35:12 +02001812 uint8_t rtcp_plaintext_ref[24] = {
1813 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe,
1814 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1815 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1816 };
1817 uint8_t rtcp_plaintext[44] = {
1818 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe,
1819 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1820 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1821 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1822 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1823 0x00, 0x00, 0x00, 0x00
1824 };
1825 uint8_t srtcp_ciphertext[44] = {
1826 0x81, 0xc8, 0x00, 0x0b, 0xca, 0xfe, 0xba, 0xbe,
1827 0xc9, 0x8b, 0x8b, 0x5d, 0xf0, 0x39, 0x2a, 0x55,
1828 0x85, 0x2b, 0x6c, 0x21, 0xac, 0x8e, 0x70, 0x25,
1829 0xc5, 0x2c, 0x6f, 0xbe, 0xa2, 0xb3, 0xb4, 0x46,
1830 0xea, 0x31, 0x12, 0x3b, 0xa8, 0x8c, 0xe6, 0x1e,
1831 0x80, 0x00, 0x00, 0x01
1832 };
1833
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001834 srtp_t srtp_snd, srtp_recv;
1835 srtp_err_status_t status;
1836 int len;
1837 srtp_policy_t policy;
1838
1839 /*
1840 * create a session with a single stream using the default srtp
1841 * policy and with the SSRC value 0xcafebabe
1842 */
1843 memset(&policy, 0, sizeof(policy));
1844 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp);
1845 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtcp);
1846 policy.ssrc.type = ssrc_specific;
1847 policy.ssrc.value = 0xcafebabe;
1848 policy.key = test_key_gcm;
1849 policy.ekt = NULL;
1850 policy.window_size = 128;
1851 policy.allow_repeat_tx = 0;
1852 policy.next = NULL;
1853
1854 status = srtp_create(&srtp_snd, &policy);
1855 if (status) {
1856 return status;
1857 }
1858
1859 /*
Pascal Bühler45019ae2016-06-10 08:35:12 +02001860 * protect plaintext rtp, then compare with srtp ciphertext
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001861 */
1862 len = 28;
Pascal Bühler45019ae2016-06-10 08:35:12 +02001863 status = srtp_protect(srtp_snd, rtp_plaintext, &len);
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001864 if (status || (len != 44)) {
1865 return srtp_err_status_fail;
1866 }
1867
Pascal Bühler45019ae2016-06-10 08:35:12 +02001868 debug_print(mod_driver, "srtp ciphertext:\n %s",
1869 octet_string_hex_string(rtp_plaintext, len));
1870 debug_print(mod_driver, "srtp ciphertext reference:\n %s",
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001871 octet_string_hex_string(srtp_ciphertext, len));
1872
Pascal Bühler45019ae2016-06-10 08:35:12 +02001873 if (octet_string_is_eq(rtp_plaintext, srtp_ciphertext, len)) {
1874 return srtp_err_status_fail;
1875 }
1876
1877 /*
1878 * protect plaintext rtcp, then compare with srtcp ciphertext
1879 */
1880 len = 24;
1881 status = srtp_protect_rtcp(srtp_snd, rtcp_plaintext, &len);
1882 if (status || (len != 44)) {
1883 return srtp_err_status_fail;
1884 }
1885
1886 debug_print(mod_driver, "srtcp ciphertext:\n %s",
1887 octet_string_hex_string(rtcp_plaintext, len));
1888 debug_print(mod_driver, "srtcp ciphertext reference:\n %s",
1889 octet_string_hex_string(srtcp_ciphertext, len));
1890
1891 if (octet_string_is_eq(rtcp_plaintext, srtcp_ciphertext, len)) {
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001892 return srtp_err_status_fail;
1893 }
1894
1895 /*
1896 * create a receiver session context comparable to the one created
1897 * above - we need to do this so that the replay checking doesn't
1898 * complain
1899 */
1900 status = srtp_create(&srtp_recv, &policy);
1901 if (status) {
1902 return status;
1903 }
1904
1905 /*
Pascal Bühler45019ae2016-06-10 08:35:12 +02001906 * unprotect srtp ciphertext, then compare with rtp plaintext
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001907 */
Pascal Bühler45019ae2016-06-10 08:35:12 +02001908 len = 44;
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001909 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
1910 if (status || (len != 28)) {
1911 return status;
1912 }
1913
Pascal Bühler45019ae2016-06-10 08:35:12 +02001914 if (octet_string_is_eq(srtp_ciphertext, rtp_plaintext_ref, len)) {
1915 return srtp_err_status_fail;
1916 }
1917
1918 /*
1919 * unprotect srtcp ciphertext, then compare with rtcp plaintext
1920 */
1921 len = 44;
1922 status = srtp_unprotect_rtcp(srtp_recv, srtcp_ciphertext, &len);
1923 if (status || (len != 24)) {
1924 return status;
1925 }
1926
1927 if (octet_string_is_eq(srtcp_ciphertext, rtcp_plaintext_ref, len)) {
Paul E. Jonese2ab5f22016-05-29 16:18:24 -04001928 return srtp_err_status_fail;
1929 }
1930
1931 status = srtp_dealloc(srtp_snd);
1932 if (status) {
1933 return status;
1934 }
1935
1936 status = srtp_dealloc(srtp_recv);
1937 if (status) {
1938 return status;
1939 }
1940
1941 return srtp_err_status_ok;
1942}
1943#endif
1944
Joachim Bauch99a74822015-11-17 00:08:19 +01001945/*
1946 * Test vectors taken from RFC 6904, Appendix A
1947 */
1948srtp_err_status_t
1949srtp_validate_encrypted_extensions_headers() {
1950 unsigned char test_key_ext_headers[30] = {
1951 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0,
1952 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde, 0x41, 0x39,
1953 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb,
1954 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
1955 };
1956 uint8_t srtp_plaintext_ref[56] = {
1957 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1958 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1959 0x17, 0x41, 0x42, 0x73, 0xA4, 0x75, 0x26, 0x27,
1960 0x48, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x8E, 0x46,
1961 0x55, 0x99, 0x63, 0x86, 0xB3, 0x95, 0xFB, 0x00,
1962 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1963 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab
1964 };
1965 uint8_t srtp_plaintext[66] = {
1966 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1967 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1968 0x17, 0x41, 0x42, 0x73, 0xA4, 0x75, 0x26, 0x27,
1969 0x48, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x8E, 0x46,
1970 0x55, 0x99, 0x63, 0x86, 0xB3, 0x95, 0xFB, 0x00,
1971 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1972 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
1973 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1974 0x00, 0x00
1975 };
1976 uint8_t srtp_ciphertext[66] = {
1977 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
1978 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
1979 0x17, 0x58, 0x8A, 0x92, 0x70, 0xF4, 0xE1, 0x5E,
1980 0x1C, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x95, 0x46,
1981 0xA9, 0x94, 0xF0, 0xBC, 0x54, 0x78, 0x97, 0x00,
1982 0x4e, 0x55, 0xdc, 0x4c, 0xe7, 0x99, 0x78, 0xd8,
1983 0x8c, 0xa4, 0xd2, 0x15, 0x94, 0x9d, 0x24, 0x02,
1984 0x5a, 0x46, 0xb3, 0xca, 0x35, 0xc5, 0x35, 0xa8,
1985 0x91, 0xc7
1986 };
1987 srtp_t srtp_snd, srtp_recv;
1988 srtp_err_status_t status;
1989 int len;
1990 srtp_policy_t policy;
1991 int headers[3] = {1, 3, 4};
1992
1993 /*
1994 * create a session with a single stream using the default srtp
1995 * policy and with the SSRC value 0xcafebabe
1996 */
1997 memset(&policy, 0, sizeof(policy));
1998 srtp_crypto_policy_set_rtp_default(&policy.rtp);
1999 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
2000 policy.ssrc.type = ssrc_specific;
2001 policy.ssrc.value = 0xcafebabe;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002002 policy.key = test_key_ext_headers;
Joachim Bauch99a74822015-11-17 00:08:19 +01002003 policy.ekt = NULL;
2004 policy.window_size = 128;
2005 policy.allow_repeat_tx = 0;
2006 policy.enc_xtn_hdr = headers;
2007 policy.enc_xtn_hdr_count = sizeof(headers) / sizeof(headers[0]);
2008 policy.next = NULL;
2009
2010 status = srtp_create(&srtp_snd, &policy);
2011 if (status)
2012 return status;
2013
2014 /*
2015 * protect plaintext, then compare with ciphertext
2016 */
2017 len = sizeof(srtp_plaintext_ref);
2018 status = srtp_protect(srtp_snd, srtp_plaintext, &len);
2019 if (status || (len != sizeof(srtp_plaintext)))
2020 return srtp_err_status_fail;
2021
2022 debug_print(mod_driver, "ciphertext:\n %s",
2023 srtp_octet_string_hex_string(srtp_plaintext, len));
2024 debug_print(mod_driver, "ciphertext reference:\n %s",
2025 srtp_octet_string_hex_string(srtp_ciphertext, len));
2026
2027 if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
2028 return srtp_err_status_fail;
2029
2030 /*
2031 * create a receiver session context comparable to the one created
2032 * above - we need to do this so that the replay checking doesn't
2033 * complain
2034 */
2035 status = srtp_create(&srtp_recv, &policy);
2036 if (status)
2037 return status;
2038
2039 /*
2040 * unprotect ciphertext, then compare with plaintext
2041 */
2042 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
Joachim Baucha9ecefe2015-12-14 21:40:42 +01002043 if (status) {
Joachim Bauch99a74822015-11-17 00:08:19 +01002044 return status;
Joachim Baucha9ecefe2015-12-14 21:40:42 +01002045 } else if (len != sizeof(srtp_plaintext_ref)) {
2046 return srtp_err_status_fail;
2047 }
Joachim Bauch99a74822015-11-17 00:08:19 +01002048
2049 if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
2050 return srtp_err_status_fail;
2051
2052 status = srtp_dealloc(srtp_snd);
2053 if (status)
2054 return status;
2055
2056 status = srtp_dealloc(srtp_recv);
2057 if (status)
2058 return status;
2059
2060 return srtp_err_status_ok;
2061}
2062
Cullen Jennings235513a2005-09-21 22:51:36 +00002063
Joachim Bauch80a45b52015-12-06 22:57:58 +01002064#ifdef OPENSSL
Joachim Baucha9ecefe2015-12-14 21:40:42 +01002065
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002066/*
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01002067 * Headers of test vectors taken from RFC 6904, Appendix A
2068 */
2069srtp_err_status_t
2070srtp_validate_encrypted_extensions_headers_gcm() {
2071 unsigned char test_key_ext_headers[30] = {
2072 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0,
2073 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde, 0x41, 0x39,
2074 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb,
2075 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
2076 };
2077 uint8_t srtp_plaintext_ref[56] = {
2078 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
2079 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
2080 0x17, 0x41, 0x42, 0x73, 0xA4, 0x75, 0x26, 0x27,
2081 0x48, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x8E, 0x46,
2082 0x55, 0x99, 0x63, 0x86, 0xB3, 0x95, 0xFB, 0x00,
2083 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
2084 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab
2085 };
2086 uint8_t srtp_plaintext[64] = {
2087 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
2088 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
2089 0x17, 0x41, 0x42, 0x73, 0xA4, 0x75, 0x26, 0x27,
2090 0x48, 0x22, 0x00, 0x00, 0xC8, 0x30, 0x8E, 0x46,
2091 0x55, 0x99, 0x63, 0x86, 0xB3, 0x95, 0xFB, 0x00,
2092 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
2093 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
2094 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2095 };
2096 uint8_t srtp_ciphertext[64] = {
2097 0x90, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
2098 0xca, 0xfe, 0xba, 0xbe, 0xBE, 0xDE, 0x00, 0x06,
Joachim Baucha3af4602017-03-30 23:51:08 +02002099 0x17, 0x12, 0xe0, 0x20, 0x5b, 0xfa, 0x94, 0x9b,
2100 0x1C, 0x22, 0x00, 0x00, 0xC8, 0x30, 0xbb, 0x46,
2101 0x73, 0x27, 0x78, 0xd9, 0x92, 0x9a, 0xab, 0x00,
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01002102 0x0e, 0xca, 0x0c, 0xf9, 0x5e, 0xe9, 0x55, 0xb2,
2103 0x6c, 0xd3, 0xd2, 0x88, 0xb4, 0x9f, 0x6c, 0xa9,
Joachim Baucha3af4602017-03-30 23:51:08 +02002104 0xf4, 0xb1, 0xb7, 0x59, 0x71, 0x9e, 0xb5, 0xbc
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01002105 };
2106 srtp_t srtp_snd, srtp_recv;
2107 srtp_err_status_t status;
2108 int len;
2109 srtp_policy_t policy;
2110 int headers[3] = {1, 3, 4};
2111
2112 /*
2113 * create a session with a single stream using the default srtp
2114 * policy and with the SSRC value 0xcafebabe
2115 */
2116 memset(&policy, 0, sizeof(policy));
2117 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtp);
2118 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtcp);
2119 policy.ssrc.type = ssrc_specific;
2120 policy.ssrc.value = 0xcafebabe;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002121 policy.key = test_key_ext_headers;
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01002122 policy.ekt = NULL;
2123 policy.window_size = 128;
2124 policy.allow_repeat_tx = 0;
2125 policy.enc_xtn_hdr = headers;
2126 policy.enc_xtn_hdr_count = sizeof(headers) / sizeof(headers[0]);
2127 policy.next = NULL;
2128
2129 status = srtp_create(&srtp_snd, &policy);
2130 if (status)
2131 return status;
2132
2133 /*
2134 * protect plaintext, then compare with ciphertext
2135 */
2136 len = sizeof(srtp_plaintext_ref);
2137 status = srtp_protect(srtp_snd, srtp_plaintext, &len);
2138 if (status || (len != sizeof(srtp_plaintext)))
2139 return srtp_err_status_fail;
2140
2141 debug_print(mod_driver, "ciphertext:\n %s",
2142 srtp_octet_string_hex_string(srtp_plaintext, len));
2143 debug_print(mod_driver, "ciphertext reference:\n %s",
2144 srtp_octet_string_hex_string(srtp_ciphertext, len));
2145
2146 if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
2147 return srtp_err_status_fail;
2148
2149 /*
2150 * create a receiver session context comparable to the one created
2151 * above - we need to do this so that the replay checking doesn't
2152 * complain
2153 */
2154 status = srtp_create(&srtp_recv, &policy);
2155 if (status)
2156 return status;
2157
2158 /*
2159 * unprotect ciphertext, then compare with plaintext
2160 */
2161 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
Joachim Baucha9ecefe2015-12-14 21:40:42 +01002162 if (status) {
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01002163 return status;
Joachim Baucha9ecefe2015-12-14 21:40:42 +01002164 } else if (len != sizeof(srtp_plaintext_ref)) {
2165 return srtp_err_status_fail;
2166 }
Joachim Bauchfa1e8c22015-11-24 23:38:48 +01002167
2168 if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
2169 return srtp_err_status_fail;
2170
2171 status = srtp_dealloc(srtp_snd);
2172 if (status)
2173 return status;
2174
2175 status = srtp_dealloc(srtp_recv);
2176 if (status)
2177 return status;
2178
2179 return srtp_err_status_ok;
2180}
Joachim Bauch80a45b52015-12-06 22:57:58 +01002181#endif
Cullen Jennings235513a2005-09-21 22:51:36 +00002182
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002183/*
2184 * srtp_validate_aes_256() verifies the correctness of libsrtp by comparing
2185 * some computed packets against some pre-computed reference values.
2186 * These packets were made with the AES-CM-256/HMAC-SHA-1-80 policy.
2187 */
2188
2189
jfigus857009c2014-11-05 11:17:43 -05002190srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05002191srtp_validate_aes_256 ()
2192{
2193 unsigned char aes_256_test_key[46] = {
2194 0xf0, 0xf0, 0x49, 0x14, 0xb5, 0x13, 0xf2, 0x76,
2195 0x3a, 0x1b, 0x1f, 0xa1, 0x30, 0xf1, 0x0e, 0x29,
2196 0x98, 0xf6, 0xf6, 0xe4, 0x3e, 0x43, 0x09, 0xd1,
2197 0xe6, 0x22, 0xa0, 0xe3, 0x32, 0xb9, 0xf1, 0xb6,
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002198
jfigus67b9c732014-11-20 10:17:21 -05002199 0x3b, 0x04, 0x80, 0x3d, 0xe5, 0x1e, 0xe7, 0xc9,
2200 0x64, 0x23, 0xab, 0x5b, 0x78, 0xd2
2201 };
2202 uint8_t srtp_plaintext_ref[28] = {
2203 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
2204 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
2205 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
2206 0xab, 0xab, 0xab, 0xab
2207 };
2208 uint8_t srtp_plaintext[38] = {
2209 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
2210 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
2211 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
2212 0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
2213 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2214 };
2215 uint8_t srtp_ciphertext[38] = {
2216 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
2217 0xca, 0xfe, 0xba, 0xbe, 0xf1, 0xd9, 0xde, 0x17,
2218 0xff, 0x25, 0x1f, 0xf1, 0xaa, 0x00, 0x77, 0x74,
2219 0xb0, 0xb4, 0xb4, 0x0d, 0xa0, 0x8d, 0x9d, 0x9a,
2220 0x5b, 0x3a, 0x55, 0xd8, 0x87, 0x3b
2221 };
2222 srtp_t srtp_snd, srtp_recv;
2223 srtp_err_status_t status;
2224 int len;
2225 srtp_policy_t policy;
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002226
jfigus67b9c732014-11-20 10:17:21 -05002227 /*
2228 * create a session with a single stream using the default srtp
2229 * policy and with the SSRC value 0xcafebabe
2230 */
Joachim Bauch99a74822015-11-17 00:08:19 +01002231 memset(&policy, 0, sizeof(policy));
jfigus67b9c732014-11-20 10:17:21 -05002232 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtp);
2233 srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtcp);
2234 policy.ssrc.type = ssrc_specific;
2235 policy.ssrc.value = 0xcafebabe;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002236 policy.key = aes_256_test_key;
jfigus67b9c732014-11-20 10:17:21 -05002237 policy.ekt = NULL;
2238 policy.window_size = 128;
2239 policy.allow_repeat_tx = 0;
2240 policy.next = NULL;
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002241
jfigus67b9c732014-11-20 10:17:21 -05002242 status = srtp_create(&srtp_snd, &policy);
2243 if (status) {
2244 return status;
2245 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002246
jfigus67b9c732014-11-20 10:17:21 -05002247 /*
2248 * protect plaintext, then compare with ciphertext
2249 */
2250 len = 28;
2251 status = srtp_protect(srtp_snd, srtp_plaintext, &len);
2252 if (status || (len != 38)) {
2253 return srtp_err_status_fail;
2254 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002255
jfigus67b9c732014-11-20 10:17:21 -05002256 debug_print(mod_driver, "ciphertext:\n %s",
2257 octet_string_hex_string(srtp_plaintext, len));
2258 debug_print(mod_driver, "ciphertext reference:\n %s",
2259 octet_string_hex_string(srtp_ciphertext, len));
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002260
jfigus67b9c732014-11-20 10:17:21 -05002261 if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) {
2262 return srtp_err_status_fail;
2263 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002264
jfigus67b9c732014-11-20 10:17:21 -05002265 /*
2266 * create a receiver session context comparable to the one created
2267 * above - we need to do this so that the replay checking doesn't
2268 * complain
2269 */
2270 status = srtp_create(&srtp_recv, &policy);
2271 if (status) {
2272 return status;
2273 }
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002274
jfigus67b9c732014-11-20 10:17:21 -05002275 /*
2276 * unprotect ciphertext, then compare with plaintext
2277 */
2278 status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
2279 if (status || (len != 28)) {
2280 return status;
2281 }
2282
2283 if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len)) {
2284 return srtp_err_status_fail;
2285 }
2286
2287 status = srtp_dealloc(srtp_snd);
2288 if (status) {
2289 return status;
2290 }
2291
2292 status = srtp_dealloc(srtp_recv);
2293 if (status) {
2294 return status;
2295 }
2296
2297 return srtp_err_status_ok;
Jonathan Lennox5df951a2010-05-20 20:55:54 +00002298}
2299
2300
jfigus857009c2014-11-05 11:17:43 -05002301srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05002302srtp_create_big_policy (srtp_policy_t **list)
2303{
2304 extern const srtp_policy_t *policy_array[];
2305 srtp_policy_t *p, *tmp;
2306 int i = 0;
2307 uint32_t ssrc = 0;
Cullen Jennings235513a2005-09-21 22:51:36 +00002308
jfigus67b9c732014-11-20 10:17:21 -05002309 /* sanity checking */
2310 if ((list == NULL) || (policy_array[0] == NULL)) {
2311 return srtp_err_status_bad_param;
2312 }
Cullen Jennings235513a2005-09-21 22:51:36 +00002313
jfigus67b9c732014-11-20 10:17:21 -05002314 /*
2315 * loop over policy list, mallocing a new list and copying values
2316 * into it (and incrementing the SSRC value as we go along)
2317 */
2318 tmp = NULL;
2319 while (policy_array[i] != NULL) {
2320 p = (srtp_policy_t*)malloc(sizeof(srtp_policy_t));
2321 if (p == NULL) {
2322 return srtp_err_status_bad_param;
2323 }
2324 memcpy(p, policy_array[i], sizeof(srtp_policy_t));
2325 p->ssrc.type = ssrc_specific;
2326 p->ssrc.value = ssrc++;
2327 p->next = tmp;
2328 tmp = p;
2329 i++;
2330 }
2331 *list = p;
2332
2333 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00002334}
2335
jfigus857009c2014-11-05 11:17:43 -05002336srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05002337srtp_dealloc_big_policy (srtp_policy_t *list)
2338{
2339 srtp_policy_t *p, *next;
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002340
jfigus67b9c732014-11-20 10:17:21 -05002341 for (p = list; p != NULL; p = next) {
2342 next = p->next;
2343 free(p);
2344 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002345
jfigus67b9c732014-11-20 10:17:21 -05002346 return srtp_err_status_ok;
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002347}
2348
Joachim Bauchc8a19ae2015-12-14 22:50:36 +01002349srtp_err_status_t
2350srtp_test_empty_payload()
2351{
2352 srtp_t srtp_snd, srtp_recv;
2353 srtp_err_status_t status;
2354 int len;
2355 srtp_policy_t policy;
2356 srtp_hdr_t *mesg;
2357
2358 /*
2359 * create a session with a single stream using the default srtp
2360 * policy and with the SSRC value 0xcafebabe
2361 */
2362 memset(&policy, 0, sizeof(policy));
2363 srtp_crypto_policy_set_rtp_default(&policy.rtp);
2364 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
2365 policy.ssrc.type = ssrc_specific;
2366 policy.ssrc.value = 0xcafebabe;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002367 policy.key = test_key;
Joachim Bauchc8a19ae2015-12-14 22:50:36 +01002368 policy.ekt = NULL;
2369 policy.window_size = 128;
2370 policy.allow_repeat_tx = 0;
2371 policy.next = NULL;
2372
2373 status = srtp_create(&srtp_snd, &policy);
2374 if (status) {
2375 return status;
2376 }
2377
2378 mesg = srtp_create_test_packet(0, policy.ssrc.value);
2379 if (mesg == NULL) {
2380 return srtp_err_status_fail;
2381 }
2382
2383 len = 12; /* only the header */
2384 status = srtp_protect(srtp_snd, mesg, &len);
2385 if (status) {
2386 return status;
2387 } else if (len != 12 + 10) {
2388 return srtp_err_status_fail;
2389 }
2390
2391 /*
2392 * create a receiver session context comparable to the one created
2393 * above - we need to do this so that the replay checking doesn't
2394 * complain
2395 */
2396 status = srtp_create(&srtp_recv, &policy);
2397 if (status) {
2398 return status;
2399 }
2400
2401 /*
2402 * unprotect ciphertext, then compare with plaintext
2403 */
2404 status = srtp_unprotect(srtp_recv, mesg, &len);
2405 if (status) {
2406 return status;
2407 } else if (len != 12) {
2408 return srtp_err_status_fail;
2409 }
2410
2411 status = srtp_dealloc(srtp_snd);
2412 if (status) {
2413 return status;
2414 }
2415
2416 status = srtp_dealloc(srtp_recv);
2417 if (status) {
2418 return status;
2419 }
2420
2421 free(mesg);
2422
2423 return srtp_err_status_ok;
2424}
2425
2426#ifdef OPENSSL
2427srtp_err_status_t
2428srtp_test_empty_payload_gcm()
2429{
2430 srtp_t srtp_snd, srtp_recv;
2431 srtp_err_status_t status;
2432 int len;
2433 srtp_policy_t policy;
2434 srtp_hdr_t *mesg;
2435
2436 /*
2437 * create a session with a single stream using the default srtp
2438 * policy and with the SSRC value 0xcafebabe
2439 */
2440 memset(&policy, 0, sizeof(policy));
2441 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtp);
2442 srtp_crypto_policy_set_aes_gcm_128_8_auth(&policy.rtcp);
2443 policy.ssrc.type = ssrc_specific;
2444 policy.ssrc.value = 0xcafebabe;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002445 policy.key = test_key;
Joachim Bauchc8a19ae2015-12-14 22:50:36 +01002446 policy.ekt = NULL;
2447 policy.window_size = 128;
2448 policy.allow_repeat_tx = 0;
2449 policy.next = NULL;
2450
2451 status = srtp_create(&srtp_snd, &policy);
2452 if (status) {
2453 return status;
2454 }
2455
2456 mesg = srtp_create_test_packet(0, policy.ssrc.value);
2457 if (mesg == NULL) {
2458 return srtp_err_status_fail;
2459 }
2460
2461 len = 12; /* only the header */
2462 status = srtp_protect(srtp_snd, mesg, &len);
2463 if (status) {
2464 return status;
2465 } else if (len != 12 + 8) {
2466 return srtp_err_status_fail;
2467 }
2468
2469 /*
2470 * create a receiver session context comparable to the one created
2471 * above - we need to do this so that the replay checking doesn't
2472 * complain
2473 */
2474 status = srtp_create(&srtp_recv, &policy);
2475 if (status) {
2476 return status;
2477 }
2478
2479 /*
2480 * unprotect ciphertext, then compare with plaintext
2481 */
2482 status = srtp_unprotect(srtp_recv, mesg, &len);
2483 if (status) {
2484 return status;
2485 } else if (len != 12) {
2486 return srtp_err_status_fail;
2487 }
2488
2489 status = srtp_dealloc(srtp_snd);
2490 if (status) {
2491 return status;
2492 }
2493
2494 status = srtp_dealloc(srtp_recv);
2495 if (status) {
2496 return status;
2497 }
2498
2499 free(mesg);
2500
2501 return srtp_err_status_ok;
2502}
2503#endif // OPENSSL
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002504
jfigus857009c2014-11-05 11:17:43 -05002505srtp_err_status_t
jfigus67b9c732014-11-20 10:17:21 -05002506srtp_test_remove_stream ()
2507{
2508 srtp_err_status_t status;
2509 srtp_policy_t *policy_list, policy;
2510 srtp_t session;
2511 srtp_stream_t stream;
Cullen Jennings235513a2005-09-21 22:51:36 +00002512
jfigus67b9c732014-11-20 10:17:21 -05002513 /*
2514 * srtp_get_stream() is a libSRTP internal function that we declare
2515 * here so that we can use it to verify the correct operation of the
2516 * library
2517 */
2518 extern srtp_stream_t srtp_get_stream(srtp_t srtp, uint32_t ssrc);
Cullen Jennings235513a2005-09-21 22:51:36 +00002519
Cullen Jennings235513a2005-09-21 22:51:36 +00002520
jfigus67b9c732014-11-20 10:17:21 -05002521 status = srtp_create_big_policy(&policy_list);
2522 if (status) {
2523 return status;
2524 }
Cullen Jennings235513a2005-09-21 22:51:36 +00002525
jfigus67b9c732014-11-20 10:17:21 -05002526 status = srtp_create(&session, policy_list);
2527 if (status) {
2528 return status;
2529 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002530
jfigus67b9c732014-11-20 10:17:21 -05002531 /*
2532 * check for false positives by trying to remove a stream that's not
2533 * in the session
2534 */
2535 status = srtp_remove_stream(session, htonl(0xaaaaaaaa));
2536 if (status != srtp_err_status_no_ctx) {
2537 return srtp_err_status_fail;
2538 }
Jonathan Lennox80c4c832010-05-17 19:30:28 +00002539
jfigus67b9c732014-11-20 10:17:21 -05002540 /*
2541 * check for false negatives by removing stream 0x1, then
2542 * searching for streams 0x0 and 0x2
2543 */
2544 status = srtp_remove_stream(session, htonl(0x1));
2545 if (status != srtp_err_status_ok) {
2546 return srtp_err_status_fail;
2547 }
2548 stream = srtp_get_stream(session, htonl(0x0));
2549 if (stream == NULL) {
2550 return srtp_err_status_fail;
2551 }
2552 stream = srtp_get_stream(session, htonl(0x2));
2553 if (stream == NULL) {
2554 return srtp_err_status_fail;
2555 }
Jonathan Lennoxad741b22010-05-27 19:23:05 +00002556
jfigus67b9c732014-11-20 10:17:21 -05002557 status = srtp_dealloc(session);
2558 if (status != srtp_err_status_ok) {
2559 return status;
2560 }
Jonathan Lennoxad741b22010-05-27 19:23:05 +00002561
jfigus67b9c732014-11-20 10:17:21 -05002562 status = srtp_dealloc_big_policy(policy_list);
2563 if (status != srtp_err_status_ok) {
2564 return status;
2565 }
Jonathan Lennoxad741b22010-05-27 19:23:05 +00002566
jfigus67b9c732014-11-20 10:17:21 -05002567 /* Now test adding and removing a single stream */
Joachim Bauch99a74822015-11-17 00:08:19 +01002568 memset(&policy, 0, sizeof(policy));
jfigus67b9c732014-11-20 10:17:21 -05002569 srtp_crypto_policy_set_rtp_default(&policy.rtp);
2570 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
2571 policy.ssrc.type = ssrc_specific;
2572 policy.ssrc.value = 0xcafebabe;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002573 policy.key = test_key;
jfigus67b9c732014-11-20 10:17:21 -05002574 policy.ekt = NULL;
2575 policy.window_size = 128;
2576 policy.allow_repeat_tx = 0;
2577 policy.next = NULL;
Jonathan Lennoxad741b22010-05-27 19:23:05 +00002578
jfigus67b9c732014-11-20 10:17:21 -05002579 status = srtp_create(&session, NULL);
2580 if (status != srtp_err_status_ok) {
2581 return status;
2582 }
2583
2584 status = srtp_add_stream(session, &policy);
2585 if (status != srtp_err_status_ok) {
2586 return status;
2587 }
2588
2589 status = srtp_remove_stream(session, htonl(0xcafebabe));
2590 if (status != srtp_err_status_ok) {
2591 return status;
2592 }
2593
2594 status = srtp_dealloc(session);
2595 if (status != srtp_err_status_ok) {
2596 return status;
2597 }
2598
2599 return srtp_err_status_ok;
Cullen Jennings235513a2005-09-21 22:51:36 +00002600}
2601
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002602
2603unsigned char test_alt_key[46] = {
2604 0xe5, 0x19, 0x6f, 0x01, 0x5e, 0xf1, 0x9b, 0xe1,
2605 0xd7, 0x47, 0xa7, 0x27, 0x07, 0xd7, 0x47, 0x33,
2606 0x01, 0xc2, 0x35, 0x4d, 0x59, 0x6a, 0xf7, 0x84,
2607 0x96, 0x98, 0xeb, 0xaa, 0xac, 0xf6, 0xa1, 0x45,
2608 0xc7, 0x15, 0xe2, 0xea, 0xfe, 0x55, 0x67, 0x96,
2609 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
2610};
2611
2612/*
2613 * srtp_test_update() verifies updating/rekeying exsisting streams.
2614 * As stated in https://tools.ietf.org/html/rfc3711#section-3.3.1
2615 * the value of the ROC must not be reset after a rekey, this test
2616 * atempts to prove that srtp_update does not reset the ROC.
2617 */
2618
2619srtp_err_status_t
2620srtp_test_update() {
2621
2622 srtp_err_status_t status;
2623 uint32_t ssrc = 0x12121212;
2624 int msg_len_octets = 32;
2625 int protected_msg_len_octets;
2626 srtp_hdr_t * msg;
2627 srtp_t srtp_snd, srtp_recv;
2628 srtp_policy_t policy;
2629
Joachim Bauch1b793352015-12-14 21:30:44 +01002630 memset(&policy, 0, sizeof(policy));
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002631 srtp_crypto_policy_set_rtp_default(&policy.rtp);
2632 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
2633 policy.ekt = NULL;
2634 policy.window_size = 128;
2635 policy.allow_repeat_tx = 0;
2636 policy.next = NULL;
2637 policy.ssrc.type = ssrc_any_outbound;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002638 policy.key = test_key;
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002639
2640 /* create a send and recive ctx with defualt profile and test_key */
2641 status = srtp_create(&srtp_recv, &policy);
2642 if (status)
2643 return status;
2644
2645 policy.ssrc.type = ssrc_any_inbound;
2646 status = srtp_create(&srtp_snd, &policy);
2647 if (status)
2648 return status;
2649
2650 /* protect and unprotect two msg's that will cause the ROC to be equal to 1 */
2651 msg = srtp_create_test_packet(msg_len_octets, ssrc);
2652 if (msg == NULL)
2653 return srtp_err_status_alloc_fail;
2654 msg->seq = htons(65535);
2655
2656 protected_msg_len_octets = msg_len_octets;
2657 status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets);
2658 if (status)
2659 return srtp_err_status_fail;
2660
2661 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2662 if (status)
2663 return status;
2664
2665 free(msg);
2666
2667 msg = srtp_create_test_packet(msg_len_octets, ssrc);
2668 if (msg == NULL)
2669 return srtp_err_status_alloc_fail;
2670 msg->seq = htons(1);
2671
2672 protected_msg_len_octets = msg_len_octets;
2673 status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets);
2674 if (status)
2675 return srtp_err_status_fail;
2676
2677 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2678 if (status)
2679 return status;
2680
2681 free(msg);
2682
Pascal Bühlerb095e7e2016-06-09 13:46:28 +02002683 /* update send ctx with same test_key t verify update works*/
2684 policy.ssrc.type = ssrc_any_outbound;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002685 policy.key = test_key;
Pascal Bühlerb095e7e2016-06-09 13:46:28 +02002686 status = srtp_update(srtp_snd, &policy);
2687 if (status)
2688 return status;
2689
2690 msg = srtp_create_test_packet(msg_len_octets, ssrc);
2691 if (msg == NULL)
2692 return srtp_err_status_alloc_fail;
2693 msg->seq = htons(2);
2694
2695 protected_msg_len_octets = msg_len_octets;
2696 status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets);
2697 if (status)
2698 return srtp_err_status_fail;
2699
2700 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2701 if (status)
2702 return status;
2703
2704 free(msg);
2705
2706
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002707 /* update send ctx to use test_alt_key */
2708 policy.ssrc.type = ssrc_any_outbound;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002709 policy.key = test_alt_key;
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002710 status = srtp_update(srtp_snd, &policy);
2711 if (status)
2712 return status;
2713
2714 /* create and protect msg with new key and ROC still equal to 1 */
2715 msg = srtp_create_test_packet(msg_len_octets, ssrc);
2716 if (msg == NULL)
2717 return srtp_err_status_alloc_fail;
Pascal Bühlerb095e7e2016-06-09 13:46:28 +02002718 msg->seq = htons(3);
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002719
2720 protected_msg_len_octets = msg_len_octets;
2721 status = srtp_protect(srtp_snd, msg, &protected_msg_len_octets);
2722 if (status)
2723 return srtp_err_status_fail;
2724
2725 /* verify that recive ctx will fail to unprotect as it still uses test_key */
2726 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2727 if (status == srtp_err_status_ok)
2728 return srtp_err_status_fail;
2729
2730 /* create a new recvieve ctx with test_alt_key but since it is new it will have ROC equal to 1
2731 * and therefore should fail to unprotected */
2732 {
2733 srtp_t srtp_recv_roc_0;
2734
2735 policy.ssrc.type = ssrc_any_inbound;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002736 policy.key = test_alt_key;
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002737 status = srtp_create(&srtp_recv_roc_0, &policy);
2738 if (status)
2739 return status;
2740
2741 status = srtp_unprotect(srtp_recv_roc_0, msg, &protected_msg_len_octets);
2742 if (status == srtp_err_status_ok)
2743 return srtp_err_status_fail;
2744
2745 status = srtp_dealloc(srtp_recv_roc_0);
2746 if (status)
2747 return status;
2748 }
2749
2750 /* update recive ctx to use test_alt_key */
2751 policy.ssrc.type = ssrc_any_inbound;
Ryan Hooper89a288b2016-12-22 16:22:47 -05002752 policy.key = test_alt_key;
Pascal Bühlerbd3112a2015-11-06 20:29:15 +01002753 status = srtp_update(srtp_recv, &policy);
2754 if (status)
2755 return status;
2756
2757 /* verify that can still unprotect, therfore key is updated and ROC value is preserved */
2758 status = srtp_unprotect(srtp_recv, msg, &protected_msg_len_octets);
2759 if (status)
2760 return status;
2761
2762 free(msg);
2763
2764 status = srtp_dealloc(srtp_snd);
2765 if (status)
2766 return status;
2767
2768 status = srtp_dealloc(srtp_recv);
2769 if (status)
2770 return status;
2771
2772 return srtp_err_status_ok;
2773}
2774
Ryan Hooperab0345b2017-02-07 16:07:59 -05002775srtp_err_status_t
2776srtp_test_setup_protect_trailer_streams(srtp_t *srtp_send, srtp_t *srtp_send_mki,
2777 srtp_t *srtp_send_aes_gcm, srtp_t *srtp_send_aes_gcm_mki) {
2778
2779 srtp_err_status_t status;
2780 srtp_policy_t policy;
2781 srtp_policy_t policy_mki;
2782#ifdef OPENSSL
2783 srtp_policy_t policy_aes_gcm;
2784 srtp_policy_t policy_aes_gcm_mki;
2785#endif // OPENSSL
2786
2787 memset(&policy, 0, sizeof(policy));
2788 srtp_crypto_policy_set_rtp_default(&policy.rtp);
2789 srtp_crypto_policy_set_rtcp_default(&policy.rtcp);
2790 policy.ekt = NULL;
2791 policy.window_size = 128;
2792 policy.allow_repeat_tx = 0;
2793 policy.next = NULL;
2794 policy.ssrc.type = ssrc_any_outbound;
2795 policy.key = test_key;
2796
2797 memset(&policy_mki, 0, sizeof(policy_mki));
2798 srtp_crypto_policy_set_rtp_default(&policy_mki.rtp);
2799 srtp_crypto_policy_set_rtcp_default(&policy_mki.rtcp);
2800 policy_mki.ekt = NULL;
2801 policy_mki.window_size = 128;
2802 policy_mki.allow_repeat_tx = 0;
2803 policy_mki.next = NULL;
2804 policy_mki.ssrc.type = ssrc_any_outbound;
2805 policy_mki.key = NULL;
2806 policy_mki.keys = test_keys;
2807 policy_mki.num_master_keys = 2;
2808
2809#ifdef OPENSSL
2810 memset(&policy_aes_gcm, 0, sizeof(policy_aes_gcm));
2811 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy_aes_gcm.rtp);
2812 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy_aes_gcm.rtcp);
2813 policy_aes_gcm.ekt = NULL;
2814 policy_aes_gcm.window_size = 128;
2815 policy_aes_gcm.allow_repeat_tx = 0;
2816 policy_aes_gcm.next = NULL;
2817 policy_aes_gcm.ssrc.type = ssrc_any_outbound;
2818 policy_aes_gcm.key = test_key;
2819
2820 memset(&policy_aes_gcm_mki, 0, sizeof(policy_aes_gcm_mki));
2821 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy_aes_gcm_mki.rtp);
2822 srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy_aes_gcm_mki.rtcp);
2823 policy_aes_gcm_mki.ekt = NULL;
2824 policy_aes_gcm_mki.window_size = 128;
2825 policy_aes_gcm_mki.allow_repeat_tx = 0;
2826 policy_aes_gcm_mki.next = NULL;
2827 policy_aes_gcm_mki.ssrc.type = ssrc_any_outbound;
2828 policy_aes_gcm_mki.key = NULL;
2829 policy_aes_gcm_mki.keys = test_keys;
2830 policy_aes_gcm_mki.num_master_keys = 2;
2831
2832#endif
2833
2834 /* create a send ctx with defualt profile and test_key */
2835 status = srtp_create(srtp_send, &policy);
2836 if (status)
2837 return status;
2838
2839 status = srtp_create(srtp_send_mki, &policy_mki);
2840 if (status)
2841 return status;
2842
2843#ifdef OPENSSL
2844 status = srtp_create(srtp_send_aes_gcm, &policy_aes_gcm);
2845 if (status)
2846 return status;
2847
2848 status = srtp_create(srtp_send_aes_gcm_mki, &policy_aes_gcm_mki);
2849 if (status)
2850 return status;
2851#endif //OPENSSL
2852
2853 return srtp_err_status_ok;
2854}
2855
2856srtp_err_status_t
2857srtp_test_protect_trailer_length() {
2858
2859 srtp_t srtp_send;
2860 srtp_t srtp_send_mki;
2861 srtp_t srtp_send_aes_gcm;
2862 srtp_t srtp_send_aes_gcm_mki;
2863 uint32_t length = 0;
2864 srtp_err_status_t status;
2865
2866 srtp_test_setup_protect_trailer_streams(&srtp_send, &srtp_send_mki,
2867 &srtp_send_aes_gcm, &srtp_send_aes_gcm_mki);
2868
2869 status = srtp_get_protect_trailer_length(srtp_send, 0, 0, &length);
2870 if (status)
2871 return status;
2872
2873 /* TAG Length: 10 bytes */
2874 if (length != 10)
2875 return srtp_err_status_fail;
2876
2877 status = srtp_get_protect_trailer_length(srtp_send_mki, 1, 1, &length);
2878 if (status)
2879 return status;
2880
2881 /* TAG Length: 10 bytes + MKI length: 4 bytes*/
2882 if (length != 14)
2883 return srtp_err_status_fail;
2884
2885#ifdef OPENSSL
2886 status = srtp_get_protect_trailer_length(srtp_send_aes_gcm, 0, 0, &length);
2887 if (status)
2888 return status;
2889
2890 /* TAG Length: 16 bytes */
2891 if (length != 16)
2892 return srtp_err_status_fail;
2893
2894
2895 status = srtp_get_protect_trailer_length(srtp_send_aes_gcm_mki, 1, 1, &length);
2896 if (status)
2897 return status;
2898
2899 /* TAG Length: 16 bytes + MKI length: 4 bytes*/
2900 if (length != 20)
2901 return srtp_err_status_fail;
2902
2903#endif //OPENSSL
2904
2905 return srtp_err_status_ok;
2906}
2907
2908srtp_err_status_t
2909srtp_test_protect_rtcp_trailer_length() {
2910
2911 srtp_t srtp_send;
2912 srtp_t srtp_send_mki;
2913 srtp_t srtp_send_aes_gcm;
2914 srtp_t srtp_send_aes_gcm_mki;
2915 uint32_t length = 0;
2916 srtp_err_status_t status;
2917
2918 srtp_test_setup_protect_trailer_streams(&srtp_send, &srtp_send_mki,
2919 &srtp_send_aes_gcm, &srtp_send_aes_gcm_mki);
2920
2921 status = srtp_get_protect_rtcp_trailer_length(srtp_send, 0, 0, &length);
2922 if (status)
2923 return status;
2924
2925 /* TAG Length: 10 bytes + SRTCP Trailer 4 bytes*/
2926 if (length != 14)
2927 return srtp_err_status_fail;
2928
2929 status = srtp_get_protect_rtcp_trailer_length(srtp_send_mki, 1, 1, &length);
2930 if (status)
2931 return status;
2932
2933 /* TAG Length: 10 bytes + SRTCP Trailer 4 bytes + MKI 4 bytes*/
2934 if (length != 18)
2935 return srtp_err_status_fail;
2936
2937#ifdef OPENSSL
2938 status = srtp_get_protect_rtcp_trailer_length(srtp_send_aes_gcm, 0, 0, &length);
2939 if (status)
2940 return status;
2941
2942 /* TAG Length: 16 bytes + SRTCP Trailer 4 bytes*/
2943 if (length != 20)
2944 return srtp_err_status_fail;
2945
2946
2947 status = srtp_get_protect_rtcp_trailer_length(srtp_send_aes_gcm_mki, 1, 1, &length);
2948 if (status)
2949 return status;
2950
2951 /* TAG Length: 16 bytes + SRTCP Trailer 4 bytes + MKI 4 bytes*/
2952 if (length != 24)
2953 return srtp_err_status_fail;
2954
2955#endif //OPENSSL
2956
2957 return srtp_err_status_ok;
2958}
2959
2960
Cullen Jennings235513a2005-09-21 22:51:36 +00002961/*
2962 * srtp policy definitions - these definitions are used above
2963 */
2964
jfigus8c36da22013-10-01 16:41:19 -04002965unsigned char test_key[46] = {
Cullen Jennings235513a2005-09-21 22:51:36 +00002966 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0,
2967 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde, 0x41, 0x39,
2968 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb,
jfigus8c36da22013-10-01 16:41:19 -04002969 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6, 0xc1, 0x73,
2970 0xc3, 0x17, 0xf2, 0xda, 0xbe, 0x35, 0x77, 0x93,
Cullen Jennings235513a2005-09-21 22:51:36 +00002971 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
2972};
2973
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05002974unsigned char test_key_2[46] = {
2975 0xf0, 0xf0, 0x49, 0x14, 0xb5, 0x13, 0xf2, 0x76,
2976 0x3a, 0x1b, 0x1f, 0xa1, 0x30, 0xf1, 0x0e, 0x29,
2977 0x98, 0xf6, 0xf6, 0xe4, 0x3e, 0x43, 0x09, 0xd1,
2978 0xe6, 0x22, 0xa0, 0xe3, 0x32, 0xb9, 0xf1, 0xb6,
2979 0xc3, 0x17, 0xf2, 0xda, 0xbe, 0x35, 0x77, 0x93,
2980 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
2981};
Cullen Jennings235513a2005-09-21 22:51:36 +00002982
Ryan Hooper89a288b2016-12-22 16:22:47 -05002983unsigned char test_mki_id[TEST_MKI_ID_SIZE] = {
2984 0xe1, 0xf9, 0x7a, 0x0d
2985};
2986
2987unsigned char test_mki_id_2[TEST_MKI_ID_SIZE] = {
2988 0xf3, 0xa1, 0x46, 0x71
2989};
2990
Cullen Jennings235513a2005-09-21 22:51:36 +00002991const srtp_policy_t default_policy = {
jfigus67b9c732014-11-20 10:17:21 -05002992 { ssrc_any_outbound, 0 }, /* SSRC */
2993 { /* SRTP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01002994 SRTP_AES_ICM_128, /* cipher type */
Pascal Bühler14df3db2017-03-13 09:50:43 +01002995 SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05002996 SRTP_HMAC_SHA1, /* authentication func type */
2997 16, /* auth key length in octets */
2998 10, /* auth tag length in octets */
2999 sec_serv_conf_and_auth /* security services flag */
3000 },
3001 { /* SRTCP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003002 SRTP_AES_ICM_128, /* cipher type */
Pascal Bühler14df3db2017-03-13 09:50:43 +01003003 SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003004 SRTP_HMAC_SHA1, /* authentication func type */
3005 16, /* auth key length in octets */
3006 10, /* auth tag length in octets */
3007 sec_serv_conf_and_auth /* security services flag */
3008 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003009 NULL,
3010 (srtp_master_key_t **)test_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003011 2, /* indicates the number of Master keys */
jfigus67b9c732014-11-20 10:17:21 -05003012 NULL, /* indicates that EKT is not in use */
3013 128, /* replay window size */
3014 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003015 NULL, /* no encrypted extension headers */
3016 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05003017 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00003018};
3019
3020const srtp_policy_t aes_only_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003021 { ssrc_any_outbound, 0 }, /* SSRC */
3022 {
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003023 SRTP_AES_ICM_128, /* cipher type */
Pascal Bühler14df3db2017-03-13 09:50:43 +01003024 SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003025 SRTP_NULL_AUTH, /* authentication func type */
3026 0, /* auth key length in octets */
3027 0, /* auth tag length in octets */
3028 sec_serv_conf /* security services flag */
3029 },
3030 {
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003031 SRTP_AES_ICM_128, /* cipher type */
Pascal Bühler14df3db2017-03-13 09:50:43 +01003032 SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003033 SRTP_NULL_AUTH, /* authentication func type */
3034 0, /* auth key length in octets */
3035 0, /* auth tag length in octets */
3036 sec_serv_conf /* security services flag */
3037 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003038 NULL,
3039 (srtp_master_key_t **)test_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003040 2, /* indicates the number of Master keys */
jfigus67b9c732014-11-20 10:17:21 -05003041 NULL, /* indicates that EKT is not in use */
3042 128, /* replay window size */
3043 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003044 NULL, /* no encrypted extension headers */
3045 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05003046 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00003047};
3048
3049const srtp_policy_t hmac_only_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003050 { ssrc_any_outbound, 0 }, /* SSRC */
3051 {
3052 SRTP_NULL_CIPHER, /* cipher type */
3053 0, /* cipher key length in octets */
3054 SRTP_HMAC_SHA1, /* authentication func type */
3055 20, /* auth key length in octets */
3056 4, /* auth tag length in octets */
3057 sec_serv_auth /* security services flag */
3058 },
3059 {
3060 SRTP_NULL_CIPHER, /* cipher type */
3061 0, /* cipher key length in octets */
3062 SRTP_HMAC_SHA1, /* authentication func type */
3063 20, /* auth key length in octets */
3064 4, /* auth tag length in octets */
3065 sec_serv_auth /* security services flag */
3066 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003067 NULL,
3068 (srtp_master_key_t **)test_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003069 2, /* Number of Master keys associated with the policy */
jfigus67b9c732014-11-20 10:17:21 -05003070 NULL, /* indicates that EKT is not in use */
3071 128, /* replay window size */
3072 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003073 NULL, /* no encrypted extension headers */
3074 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05003075 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00003076};
3077
jfigus8c36da22013-10-01 16:41:19 -04003078#ifdef OPENSSL
3079const srtp_policy_t aes128_gcm_8_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003080 { ssrc_any_outbound, 0 }, /* SSRC */
3081 { /* SRTP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003082 SRTP_AES_GCM_128, /* cipher type */
Pascal Bühler20e66122017-03-13 09:09:36 +01003083 SRTP_AES_GCM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003084 SRTP_NULL_AUTH, /* authentication func type */
3085 0, /* auth key length in octets */
3086 8, /* auth tag length in octets */
3087 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04003088 },
jfigus67b9c732014-11-20 10:17:21 -05003089 { /* SRTCP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003090 SRTP_AES_GCM_128, /* cipher type */
Pascal Bühler20e66122017-03-13 09:09:36 +01003091 SRTP_AES_GCM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003092 SRTP_NULL_AUTH, /* authentication func type */
3093 0, /* auth key length in octets */
3094 8, /* auth tag length in octets */
3095 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04003096 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003097 NULL,
3098 (srtp_master_key_t **)test_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003099 2, /* indicates the number of Master keys */
jfigus8c36da22013-10-01 16:41:19 -04003100 NULL, /* indicates that EKT is not in use */
3101 128, /* replay window size */
3102 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003103 NULL, /* no encrypted extension headers */
3104 0, /* list of encrypted extension headers is empty */
jfigus8c36da22013-10-01 16:41:19 -04003105 NULL
3106};
3107
3108const srtp_policy_t aes128_gcm_8_cauth_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003109 { ssrc_any_outbound, 0 }, /* SSRC */
3110 { /* SRTP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003111 SRTP_AES_GCM_128, /* cipher type */
Pascal Bühler20e66122017-03-13 09:09:36 +01003112 SRTP_AES_GCM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003113 SRTP_NULL_AUTH, /* authentication func type */
3114 0, /* auth key length in octets */
3115 8, /* auth tag length in octets */
3116 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04003117 },
jfigus67b9c732014-11-20 10:17:21 -05003118 { /* SRTCP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003119 SRTP_AES_GCM_128, /* cipher type */
Pascal Bühler20e66122017-03-13 09:09:36 +01003120 SRTP_AES_GCM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003121 SRTP_NULL_AUTH, /* authentication func type */
3122 0, /* auth key length in octets */
3123 8, /* auth tag length in octets */
3124 sec_serv_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04003125 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003126 NULL,
Ryan Hooper6c339f72017-01-03 13:45:18 -05003127 (srtp_master_key_t **)test_keys,
3128 2, /* indicates the number of Master keys */
jfigus8c36da22013-10-01 16:41:19 -04003129 NULL, /* indicates that EKT is not in use */
3130 128, /* replay window size */
3131 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003132 NULL, /* no encrypted extension headers */
3133 0, /* list of encrypted extension headers is empty */
jfigus8c36da22013-10-01 16:41:19 -04003134 NULL
3135};
jfigus67b9c732014-11-20 10:17:21 -05003136
jfigus8c36da22013-10-01 16:41:19 -04003137const srtp_policy_t aes256_gcm_8_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003138 { ssrc_any_outbound, 0 }, /* SSRC */
3139 { /* SRTP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003140 SRTP_AES_GCM_256, /* cipher type */
Pascal Bühler20e66122017-03-13 09:09:36 +01003141 SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003142 SRTP_NULL_AUTH, /* authentication func type */
3143 0, /* auth key length in octets */
3144 8, /* auth tag length in octets */
3145 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04003146 },
jfigus67b9c732014-11-20 10:17:21 -05003147 { /* SRTCP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003148 SRTP_AES_GCM_256, /* cipher type */
Pascal Bühler20e66122017-03-13 09:09:36 +01003149 SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003150 SRTP_NULL_AUTH, /* authentication func type */
3151 0, /* auth key length in octets */
3152 8, /* auth tag length in octets */
3153 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04003154 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003155 NULL,
3156 (srtp_master_key_t **)test_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003157 2, /* indicates the number of Master keys */
jfigus8c36da22013-10-01 16:41:19 -04003158 NULL, /* indicates that EKT is not in use */
3159 128, /* replay window size */
3160 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003161 NULL, /* no encrypted extension headers */
3162 0, /* list of encrypted extension headers is empty */
jfigus8c36da22013-10-01 16:41:19 -04003163 NULL
3164};
jfigus67b9c732014-11-20 10:17:21 -05003165
jfigus8c36da22013-10-01 16:41:19 -04003166const srtp_policy_t aes256_gcm_8_cauth_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003167 { ssrc_any_outbound, 0 }, /* SSRC */
3168 { /* SRTP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003169 SRTP_AES_GCM_256, /* cipher type */
Pascal Bühler20e66122017-03-13 09:09:36 +01003170 SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003171 SRTP_NULL_AUTH, /* authentication func type */
3172 0, /* auth key length in octets */
3173 8, /* auth tag length in octets */
3174 sec_serv_conf_and_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04003175 },
jfigus67b9c732014-11-20 10:17:21 -05003176 { /* SRTCP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003177 SRTP_AES_GCM_256, /* cipher type */
Pascal Bühler20e66122017-03-13 09:09:36 +01003178 SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003179 SRTP_NULL_AUTH, /* authentication func type */
3180 0, /* auth key length in octets */
3181 8, /* auth tag length in octets */
3182 sec_serv_auth /* security services flag */
jfigus8c36da22013-10-01 16:41:19 -04003183 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003184 NULL,
3185 (srtp_master_key_t **)test_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003186 2, /* indicates the number of Master keys */
jfigus8c36da22013-10-01 16:41:19 -04003187 NULL, /* indicates that EKT is not in use */
3188 128, /* replay window size */
3189 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003190 NULL, /* no encrypted extension headers */
3191 0, /* list of encrypted extension headers is empty */
jfigus8c36da22013-10-01 16:41:19 -04003192 NULL
3193};
3194#endif
3195
Cullen Jennings235513a2005-09-21 22:51:36 +00003196const srtp_policy_t null_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003197 { ssrc_any_outbound, 0 }, /* SSRC */
3198 {
3199 SRTP_NULL_CIPHER, /* cipher type */
3200 0, /* cipher key length in octets */
3201 SRTP_NULL_AUTH, /* authentication func type */
3202 0, /* auth key length in octets */
3203 0, /* auth tag length in octets */
3204 sec_serv_none /* security services flag */
3205 },
3206 {
3207 SRTP_NULL_CIPHER, /* cipher type */
3208 0, /* cipher key length in octets */
3209 SRTP_NULL_AUTH, /* authentication func type */
3210 0, /* auth key length in octets */
3211 0, /* auth tag length in octets */
3212 sec_serv_none /* security services flag */
3213 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003214 NULL,
3215 (srtp_master_key_t **)test_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003216 2, /* indicates the number of Master keys */
jfigus67b9c732014-11-20 10:17:21 -05003217 NULL, /* indicates that EKT is not in use */
3218 128, /* replay window size */
3219 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003220 NULL, /* no encrypted extension headers */
3221 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05003222 NULL
David McGrew79870d62007-06-15 18:17:39 +00003223};
3224
Jonathan Lennox5df951a2010-05-20 20:55:54 +00003225unsigned char test_256_key[46] = {
jfigus67b9c732014-11-20 10:17:21 -05003226 0xf0, 0xf0, 0x49, 0x14, 0xb5, 0x13, 0xf2, 0x76,
3227 0x3a, 0x1b, 0x1f, 0xa1, 0x30, 0xf1, 0x0e, 0x29,
3228 0x98, 0xf6, 0xf6, 0xe4, 0x3e, 0x43, 0x09, 0xd1,
3229 0xe6, 0x22, 0xa0, 0xe3, 0x32, 0xb9, 0xf1, 0xb6,
Jonathan Lennox5df951a2010-05-20 20:55:54 +00003230
jfigus67b9c732014-11-20 10:17:21 -05003231 0x3b, 0x04, 0x80, 0x3d, 0xe5, 0x1e, 0xe7, 0xc9,
3232 0x64, 0x23, 0xab, 0x5b, 0x78, 0xd2
Jonathan Lennox5df951a2010-05-20 20:55:54 +00003233};
3234
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003235unsigned char test_256_key_2[46] = {
3236 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0,
3237 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde, 0x41, 0x39,
3238 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb,
3239 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6, 0xc1, 0x73,
3240 0x3b, 0x04, 0x80, 0x3d, 0xe5, 0x1e, 0xe7, 0xc9,
3241 0x64, 0x23, 0xab, 0x5b, 0x78, 0xd2
3242};
3243
Ryan Hooper89a288b2016-12-22 16:22:47 -05003244srtp_master_key_t master_256_key_1 = {
3245 test_256_key,
3246 test_mki_id,
3247 TEST_MKI_ID_SIZE
3248};
3249
3250srtp_master_key_t master_256_key_2 = {
3251 test_256_key_2,
3252 test_mki_id_2,
3253 TEST_MKI_ID_SIZE
3254};
3255
3256srtp_master_key_t *test_256_keys[2] = {
3257 &master_key_1,
3258 &master_key_2
3259};
3260
Jonathan Lennox5df951a2010-05-20 20:55:54 +00003261const srtp_policy_t aes_256_hmac_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003262 { ssrc_any_outbound, 0 }, /* SSRC */
3263 { /* SRTP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003264 SRTP_AES_ICM_256, /* cipher type */
Pascal Bühler14df3db2017-03-13 09:50:43 +01003265 SRTP_AES_ICM_256_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003266 SRTP_HMAC_SHA1, /* authentication func type */
3267 20, /* auth key length in octets */
3268 10, /* auth tag length in octets */
3269 sec_serv_conf_and_auth /* security services flag */
3270 },
3271 { /* SRTCP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003272 SRTP_AES_ICM_256, /* cipher type */
Pascal Bühler14df3db2017-03-13 09:50:43 +01003273 SRTP_AES_ICM_256_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003274 SRTP_HMAC_SHA1, /* authentication func type */
3275 20, /* auth key length in octets */
3276 10, /* auth tag length in octets */
3277 sec_serv_conf_and_auth /* security services flag */
3278 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003279 NULL,
3280 (srtp_master_key_t **)test_256_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003281 2, /* indicates the number of Master keys */
jfigus67b9c732014-11-20 10:17:21 -05003282 NULL, /* indicates that EKT is not in use */
3283 128, /* replay window size */
3284 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003285 NULL, /* no encrypted extension headers */
3286 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05003287 NULL
Jonathan Lennox5df951a2010-05-20 20:55:54 +00003288};
3289
David McGrew79870d62007-06-15 18:17:39 +00003290uint8_t ekt_test_key[16] = {
jfigus67b9c732014-11-20 10:17:21 -05003291 0x77, 0x26, 0x9d, 0xac, 0x16, 0xa3, 0x28, 0xca,
3292 0x8e, 0xc9, 0x68, 0x4b, 0xcc, 0xc4, 0xd2, 0x1b
David McGrew79870d62007-06-15 18:17:39 +00003293};
3294
3295#include "ekt.h"
3296
jfigusc5887e72014-11-06 09:46:18 -05003297srtp_ekt_policy_ctx_t ekt_test_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003298 0xa5a5, /* SPI */
3299 SRTP_EKT_CIPHER_AES_128_ECB,
3300 ekt_test_key,
3301 NULL
David McGrew79870d62007-06-15 18:17:39 +00003302};
3303
3304const srtp_policy_t hmac_only_with_ekt_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003305 { ssrc_any_outbound, 0 }, /* SSRC */
3306 {
3307 SRTP_NULL_CIPHER, /* cipher type */
3308 0, /* cipher key length in octets */
3309 SRTP_HMAC_SHA1, /* authentication func type */
3310 20, /* auth key length in octets */
3311 4, /* auth tag length in octets */
3312 sec_serv_auth /* security services flag */
3313 },
3314 {
3315 SRTP_NULL_CIPHER, /* cipher type */
3316 0, /* cipher key length in octets */
3317 SRTP_HMAC_SHA1, /* authentication func type */
3318 20, /* auth key length in octets */
3319 4, /* auth tag length in octets */
3320 sec_serv_auth /* security services flag */
3321 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003322 NULL,
3323 (srtp_master_key_t **)test_keys,
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05003324 2, /* indicates the number of Master keys */
jfigus67b9c732014-11-20 10:17:21 -05003325 &ekt_test_policy, /* indicates that EKT is not in use */
3326 128, /* replay window size */
3327 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003328 NULL, /* no encrypted extension headers */
3329 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05003330 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00003331};
3332
3333
3334/*
3335 * an array of pointers to the policies listed above
3336 *
3337 * This array is used to test various aspects of libSRTP for
3338 * different cryptographic policies. The order of the elements
3339 * matters - the timing test generates output that can be used
jfigus67b9c732014-11-20 10:17:21 -05003340 * in a plot (see the gnuplot script file 'timing'). If you
Cullen Jennings235513a2005-09-21 22:51:36 +00003341 * add to this list, you should do it at the end.
3342 */
3343
Cullen Jennings235513a2005-09-21 22:51:36 +00003344const srtp_policy_t *
3345policy_array[] = {
jfigus67b9c732014-11-20 10:17:21 -05003346 &hmac_only_policy,
3347 &aes_only_policy,
3348 &default_policy,
jfigus8c36da22013-10-01 16:41:19 -04003349#ifdef OPENSSL
jfigus67b9c732014-11-20 10:17:21 -05003350 &aes128_gcm_8_policy,
3351 &aes128_gcm_8_cauth_policy,
3352 &aes256_gcm_8_policy,
3353 &aes256_gcm_8_cauth_policy,
jfigus8c36da22013-10-01 16:41:19 -04003354#endif
jfigus67b9c732014-11-20 10:17:21 -05003355 &null_policy,
3356 &aes_256_hmac_policy,
3357 &hmac_only_with_ekt_policy,
3358 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00003359};
3360
3361const srtp_policy_t wildcard_policy = {
jfigus67b9c732014-11-20 10:17:21 -05003362 { ssrc_any_outbound, 0 }, /* SSRC */
3363 { /* SRTP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003364 SRTP_AES_ICM_128, /* cipher type */
Pascal Bühler14df3db2017-03-13 09:50:43 +01003365 SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003366 SRTP_HMAC_SHA1, /* authentication func type */
3367 16, /* auth key length in octets */
3368 10, /* auth tag length in octets */
3369 sec_serv_conf_and_auth /* security services flag */
3370 },
3371 { /* SRTCP policy */
Pascal Bühlerd335bd82017-02-23 09:56:17 +01003372 SRTP_AES_ICM_128, /* cipher type */
Pascal Bühler14df3db2017-03-13 09:50:43 +01003373 SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */
jfigus67b9c732014-11-20 10:17:21 -05003374 SRTP_HMAC_SHA1, /* authentication func type */
3375 16, /* auth key length in octets */
3376 10, /* auth tag length in octets */
3377 sec_serv_conf_and_auth /* security services flag */
3378 },
Ryan Hooper89a288b2016-12-22 16:22:47 -05003379 test_key,
3380 NULL,
3381 0,
jfigus67b9c732014-11-20 10:17:21 -05003382 NULL,
3383 128, /* replay window size */
3384 0, /* retransmission not allowed */
Joachim Bauch99a74822015-11-17 00:08:19 +01003385 NULL, /* no encrypted extension headers */
3386 0, /* list of encrypted extension headers is empty */
jfigus67b9c732014-11-20 10:17:21 -05003387 NULL
Cullen Jennings235513a2005-09-21 22:51:36 +00003388};