2
0

srtp_driver.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. /*
  2. * srtp_driver.c
  3. *
  4. * a test driver for libSRTP
  5. *
  6. * David A. McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. /*
  10. *
  11. * Copyright (c) 2001-2006, Cisco Systems, Inc.
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * Neither the name of the Cisco Systems, Inc. nor the names of its
  27. * contributors may be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  35. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  36. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  37. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  41. * OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. */
  44. #include <string.h> /* for memcpy() */
  45. #include <time.h> /* for clock() */
  46. #include <stdlib.h> /* for malloc(), free() */
  47. #include <stdio.h> /* for print(), fflush() */
  48. #include "getopt_s.h" /* for local getopt() */
  49. #include "srtp_priv.h"
  50. #ifdef HAVE_NETINET_IN_H
  51. # include <netinet/in.h>
  52. #elif defined HAVE_WINSOCK2_H
  53. # include <winsock2.h>
  54. #endif
  55. #define PRINT_REFERENCE_PACKET 1
  56. err_status_t
  57. srtp_validate(void);
  58. err_status_t
  59. srtp_validate_aes_256(void);
  60. err_status_t
  61. srtp_create_big_policy(srtp_policy_t **list);
  62. err_status_t
  63. srtp_dealloc_big_policy(srtp_policy_t *list);
  64. err_status_t
  65. srtp_test_remove_stream(void);
  66. double
  67. srtp_bits_per_second(int msg_len_octets, const srtp_policy_t *policy);
  68. double
  69. srtp_rejections_per_second(int msg_len_octets, const srtp_policy_t *policy);
  70. void
  71. srtp_do_timing(const srtp_policy_t *policy);
  72. void
  73. srtp_do_rejection_timing(const srtp_policy_t *policy);
  74. err_status_t
  75. srtp_test(const srtp_policy_t *policy);
  76. err_status_t
  77. srtcp_test(const srtp_policy_t *policy);
  78. err_status_t
  79. srtp_session_print_policy(srtp_t srtp);
  80. err_status_t
  81. srtp_print_policy(const srtp_policy_t *policy);
  82. char *
  83. srtp_packet_to_string(srtp_hdr_t *hdr, int packet_len);
  84. double
  85. mips_estimate(int num_trials, int *ignore);
  86. extern uint8_t test_key[46];
  87. void
  88. usage(char *prog_name) {
  89. printf("usage: %s [ -t ][ -c ][ -v ][-d <debug_module> ]* [ -l ]\n"
  90. " -t run timing test\n"
  91. " -r run rejection timing test\n"
  92. " -c run codec timing test\n"
  93. " -v run validation tests\n"
  94. " -d <mod> turn on debugging module <mod>\n"
  95. " -l list debugging modules\n", prog_name);
  96. exit(1);
  97. }
  98. /*
  99. * The policy_array is a null-terminated array of policy structs. it
  100. * is declared at the end of this file
  101. */
  102. extern const srtp_policy_t *policy_array[];
  103. /* the wildcard_policy is declared below; it has a wildcard ssrc */
  104. extern const srtp_policy_t wildcard_policy;
  105. /*
  106. * mod_driver debug module - debugging module for this test driver
  107. *
  108. * we use the crypto_kernel debugging system in this driver, which
  109. * makes the interface uniform and increases portability
  110. */
  111. debug_module_t mod_driver = {
  112. 0, /* debugging is off by default */
  113. "driver" /* printable name for module */
  114. };
  115. int
  116. main (int argc, char *argv[]) {
  117. int q;
  118. unsigned do_timing_test = 0;
  119. unsigned do_rejection_test = 0;
  120. unsigned do_codec_timing = 0;
  121. unsigned do_validation = 0;
  122. unsigned do_list_mods = 0;
  123. err_status_t status;
  124. /*
  125. * verify that the compiler has interpreted the header data
  126. * structure srtp_hdr_t correctly
  127. */
  128. if (sizeof(srtp_hdr_t) != 12) {
  129. printf("error: srtp_hdr_t has incorrect size"
  130. "(size is %ld bytes, expected 12)\n",
  131. (long)sizeof(srtp_hdr_t));
  132. exit(1);
  133. }
  134. /* initialize srtp library */
  135. status = srtp_init();
  136. if (status) {
  137. printf("error: srtp init failed with error code %d\n", status);
  138. exit(1);
  139. }
  140. /* load srtp_driver debug module */
  141. status = crypto_kernel_load_debug_module(&mod_driver);
  142. if (status) {
  143. printf("error: load of srtp_driver debug module failed "
  144. "with error code %d\n", status);
  145. exit(1);
  146. }
  147. /* process input arguments */
  148. while (1) {
  149. q = getopt_s(argc, argv, "trcvld:");
  150. if (q == -1)
  151. break;
  152. switch (q) {
  153. case 't':
  154. do_timing_test = 1;
  155. break;
  156. case 'r':
  157. do_rejection_test = 1;
  158. break;
  159. case 'c':
  160. do_codec_timing = 1;
  161. break;
  162. case 'v':
  163. do_validation = 1;
  164. break;
  165. case 'l':
  166. do_list_mods = 1;
  167. break;
  168. case 'd':
  169. status = crypto_kernel_set_debug_module(optarg_s, 1);
  170. if (status) {
  171. printf("error: set debug module (%s) failed\n", optarg_s);
  172. exit(1);
  173. }
  174. break;
  175. default:
  176. usage(argv[0]);
  177. }
  178. }
  179. if (!do_validation && !do_timing_test && !do_codec_timing
  180. && !do_list_mods && !do_rejection_test)
  181. usage(argv[0]);
  182. if (do_list_mods) {
  183. status = crypto_kernel_list_debug_modules();
  184. if (status) {
  185. printf("error: list of debug modules failed\n");
  186. exit(1);
  187. }
  188. }
  189. if (do_validation) {
  190. const srtp_policy_t **policy = policy_array;
  191. srtp_policy_t *big_policy;
  192. /* loop over policy array, testing srtp and srtcp for each policy */
  193. while (*policy != NULL) {
  194. printf("testing srtp_protect and srtp_unprotect\n");
  195. if (srtp_test(*policy) == err_status_ok)
  196. printf("passed\n\n");
  197. else {
  198. printf("failed\n");
  199. exit(1);
  200. }
  201. printf("testing srtp_protect_rtcp and srtp_unprotect_rtcp\n");
  202. if (srtcp_test(*policy) == err_status_ok)
  203. printf("passed\n\n");
  204. else {
  205. printf("failed\n");
  206. exit(1);
  207. }
  208. policy++;
  209. }
  210. /* create a big policy list and run tests on it */
  211. status = srtp_create_big_policy(&big_policy);
  212. if (status) {
  213. printf("unexpected failure with error code %d\n", status);
  214. exit(1);
  215. }
  216. printf("testing srtp_protect and srtp_unprotect with big policy\n");
  217. if (srtp_test(big_policy) == err_status_ok)
  218. printf("passed\n\n");
  219. else {
  220. printf("failed\n");
  221. exit(1);
  222. }
  223. status = srtp_dealloc_big_policy(big_policy);
  224. if (status) {
  225. printf("unexpected failure with error code %d\n", status);
  226. exit(1);
  227. }
  228. /* run test on wildcard policy */
  229. printf("testing srtp_protect and srtp_unprotect on "
  230. "wildcard ssrc policy\n");
  231. if (srtp_test(&wildcard_policy) == err_status_ok)
  232. printf("passed\n\n");
  233. else {
  234. printf("failed\n");
  235. exit(1);
  236. }
  237. /*
  238. * run validation test against the reference packets - note
  239. * that this test only covers the default policy
  240. */
  241. printf("testing srtp_protect and srtp_unprotect against "
  242. "reference packets\n");
  243. if (srtp_validate() == err_status_ok)
  244. printf("passed\n\n");
  245. else {
  246. printf("failed\n");
  247. exit(1);
  248. }
  249. //FIXME: need to get this working with the OpenSSL AES module
  250. #ifndef OPENSSL
  251. /*
  252. * run validation test against the reference packets for
  253. * AES-256
  254. */
  255. printf("testing srtp_protect and srtp_unprotect against "
  256. "reference packets (AES-256)\n");
  257. if (srtp_validate_aes_256() == err_status_ok)
  258. printf("passed\n\n");
  259. else {
  260. printf("failed\n");
  261. exit(1);
  262. }
  263. #endif
  264. /*
  265. * test the function srtp_remove_stream()
  266. */
  267. printf("testing srtp_remove_stream()...");
  268. if (srtp_test_remove_stream() == err_status_ok)
  269. printf("passed\n");
  270. else {
  271. printf("failed\n");
  272. exit(1);
  273. }
  274. }
  275. if (do_timing_test) {
  276. const srtp_policy_t **policy = policy_array;
  277. /* loop over policies, run timing test for each */
  278. while (*policy != NULL) {
  279. srtp_print_policy(*policy);
  280. srtp_do_timing(*policy);
  281. policy++;
  282. }
  283. }
  284. if (do_rejection_test) {
  285. const srtp_policy_t **policy = policy_array;
  286. /* loop over policies, run rejection timing test for each */
  287. while (*policy != NULL) {
  288. srtp_print_policy(*policy);
  289. srtp_do_rejection_timing(*policy);
  290. policy++;
  291. }
  292. }
  293. if (do_codec_timing) {
  294. srtp_policy_t policy;
  295. int ignore;
  296. double mips = mips_estimate(1000000000, &ignore);
  297. crypto_policy_set_rtp_default(&policy.rtp);
  298. crypto_policy_set_rtcp_default(&policy.rtcp);
  299. policy.ssrc.type = ssrc_specific;
  300. policy.ssrc.value = 0xdecafbad;
  301. policy.key = test_key;
  302. policy.ekt = NULL;
  303. policy.window_size = 128;
  304. policy.allow_repeat_tx = 0;
  305. policy.next = NULL;
  306. printf("mips estimate: %e\n", mips);
  307. printf("testing srtp processing time for voice codecs:\n");
  308. printf("codec\t\tlength (octets)\t\tsrtp instructions/second\n");
  309. printf("G.711\t\t%d\t\t\t%e\n", 80,
  310. (double) mips * (80 * 8) /
  311. srtp_bits_per_second(80, &policy) / .01 );
  312. printf("G.711\t\t%d\t\t\t%e\n", 160,
  313. (double) mips * (160 * 8) /
  314. srtp_bits_per_second(160, &policy) / .02);
  315. printf("G.726-32\t%d\t\t\t%e\n", 40,
  316. (double) mips * (40 * 8) /
  317. srtp_bits_per_second(40, &policy) / .01 );
  318. printf("G.726-32\t%d\t\t\t%e\n", 80,
  319. (double) mips * (80 * 8) /
  320. srtp_bits_per_second(80, &policy) / .02);
  321. printf("G.729\t\t%d\t\t\t%e\n", 10,
  322. (double) mips * (10 * 8) /
  323. srtp_bits_per_second(10, &policy) / .01 );
  324. printf("G.729\t\t%d\t\t\t%e\n", 20,
  325. (double) mips * (20 * 8) /
  326. srtp_bits_per_second(20, &policy) / .02 );
  327. printf("Wideband\t%d\t\t\t%e\n", 320,
  328. (double) mips * (320 * 8) /
  329. srtp_bits_per_second(320, &policy) / .01 );
  330. printf("Wideband\t%d\t\t\t%e\n", 640,
  331. (double) mips * (640 * 8) /
  332. srtp_bits_per_second(640, &policy) / .02 );
  333. }
  334. status = srtp_shutdown();
  335. if (status) {
  336. printf("error: srtp shutdown failed with error code %d\n", status);
  337. exit(1);
  338. }
  339. return 0;
  340. }
  341. /*
  342. * srtp_create_test_packet(len, ssrc) returns a pointer to a
  343. * (malloced) example RTP packet whose data field has the length given
  344. * by pkt_octet_len and the SSRC value ssrc. The total length of the
  345. * packet is twelve octets longer, since the header is at the
  346. * beginning. There is room at the end of the packet for a trailer,
  347. * and the four octets following the packet are filled with 0xff
  348. * values to enable testing for overwrites.
  349. *
  350. * note that the location of the test packet can (and should) be
  351. * deallocated with the free() call once it is no longer needed.
  352. */
  353. srtp_hdr_t *
  354. srtp_create_test_packet(int pkt_octet_len, uint32_t ssrc) {
  355. int i;
  356. uint8_t *buffer;
  357. srtp_hdr_t *hdr;
  358. int bytes_in_hdr = 12;
  359. /* allocate memory for test packet */
  360. hdr = (srtp_hdr_t*) malloc(pkt_octet_len + bytes_in_hdr
  361. + SRTP_MAX_TRAILER_LEN + 4);
  362. if (!hdr)
  363. return NULL;
  364. hdr->version = 2; /* RTP version two */
  365. hdr->p = 0; /* no padding needed */
  366. hdr->x = 0; /* no header extension */
  367. hdr->cc = 0; /* no CSRCs */
  368. hdr->m = 0; /* marker bit */
  369. hdr->pt = 0xf; /* payload type */
  370. hdr->seq = htons(0x1234); /* sequence number */
  371. hdr->ts = htonl(0xdecafbad); /* timestamp */
  372. hdr->ssrc = htonl(ssrc); /* synch. source */
  373. buffer = (uint8_t *)hdr;
  374. buffer += bytes_in_hdr;
  375. /* set RTP data to 0xab */
  376. for (i=0; i < pkt_octet_len; i++)
  377. *buffer++ = 0xab;
  378. /* set post-data value to 0xffff to enable overrun checking */
  379. for (i=0; i < SRTP_MAX_TRAILER_LEN+4; i++)
  380. *buffer++ = 0xff;
  381. return hdr;
  382. }
  383. void
  384. srtp_do_timing(const srtp_policy_t *policy) {
  385. int len;
  386. /*
  387. * note: the output of this function is formatted so that it
  388. * can be used in gnuplot. '#' indicates a comment, and "\r\n"
  389. * terminates a record
  390. */
  391. printf("# testing srtp throughput:\r\n");
  392. printf("# mesg length (octets)\tthroughput (megabits per second)\r\n");
  393. for (len=16; len <= 2048; len *= 2)
  394. printf("%d\t\t\t%f\r\n", len,
  395. srtp_bits_per_second(len, policy) / 1.0E6);
  396. /* these extra linefeeds let gnuplot know that a dataset is done */
  397. printf("\r\n\r\n");
  398. }
  399. void
  400. srtp_do_rejection_timing(const srtp_policy_t *policy) {
  401. int len;
  402. /*
  403. * note: the output of this function is formatted so that it
  404. * can be used in gnuplot. '#' indicates a comment, and "\r\n"
  405. * terminates a record
  406. */
  407. printf("# testing srtp rejection throughput:\r\n");
  408. printf("# mesg length (octets)\trejections per second\r\n");
  409. for (len=8; len <= 2048; len *= 2)
  410. printf("%d\t\t\t%e\r\n", len, srtp_rejections_per_second(len, policy));
  411. /* these extra linefeeds let gnuplot know that a dataset is done */
  412. printf("\r\n\r\n");
  413. }
  414. #define MAX_MSG_LEN 1024
  415. double
  416. srtp_bits_per_second(int msg_len_octets, const srtp_policy_t *policy) {
  417. srtp_t srtp;
  418. srtp_hdr_t *mesg;
  419. int i;
  420. clock_t timer;
  421. int num_trials = 100000;
  422. int len;
  423. uint32_t ssrc;
  424. err_status_t status;
  425. /*
  426. * allocate and initialize an srtp session
  427. */
  428. status = srtp_create(&srtp, policy);
  429. if (status) {
  430. printf("error: srtp_create() failed with error code %d\n", status);
  431. exit(1);
  432. }
  433. /*
  434. * if the ssrc is unspecified, use a predetermined one
  435. */
  436. if (policy->ssrc.type != ssrc_specific) {
  437. ssrc = 0xdeadbeef;
  438. } else {
  439. ssrc = policy->ssrc.value;
  440. }
  441. /*
  442. * create a test packet
  443. */
  444. mesg = srtp_create_test_packet(msg_len_octets, ssrc);
  445. if (mesg == NULL)
  446. return 0.0; /* indicate failure by returning zero */
  447. timer = clock();
  448. for (i=0; i < num_trials; i++) {
  449. len = msg_len_octets + 12; /* add in rtp header length */
  450. /* srtp protect message */
  451. status = srtp_protect(srtp, mesg, &len);
  452. if (status) {
  453. printf("error: srtp_protect() failed with error code %d\n", status);
  454. exit(1);
  455. }
  456. /* increment message number */
  457. {
  458. /* hack sequence to avoid problems with macros for htons/ntohs on some systems */
  459. short new_seq = ntohs(mesg->seq) + 1;
  460. mesg->seq = htons(new_seq);
  461. }
  462. }
  463. timer = clock() - timer;
  464. free(mesg);
  465. status = srtp_dealloc(srtp);
  466. if (status) {
  467. printf("error: srtp_dealloc() failed with error code %d\n", status);
  468. exit(1);
  469. }
  470. return (double) (msg_len_octets) * 8 *
  471. num_trials * CLOCKS_PER_SEC / timer;
  472. }
  473. double
  474. srtp_rejections_per_second(int msg_len_octets, const srtp_policy_t *policy) {
  475. srtp_ctx_t *srtp;
  476. srtp_hdr_t *mesg;
  477. int i;
  478. int len;
  479. clock_t timer;
  480. int num_trials = 1000000;
  481. uint32_t ssrc = policy->ssrc.value;
  482. err_status_t status;
  483. /*
  484. * allocate and initialize an srtp session
  485. */
  486. status = srtp_create(&srtp, policy);
  487. if (status) {
  488. printf("error: srtp_create() failed with error code %d\n", status);
  489. exit(1);
  490. }
  491. mesg = srtp_create_test_packet(msg_len_octets, ssrc);
  492. if (mesg == NULL)
  493. return 0.0; /* indicate failure by returning zero */
  494. len = msg_len_octets;
  495. srtp_protect(srtp, (srtp_hdr_t *)mesg, &len);
  496. timer = clock();
  497. for (i=0; i < num_trials; i++) {
  498. len = msg_len_octets;
  499. srtp_unprotect(srtp, (srtp_hdr_t *)mesg, &len);
  500. }
  501. timer = clock() - timer;
  502. free(mesg);
  503. status = srtp_dealloc(srtp);
  504. if (status) {
  505. printf("error: srtp_dealloc() failed with error code %d\n", status);
  506. exit(1);
  507. }
  508. return (double) num_trials * CLOCKS_PER_SEC / timer;
  509. }
  510. void
  511. err_check(err_status_t s) {
  512. if (s == err_status_ok)
  513. return;
  514. else
  515. fprintf(stderr, "error: unexpected srtp failure (code %d)\n", s);
  516. exit (1);
  517. }
  518. err_status_t
  519. srtp_test(const srtp_policy_t *policy) {
  520. int i;
  521. srtp_t srtp_sender;
  522. srtp_t srtp_rcvr;
  523. err_status_t status = err_status_ok;
  524. srtp_hdr_t *hdr, *hdr2;
  525. uint8_t hdr_enc[64];
  526. uint8_t *pkt_end;
  527. int msg_len_octets, msg_len_enc;
  528. int len;
  529. int tag_length = policy->rtp.auth_tag_len;
  530. uint32_t ssrc;
  531. srtp_policy_t *rcvr_policy;
  532. err_check(srtp_create(&srtp_sender, policy));
  533. /* print out policy */
  534. err_check(srtp_session_print_policy(srtp_sender));
  535. /*
  536. * initialize data buffer, using the ssrc in the policy unless that
  537. * value is a wildcard, in which case we'll just use an arbitrary
  538. * one
  539. */
  540. if (policy->ssrc.type != ssrc_specific)
  541. ssrc = 0xdecafbad;
  542. else
  543. ssrc = policy->ssrc.value;
  544. msg_len_octets = 28;
  545. hdr = srtp_create_test_packet(msg_len_octets, ssrc);
  546. if (hdr == NULL)
  547. return err_status_alloc_fail;
  548. hdr2 = srtp_create_test_packet(msg_len_octets, ssrc);
  549. if (hdr2 == NULL) {
  550. free(hdr);
  551. return err_status_alloc_fail;
  552. }
  553. /* set message length */
  554. len = msg_len_octets;
  555. debug_print(mod_driver, "before protection:\n%s",
  556. srtp_packet_to_string(hdr, len));
  557. #if PRINT_REFERENCE_PACKET
  558. debug_print(mod_driver, "reference packet before protection:\n%s",
  559. octet_string_hex_string((uint8_t *)hdr, len));
  560. #endif
  561. err_check(srtp_protect(srtp_sender, hdr, &len));
  562. debug_print(mod_driver, "after protection:\n%s",
  563. srtp_packet_to_string(hdr, len));
  564. #if PRINT_REFERENCE_PACKET
  565. debug_print(mod_driver, "after protection:\n%s",
  566. octet_string_hex_string((uint8_t *)hdr, len));
  567. #endif
  568. /* save protected message and length */
  569. memcpy(hdr_enc, hdr, len);
  570. msg_len_enc = len;
  571. /*
  572. * check for overrun of the srtp_protect() function
  573. *
  574. * The packet is followed by a value of 0xfffff; if the value of the
  575. * data following the packet is different, then we know that the
  576. * protect function is overwriting the end of the packet.
  577. */
  578. pkt_end = (uint8_t *)hdr + sizeof(srtp_hdr_t)
  579. + msg_len_octets + tag_length;
  580. for (i = 0; i < 4; i++)
  581. if (pkt_end[i] != 0xff) {
  582. fprintf(stdout, "overwrite in srtp_protect() function "
  583. "(expected %x, found %x in trailing octet %d)\n",
  584. 0xff, ((uint8_t *)hdr)[i], i);
  585. free(hdr);
  586. free(hdr2);
  587. return err_status_algo_fail;
  588. }
  589. /*
  590. * if the policy includes confidentiality, check that ciphertext is
  591. * different than plaintext
  592. *
  593. * Note that this check will give false negatives, with some small
  594. * probability, especially if the packets are short. For that
  595. * reason, we skip this check if the plaintext is less than four
  596. * octets long.
  597. */
  598. if ((policy->rtp.sec_serv & sec_serv_conf) && (msg_len_octets >= 4)) {
  599. printf("testing that ciphertext is distinct from plaintext...");
  600. status = err_status_algo_fail;
  601. for (i=12; i < msg_len_octets+12; i++)
  602. if (((uint8_t *)hdr)[i] != ((uint8_t *)hdr2)[i]) {
  603. status = err_status_ok;
  604. }
  605. if (status) {
  606. printf("failed\n");
  607. free(hdr);
  608. free(hdr2);
  609. return status;
  610. }
  611. printf("passed\n");
  612. }
  613. /*
  614. * if the policy uses a 'wildcard' ssrc, then we need to make a copy
  615. * of the policy that changes the direction to inbound
  616. *
  617. * we always copy the policy into the rcvr_policy, since otherwise
  618. * the compiler would fret about the constness of the policy
  619. */
  620. rcvr_policy = (srtp_policy_t*) malloc(sizeof(srtp_policy_t));
  621. if (rcvr_policy == NULL) {
  622. free(hdr);
  623. free(hdr2);
  624. return err_status_alloc_fail;
  625. }
  626. memcpy(rcvr_policy, policy, sizeof(srtp_policy_t));
  627. if (policy->ssrc.type == ssrc_any_outbound) {
  628. rcvr_policy->ssrc.type = ssrc_any_inbound;
  629. }
  630. err_check(srtp_create(&srtp_rcvr, rcvr_policy));
  631. err_check(srtp_unprotect(srtp_rcvr, hdr, &len));
  632. debug_print(mod_driver, "after unprotection:\n%s",
  633. srtp_packet_to_string(hdr, len));
  634. /* verify that the unprotected packet matches the origial one */
  635. for (i=0; i < msg_len_octets; i++)
  636. if (((uint8_t *)hdr)[i] != ((uint8_t *)hdr2)[i]) {
  637. fprintf(stdout, "mismatch at octet %d\n", i);
  638. status = err_status_algo_fail;
  639. }
  640. if (status) {
  641. free(hdr);
  642. free(hdr2);
  643. free(rcvr_policy);
  644. return status;
  645. }
  646. /*
  647. * if the policy includes authentication, then test for false positives
  648. */
  649. if (policy->rtp.sec_serv & sec_serv_auth) {
  650. char *data = ((char *)hdr) + 12;
  651. printf("testing for false positives in replay check...");
  652. /* set message length */
  653. len = msg_len_enc;
  654. /* unprotect a second time - should fail with a replay error */
  655. status = srtp_unprotect(srtp_rcvr, hdr_enc, &len);
  656. if (status != err_status_replay_fail) {
  657. printf("failed with error code %d\n", status);
  658. free(hdr);
  659. free(hdr2);
  660. free(rcvr_policy);
  661. return status;
  662. } else {
  663. printf("passed\n");
  664. }
  665. printf("testing for false positives in auth check...");
  666. /* increment sequence number in header */
  667. hdr->seq++;
  668. /* set message length */
  669. len = msg_len_octets;
  670. /* apply protection */
  671. err_check(srtp_protect(srtp_sender, hdr, &len));
  672. /* flip bits in packet */
  673. data[0] ^= 0xff;
  674. /* unprotect, and check for authentication failure */
  675. status = srtp_unprotect(srtp_rcvr, hdr, &len);
  676. if (status != err_status_auth_fail) {
  677. printf("failed\n");
  678. free(hdr);
  679. free(hdr2);
  680. free(rcvr_policy);
  681. return status;
  682. } else {
  683. printf("passed\n");
  684. }
  685. }
  686. err_check(srtp_dealloc(srtp_sender));
  687. err_check(srtp_dealloc(srtp_rcvr));
  688. free(hdr);
  689. free(hdr2);
  690. free(rcvr_policy);
  691. return err_status_ok;
  692. }
  693. err_status_t
  694. srtcp_test(const srtp_policy_t *policy) {
  695. int i;
  696. srtp_t srtcp_sender;
  697. srtp_t srtcp_rcvr;
  698. err_status_t status = err_status_ok;
  699. srtp_hdr_t *hdr, *hdr2;
  700. uint8_t hdr_enc[64];
  701. uint8_t *pkt_end;
  702. int msg_len_octets, msg_len_enc;
  703. int len;
  704. int tag_length = policy->rtp.auth_tag_len;
  705. uint32_t ssrc;
  706. srtp_policy_t *rcvr_policy;
  707. err_check(srtp_create(&srtcp_sender, policy));
  708. /* print out policy */
  709. err_check(srtp_session_print_policy(srtcp_sender));
  710. /*
  711. * initialize data buffer, using the ssrc in the policy unless that
  712. * value is a wildcard, in which case we'll just use an arbitrary
  713. * one
  714. */
  715. if (policy->ssrc.type != ssrc_specific)
  716. ssrc = 0xdecafbad;
  717. else
  718. ssrc = policy->ssrc.value;
  719. msg_len_octets = 28;
  720. hdr = srtp_create_test_packet(msg_len_octets, ssrc);
  721. if (hdr == NULL)
  722. return err_status_alloc_fail;
  723. hdr2 = srtp_create_test_packet(msg_len_octets, ssrc);
  724. if (hdr2 == NULL) {
  725. free(hdr);
  726. return err_status_alloc_fail;
  727. }
  728. /* set message length */
  729. len = msg_len_octets;
  730. debug_print(mod_driver, "before protection:\n%s",
  731. srtp_packet_to_string(hdr, len));
  732. #if PRINT_REFERENCE_PACKET
  733. debug_print(mod_driver, "reference packet before protection:\n%s",
  734. octet_string_hex_string((uint8_t *)hdr, len));
  735. #endif
  736. err_check(srtp_protect_rtcp(srtcp_sender, hdr, &len));
  737. debug_print(mod_driver, "after protection:\n%s",
  738. srtp_packet_to_string(hdr, len));
  739. #if PRINT_REFERENCE_PACKET
  740. debug_print(mod_driver, "after protection:\n%s",
  741. octet_string_hex_string((uint8_t *)hdr, len));
  742. #endif
  743. /* save protected message and length */
  744. memcpy(hdr_enc, hdr, len);
  745. msg_len_enc = len;
  746. /*
  747. * check for overrun of the srtp_protect() function
  748. *
  749. * The packet is followed by a value of 0xfffff; if the value of the
  750. * data following the packet is different, then we know that the
  751. * protect function is overwriting the end of the packet.
  752. */
  753. pkt_end = (uint8_t *)hdr + sizeof(srtp_hdr_t)
  754. + msg_len_octets + tag_length;
  755. for (i = 0; i < 4; i++)
  756. if (pkt_end[i] != 0xff) {
  757. fprintf(stdout, "overwrite in srtp_protect_rtcp() function "
  758. "(expected %x, found %x in trailing octet %d)\n",
  759. 0xff, ((uint8_t *)hdr)[i], i);
  760. free(hdr);
  761. free(hdr2);
  762. return err_status_algo_fail;
  763. }
  764. /*
  765. * if the policy includes confidentiality, check that ciphertext is
  766. * different than plaintext
  767. *
  768. * Note that this check will give false negatives, with some small
  769. * probability, especially if the packets are short. For that
  770. * reason, we skip this check if the plaintext is less than four
  771. * octets long.
  772. */
  773. if ((policy->rtp.sec_serv & sec_serv_conf) && (msg_len_octets >= 4)) {
  774. printf("testing that ciphertext is distinct from plaintext...");
  775. status = err_status_algo_fail;
  776. for (i=12; i < msg_len_octets+12; i++)
  777. if (((uint8_t *)hdr)[i] != ((uint8_t *)hdr2)[i]) {
  778. status = err_status_ok;
  779. }
  780. if (status) {
  781. printf("failed\n");
  782. free(hdr);
  783. free(hdr2);
  784. return status;
  785. }
  786. printf("passed\n");
  787. }
  788. /*
  789. * if the policy uses a 'wildcard' ssrc, then we need to make a copy
  790. * of the policy that changes the direction to inbound
  791. *
  792. * we always copy the policy into the rcvr_policy, since otherwise
  793. * the compiler would fret about the constness of the policy
  794. */
  795. rcvr_policy = (srtp_policy_t*) malloc(sizeof(srtp_policy_t));
  796. if (rcvr_policy == NULL)
  797. return err_status_alloc_fail;
  798. memcpy(rcvr_policy, policy, sizeof(srtp_policy_t));
  799. if (policy->ssrc.type == ssrc_any_outbound) {
  800. rcvr_policy->ssrc.type = ssrc_any_inbound;
  801. }
  802. err_check(srtp_create(&srtcp_rcvr, rcvr_policy));
  803. err_check(srtp_unprotect_rtcp(srtcp_rcvr, hdr, &len));
  804. debug_print(mod_driver, "after unprotection:\n%s",
  805. srtp_packet_to_string(hdr, len));
  806. /* verify that the unprotected packet matches the origial one */
  807. for (i=0; i < msg_len_octets; i++)
  808. if (((uint8_t *)hdr)[i] != ((uint8_t *)hdr2)[i]) {
  809. fprintf(stdout, "mismatch at octet %d\n", i);
  810. status = err_status_algo_fail;
  811. }
  812. if (status) {
  813. free(hdr);
  814. free(hdr2);
  815. free(rcvr_policy);
  816. return status;
  817. }
  818. /*
  819. * if the policy includes authentication, then test for false positives
  820. */
  821. if (policy->rtp.sec_serv & sec_serv_auth) {
  822. char *data = ((char *)hdr) + 12;
  823. printf("testing for false positives in replay check...");
  824. /* set message length */
  825. len = msg_len_enc;
  826. /* unprotect a second time - should fail with a replay error */
  827. status = srtp_unprotect_rtcp(srtcp_rcvr, hdr_enc, &len);
  828. if (status != err_status_replay_fail) {
  829. printf("failed with error code %d\n", status);
  830. free(hdr);
  831. free(hdr2);
  832. free(rcvr_policy);
  833. return status;
  834. } else {
  835. printf("passed\n");
  836. }
  837. printf("testing for false positives in auth check...");
  838. /* increment sequence number in header */
  839. hdr->seq++;
  840. /* set message length */
  841. len = msg_len_octets;
  842. /* apply protection */
  843. err_check(srtp_protect_rtcp(srtcp_sender, hdr, &len));
  844. /* flip bits in packet */
  845. data[0] ^= 0xff;
  846. /* unprotect, and check for authentication failure */
  847. status = srtp_unprotect_rtcp(srtcp_rcvr, hdr, &len);
  848. if (status != err_status_auth_fail) {
  849. printf("failed\n");
  850. free(hdr);
  851. free(hdr2);
  852. free(rcvr_policy);
  853. return status;
  854. } else {
  855. printf("passed\n");
  856. }
  857. }
  858. err_check(srtp_dealloc(srtcp_sender));
  859. err_check(srtp_dealloc(srtcp_rcvr));
  860. free(hdr);
  861. free(hdr2);
  862. free(rcvr_policy);
  863. return err_status_ok;
  864. }
  865. err_status_t
  866. srtp_session_print_policy(srtp_t srtp) {
  867. char *serv_descr[4] = {
  868. "none",
  869. "confidentiality",
  870. "authentication",
  871. "confidentiality and authentication"
  872. };
  873. char *direction[3] = {
  874. "unknown",
  875. "outbound",
  876. "inbound"
  877. };
  878. srtp_stream_t stream;
  879. /* sanity checking */
  880. if (srtp == NULL)
  881. return err_status_fail;
  882. /* if there's a template stream, print it out */
  883. if (srtp->stream_template != NULL) {
  884. stream = srtp->stream_template;
  885. printf("# SSRC: any %s\r\n"
  886. "# rtp cipher: %s\r\n"
  887. "# rtp auth: %s\r\n"
  888. "# rtp services: %s\r\n"
  889. "# rtcp cipher: %s\r\n"
  890. "# rtcp auth: %s\r\n"
  891. "# rtcp services: %s\r\n"
  892. "# window size: %lu\r\n"
  893. "# tx rtx allowed:%s\r\n",
  894. direction[stream->direction],
  895. stream->rtp_cipher->type->description,
  896. stream->rtp_auth->type->description,
  897. serv_descr[stream->rtp_services],
  898. stream->rtcp_cipher->type->description,
  899. stream->rtcp_auth->type->description,
  900. serv_descr[stream->rtcp_services],
  901. rdbx_get_window_size(&stream->rtp_rdbx),
  902. stream->allow_repeat_tx ? "true" : "false");
  903. }
  904. /* loop over streams in session, printing the policy of each */
  905. stream = srtp->stream_list;
  906. while (stream != NULL) {
  907. if (stream->rtp_services > sec_serv_conf_and_auth)
  908. return err_status_bad_param;
  909. printf("# SSRC: 0x%08x\r\n"
  910. "# rtp cipher: %s\r\n"
  911. "# rtp auth: %s\r\n"
  912. "# rtp services: %s\r\n"
  913. "# rtcp cipher: %s\r\n"
  914. "# rtcp auth: %s\r\n"
  915. "# rtcp services: %s\r\n"
  916. "# window size: %lu\r\n"
  917. "# tx rtx allowed:%s\r\n",
  918. stream->ssrc,
  919. stream->rtp_cipher->type->description,
  920. stream->rtp_auth->type->description,
  921. serv_descr[stream->rtp_services],
  922. stream->rtcp_cipher->type->description,
  923. stream->rtcp_auth->type->description,
  924. serv_descr[stream->rtcp_services],
  925. rdbx_get_window_size(&stream->rtp_rdbx),
  926. stream->allow_repeat_tx ? "true" : "false");
  927. /* advance to next stream in the list */
  928. stream = stream->next;
  929. }
  930. return err_status_ok;
  931. }
  932. err_status_t
  933. srtp_print_policy(const srtp_policy_t *policy) {
  934. err_status_t status;
  935. srtp_t session;
  936. status = srtp_create(&session, policy);
  937. if (status)
  938. return status;
  939. status = srtp_session_print_policy(session);
  940. if (status)
  941. return status;
  942. status = srtp_dealloc(session);
  943. if (status)
  944. return status;
  945. return err_status_ok;
  946. }
  947. /*
  948. * srtp_print_packet(...) is for debugging only
  949. * it prints an RTP packet to the stdout
  950. *
  951. * note that this function is *not* threadsafe
  952. */
  953. #include <stdio.h>
  954. #define MTU 2048
  955. char packet_string[MTU];
  956. char *
  957. srtp_packet_to_string(srtp_hdr_t *hdr, int pkt_octet_len) {
  958. int octets_in_rtp_header = 12;
  959. uint8_t *data = ((uint8_t *)hdr)+octets_in_rtp_header;
  960. int hex_len = pkt_octet_len-octets_in_rtp_header;
  961. /* sanity checking */
  962. if ((hdr == NULL) || (pkt_octet_len > MTU))
  963. return NULL;
  964. /* write packet into string */
  965. sprintf(packet_string,
  966. "(s)rtp packet: {\n"
  967. " version:\t%d\n"
  968. " p:\t\t%d\n"
  969. " x:\t\t%d\n"
  970. " cc:\t\t%d\n"
  971. " m:\t\t%d\n"
  972. " pt:\t\t%x\n"
  973. " seq:\t\t%x\n"
  974. " ts:\t\t%x\n"
  975. " ssrc:\t%x\n"
  976. " data:\t%s\n"
  977. "} (%d octets in total)\n",
  978. hdr->version,
  979. hdr->p,
  980. hdr->x,
  981. hdr->cc,
  982. hdr->m,
  983. hdr->pt,
  984. hdr->seq,
  985. hdr->ts,
  986. hdr->ssrc,
  987. octet_string_hex_string(data, hex_len),
  988. pkt_octet_len);
  989. return packet_string;
  990. }
  991. /*
  992. * mips_estimate() is a simple function to estimate the number of
  993. * instructions per second that the host can perform. note that this
  994. * function can be grossly wrong; you may want to have a manual sanity
  995. * check of its output!
  996. *
  997. * the 'ignore' pointer is there to convince the compiler to not just
  998. * optimize away the function
  999. */
  1000. double
  1001. mips_estimate(int num_trials, int *ignore) {
  1002. clock_t t;
  1003. volatile int i, sum;
  1004. sum = 0;
  1005. t = clock();
  1006. for (i=0; i<num_trials; i++)
  1007. sum += i;
  1008. t = clock() - t;
  1009. /* printf("%d\n", sum); */
  1010. *ignore = sum;
  1011. return (double) num_trials * CLOCKS_PER_SEC / t;
  1012. }
  1013. /*
  1014. * srtp_validate() verifies the correctness of libsrtp by comparing
  1015. * some computed packets against some pre-computed reference values.
  1016. * These packets were made with the default SRTP policy.
  1017. */
  1018. err_status_t
  1019. srtp_validate() {
  1020. uint8_t srtp_plaintext_ref[28] = {
  1021. 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
  1022. 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
  1023. 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
  1024. 0xab, 0xab, 0xab, 0xab
  1025. };
  1026. uint8_t srtp_plaintext[38] = {
  1027. 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
  1028. 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
  1029. 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
  1030. 0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
  1031. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  1032. };
  1033. uint8_t srtp_ciphertext[38] = {
  1034. 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
  1035. 0xca, 0xfe, 0xba, 0xbe, 0x4e, 0x55, 0xdc, 0x4c,
  1036. 0xe7, 0x99, 0x78, 0xd8, 0x8c, 0xa4, 0xd2, 0x15,
  1037. 0x94, 0x9d, 0x24, 0x02, 0xb7, 0x8d, 0x6a, 0xcc,
  1038. 0x99, 0xea, 0x17, 0x9b, 0x8d, 0xbb
  1039. };
  1040. srtp_t srtp_snd, srtp_recv;
  1041. err_status_t status;
  1042. int len;
  1043. srtp_policy_t policy;
  1044. /*
  1045. * create a session with a single stream using the default srtp
  1046. * policy and with the SSRC value 0xcafebabe
  1047. */
  1048. crypto_policy_set_rtp_default(&policy.rtp);
  1049. crypto_policy_set_rtcp_default(&policy.rtcp);
  1050. policy.ssrc.type = ssrc_specific;
  1051. policy.ssrc.value = 0xcafebabe;
  1052. policy.key = test_key;
  1053. policy.ekt = NULL;
  1054. policy.window_size = 128;
  1055. policy.allow_repeat_tx = 0;
  1056. policy.next = NULL;
  1057. status = srtp_create(&srtp_snd, &policy);
  1058. if (status)
  1059. return status;
  1060. /*
  1061. * protect plaintext, then compare with ciphertext
  1062. */
  1063. len = 28;
  1064. status = srtp_protect(srtp_snd, srtp_plaintext, &len);
  1065. if (status || (len != 38))
  1066. return err_status_fail;
  1067. debug_print(mod_driver, "ciphertext:\n %s",
  1068. octet_string_hex_string(srtp_plaintext, len));
  1069. debug_print(mod_driver, "ciphertext reference:\n %s",
  1070. octet_string_hex_string(srtp_ciphertext, len));
  1071. if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
  1072. return err_status_fail;
  1073. /*
  1074. * create a receiver session context comparable to the one created
  1075. * above - we need to do this so that the replay checking doesn't
  1076. * complain
  1077. */
  1078. status = srtp_create(&srtp_recv, &policy);
  1079. if (status)
  1080. return status;
  1081. /*
  1082. * unprotect ciphertext, then compare with plaintext
  1083. */
  1084. status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
  1085. if (status || (len != 28))
  1086. return status;
  1087. if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
  1088. return err_status_fail;
  1089. status = srtp_dealloc(srtp_snd);
  1090. if (status)
  1091. return status;
  1092. status = srtp_dealloc(srtp_recv);
  1093. if (status)
  1094. return status;
  1095. return err_status_ok;
  1096. }
  1097. /*
  1098. * srtp_validate_aes_256() verifies the correctness of libsrtp by comparing
  1099. * some computed packets against some pre-computed reference values.
  1100. * These packets were made with the AES-CM-256/HMAC-SHA-1-80 policy.
  1101. */
  1102. err_status_t
  1103. srtp_validate_aes_256() {
  1104. unsigned char aes_256_test_key[46] = {
  1105. 0xf0, 0xf0, 0x49, 0x14, 0xb5, 0x13, 0xf2, 0x76,
  1106. 0x3a, 0x1b, 0x1f, 0xa1, 0x30, 0xf1, 0x0e, 0x29,
  1107. 0x98, 0xf6, 0xf6, 0xe4, 0x3e, 0x43, 0x09, 0xd1,
  1108. 0xe6, 0x22, 0xa0, 0xe3, 0x32, 0xb9, 0xf1, 0xb6,
  1109. 0x3b, 0x04, 0x80, 0x3d, 0xe5, 0x1e, 0xe7, 0xc9,
  1110. 0x64, 0x23, 0xab, 0x5b, 0x78, 0xd2
  1111. };
  1112. uint8_t srtp_plaintext_ref[28] = {
  1113. 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
  1114. 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
  1115. 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
  1116. 0xab, 0xab, 0xab, 0xab
  1117. };
  1118. uint8_t srtp_plaintext[38] = {
  1119. 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
  1120. 0xca, 0xfe, 0xba, 0xbe, 0xab, 0xab, 0xab, 0xab,
  1121. 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab,
  1122. 0xab, 0xab, 0xab, 0xab, 0x00, 0x00, 0x00, 0x00,
  1123. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  1124. };
  1125. uint8_t srtp_ciphertext[38] = {
  1126. 0x80, 0x0f, 0x12, 0x34, 0xde, 0xca, 0xfb, 0xad,
  1127. 0xca, 0xfe, 0xba, 0xbe, 0xf1, 0xd9, 0xde, 0x17,
  1128. 0xff, 0x25, 0x1f, 0xf1, 0xaa, 0x00, 0x77, 0x74,
  1129. 0xb0, 0xb4, 0xb4, 0x0d, 0xa0, 0x8d, 0x9d, 0x9a,
  1130. 0x5b, 0x3a, 0x55, 0xd8, 0x87, 0x3b
  1131. };
  1132. srtp_t srtp_snd, srtp_recv;
  1133. err_status_t status;
  1134. int len;
  1135. srtp_policy_t policy;
  1136. /*
  1137. * create a session with a single stream using the default srtp
  1138. * policy and with the SSRC value 0xcafebabe
  1139. */
  1140. crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtp);
  1141. crypto_policy_set_aes_cm_256_hmac_sha1_80(&policy.rtcp);
  1142. policy.ssrc.type = ssrc_specific;
  1143. policy.ssrc.value = 0xcafebabe;
  1144. policy.key = aes_256_test_key;
  1145. policy.ekt = NULL;
  1146. policy.window_size = 128;
  1147. policy.allow_repeat_tx = 0;
  1148. policy.next = NULL;
  1149. status = srtp_create(&srtp_snd, &policy);
  1150. if (status)
  1151. return status;
  1152. /*
  1153. * protect plaintext, then compare with ciphertext
  1154. */
  1155. len = 28;
  1156. status = srtp_protect(srtp_snd, srtp_plaintext, &len);
  1157. if (status || (len != 38))
  1158. return err_status_fail;
  1159. debug_print(mod_driver, "ciphertext:\n %s",
  1160. octet_string_hex_string(srtp_plaintext, len));
  1161. debug_print(mod_driver, "ciphertext reference:\n %s",
  1162. octet_string_hex_string(srtp_ciphertext, len));
  1163. if (octet_string_is_eq(srtp_plaintext, srtp_ciphertext, len))
  1164. return err_status_fail;
  1165. /*
  1166. * create a receiver session context comparable to the one created
  1167. * above - we need to do this so that the replay checking doesn't
  1168. * complain
  1169. */
  1170. status = srtp_create(&srtp_recv, &policy);
  1171. if (status)
  1172. return status;
  1173. /*
  1174. * unprotect ciphertext, then compare with plaintext
  1175. */
  1176. status = srtp_unprotect(srtp_recv, srtp_ciphertext, &len);
  1177. if (status || (len != 28))
  1178. return status;
  1179. if (octet_string_is_eq(srtp_ciphertext, srtp_plaintext_ref, len))
  1180. return err_status_fail;
  1181. status = srtp_dealloc(srtp_snd);
  1182. if (status)
  1183. return status;
  1184. status = srtp_dealloc(srtp_recv);
  1185. if (status)
  1186. return status;
  1187. return err_status_ok;
  1188. }
  1189. err_status_t
  1190. srtp_create_big_policy(srtp_policy_t **list) {
  1191. extern const srtp_policy_t *policy_array[];
  1192. srtp_policy_t *p, *tmp;
  1193. int i = 0;
  1194. uint32_t ssrc = 0;
  1195. /* sanity checking */
  1196. if ((list == NULL) || (policy_array[0] == NULL))
  1197. return err_status_bad_param;
  1198. /*
  1199. * loop over policy list, mallocing a new list and copying values
  1200. * into it (and incrementing the SSRC value as we go along)
  1201. */
  1202. tmp = NULL;
  1203. while (policy_array[i] != NULL) {
  1204. p = (srtp_policy_t*) malloc(sizeof(srtp_policy_t));
  1205. if (p == NULL)
  1206. return err_status_bad_param;
  1207. memcpy(p, policy_array[i], sizeof(srtp_policy_t));
  1208. p->ssrc.type = ssrc_specific;
  1209. p->ssrc.value = ssrc++;
  1210. p->next = tmp;
  1211. tmp = p;
  1212. i++;
  1213. }
  1214. *list = p;
  1215. return err_status_ok;
  1216. }
  1217. err_status_t
  1218. srtp_dealloc_big_policy(srtp_policy_t *list) {
  1219. srtp_policy_t *p, *next;
  1220. for (p = list; p != NULL; p = next) {
  1221. next = p->next;
  1222. free(p);
  1223. }
  1224. return err_status_ok;
  1225. }
  1226. err_status_t
  1227. srtp_test_remove_stream() {
  1228. err_status_t status;
  1229. srtp_policy_t *policy_list, policy;
  1230. srtp_t session;
  1231. srtp_stream_t stream;
  1232. /*
  1233. * srtp_get_stream() is a libSRTP internal function that we declare
  1234. * here so that we can use it to verify the correct operation of the
  1235. * library
  1236. */
  1237. extern srtp_stream_t srtp_get_stream(srtp_t srtp, uint32_t ssrc);
  1238. status = srtp_create_big_policy(&policy_list);
  1239. if (status)
  1240. return status;
  1241. status = srtp_create(&session, policy_list);
  1242. if (status)
  1243. return status;
  1244. /*
  1245. * check for false positives by trying to remove a stream that's not
  1246. * in the session
  1247. */
  1248. status = srtp_remove_stream(session, htonl(0xaaaaaaaa));
  1249. if (status != err_status_no_ctx)
  1250. return err_status_fail;
  1251. /*
  1252. * check for false negatives by removing stream 0x1, then
  1253. * searching for streams 0x0 and 0x2
  1254. */
  1255. status = srtp_remove_stream(session, htonl(0x1));
  1256. if (status != err_status_ok)
  1257. return err_status_fail;
  1258. stream = srtp_get_stream(session, htonl(0x0));
  1259. if (stream == NULL)
  1260. return err_status_fail;
  1261. stream = srtp_get_stream(session, htonl(0x2));
  1262. if (stream == NULL)
  1263. return err_status_fail;
  1264. status = srtp_dealloc(session);
  1265. if (status != err_status_ok)
  1266. return status;
  1267. status = srtp_dealloc_big_policy(policy_list);
  1268. if (status != err_status_ok)
  1269. return status;
  1270. /* Now test adding and removing a single stream */
  1271. crypto_policy_set_rtp_default(&policy.rtp);
  1272. crypto_policy_set_rtcp_default(&policy.rtcp);
  1273. policy.ssrc.type = ssrc_specific;
  1274. policy.ssrc.value = 0xcafebabe;
  1275. policy.key = test_key;
  1276. policy.ekt = NULL;
  1277. policy.window_size = 128;
  1278. policy.allow_repeat_tx = 0;
  1279. policy.next = NULL;
  1280. status = srtp_create(&session, NULL);
  1281. if (status != err_status_ok)
  1282. return status;
  1283. status = srtp_add_stream(session, &policy);
  1284. if (status != err_status_ok)
  1285. return status;
  1286. status = srtp_remove_stream(session, htonl(0xcafebabe));
  1287. if (status != err_status_ok)
  1288. return status;
  1289. status = srtp_dealloc(session);
  1290. if (status != err_status_ok)
  1291. return status;
  1292. return err_status_ok;
  1293. }
  1294. /*
  1295. * srtp policy definitions - these definitions are used above
  1296. */
  1297. unsigned char test_key[46] = {
  1298. 0xe1, 0xf9, 0x7a, 0x0d, 0x3e, 0x01, 0x8b, 0xe0,
  1299. 0xd6, 0x4f, 0xa3, 0x2c, 0x06, 0xde, 0x41, 0x39,
  1300. 0x0e, 0xc6, 0x75, 0xad, 0x49, 0x8a, 0xfe, 0xeb,
  1301. 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6, 0xc1, 0x73,
  1302. 0xc3, 0x17, 0xf2, 0xda, 0xbe, 0x35, 0x77, 0x93,
  1303. 0xb6, 0x96, 0x0b, 0x3a, 0xab, 0xe6
  1304. };
  1305. const srtp_policy_t default_policy = {
  1306. { ssrc_any_outbound, 0 }, /* SSRC */
  1307. { /* SRTP policy */
  1308. AES_128_ICM, /* cipher type */
  1309. 30, /* cipher key length in octets */
  1310. HMAC_SHA1, /* authentication func type */
  1311. 16, /* auth key length in octets */
  1312. 10, /* auth tag length in octets */
  1313. sec_serv_conf_and_auth /* security services flag */
  1314. },
  1315. { /* SRTCP policy */
  1316. AES_128_ICM, /* cipher type */
  1317. 30, /* cipher key length in octets */
  1318. HMAC_SHA1, /* authentication func type */
  1319. 16, /* auth key length in octets */
  1320. 10, /* auth tag length in octets */
  1321. sec_serv_conf_and_auth /* security services flag */
  1322. },
  1323. test_key,
  1324. NULL, /* indicates that EKT is not in use */
  1325. 128, /* replay window size */
  1326. 0, /* retransmission not allowed */
  1327. NULL
  1328. };
  1329. const srtp_policy_t aes_tmmh_policy = {
  1330. { ssrc_any_outbound, 0 }, /* SSRC */
  1331. {
  1332. AES_128_ICM, /* cipher type */
  1333. 30, /* cipher key length in octets */
  1334. UST_TMMHv2, /* authentication func type */
  1335. 94, /* auth key length in octets */
  1336. 4, /* auth tag length in octets */
  1337. sec_serv_conf_and_auth /* security services flag */
  1338. },
  1339. {
  1340. AES_128_ICM, /* cipher type */
  1341. 30, /* cipher key length in octets */
  1342. UST_TMMHv2, /* authentication func type */
  1343. 94, /* auth key length in octets */
  1344. 4, /* auth tag length in octets */
  1345. sec_serv_conf_and_auth /* security services flag */
  1346. },
  1347. test_key,
  1348. NULL, /* indicates that EKT is not in use */
  1349. 128, /* replay window size */
  1350. 0, /* retransmission not allowed */
  1351. NULL
  1352. };
  1353. const srtp_policy_t tmmh_only_policy = {
  1354. { ssrc_any_outbound, 0 }, /* SSRC */
  1355. {
  1356. AES_128_ICM, /* cipher type */
  1357. 30, /* cipher key length in octets */
  1358. UST_TMMHv2, /* authentication func type */
  1359. 94, /* auth key length in octets */
  1360. 4, /* auth tag length in octets */
  1361. sec_serv_auth /* security services flag */
  1362. },
  1363. {
  1364. AES_128_ICM, /* cipher type */
  1365. 30, /* cipher key length in octets */
  1366. UST_TMMHv2, /* authentication func type */
  1367. 94, /* auth key length in octets */
  1368. 4, /* auth tag length in octets */
  1369. sec_serv_auth /* security services flag */
  1370. },
  1371. test_key,
  1372. NULL, /* indicates that EKT is not in use */
  1373. 128, /* replay window size */
  1374. 0, /* retransmission not allowed */
  1375. NULL
  1376. };
  1377. const srtp_policy_t aes_only_policy = {
  1378. { ssrc_any_outbound, 0 }, /* SSRC */
  1379. {
  1380. AES_128_ICM, /* cipher type */
  1381. 30, /* cipher key length in octets */
  1382. NULL_AUTH, /* authentication func type */
  1383. 0, /* auth key length in octets */
  1384. 0, /* auth tag length in octets */
  1385. sec_serv_conf /* security services flag */
  1386. },
  1387. {
  1388. AES_128_ICM, /* cipher type */
  1389. 30, /* cipher key length in octets */
  1390. NULL_AUTH, /* authentication func type */
  1391. 0, /* auth key length in octets */
  1392. 0, /* auth tag length in octets */
  1393. sec_serv_conf /* security services flag */
  1394. },
  1395. test_key,
  1396. NULL, /* indicates that EKT is not in use */
  1397. 128, /* replay window size */
  1398. 0, /* retransmission not allowed */
  1399. NULL
  1400. };
  1401. const srtp_policy_t hmac_only_policy = {
  1402. { ssrc_any_outbound, 0 }, /* SSRC */
  1403. {
  1404. NULL_CIPHER, /* cipher type */
  1405. 0, /* cipher key length in octets */
  1406. HMAC_SHA1, /* authentication func type */
  1407. 20, /* auth key length in octets */
  1408. 4, /* auth tag length in octets */
  1409. sec_serv_auth /* security services flag */
  1410. },
  1411. {
  1412. NULL_CIPHER, /* cipher type */
  1413. 0, /* cipher key length in octets */
  1414. HMAC_SHA1, /* authentication func type */
  1415. 20, /* auth key length in octets */
  1416. 4, /* auth tag length in octets */
  1417. sec_serv_auth /* security services flag */
  1418. },
  1419. test_key,
  1420. NULL, /* indicates that EKT is not in use */
  1421. 128, /* replay window size */
  1422. 0, /* retransmission not allowed */
  1423. NULL
  1424. };
  1425. #ifdef OPENSSL
  1426. const srtp_policy_t aes128_gcm_8_policy = {
  1427. { ssrc_any_outbound, 0 }, /* SSRC */
  1428. { /* SRTP policy */
  1429. AES_128_GCM, /* cipher type */
  1430. AES_128_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
  1431. NULL_AUTH, /* authentication func type */
  1432. 0, /* auth key length in octets */
  1433. 8, /* auth tag length in octets */
  1434. sec_serv_conf_and_auth /* security services flag */
  1435. },
  1436. { /* SRTCP policy */
  1437. AES_128_GCM, /* cipher type */
  1438. AES_128_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
  1439. NULL_AUTH, /* authentication func type */
  1440. 0, /* auth key length in octets */
  1441. 8, /* auth tag length in octets */
  1442. sec_serv_conf_and_auth /* security services flag */
  1443. },
  1444. test_key,
  1445. NULL, /* indicates that EKT is not in use */
  1446. 128, /* replay window size */
  1447. 0, /* retransmission not allowed */
  1448. NULL
  1449. };
  1450. const srtp_policy_t aes128_gcm_8_cauth_policy = {
  1451. { ssrc_any_outbound, 0 }, /* SSRC */
  1452. { /* SRTP policy */
  1453. AES_128_GCM, /* cipher type */
  1454. AES_128_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
  1455. NULL_AUTH, /* authentication func type */
  1456. 0, /* auth key length in octets */
  1457. 8, /* auth tag length in octets */
  1458. sec_serv_conf_and_auth /* security services flag */
  1459. },
  1460. { /* SRTCP policy */
  1461. AES_128_GCM, /* cipher type */
  1462. AES_128_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
  1463. NULL_AUTH, /* authentication func type */
  1464. 0, /* auth key length in octets */
  1465. 8, /* auth tag length in octets */
  1466. sec_serv_auth /* security services flag */
  1467. },
  1468. test_key,
  1469. NULL, /* indicates that EKT is not in use */
  1470. 128, /* replay window size */
  1471. 0, /* retransmission not allowed */
  1472. NULL
  1473. };
  1474. const srtp_policy_t aes256_gcm_8_policy = {
  1475. { ssrc_any_outbound, 0 }, /* SSRC */
  1476. { /* SRTP policy */
  1477. AES_256_GCM, /* cipher type */
  1478. AES_256_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
  1479. NULL_AUTH, /* authentication func type */
  1480. 0, /* auth key length in octets */
  1481. 8, /* auth tag length in octets */
  1482. sec_serv_conf_and_auth /* security services flag */
  1483. },
  1484. { /* SRTCP policy */
  1485. AES_256_GCM, /* cipher type */
  1486. AES_256_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
  1487. NULL_AUTH, /* authentication func type */
  1488. 0, /* auth key length in octets */
  1489. 8, /* auth tag length in octets */
  1490. sec_serv_conf_and_auth /* security services flag */
  1491. },
  1492. test_key,
  1493. NULL, /* indicates that EKT is not in use */
  1494. 128, /* replay window size */
  1495. 0, /* retransmission not allowed */
  1496. NULL
  1497. };
  1498. const srtp_policy_t aes256_gcm_8_cauth_policy = {
  1499. { ssrc_any_outbound, 0 }, /* SSRC */
  1500. { /* SRTP policy */
  1501. AES_256_GCM, /* cipher type */
  1502. AES_256_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
  1503. NULL_AUTH, /* authentication func type */
  1504. 0, /* auth key length in octets */
  1505. 8, /* auth tag length in octets */
  1506. sec_serv_conf_and_auth /* security services flag */
  1507. },
  1508. { /* SRTCP policy */
  1509. AES_256_GCM, /* cipher type */
  1510. AES_256_GCM_KEYSIZE_WSALT, /* cipher key length in octets */
  1511. NULL_AUTH, /* authentication func type */
  1512. 0, /* auth key length in octets */
  1513. 8, /* auth tag length in octets */
  1514. sec_serv_auth /* security services flag */
  1515. },
  1516. test_key,
  1517. NULL, /* indicates that EKT is not in use */
  1518. 128, /* replay window size */
  1519. 0, /* retransmission not allowed */
  1520. NULL
  1521. };
  1522. #endif
  1523. const srtp_policy_t null_policy = {
  1524. { ssrc_any_outbound, 0 }, /* SSRC */
  1525. {
  1526. NULL_CIPHER, /* cipher type */
  1527. 0, /* cipher key length in octets */
  1528. NULL_AUTH, /* authentication func type */
  1529. 0, /* auth key length in octets */
  1530. 0, /* auth tag length in octets */
  1531. sec_serv_none /* security services flag */
  1532. },
  1533. {
  1534. NULL_CIPHER, /* cipher type */
  1535. 0, /* cipher key length in octets */
  1536. NULL_AUTH, /* authentication func type */
  1537. 0, /* auth key length in octets */
  1538. 0, /* auth tag length in octets */
  1539. sec_serv_none /* security services flag */
  1540. },
  1541. test_key,
  1542. NULL, /* indicates that EKT is not in use */
  1543. 128, /* replay window size */
  1544. 0, /* retransmission not allowed */
  1545. NULL
  1546. };
  1547. unsigned char test_256_key[46] = {
  1548. 0xf0, 0xf0, 0x49, 0x14, 0xb5, 0x13, 0xf2, 0x76,
  1549. 0x3a, 0x1b, 0x1f, 0xa1, 0x30, 0xf1, 0x0e, 0x29,
  1550. 0x98, 0xf6, 0xf6, 0xe4, 0x3e, 0x43, 0x09, 0xd1,
  1551. 0xe6, 0x22, 0xa0, 0xe3, 0x32, 0xb9, 0xf1, 0xb6,
  1552. 0x3b, 0x04, 0x80, 0x3d, 0xe5, 0x1e, 0xe7, 0xc9,
  1553. 0x64, 0x23, 0xab, 0x5b, 0x78, 0xd2
  1554. };
  1555. const srtp_policy_t aes_256_hmac_policy = {
  1556. { ssrc_any_outbound, 0 }, /* SSRC */
  1557. { /* SRTP policy */
  1558. AES_ICM, /* cipher type */
  1559. 46, /* cipher key length in octets */
  1560. HMAC_SHA1, /* authentication func type */
  1561. 20, /* auth key length in octets */
  1562. 10, /* auth tag length in octets */
  1563. sec_serv_conf_and_auth /* security services flag */
  1564. },
  1565. { /* SRTCP policy */
  1566. AES_ICM, /* cipher type */
  1567. 46, /* cipher key length in octets */
  1568. HMAC_SHA1, /* authentication func type */
  1569. 20, /* auth key length in octets */
  1570. 10, /* auth tag length in octets */
  1571. sec_serv_conf_and_auth /* security services flag */
  1572. },
  1573. test_256_key,
  1574. NULL, /* indicates that EKT is not in use */
  1575. 128, /* replay window size */
  1576. 0, /* retransmission not allowed */
  1577. NULL
  1578. };
  1579. uint8_t ekt_test_key[16] = {
  1580. 0x77, 0x26, 0x9d, 0xac, 0x16, 0xa3, 0x28, 0xca,
  1581. 0x8e, 0xc9, 0x68, 0x4b, 0xcc, 0xc4, 0xd2, 0x1b
  1582. };
  1583. #include "ekt.h"
  1584. ekt_policy_ctx_t ekt_test_policy = {
  1585. 0xa5a5, /* SPI */
  1586. EKT_CIPHER_AES_128_ECB,
  1587. ekt_test_key,
  1588. NULL
  1589. };
  1590. const srtp_policy_t hmac_only_with_ekt_policy = {
  1591. { ssrc_any_outbound, 0 }, /* SSRC */
  1592. {
  1593. NULL_CIPHER, /* cipher type */
  1594. 0, /* cipher key length in octets */
  1595. HMAC_SHA1, /* authentication func type */
  1596. 20, /* auth key length in octets */
  1597. 4, /* auth tag length in octets */
  1598. sec_serv_auth /* security services flag */
  1599. },
  1600. {
  1601. NULL_CIPHER, /* cipher type */
  1602. 0, /* cipher key length in octets */
  1603. HMAC_SHA1, /* authentication func type */
  1604. 20, /* auth key length in octets */
  1605. 4, /* auth tag length in octets */
  1606. sec_serv_auth /* security services flag */
  1607. },
  1608. test_key,
  1609. &ekt_test_policy, /* indicates that EKT is not in use */
  1610. 128, /* replay window size */
  1611. 0, /* retransmission not allowed */
  1612. NULL
  1613. };
  1614. /*
  1615. * an array of pointers to the policies listed above
  1616. *
  1617. * This array is used to test various aspects of libSRTP for
  1618. * different cryptographic policies. The order of the elements
  1619. * matters - the timing test generates output that can be used
  1620. * in a plot (see the gnuplot script file 'timing'). If you
  1621. * add to this list, you should do it at the end.
  1622. */
  1623. #define USE_TMMH 0
  1624. const srtp_policy_t *
  1625. policy_array[] = {
  1626. &hmac_only_policy,
  1627. #if USE_TMMH
  1628. &tmmh_only_policy,
  1629. #endif
  1630. &aes_only_policy,
  1631. #if USE_TMMH
  1632. &aes_tmmh_policy,
  1633. #endif
  1634. &default_policy,
  1635. #ifdef OPENSSL
  1636. &aes128_gcm_8_policy,
  1637. &aes128_gcm_8_cauth_policy,
  1638. &aes256_gcm_8_policy,
  1639. &aes256_gcm_8_cauth_policy,
  1640. #endif
  1641. &null_policy,
  1642. &aes_256_hmac_policy,
  1643. &hmac_only_with_ekt_policy,
  1644. NULL
  1645. };
  1646. const srtp_policy_t wildcard_policy = {
  1647. { ssrc_any_outbound, 0 }, /* SSRC */
  1648. { /* SRTP policy */
  1649. AES_128_ICM, /* cipher type */
  1650. 30, /* cipher key length in octets */
  1651. HMAC_SHA1, /* authentication func type */
  1652. 16, /* auth key length in octets */
  1653. 10, /* auth tag length in octets */
  1654. sec_serv_conf_and_auth /* security services flag */
  1655. },
  1656. { /* SRTCP policy */
  1657. AES_128_ICM, /* cipher type */
  1658. 30, /* cipher key length in octets */
  1659. HMAC_SHA1, /* authentication func type */
  1660. 16, /* auth key length in octets */
  1661. 10, /* auth tag length in octets */
  1662. sec_serv_conf_and_auth /* security services flag */
  1663. },
  1664. test_key,
  1665. NULL,
  1666. 128, /* replay window size */
  1667. 0, /* retransmission not allowed */
  1668. NULL
  1669. };