Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 1 | |
Ryan Hooper | ab0345b | 2017-02-07 16:07:59 -0500 | [diff] [blame] | 2 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3 | /* |
| 4 | * srtp_driver.c |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 5 | * |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 6 | * a test driver for libSRTP |
| 7 | * |
| 8 | * David A. McGrew |
| 9 | * Cisco Systems, Inc. |
| 10 | */ |
| 11 | /* |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 12 | * |
Geir Istad | 445c1c9 | 2017-03-27 08:13:49 +0200 | [diff] [blame] | 13 | * Copyright (c) 2001-2017, Cisco Systems, Inc. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 14 | * All rights reserved. |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 15 | * |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 16 | * Redistribution and use in source and binary forms, with or without |
| 17 | * modification, are permitted provided that the following conditions |
| 18 | * are met: |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 19 | * |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 20 | * Redistributions of source code must retain the above copyright |
| 21 | * notice, this list of conditions and the following disclaimer. |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 22 | * |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 23 | * 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. |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 27 | * |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 28 | * 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. |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 31 | * |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 32 | * 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 McGrew | 79bd301 | 2006-07-17 20:41:21 +0000 | [diff] [blame] | 52 | #include "getopt_s.h" /* for local getopt() */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 53 | |
David McGrew | 3c45e0c | 2006-07-12 00:50:56 +0000 | [diff] [blame] | 54 | #include "srtp_priv.h" |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 55 | #include "util.h" |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 56 | |
Marcus Sundberg | 1cbca88 | 2005-10-02 20:50:06 +0000 | [diff] [blame] | 57 | #ifdef HAVE_NETINET_IN_H |
| 58 | # include <netinet/in.h> |
| 59 | #elif defined HAVE_WINSOCK2_H |
| 60 | # include <winsock2.h> |
| 61 | #endif |
| 62 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 63 | #define PRINT_REFERENCE_PACKET 1 |
| 64 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 65 | srtp_err_status_t |
Marcus Sundberg | a3f95fe | 2005-09-29 12:48:41 +0000 | [diff] [blame] | 66 | srtp_validate(void); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 67 | |
Paul E. Jones | 9fc018c | 2016-06-03 02:56:56 -0400 | [diff] [blame] | 68 | #ifdef OPENSSL |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 69 | srtp_err_status_t |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 70 | srtp_validate_gcm(void); |
Paul E. Jones | 9fc018c | 2016-06-03 02:56:56 -0400 | [diff] [blame] | 71 | #endif |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 72 | |
| 73 | srtp_err_status_t |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 74 | srtp_validate_encrypted_extensions_headers(void); |
| 75 | |
Joachim Bauch | 80a45b5 | 2015-12-06 22:57:58 +0100 | [diff] [blame] | 76 | #ifdef OPENSSL |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 77 | srtp_err_status_t |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 78 | srtp_validate_encrypted_extensions_headers_gcm(void); |
Joachim Bauch | 80a45b5 | 2015-12-06 22:57:58 +0100 | [diff] [blame] | 79 | #endif |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 80 | |
| 81 | srtp_err_status_t |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 82 | srtp_validate_aes_256(void); |
| 83 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 84 | srtp_err_status_t |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 85 | srtp_create_big_policy(srtp_policy_t **list); |
| 86 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 87 | srtp_err_status_t |
Jonathan Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 88 | srtp_dealloc_big_policy(srtp_policy_t *list); |
| 89 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 90 | srtp_err_status_t |
Joachim Bauch | c8a19ae | 2015-12-14 22:50:36 +0100 | [diff] [blame] | 91 | srtp_test_empty_payload(void); |
| 92 | |
| 93 | #ifdef OPENSSL |
| 94 | srtp_err_status_t |
| 95 | srtp_test_empty_payload_gcm(void); |
| 96 | #endif |
| 97 | |
| 98 | srtp_err_status_t |
Marcus Sundberg | a3f95fe | 2005-09-29 12:48:41 +0000 | [diff] [blame] | 99 | srtp_test_remove_stream(void); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 100 | |
Pascal Bühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 101 | srtp_err_status_t |
| 102 | srtp_test_update(void); |
| 103 | |
Ryan Hooper | ab0345b | 2017-02-07 16:07:59 -0500 | [diff] [blame] | 104 | srtp_err_status_t |
| 105 | srtp_test_protect_trailer_length(void); |
| 106 | |
| 107 | srtp_err_status_t |
| 108 | srtp_test_protect_rtcp_trailer_length(void); |
| 109 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 110 | double |
| 111 | srtp_bits_per_second(int msg_len_octets, const srtp_policy_t *policy); |
| 112 | |
| 113 | double |
| 114 | srtp_rejections_per_second(int msg_len_octets, const srtp_policy_t *policy); |
| 115 | |
| 116 | void |
| 117 | srtp_do_timing(const srtp_policy_t *policy); |
| 118 | |
| 119 | void |
| 120 | srtp_do_rejection_timing(const srtp_policy_t *policy); |
| 121 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 122 | srtp_err_status_t |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 123 | srtp_test(const srtp_policy_t *policy, int extension_header, int mki_index); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 124 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 125 | srtp_err_status_t |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 126 | srtcp_test(const srtp_policy_t *policy, int mki_index); |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 127 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 128 | srtp_err_status_t |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 129 | srtp_session_print_policy(srtp_t srtp); |
| 130 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 131 | srtp_err_status_t |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 132 | srtp_print_policy(const srtp_policy_t *policy); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 133 | |
| 134 | char * |
| 135 | srtp_packet_to_string(srtp_hdr_t *hdr, int packet_len); |
| 136 | |
| 137 | double |
| 138 | mips_estimate(int num_trials, int *ignore); |
| 139 | |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 140 | #define TEST_MKI_ID_SIZE 4 |
| 141 | |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 142 | extern uint8_t test_key[46]; |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 143 | extern uint8_t test_key_2[46]; |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 144 | extern uint8_t test_mki_id[TEST_MKI_ID_SIZE]; |
| 145 | extern uint8_t test_mki_id_2[TEST_MKI_ID_SIZE]; |
| 146 | |
| 147 | srtp_master_key_t master_key_1 = { |
| 148 | test_key, |
| 149 | test_mki_id, |
| 150 | TEST_MKI_ID_SIZE |
| 151 | }; |
| 152 | |
| 153 | srtp_master_key_t master_key_2 = { |
| 154 | test_key_2, |
| 155 | test_mki_id_2, |
| 156 | TEST_MKI_ID_SIZE |
| 157 | }; |
| 158 | |
| 159 | srtp_master_key_t *test_keys[2] = { |
| 160 | &master_key_1, |
| 161 | &master_key_2 |
| 162 | }; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 163 | |
| 164 | void |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 165 | usage (char *prog_name) |
| 166 | { |
Pascal Bühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 167 | printf("usage: %s [ -t ][ -c ][ -v ][ -o ][-d <debug_module> ]* [ -l ]\n" |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 168 | " -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ühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 172 | " -o output logging to stdout\n" |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 173 | " -d <mod> turn on debugging module <mod>\n" |
| 174 | " -l list debugging modules\n", prog_name); |
| 175 | exit(1); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Pascal Bühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 178 | void |
Pascal Bühler | 9876231 | 2017-03-01 11:24:35 +0100 | [diff] [blame] | 179 | log_handler (srtp_log_level_t level, const char * msg, void * data) |
Pascal Bühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 180 | { |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 191 | /* |
| 192 | * The policy_array is a null-terminated array of policy structs. it |
| 193 | * is declared at the end of this file |
| 194 | */ |
| 195 | |
| 196 | extern const srtp_policy_t *policy_array[]; |
| 197 | |
| 198 | |
| 199 | /* the wildcard_policy is declared below; it has a wildcard ssrc */ |
| 200 | |
| 201 | extern const srtp_policy_t wildcard_policy; |
| 202 | |
| 203 | /* |
| 204 | * mod_driver debug module - debugging module for this test driver |
| 205 | * |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 206 | * we use the crypto_kernel debugging system in this driver, which |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 207 | * makes the interface uniform and increases portability |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 208 | */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 209 | |
jfigus | 02d6f03 | 2014-11-21 10:56:42 -0500 | [diff] [blame] | 210 | srtp_debug_module_t mod_driver = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 211 | 0, /* debugging is off by default */ |
| 212 | "driver" /* printable name for module */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | int |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 216 | main (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ühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 224 | unsigned do_log_stdout = 0; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 225 | srtp_err_status_t status; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 226 | |
| 227 | /* |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 228 | * verify that the compiler has interpreted the header data |
| 229 | * structure srtp_hdr_t correctly |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 230 | */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 231 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 236 | } |
| 237 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 238 | /* 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 */ |
jfigus | 92736bc | 2014-11-21 10:30:54 -0500 | [diff] [blame] | 246 | status = srtp_crypto_kernel_load_debug_module(&mod_driver); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 247 | 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ühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 255 | q = getopt_s(argc, argv, "trcvold:"); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 256 | 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ühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 272 | case 'o': |
| 273 | do_log_stdout = 1; |
| 274 | break; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 275 | case 'l': |
| 276 | do_list_mods = 1; |
| 277 | break; |
| 278 | case 'd': |
Pascal Bühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 279 | status = srtp_set_debug_module(optarg_s, 1); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 280 | 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ühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 295 | if (do_log_stdout) { |
Pascal Bühler | 9876231 | 2017-03-01 11:24:35 +0100 | [diff] [blame] | 296 | status = srtp_install_log_handler(log_handler, NULL); |
Pascal Bühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 297 | if (status) { |
| 298 | printf("error: install log handler failed\n"); |
| 299 | exit(1); |
| 300 | } |
| 301 | } |
| 302 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 303 | if (do_list_mods) { |
Pascal Bühler | af15178 | 2017-02-24 10:51:52 +0100 | [diff] [blame] | 304 | status = srtp_list_debug_modules(); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 305 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 318 | if (srtp_test(*policy, 0, -1) == srtp_err_status_ok) { |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 319 | printf("passed\n\n"); |
| 320 | } else{ |
| 321 | printf("failed\n"); |
| 322 | exit(1); |
| 323 | } |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 324 | |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 325 | printf("testing srtp_protect and srtp_unprotect with encrypted extensions headers\n"); |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 326 | if (srtp_test(*policy, 1, -1) == srtp_err_status_ok) { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 327 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 333 | 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) { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 363 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 378 | if (srtp_test(big_policy, 0, -1) == srtp_err_status_ok) { |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 379 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 385 | if (srtp_test(big_policy, 1, -1) == srtp_err_status_ok) { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 386 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 400 | if (srtp_test(&wildcard_policy, 0, -1) == srtp_err_status_ok) { |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 401 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 408 | if (srtp_test(&wildcard_policy, 1, -1) == srtp_err_status_ok) { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 409 | 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. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 420 | "reference packet\n"); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 421 | if (srtp_validate() == srtp_err_status_ok) { |
| 422 | printf("passed\n\n"); |
| 423 | } else{ |
| 424 | printf("failed\n"); |
| 425 | exit(1); |
| 426 | } |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 427 | |
| 428 | #ifdef OPENSSL |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 429 | printf("testing srtp_protect and srtp_unprotect against " |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 430 | "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 Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 441 | 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 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 447 | |
Joachim Bauch | b8cb577 | 2015-11-24 21:46:25 +0100 | [diff] [blame] | 448 | #ifdef OPENSSL |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 449 | printf("testing srtp_protect and srtp_unprotect against " |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 450 | "reference packet with encrypted extension headers (GCM)\n"); |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 451 | 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 Bauch | 80a45b5 | 2015-12-06 22:57:58 +0100 | [diff] [blame] | 457 | #endif |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 458 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 459 | /* |
| 460 | * run validation test against the reference packets for |
| 461 | * AES-256 |
| 462 | */ |
| 463 | printf("testing srtp_protect and srtp_unprotect against " |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 464 | "reference packet (AES-256)\n"); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 465 | 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 Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 471 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 472 | /* |
Joachim Bauch | c8a19ae | 2015-12-14 22:50:36 +0100 | [diff] [blame] | 473 | * test packets with empty payload |
| 474 | */ |
| 475 | printf("testing srtp_protect and srtp_unprotect against " |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 476 | "packet with empty payload\n"); |
Joachim Bauch | c8a19ae | 2015-12-14 22:50:36 +0100 | [diff] [blame] | 477 | 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. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 485 | "packet with empty payload (GCM)\n"); |
Joachim Bauch | c8a19ae | 2015-12-14 22:50:36 +0100 | [diff] [blame] | 486 | 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 | /* |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 495 | * 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ühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 504 | |
| 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 Hooper | ab0345b | 2017-02-07 16:07:59 -0500 | [diff] [blame] | 515 | |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 535 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 536 | |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 546 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 547 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 548 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 557 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 558 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 559 | if (do_codec_timing) { |
| 560 | srtp_policy_t policy; |
| 561 | int ignore; |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 562 | double mips_value = mips_estimate(1000000000, &ignore); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 563 | |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 564 | memset(&policy, 0, sizeof(policy)); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 565 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 569 | policy.key = test_key; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 570 | policy.ekt = NULL; |
| 571 | policy.window_size = 128; |
| 572 | policy.allow_repeat_tx = 0; |
| 573 | policy.next = NULL; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 574 | |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 575 | printf("mips estimate: %e\n", mips_value); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 576 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 577 | 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 Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 580 | (double)mips_value * (80 * 8) / |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 581 | srtp_bits_per_second(80, &policy) / .01 ); |
| 582 | printf("G.711\t\t%d\t\t\t%e\n", 160, |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 583 | (double)mips_value * (160 * 8) / |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 584 | srtp_bits_per_second(160, &policy) / .02); |
| 585 | printf("G.726-32\t%d\t\t\t%e\n", 40, |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 586 | (double)mips_value * (40 * 8) / |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 587 | srtp_bits_per_second(40, &policy) / .01 ); |
| 588 | printf("G.726-32\t%d\t\t\t%e\n", 80, |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 589 | (double)mips_value * (80 * 8) / |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 590 | srtp_bits_per_second(80, &policy) / .02); |
| 591 | printf("G.729\t\t%d\t\t\t%e\n", 10, |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 592 | (double)mips_value * (10 * 8) / |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 593 | srtp_bits_per_second(10, &policy) / .01 ); |
| 594 | printf("G.729\t\t%d\t\t\t%e\n", 20, |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 595 | (double)mips_value * (20 * 8) / |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 596 | srtp_bits_per_second(20, &policy) / .02 ); |
| 597 | printf("Wideband\t%d\t\t\t%e\n", 320, |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 598 | (double)mips_value * (320 * 8) / |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 599 | srtp_bits_per_second(320, &policy) / .01 ); |
| 600 | printf("Wideband\t%d\t\t\t%e\n", 640, |
Joachim Bauch | dc53dcb | 2016-03-10 20:32:44 +0100 | [diff] [blame] | 601 | (double)mips_value * (640 * 8) / |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 602 | srtp_bits_per_second(640, &policy) / .02 ); |
| 603 | } |
Jonathan Lennox | dfb3084 | 2010-05-15 04:52:01 +0000 | [diff] [blame] | 604 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 605 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 612 | } |
| 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 | |
| 629 | srtp_hdr_t * |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 630 | srtp_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 636 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 637 | /* 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 643 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 644 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 653 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 654 | buffer = (uint8_t*)hdr; |
| 655 | buffer += bytes_in_hdr; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 656 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 657 | /* set RTP data to 0xab */ |
| 658 | for (i = 0; i < pkt_octet_len; i++) { |
| 659 | *buffer++ = 0xab; |
| 660 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 661 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 662 | /* 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 670 | srtp_hdr_t * |
| 671 | srtp_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 730 | void |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 731 | srtp_do_timing (const srtp_policy_t *policy) |
| 732 | { |
| 733 | int len; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 734 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 735 | /* |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 751 | |
| 752 | } |
| 753 | |
| 754 | void |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 755 | srtp_do_rejection_timing (const srtp_policy_t *policy) |
| 756 | { |
| 757 | int len; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 758 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 759 | /* |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 774 | |
| 775 | } |
| 776 | |
| 777 | |
| 778 | #define MAX_MSG_LEN 1024 |
| 779 | |
| 780 | double |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 781 | srtp_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 791 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 792 | /* |
| 793 | * allocate and initialize an srtp session |
| 794 | */ |
| 795 | status = srtp_create(&srtp, policy); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 796 | if (status) { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 797 | printf("error: srtp_create() failed with error code %d\n", status); |
| 798 | exit(1); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 799 | } |
| 800 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 801 | /* |
| 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 Lennox | 75b3687 | 2010-05-21 00:30:21 +0000 | [diff] [blame] | 808 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 809 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 810 | /* |
| 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 Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 816 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 817 | } |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | double |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 851 | srtp_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 861 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 862 | /* |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 870 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 871 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 876 | len = msg_len_octets; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 877 | srtp_protect(srtp, (srtp_hdr_t*)mesg, &len); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 878 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 879 | 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 Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 885 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 886 | free(mesg); |
Jonathan Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 887 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 888 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | |
| 898 | void |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 899 | err_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 907 | } |
| 908 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 909 | srtp_err_status_t |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 910 | srtp_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 | |
| 918 | srtp_err_status_t |
| 919 | srtp_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 | |
| 927 | srtp_err_status_t |
| 928 | srtp_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 | |
| 936 | srtp_err_status_t |
| 937 | srtp_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 | |
| 945 | srtp_err_status_t |
| 946 | srtp_test (const srtp_policy_t *policy, int extension_header, int mki_index) |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 947 | { |
| 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 Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 960 | srtp_policy_t tmp_policy; |
| 961 | int header = 1; |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 962 | int use_mki = 0; |
| 963 | |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 964 | if (mki_index >= 0) |
| 965 | use_mki = 1; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 966 | |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 967 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 975 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 976 | /* print out policy */ |
| 977 | err_check(srtp_session_print_policy(srtp_sender)); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 978 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 979 | /* |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 988 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 989 | msg_len_octets = 28; |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 990 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 997 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 998 | if (hdr == NULL) { |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 999 | free(hdr2); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1000 | return srtp_err_status_alloc_fail; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1001 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1002 | if (hdr2 == NULL) { |
| 1003 | free(hdr); |
| 1004 | return srtp_err_status_alloc_fail; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
Marcus Sundberg | 5c40da8 | 2005-10-08 18:15:00 +0000 | [diff] [blame] | 1007 | /* set message length */ |
| 1008 | len = msg_len_octets; |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 1009 | if (extension_header) { |
| 1010 | len += 12; |
| 1011 | } |
Marcus Sundberg | 5c40da8 | 2005-10-08 18:15:00 +0000 | [diff] [blame] | 1012 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1013 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1020 | err_check(srtp_test_call_protect(srtp_sender, hdr, &len, mki_index)); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1021 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1022 | 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 Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 1042 | if (extension_header) { |
| 1043 | pkt_end += 12; |
| 1044 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1045 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1054 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1055 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1056 | /* |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1081 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1082 | /* |
| 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 Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 1095 | 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 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | err_check(srtp_create(&srtp_rcvr, rcvr_policy)); |
| 1108 | |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1109 | err_check(srtp_test_call_unprotect(srtp_rcvr, hdr, &len, use_mki)); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1110 | |
| 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1140 | status = srtp_test_call_unprotect(srtp_rcvr, hdr, &len, use_mki); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1141 | 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 Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 1158 | if (extension_header) { |
| 1159 | len += 12; |
| 1160 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1161 | |
| 1162 | /* apply protection */ |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1163 | err_check(srtp_test_call_protect(srtp_sender, hdr, &len, mki_index)); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1164 | |
| 1165 | /* flip bits in packet */ |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 1166 | data[extension_header ? 12 : 0] ^= 0xff; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1167 | |
| 1168 | /* unprotect, and check for authentication failure */ |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1169 | status = srtp_test_call_unprotect(srtp_rcvr, hdr, &len, use_mki); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1170 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1192 | srtp_err_status_t |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1193 | srtcp_test (const srtp_policy_t *policy, int mki_index) |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1194 | { |
| 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1207 | int use_mki = 0; |
| 1208 | |
| 1209 | if (mki_index >= 0) |
| 1210 | use_mki = 1; |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1211 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1212 | err_check(srtp_create(&srtcp_sender, policy)); |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1213 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1214 | /* print out policy */ |
| 1215 | err_check(srtp_session_print_policy(srtcp_sender)); |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1216 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1217 | /* |
| 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 McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1226 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1227 | msg_len_octets = 28; |
| 1228 | hdr = srtp_create_test_packet(msg_len_octets, ssrc); |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1229 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1230 | if (hdr == NULL) { |
| 1231 | return srtp_err_status_alloc_fail; |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1232 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1233 | hdr2 = srtp_create_test_packet(msg_len_octets, ssrc); |
| 1234 | if (hdr2 == NULL) { |
| 1235 | free(hdr); |
| 1236 | return srtp_err_status_alloc_fail; |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1239 | /* set message length */ |
| 1240 | len = msg_len_octets; |
| 1241 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1242 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1249 | err_check(srtp_test_call_protect_rtcp(srtcp_sender, hdr, &len, mki_index)); |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1250 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1251 | 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 McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1280 | } |
David McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1281 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1282 | /* |
| 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 McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1307 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1308 | /* |
| 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1326 | err_check(srtp_test_call_unprotect_rtcp(srtcp_rcvr, hdr, &len, use_mki)); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1327 | |
| 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1357 | status = srtp_test_call_unprotect_rtcp(srtcp_rcvr, hdr, &len, use_mki); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1358 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1377 | err_check(srtp_test_call_protect_rtcp(srtcp_sender, hdr, &len, mki_index)); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1378 | |
| 1379 | /* flip bits in packet */ |
| 1380 | data[0] ^= 0xff; |
| 1381 | |
| 1382 | /* unprotect, and check for authentication failure */ |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1383 | status = srtp_test_call_unprotect_rtcp(srtcp_rcvr, hdr, &len, use_mki); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1384 | 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 McGrew | 9c70f29 | 2006-05-03 19:38:38 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
| 1405 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1406 | srtp_err_status_t |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1407 | srtp_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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1421 | srtp_session_keys_t *session_keys = NULL; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1422 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1423 | /* sanity checking */ |
| 1424 | if (srtp == NULL) { |
| 1425 | return srtp_err_status_fail; |
| 1426 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1427 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1428 | /* if there's a template stream, print it out */ |
| 1429 | if (srtp->stream_template != NULL) { |
| 1430 | stream = srtp->stream_template; |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1431 | session_keys = &stream->session_keys[0]; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1432 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1442 | session_keys->rtp_cipher->type->description, |
| 1443 | session_keys->rtp_auth->type->description, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1444 | serv_descr[stream->rtp_services], |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1445 | session_keys->rtcp_cipher->type->description, |
| 1446 | session_keys->rtcp_auth->type->description, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1447 | serv_descr[stream->rtcp_services], |
jfigus | de8deb3 | 2014-11-25 12:58:11 -0500 | [diff] [blame] | 1448 | srtp_rdbx_get_window_size(&stream->rtp_rdbx), |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1449 | stream->allow_repeat_tx ? "true" : "false"); |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 1450 | |
| 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 | } |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1464 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1465 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1466 | /* 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1472 | session_keys = &stream->session_keys[0]; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1473 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1474 | 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 Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1484 | session_keys->rtp_cipher->type->description, |
| 1485 | session_keys->rtp_auth->type->description, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1486 | serv_descr[stream->rtp_services], |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 1487 | session_keys->rtcp_cipher->type->description, |
| 1488 | session_keys->rtcp_auth->type->description, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1489 | serv_descr[stream->rtcp_services], |
jfigus | de8deb3 | 2014-11-25 12:58:11 -0500 | [diff] [blame] | 1490 | srtp_rdbx_get_window_size(&stream->rtp_rdbx), |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1491 | stream->allow_repeat_tx ? "true" : "false"); |
| 1492 | |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 1493 | 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 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1507 | /* advance to next stream in the list */ |
| 1508 | stream = stream->next; |
| 1509 | } |
| 1510 | return srtp_err_status_ok; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1513 | srtp_err_status_t |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1514 | srtp_print_policy (const srtp_policy_t *policy) |
| 1515 | { |
| 1516 | srtp_err_status_t status; |
| 1517 | srtp_t session; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1518 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1519 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1534 | /* |
| 1535 | * srtp_print_packet(...) is for debugging only |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1536 | * 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 | |
| 1545 | char packet_string[MTU]; |
| 1546 | |
| 1547 | char * |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1548 | srtp_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1553 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1554 | /* sanity checking */ |
| 1555 | if ((hdr == NULL) || (pkt_octet_len > MTU)) { |
| 1556 | return NULL; |
| 1557 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1558 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1559 | /* 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1584 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1585 | return packet_string; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1586 | } |
| 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 | |
| 1598 | double |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1599 | mips_estimate (int num_trials, int *ignore) |
| 1600 | { |
| 1601 | clock_t t; |
| 1602 | volatile int i, sum; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1603 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1604 | sum = 0; |
| 1605 | t = clock(); |
| 1606 | for (i = 0; i < num_trials; i++) { |
| 1607 | sum += i; |
| 1608 | } |
| 1609 | t = clock() - t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1610 | |
| 1611 | /* printf("%d\n", sum); */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1612 | *ignore = sum; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1613 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1614 | return (double)num_trials * CLOCKS_PER_SEC / t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1615 | } |
| 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 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1625 | srtp_err_status_t |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1626 | srtp_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ühler | 941cf12 | 2016-06-10 09:30:52 +0200 | [diff] [blame] | 1648 | 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 | }; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1667 | srtp_t srtp_snd, srtp_recv; |
| 1668 | srtp_err_status_t status; |
| 1669 | int len; |
| 1670 | srtp_policy_t policy; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1671 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1672 | /* |
| 1673 | * create a session with a single stream using the default srtp |
| 1674 | * policy and with the SSRC value 0xcafebabe |
| 1675 | */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 1676 | memset(&policy, 0, sizeof(policy)); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1677 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 1681 | policy.key = test_key; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1682 | policy.ekt = NULL; |
| 1683 | policy.window_size = 128; |
| 1684 | policy.allow_repeat_tx = 0; |
| 1685 | policy.next = NULL; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1686 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1687 | status = srtp_create(&srtp_snd, &policy); |
| 1688 | if (status) { |
| 1689 | return status; |
| 1690 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1691 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1692 | /* |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1700 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1701 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1705 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1706 | if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) { |
| 1707 | return srtp_err_status_fail; |
| 1708 | } |
Jonathan Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 1709 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1710 | /* |
Pascal Bühler | 941cf12 | 2016-06-10 09:30:52 +0200 | [diff] [blame] | 1711 | * 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 | /* |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1729 | * 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 Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 1737 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1738 | /* |
| 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ühler | 941cf12 | 2016-06-10 09:30:52 +0200 | [diff] [blame] | 1750 | /* |
| 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 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 1763 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1774 | } |
| 1775 | |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1776 | #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 | */ |
| 1781 | srtp_err_status_t |
| 1782 | srtp_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ühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1790 | uint8_t rtp_plaintext_ref[28] = { |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1791 | 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ühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1796 | uint8_t rtp_plaintext[44] = { |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1797 | 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ühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1812 | 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. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1834 | 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ühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1860 | * protect plaintext rtp, then compare with srtp ciphertext |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1861 | */ |
| 1862 | len = 28; |
Pascal Bühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1863 | status = srtp_protect(srtp_snd, rtp_plaintext, &len); |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1864 | if (status || (len != 44)) { |
| 1865 | return srtp_err_status_fail; |
| 1866 | } |
| 1867 | |
Pascal Bühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1868 | 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. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1871 | octet_string_hex_string(srtp_ciphertext, len)); |
| 1872 | |
Pascal Bühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1873 | 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. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1892 | 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ühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1906 | * unprotect srtp ciphertext, then compare with rtp plaintext |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1907 | */ |
Pascal Bühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1908 | len = 44; |
Paul E. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1909 | status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len); |
| 1910 | if (status || (len != 28)) { |
| 1911 | return status; |
| 1912 | } |
| 1913 | |
Pascal Bühler | 45019ae | 2016-06-10 08:35:12 +0200 | [diff] [blame] | 1914 | 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. Jones | e2ab5f2 | 2016-05-29 16:18:24 -0400 | [diff] [blame] | 1928 | 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 Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 1945 | /* |
| 1946 | * Test vectors taken from RFC 6904, Appendix A |
| 1947 | */ |
| 1948 | srtp_err_status_t |
| 1949 | srtp_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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2002 | policy.key = test_key_ext_headers; |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 2003 | 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 Bauch | a9ecefe | 2015-12-14 21:40:42 +0100 | [diff] [blame] | 2043 | if (status) { |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 2044 | return status; |
Joachim Bauch | a9ecefe | 2015-12-14 21:40:42 +0100 | [diff] [blame] | 2045 | } else if (len != sizeof(srtp_plaintext_ref)) { |
| 2046 | return srtp_err_status_fail; |
| 2047 | } |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 2048 | |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2063 | |
Joachim Bauch | 80a45b5 | 2015-12-06 22:57:58 +0100 | [diff] [blame] | 2064 | #ifdef OPENSSL |
Joachim Bauch | a9ecefe | 2015-12-14 21:40:42 +0100 | [diff] [blame] | 2065 | |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2066 | /* |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 2067 | * Headers of test vectors taken from RFC 6904, Appendix A |
| 2068 | */ |
| 2069 | srtp_err_status_t |
| 2070 | srtp_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 Bauch | a3af460 | 2017-03-30 23:51:08 +0200 | [diff] [blame^] | 2099 | 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 Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 2102 | 0x0e, 0xca, 0x0c, 0xf9, 0x5e, 0xe9, 0x55, 0xb2, |
| 2103 | 0x6c, 0xd3, 0xd2, 0x88, 0xb4, 0x9f, 0x6c, 0xa9, |
Joachim Bauch | a3af460 | 2017-03-30 23:51:08 +0200 | [diff] [blame^] | 2104 | 0xf4, 0xb1, 0xb7, 0x59, 0x71, 0x9e, 0xb5, 0xbc |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 2105 | }; |
| 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2121 | policy.key = test_key_ext_headers; |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 2122 | 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 Bauch | a9ecefe | 2015-12-14 21:40:42 +0100 | [diff] [blame] | 2162 | if (status) { |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 2163 | return status; |
Joachim Bauch | a9ecefe | 2015-12-14 21:40:42 +0100 | [diff] [blame] | 2164 | } else if (len != sizeof(srtp_plaintext_ref)) { |
| 2165 | return srtp_err_status_fail; |
| 2166 | } |
Joachim Bauch | fa1e8c2 | 2015-11-24 23:38:48 +0100 | [diff] [blame] | 2167 | |
| 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 Bauch | 80a45b5 | 2015-12-06 22:57:58 +0100 | [diff] [blame] | 2181 | #endif |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2182 | |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2183 | /* |
| 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 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 2190 | srtp_err_status_t |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2191 | srtp_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 Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2198 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2199 | 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 Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2226 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2227 | /* |
| 2228 | * create a session with a single stream using the default srtp |
| 2229 | * policy and with the SSRC value 0xcafebabe |
| 2230 | */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 2231 | memset(&policy, 0, sizeof(policy)); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2232 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2236 | policy.key = aes_256_test_key; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2237 | policy.ekt = NULL; |
| 2238 | policy.window_size = 128; |
| 2239 | policy.allow_repeat_tx = 0; |
| 2240 | policy.next = NULL; |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2241 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2242 | status = srtp_create(&srtp_snd, &policy); |
| 2243 | if (status) { |
| 2244 | return status; |
| 2245 | } |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2246 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2247 | /* |
| 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 Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2255 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2256 | 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 Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2260 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2261 | if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len)) { |
| 2262 | return srtp_err_status_fail; |
| 2263 | } |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2264 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2265 | /* |
| 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 Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2274 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2275 | /* |
| 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 Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 2301 | srtp_err_status_t |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2302 | srtp_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2308 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2309 | /* sanity checking */ |
| 2310 | if ((list == NULL) || (policy_array[0] == NULL)) { |
| 2311 | return srtp_err_status_bad_param; |
| 2312 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2313 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2314 | /* |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 2336 | srtp_err_status_t |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2337 | srtp_dealloc_big_policy (srtp_policy_t *list) |
| 2338 | { |
| 2339 | srtp_policy_t *p, *next; |
Jonathan Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 2340 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2341 | for (p = list; p != NULL; p = next) { |
| 2342 | next = p->next; |
| 2343 | free(p); |
| 2344 | } |
Jonathan Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 2345 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2346 | return srtp_err_status_ok; |
Jonathan Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 2347 | } |
| 2348 | |
Joachim Bauch | c8a19ae | 2015-12-14 22:50:36 +0100 | [diff] [blame] | 2349 | srtp_err_status_t |
| 2350 | srtp_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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2367 | policy.key = test_key; |
Joachim Bauch | c8a19ae | 2015-12-14 22:50:36 +0100 | [diff] [blame] | 2368 | 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 |
| 2427 | srtp_err_status_t |
| 2428 | srtp_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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2445 | policy.key = test_key; |
Joachim Bauch | c8a19ae | 2015-12-14 22:50:36 +0100 | [diff] [blame] | 2446 | 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 Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 2504 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 2505 | srtp_err_status_t |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2506 | srtp_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2512 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2513 | /* |
| 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2519 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2520 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2521 | status = srtp_create_big_policy(&policy_list); |
| 2522 | if (status) { |
| 2523 | return status; |
| 2524 | } |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2525 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2526 | status = srtp_create(&session, policy_list); |
| 2527 | if (status) { |
| 2528 | return status; |
| 2529 | } |
Jonathan Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 2530 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2531 | /* |
| 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 Lennox | 80c4c83 | 2010-05-17 19:30:28 +0000 | [diff] [blame] | 2539 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2540 | /* |
| 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 Lennox | ad741b2 | 2010-05-27 19:23:05 +0000 | [diff] [blame] | 2556 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2557 | status = srtp_dealloc(session); |
| 2558 | if (status != srtp_err_status_ok) { |
| 2559 | return status; |
| 2560 | } |
Jonathan Lennox | ad741b2 | 2010-05-27 19:23:05 +0000 | [diff] [blame] | 2561 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2562 | status = srtp_dealloc_big_policy(policy_list); |
| 2563 | if (status != srtp_err_status_ok) { |
| 2564 | return status; |
| 2565 | } |
Jonathan Lennox | ad741b2 | 2010-05-27 19:23:05 +0000 | [diff] [blame] | 2566 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2567 | /* Now test adding and removing a single stream */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 2568 | memset(&policy, 0, sizeof(policy)); |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2569 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2573 | policy.key = test_key; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2574 | policy.ekt = NULL; |
| 2575 | policy.window_size = 128; |
| 2576 | policy.allow_repeat_tx = 0; |
| 2577 | policy.next = NULL; |
Jonathan Lennox | ad741b2 | 2010-05-27 19:23:05 +0000 | [diff] [blame] | 2578 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2579 | 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
Pascal Bühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 2602 | |
| 2603 | unsigned 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 | |
| 2619 | srtp_err_status_t |
| 2620 | srtp_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 Bauch | 1b79335 | 2015-12-14 21:30:44 +0100 | [diff] [blame] | 2630 | memset(&policy, 0, sizeof(policy)); |
Pascal Bühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 2631 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2638 | policy.key = test_key; |
Pascal Bühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 2639 | |
| 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ühler | b095e7e | 2016-06-09 13:46:28 +0200 | [diff] [blame] | 2683 | /* update send ctx with same test_key t verify update works*/ |
| 2684 | policy.ssrc.type = ssrc_any_outbound; |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2685 | policy.key = test_key; |
Pascal Bühler | b095e7e | 2016-06-09 13:46:28 +0200 | [diff] [blame] | 2686 | 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ühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 2707 | /* update send ctx to use test_alt_key */ |
| 2708 | policy.ssrc.type = ssrc_any_outbound; |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2709 | policy.key = test_alt_key; |
Pascal Bühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 2710 | 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ühler | b095e7e | 2016-06-09 13:46:28 +0200 | [diff] [blame] | 2718 | msg->seq = htons(3); |
Pascal Bühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 2719 | |
| 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2736 | policy.key = test_alt_key; |
Pascal Bühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 2737 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2752 | policy.key = test_alt_key; |
Pascal Bühler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 2753 | 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 Hooper | ab0345b | 2017-02-07 16:07:59 -0500 | [diff] [blame] | 2775 | srtp_err_status_t |
| 2776 | srtp_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 | |
| 2856 | srtp_err_status_t |
| 2857 | srtp_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 | |
| 2908 | srtp_err_status_t |
| 2909 | srtp_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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2961 | /* |
| 2962 | * srtp policy definitions - these definitions are used above |
| 2963 | */ |
| 2964 | |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 2965 | unsigned char test_key[46] = { |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2966 | 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, |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 2969 | 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6, 0xc1, 0x73, |
| 2970 | 0xc3, 0x17, 0xf2, 0xda, 0xbe, 0x35, 0x77, 0x93, |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2971 | 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6 |
| 2972 | }; |
| 2973 | |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 2974 | unsigned 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 Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2982 | |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 2983 | unsigned char test_mki_id[TEST_MKI_ID_SIZE] = { |
| 2984 | 0xe1, 0xf9, 0x7a, 0x0d |
| 2985 | }; |
| 2986 | |
| 2987 | unsigned char test_mki_id_2[TEST_MKI_ID_SIZE] = { |
| 2988 | 0xf3, 0xa1, 0x46, 0x71 |
| 2989 | }; |
| 2990 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 2991 | const srtp_policy_t default_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2992 | { ssrc_any_outbound, 0 }, /* SSRC */ |
| 2993 | { /* SRTP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 2994 | SRTP_AES_ICM_128, /* cipher type */ |
Pascal Bühler | 14df3db | 2017-03-13 09:50:43 +0100 | [diff] [blame] | 2995 | SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 2996 | 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ühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3002 | SRTP_AES_ICM_128, /* cipher type */ |
Pascal Bühler | 14df3db | 2017-03-13 09:50:43 +0100 | [diff] [blame] | 3003 | SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3004 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3009 | NULL, |
| 3010 | (srtp_master_key_t **)test_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3011 | 2, /* indicates the number of Master keys */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3012 | NULL, /* indicates that EKT is not in use */ |
| 3013 | 128, /* replay window size */ |
| 3014 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3015 | NULL, /* no encrypted extension headers */ |
| 3016 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3017 | NULL |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3018 | }; |
| 3019 | |
| 3020 | const srtp_policy_t aes_only_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3021 | { ssrc_any_outbound, 0 }, /* SSRC */ |
| 3022 | { |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3023 | SRTP_AES_ICM_128, /* cipher type */ |
Pascal Bühler | 14df3db | 2017-03-13 09:50:43 +0100 | [diff] [blame] | 3024 | SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3025 | 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ühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3031 | SRTP_AES_ICM_128, /* cipher type */ |
Pascal Bühler | 14df3db | 2017-03-13 09:50:43 +0100 | [diff] [blame] | 3032 | SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3033 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3038 | NULL, |
| 3039 | (srtp_master_key_t **)test_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3040 | 2, /* indicates the number of Master keys */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3041 | NULL, /* indicates that EKT is not in use */ |
| 3042 | 128, /* replay window size */ |
| 3043 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3044 | NULL, /* no encrypted extension headers */ |
| 3045 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3046 | NULL |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3047 | }; |
| 3048 | |
| 3049 | const srtp_policy_t hmac_only_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3050 | { 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3067 | NULL, |
| 3068 | (srtp_master_key_t **)test_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3069 | 2, /* Number of Master keys associated with the policy */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3070 | NULL, /* indicates that EKT is not in use */ |
| 3071 | 128, /* replay window size */ |
| 3072 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3073 | NULL, /* no encrypted extension headers */ |
| 3074 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3075 | NULL |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3076 | }; |
| 3077 | |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3078 | #ifdef OPENSSL |
| 3079 | const srtp_policy_t aes128_gcm_8_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3080 | { ssrc_any_outbound, 0 }, /* SSRC */ |
| 3081 | { /* SRTP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3082 | SRTP_AES_GCM_128, /* cipher type */ |
Pascal Bühler | 20e6612 | 2017-03-13 09:09:36 +0100 | [diff] [blame] | 3083 | SRTP_AES_GCM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3084 | 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 */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3088 | }, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3089 | { /* SRTCP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3090 | SRTP_AES_GCM_128, /* cipher type */ |
Pascal Bühler | 20e6612 | 2017-03-13 09:09:36 +0100 | [diff] [blame] | 3091 | SRTP_AES_GCM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3092 | 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 */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3096 | }, |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3097 | NULL, |
| 3098 | (srtp_master_key_t **)test_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3099 | 2, /* indicates the number of Master keys */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3100 | NULL, /* indicates that EKT is not in use */ |
| 3101 | 128, /* replay window size */ |
| 3102 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3103 | NULL, /* no encrypted extension headers */ |
| 3104 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3105 | NULL |
| 3106 | }; |
| 3107 | |
| 3108 | const srtp_policy_t aes128_gcm_8_cauth_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3109 | { ssrc_any_outbound, 0 }, /* SSRC */ |
| 3110 | { /* SRTP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3111 | SRTP_AES_GCM_128, /* cipher type */ |
Pascal Bühler | 20e6612 | 2017-03-13 09:09:36 +0100 | [diff] [blame] | 3112 | SRTP_AES_GCM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3113 | 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 */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3117 | }, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3118 | { /* SRTCP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3119 | SRTP_AES_GCM_128, /* cipher type */ |
Pascal Bühler | 20e6612 | 2017-03-13 09:09:36 +0100 | [diff] [blame] | 3120 | SRTP_AES_GCM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3121 | 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 */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3125 | }, |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3126 | NULL, |
Ryan Hooper | 6c339f7 | 2017-01-03 13:45:18 -0500 | [diff] [blame] | 3127 | (srtp_master_key_t **)test_keys, |
| 3128 | 2, /* indicates the number of Master keys */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3129 | NULL, /* indicates that EKT is not in use */ |
| 3130 | 128, /* replay window size */ |
| 3131 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3132 | NULL, /* no encrypted extension headers */ |
| 3133 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3134 | NULL |
| 3135 | }; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3136 | |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3137 | const srtp_policy_t aes256_gcm_8_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3138 | { ssrc_any_outbound, 0 }, /* SSRC */ |
| 3139 | { /* SRTP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3140 | SRTP_AES_GCM_256, /* cipher type */ |
Pascal Bühler | 20e6612 | 2017-03-13 09:09:36 +0100 | [diff] [blame] | 3141 | SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3142 | 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 */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3146 | }, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3147 | { /* SRTCP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3148 | SRTP_AES_GCM_256, /* cipher type */ |
Pascal Bühler | 20e6612 | 2017-03-13 09:09:36 +0100 | [diff] [blame] | 3149 | SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3150 | 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 */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3154 | }, |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3155 | NULL, |
| 3156 | (srtp_master_key_t **)test_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3157 | 2, /* indicates the number of Master keys */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3158 | NULL, /* indicates that EKT is not in use */ |
| 3159 | 128, /* replay window size */ |
| 3160 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3161 | NULL, /* no encrypted extension headers */ |
| 3162 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3163 | NULL |
| 3164 | }; |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3165 | |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3166 | const srtp_policy_t aes256_gcm_8_cauth_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3167 | { ssrc_any_outbound, 0 }, /* SSRC */ |
| 3168 | { /* SRTP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3169 | SRTP_AES_GCM_256, /* cipher type */ |
Pascal Bühler | 20e6612 | 2017-03-13 09:09:36 +0100 | [diff] [blame] | 3170 | SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3171 | 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 */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3175 | }, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3176 | { /* SRTCP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3177 | SRTP_AES_GCM_256, /* cipher type */ |
Pascal Bühler | 20e6612 | 2017-03-13 09:09:36 +0100 | [diff] [blame] | 3178 | SRTP_AES_GCM_256_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3179 | 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 */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3183 | }, |
Ryan Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3184 | NULL, |
| 3185 | (srtp_master_key_t **)test_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3186 | 2, /* indicates the number of Master keys */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3187 | NULL, /* indicates that EKT is not in use */ |
| 3188 | 128, /* replay window size */ |
| 3189 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3190 | NULL, /* no encrypted extension headers */ |
| 3191 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3192 | NULL |
| 3193 | }; |
| 3194 | #endif |
| 3195 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3196 | const srtp_policy_t null_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3197 | { 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3214 | NULL, |
| 3215 | (srtp_master_key_t **)test_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3216 | 2, /* indicates the number of Master keys */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3217 | NULL, /* indicates that EKT is not in use */ |
| 3218 | 128, /* replay window size */ |
| 3219 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3220 | NULL, /* no encrypted extension headers */ |
| 3221 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3222 | NULL |
David McGrew | 79870d6 | 2007-06-15 18:17:39 +0000 | [diff] [blame] | 3223 | }; |
| 3224 | |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 3225 | unsigned char test_256_key[46] = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3226 | 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 Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 3230 | |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3231 | 0x3b, 0x04, 0x80, 0x3d, 0xe5, 0x1e, 0xe7, 0xc9, |
| 3232 | 0x64, 0x23, 0xab, 0x5b, 0x78, 0xd2 |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 3233 | }; |
| 3234 | |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3235 | unsigned 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3244 | srtp_master_key_t master_256_key_1 = { |
| 3245 | test_256_key, |
| 3246 | test_mki_id, |
| 3247 | TEST_MKI_ID_SIZE |
| 3248 | }; |
| 3249 | |
| 3250 | srtp_master_key_t master_256_key_2 = { |
| 3251 | test_256_key_2, |
| 3252 | test_mki_id_2, |
| 3253 | TEST_MKI_ID_SIZE |
| 3254 | }; |
| 3255 | |
| 3256 | srtp_master_key_t *test_256_keys[2] = { |
| 3257 | &master_key_1, |
| 3258 | &master_key_2 |
| 3259 | }; |
| 3260 | |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 3261 | const srtp_policy_t aes_256_hmac_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3262 | { ssrc_any_outbound, 0 }, /* SSRC */ |
| 3263 | { /* SRTP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3264 | SRTP_AES_ICM_256, /* cipher type */ |
Pascal Bühler | 14df3db | 2017-03-13 09:50:43 +0100 | [diff] [blame] | 3265 | SRTP_AES_ICM_256_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3266 | 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ühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3272 | SRTP_AES_ICM_256, /* cipher type */ |
Pascal Bühler | 14df3db | 2017-03-13 09:50:43 +0100 | [diff] [blame] | 3273 | SRTP_AES_ICM_256_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3274 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3279 | NULL, |
| 3280 | (srtp_master_key_t **)test_256_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3281 | 2, /* indicates the number of Master keys */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3282 | NULL, /* indicates that EKT is not in use */ |
| 3283 | 128, /* replay window size */ |
| 3284 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3285 | NULL, /* no encrypted extension headers */ |
| 3286 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3287 | NULL |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 3288 | }; |
| 3289 | |
David McGrew | 79870d6 | 2007-06-15 18:17:39 +0000 | [diff] [blame] | 3290 | uint8_t ekt_test_key[16] = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3291 | 0x77, 0x26, 0x9d, 0xac, 0x16, 0xa3, 0x28, 0xca, |
| 3292 | 0x8e, 0xc9, 0x68, 0x4b, 0xcc, 0xc4, 0xd2, 0x1b |
David McGrew | 79870d6 | 2007-06-15 18:17:39 +0000 | [diff] [blame] | 3293 | }; |
| 3294 | |
| 3295 | #include "ekt.h" |
| 3296 | |
jfigus | c5887e7 | 2014-11-06 09:46:18 -0500 | [diff] [blame] | 3297 | srtp_ekt_policy_ctx_t ekt_test_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3298 | 0xa5a5, /* SPI */ |
| 3299 | SRTP_EKT_CIPHER_AES_128_ECB, |
| 3300 | ekt_test_key, |
| 3301 | NULL |
David McGrew | 79870d6 | 2007-06-15 18:17:39 +0000 | [diff] [blame] | 3302 | }; |
| 3303 | |
| 3304 | const srtp_policy_t hmac_only_with_ekt_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3305 | { 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3322 | NULL, |
| 3323 | (srtp_master_key_t **)test_keys, |
Ryan Hooper | fe5d8b8 | 2016-12-15 14:53:58 -0500 | [diff] [blame] | 3324 | 2, /* indicates the number of Master keys */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3325 | &ekt_test_policy, /* indicates that EKT is not in use */ |
| 3326 | 128, /* replay window size */ |
| 3327 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3328 | NULL, /* no encrypted extension headers */ |
| 3329 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3330 | NULL |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3331 | }; |
| 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 |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3340 | * in a plot (see the gnuplot script file 'timing'). If you |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3341 | * add to this list, you should do it at the end. |
| 3342 | */ |
| 3343 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3344 | const srtp_policy_t * |
| 3345 | policy_array[] = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3346 | &hmac_only_policy, |
| 3347 | &aes_only_policy, |
| 3348 | &default_policy, |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3349 | #ifdef OPENSSL |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3350 | &aes128_gcm_8_policy, |
| 3351 | &aes128_gcm_8_cauth_policy, |
| 3352 | &aes256_gcm_8_policy, |
| 3353 | &aes256_gcm_8_cauth_policy, |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 3354 | #endif |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3355 | &null_policy, |
| 3356 | &aes_256_hmac_policy, |
| 3357 | &hmac_only_with_ekt_policy, |
| 3358 | NULL |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3359 | }; |
| 3360 | |
| 3361 | const srtp_policy_t wildcard_policy = { |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3362 | { ssrc_any_outbound, 0 }, /* SSRC */ |
| 3363 | { /* SRTP policy */ |
Pascal Bühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3364 | SRTP_AES_ICM_128, /* cipher type */ |
Pascal Bühler | 14df3db | 2017-03-13 09:50:43 +0100 | [diff] [blame] | 3365 | SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3366 | 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ühler | d335bd8 | 2017-02-23 09:56:17 +0100 | [diff] [blame] | 3372 | SRTP_AES_ICM_128, /* cipher type */ |
Pascal Bühler | 14df3db | 2017-03-13 09:50:43 +0100 | [diff] [blame] | 3373 | SRTP_AES_ICM_128_KEY_LEN_WSALT, /* cipher key length in octets */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3374 | 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 Hooper | 89a288b | 2016-12-22 16:22:47 -0500 | [diff] [blame] | 3379 | test_key, |
| 3380 | NULL, |
| 3381 | 0, |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3382 | NULL, |
| 3383 | 128, /* replay window size */ |
| 3384 | 0, /* retransmission not allowed */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 3385 | NULL, /* no encrypted extension headers */ |
| 3386 | 0, /* list of encrypted extension headers is empty */ |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 3387 | NULL |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 3388 | }; |