srtp.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. /*
  2. * srtp.h
  3. *
  4. * interface to 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. #ifndef SRTP_H
  45. #define SRTP_H
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. #include "crypto_kernel.h"
  50. /**
  51. * @defgroup SRTP Secure RTP
  52. *
  53. * @brief libSRTP provides functions for protecting RTP and RTCP. See
  54. * Section @ref Overview for an introduction to the use of the library.
  55. *
  56. * @{
  57. */
  58. /*
  59. * SRTP_MASTER_KEY_LEN is the nominal master key length supported by libSRTP
  60. */
  61. #define SRTP_MASTER_KEY_LEN 30
  62. /*
  63. * SRTP_MAX_KEY_LEN is the maximum key length supported by libSRTP
  64. */
  65. #define SRTP_MAX_KEY_LEN 64
  66. /*
  67. * SRTP_MAX_TAG_LEN is the maximum tag length supported by libSRTP
  68. */
  69. #define SRTP_MAX_TAG_LEN 12
  70. /**
  71. * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer
  72. * (authentication tag and MKI) supported by libSRTP. This value is
  73. * the maximum number of octets that will be added to an RTP packet by
  74. * srtp_protect().
  75. *
  76. * @brief the maximum number of octets added by srtp_protect().
  77. */
  78. #define SRTP_MAX_TRAILER_LEN SRTP_MAX_TAG_LEN
  79. /*
  80. * SRTP_AEAD_SALT_LEN is the length of the SALT values used with
  81. * GCM mode. GCM mode requires an IV. The SALT value is used
  82. * as part of the IV formation logic applied to each RTP packet.
  83. */
  84. #define SRTP_AEAD_SALT_LEN 12
  85. #define AES_128_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 16
  86. #define AES_192_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 24
  87. #define AES_256_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 32
  88. /*
  89. * nota bene: since libSRTP doesn't support the use of the MKI, the
  90. * SRTP_MAX_TRAILER_LEN value is just the maximum tag length
  91. */
  92. /**
  93. * @brief sec_serv_t describes a set of security services.
  94. *
  95. * A sec_serv_t enumeration is used to describe the particular
  96. * security services that will be applied by a particular crypto
  97. * policy (or other mechanism).
  98. */
  99. typedef enum {
  100. sec_serv_none = 0, /**< no services */
  101. sec_serv_conf = 1, /**< confidentiality */
  102. sec_serv_auth = 2, /**< authentication */
  103. sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */
  104. }
  105. sec_serv_t;
  106. /**
  107. * @brief crypto_policy_t describes a particular crypto policy that
  108. * can be applied to an SRTP stream.
  109. *
  110. * A crypto_policy_t describes a particular cryptographic policy that
  111. * can be applied to an SRTP or SRTCP stream. An SRTP session policy
  112. * consists of a list of these policies, one for each SRTP stream
  113. * in the session.
  114. */
  115. typedef struct crypto_policy_t {
  116. cipher_type_id_t cipher_type; /**< An integer representing
  117. * the type of cipher. */
  118. int cipher_key_len; /**< The length of the cipher key
  119. * in octets. */
  120. auth_type_id_t auth_type; /**< An integer representing the
  121. * authentication function. */
  122. int auth_key_len; /**< The length of the authentication
  123. * function key in octets. */
  124. int auth_tag_len; /**< The length of the authentication
  125. * tag in octets. */
  126. sec_serv_t sec_serv; /**< The flag indicating the security
  127. * services to be applied. */
  128. } crypto_policy_t;
  129. /**
  130. * @brief ssrc_type_t describes the type of an SSRC.
  131. *
  132. * An ssrc_type_t enumeration is used to indicate a type of SSRC. See
  133. * @ref srtp_policy_t for more informataion.
  134. */
  135. typedef enum {
  136. ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */
  137. ssrc_specific = 1, /**< Indicates a specific SSRC value */
  138. ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value
  139. (i.e. a value that is used in the
  140. function srtp_unprotect()) */
  141. ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value
  142. (i.e. a value that is used in the
  143. function srtp_protect()) */
  144. } ssrc_type_t;
  145. /**
  146. * @brief An ssrc_t represents a particular SSRC value, or a `wildcard' SSRC.
  147. *
  148. * An ssrc_t represents a particular SSRC value (if its type is
  149. * ssrc_specific), or a wildcard SSRC value that will match all
  150. * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound
  151. * SSRCs (if its type is ssrc_any_inbound).
  152. *
  153. */
  154. typedef struct {
  155. ssrc_type_t type; /**< The type of this particular SSRC */
  156. unsigned int value; /**< The value of this SSRC, if it is not a wildcard */
  157. } ssrc_t;
  158. /**
  159. * @brief points to an EKT policy
  160. */
  161. typedef struct ekt_policy_ctx_t *ekt_policy_t;
  162. /**
  163. * @brief points to EKT stream data
  164. */
  165. typedef struct ekt_stream_ctx_t *ekt_stream_t;
  166. /**
  167. * @brief represents the policy for an SRTP session.
  168. *
  169. * A single srtp_policy_t struct represents the policy for a single
  170. * SRTP stream, and a linked list of these elements represents the
  171. * policy for an entire SRTP session. Each element contains the SRTP
  172. * and SRTCP crypto policies for that stream, a pointer to the SRTP
  173. * master key for that stream, the SSRC describing that stream, or a
  174. * flag indicating a `wildcard' SSRC value, and a `next' field that
  175. * holds a pointer to the next element in the list of policy elements,
  176. * or NULL if it is the last element.
  177. *
  178. * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an
  179. * inbound stream that for which there is no explicit SSRC entry in
  180. * another policy element. Similarly, the value SSRC_ANY_OUTBOUND
  181. * will matches any SSRC from an outbound stream that does not appear
  182. * in another policy element. Note that wildcard SSRCs &b cannot be
  183. * used to match both inbound and outbound traffic. This restriction
  184. * is intentional, and it allows libSRTP to ensure that no security
  185. * lapses result from accidental re-use of SSRC values during key
  186. * sharing.
  187. *
  188. *
  189. * @warning The final element of the list @b must have its `next' pointer
  190. * set to NULL.
  191. */
  192. typedef struct srtp_policy_t {
  193. ssrc_t ssrc; /**< The SSRC value of stream, or the
  194. * flags SSRC_ANY_INBOUND or
  195. * SSRC_ANY_OUTBOUND if key sharing
  196. * is used for this policy element.
  197. */
  198. crypto_policy_t rtp; /**< SRTP crypto policy. */
  199. crypto_policy_t rtcp; /**< SRTCP crypto policy. */
  200. unsigned char *key; /**< Pointer to the SRTP master key for
  201. * this stream. */
  202. ekt_policy_t ekt; /**< Pointer to the EKT policy structure
  203. * for this stream (if any) */
  204. unsigned long window_size; /**< The window size to use for replay
  205. * protection. */
  206. int allow_repeat_tx; /**< Whether retransmissions of
  207. * packets with the same sequence number
  208. * are allowed. (Note that such repeated
  209. * transmissions must have the same RTP
  210. * payload, or a severe security weakness
  211. * is introduced!) */
  212. struct srtp_policy_t *next; /**< Pointer to next stream policy. */
  213. } srtp_policy_t;
  214. /**
  215. * @brief An srtp_t points to an SRTP session structure.
  216. *
  217. * The typedef srtp_t is a pointer to a structure that represents
  218. * an SRTP session. This datatype is intentially opaque in
  219. * order to separate the interface from the implementation.
  220. *
  221. * An SRTP session consists of all of the traffic sent to the RTP and
  222. * RTCP destination transport addresses, using the RTP/SAVP (Secure
  223. * Audio/Video Profile). A session can be viewed as a set of SRTP
  224. * streams, each of which originates with a different participant.
  225. */
  226. typedef struct srtp_ctx_t *srtp_t;
  227. /**
  228. * @brief An srtp_stream_t points to an SRTP stream structure.
  229. *
  230. * The typedef srtp_stream_t is a pointer to a structure that
  231. * represents an SRTP stream. This datatype is intentionally
  232. * opaque in order to separate the interface from the implementation.
  233. *
  234. * An SRTP stream consists of all of the traffic sent to an SRTP
  235. * session by a single participant. A session can be viewed as
  236. * a set of streams.
  237. *
  238. */
  239. typedef struct srtp_stream_ctx_t *srtp_stream_t;
  240. /**
  241. * @brief srtp_init() initializes the srtp library.
  242. *
  243. * @warning This function @b must be called before any other srtp
  244. * functions.
  245. */
  246. err_status_t
  247. srtp_init(void);
  248. /**
  249. * @brief srtp_shutdown() de-initializes the srtp library.
  250. *
  251. * @warning No srtp functions may be called after calling this function.
  252. */
  253. err_status_t
  254. srtp_shutdown(void);
  255. /**
  256. * @brief srtp_protect() is the Secure RTP sender-side packet processing
  257. * function.
  258. *
  259. * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
  260. * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
  261. * the SRTP context ctx. If err_status_ok is returned, then rtp_hdr
  262. * points to the resulting SRTP packet and *len_ptr is the number of
  263. * octets in that packet; otherwise, no assumptions should be made
  264. * about the value of either data elements.
  265. *
  266. * The sequence numbers of the RTP packets presented to this function
  267. * need not be consecutive, but they @b must be out of order by less
  268. * than 2^15 = 32,768 packets.
  269. *
  270. * @warning This function assumes that it can write the authentication
  271. * tag into the location in memory immediately following the RTP
  272. * packet, and assumes that the RTP packet is aligned on a 32-bit
  273. * boundary.
  274. *
  275. * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
  276. * into the location in memory immediately following the RTP packet.
  277. * Callers MUST ensure that this much writable memory is available in
  278. * the buffer that holds the RTP packet.
  279. *
  280. * @param ctx is the SRTP context to use in processing the packet.
  281. *
  282. * @param rtp_hdr is a pointer to the RTP packet (before the call); after
  283. * the function returns, it points to the srtp packet.
  284. *
  285. * @param len_ptr is a pointer to the length in octets of the complete
  286. * RTP packet (header and body) before the function call, and of the
  287. * complete SRTP packet after the call, if err_status_ok was returned.
  288. * Otherwise, the value of the data to which it points is undefined.
  289. *
  290. * @return
  291. * - err_status_ok no problems
  292. * - err_status_replay_fail rtp sequence number was non-increasing
  293. * - @e other failure in cryptographic mechanisms
  294. */
  295. err_status_t
  296. srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
  297. /**
  298. * @brief srtp_unprotect() is the Secure RTP receiver-side packet
  299. * processing function.
  300. *
  301. * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
  302. * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
  303. * (which has length *len_ptr), using the SRTP context ctx. If
  304. * err_status_ok is returned, then srtp_hdr points to the resulting
  305. * RTP packet and *len_ptr is the number of octets in that packet;
  306. * otherwise, no assumptions should be made about the value of either
  307. * data elements.
  308. *
  309. * The sequence numbers of the RTP packets presented to this function
  310. * need not be consecutive, but they @b must be out of order by less
  311. * than 2^15 = 32,768 packets.
  312. *
  313. * @warning This function assumes that the SRTP packet is aligned on a
  314. * 32-bit boundary.
  315. *
  316. * @param ctx is a pointer to the srtp_t which applies to the
  317. * particular packet.
  318. *
  319. * @param srtp_hdr is a pointer to the header of the SRTP packet
  320. * (before the call). after the function returns, it points to the
  321. * rtp packet if err_status_ok was returned; otherwise, the value of
  322. * the data to which it points is undefined.
  323. *
  324. * @param len_ptr is a pointer to the length in octets of the complete
  325. * srtp packet (header and body) before the function call, and of the
  326. * complete rtp packet after the call, if err_status_ok was returned.
  327. * Otherwise, the value of the data to which it points is undefined.
  328. *
  329. * @return
  330. * - err_status_ok if the RTP packet is valid.
  331. * - err_status_auth_fail if the SRTP packet failed the message
  332. * authentication check.
  333. * - err_status_replay_fail if the SRTP packet is a replay (e.g. packet has
  334. * already been processed and accepted).
  335. * - [other] if there has been an error in the cryptographic mechanisms.
  336. *
  337. */
  338. err_status_t
  339. srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
  340. /**
  341. * @brief srtp_create() allocates and initializes an SRTP session.
  342. * The function call srtp_create(session, policy, key) allocates and
  343. * initializes an SRTP session context, applying the given policy and
  344. * key.
  345. *
  346. * @param session is the SRTP session to which the policy is to be added.
  347. *
  348. * @param policy is the srtp_policy_t struct that describes the policy
  349. * for the session. The struct may be a single element, or it may be
  350. * the head of a list, in which case each element of the list is
  351. * processed. It may also be NULL, in which case streams should be added
  352. * later using srtp_add_stream(). The final element of the list @b must
  353. * have its `next' field set to NULL.
  354. *
  355. * @return
  356. * - err_status_ok if creation succeded.
  357. * - err_status_alloc_fail if allocation failed.
  358. * - err_status_init_fail if initialization failed.
  359. */
  360. err_status_t
  361. srtp_create(srtp_t *session, const srtp_policy_t *policy);
  362. /**
  363. * @brief srtp_add_stream() allocates and initializes an SRTP stream
  364. * within a given SRTP session.
  365. *
  366. * The function call srtp_add_stream(session, policy) allocates and
  367. * initializes a new SRTP stream within a given, previously created
  368. * session, applying the policy given as the other argument to that
  369. * stream.
  370. *
  371. * @return values:
  372. * - err_status_ok if stream creation succeded.
  373. * - err_status_alloc_fail if stream allocation failed
  374. * - err_status_init_fail if stream initialization failed.
  375. */
  376. err_status_t
  377. srtp_add_stream(srtp_t session,
  378. const srtp_policy_t *policy);
  379. /**
  380. * @brief srtp_remove_stream() deallocates an SRTP stream.
  381. *
  382. * The function call srtp_remove_stream(session, ssrc) removes
  383. * the SRTP stream with the SSRC value ssrc from the SRTP session
  384. * context given by the argument session.
  385. *
  386. * @param session is the SRTP session from which the stream
  387. * will be removed.
  388. *
  389. * @param ssrc is the SSRC value of the stream to be removed.
  390. *
  391. * @warning Wildcard SSRC values cannot be removed from a
  392. * session.
  393. *
  394. * @return
  395. * - err_status_ok if the stream deallocation succeded.
  396. * - [other] otherwise.
  397. *
  398. */
  399. err_status_t
  400. srtp_remove_stream(srtp_t session, unsigned int ssrc);
  401. /**
  402. * @brief crypto_policy_set_rtp_default() sets a crypto policy
  403. * structure to the SRTP default policy for RTP protection.
  404. *
  405. * @param p is a pointer to the policy structure to be set
  406. *
  407. * The function call crypto_policy_set_rtp_default(&p) sets the
  408. * crypto_policy_t at location p to the SRTP default policy for RTP
  409. * protection, as defined in the specification. This function is a
  410. * convenience that helps to avoid dealing directly with the policy
  411. * data structure. You are encouraged to initialize policy elements
  412. * with this function call. Doing so may allow your code to be
  413. * forward compatible with later versions of libSRTP that include more
  414. * elements in the crypto_policy_t datatype.
  415. *
  416. * @return void.
  417. *
  418. */
  419. void
  420. crypto_policy_set_rtp_default(crypto_policy_t *p);
  421. /**
  422. * @brief crypto_policy_set_rtcp_default() sets a crypto policy
  423. * structure to the SRTP default policy for RTCP protection.
  424. *
  425. * @param p is a pointer to the policy structure to be set
  426. *
  427. * The function call crypto_policy_set_rtcp_default(&p) sets the
  428. * crypto_policy_t at location p to the SRTP default policy for RTCP
  429. * protection, as defined in the specification. This function is a
  430. * convenience that helps to avoid dealing directly with the policy
  431. * data structure. You are encouraged to initialize policy elements
  432. * with this function call. Doing so may allow your code to be
  433. * forward compatible with later versions of libSRTP that include more
  434. * elements in the crypto_policy_t datatype.
  435. *
  436. * @return void.
  437. *
  438. */
  439. void
  440. crypto_policy_set_rtcp_default(crypto_policy_t *p);
  441. /**
  442. * @brief crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
  443. * policy structure to the SRTP default policy for RTP protection.
  444. *
  445. * @param p is a pointer to the policy structure to be set
  446. *
  447. * The function crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
  448. * synonym for crypto_policy_set_rtp_default(). It conforms to the
  449. * naming convention used in RFC 4568 (SDP Security Descriptions for
  450. * Media Streams).
  451. *
  452. * @return void.
  453. *
  454. */
  455. #define crypto_policy_set_aes_cm_128_hmac_sha1_80(p) crypto_policy_set_rtp_default(p)
  456. /**
  457. * @brief crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
  458. * policy structure to a short-authentication tag policy
  459. *
  460. * @param p is a pointer to the policy structure to be set
  461. *
  462. * The function call crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
  463. * sets the crypto_policy_t at location p to use policy
  464. * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568.
  465. * This policy uses AES-128
  466. * Counter Mode encryption and HMAC-SHA1 authentication, with an
  467. * authentication tag that is only 32 bits long. This length is
  468. * considered adequate only for protecting audio and video media that
  469. * use a stateless playback function. See Section 7.5 of RFC 3711
  470. * (http://www.ietf.org/rfc/rfc3711.txt).
  471. *
  472. * This function is a convenience that helps to avoid dealing directly
  473. * with the policy data structure. You are encouraged to initialize
  474. * policy elements with this function call. Doing so may allow your
  475. * code to be forward compatible with later versions of libSRTP that
  476. * include more elements in the crypto_policy_t datatype.
  477. *
  478. * @warning This crypto policy is intended for use in SRTP, but not in
  479. * SRTCP. It is recommended that a policy that uses longer
  480. * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
  481. * (http://www.ietf.org/rfc/rfc3711.txt).
  482. *
  483. * @return void.
  484. *
  485. */
  486. void
  487. crypto_policy_set_aes_cm_128_hmac_sha1_32(crypto_policy_t *p);
  488. /**
  489. * @brief crypto_policy_set_aes_cm_128_null_auth() sets a crypto
  490. * policy structure to an encryption-only policy
  491. *
  492. * @param p is a pointer to the policy structure to be set
  493. *
  494. * The function call crypto_policy_set_aes_cm_128_null_auth(&p) sets
  495. * the crypto_policy_t at location p to use the SRTP default cipher
  496. * (AES-128 Counter Mode), but to use no authentication method. This
  497. * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
  498. * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  499. *
  500. * This function is a convenience that helps to avoid dealing directly
  501. * with the policy data structure. You are encouraged to initialize
  502. * policy elements with this function call. Doing so may allow your
  503. * code to be forward compatible with later versions of libSRTP that
  504. * include more elements in the crypto_policy_t datatype.
  505. *
  506. * @warning This policy is NOT RECOMMENDED for SRTP unless it is
  507. * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
  508. * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  509. *
  510. * @return void.
  511. *
  512. */
  513. void
  514. crypto_policy_set_aes_cm_128_null_auth(crypto_policy_t *p);
  515. /**
  516. * @brief crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
  517. * policy structure to an authentication-only policy
  518. *
  519. * @param p is a pointer to the policy structure to be set
  520. *
  521. * The function call crypto_policy_set_null_cipher_hmac_sha1_80(&p)
  522. * sets the crypto_policy_t at location p to use HMAC-SHA1 with an 80
  523. * bit authentication tag to provide message authentication, but to
  524. * use no encryption. This policy is NOT RECOMMENDED for SRTP unless
  525. * there is a requirement to forego encryption.
  526. *
  527. * This function is a convenience that helps to avoid dealing directly
  528. * with the policy data structure. You are encouraged to initialize
  529. * policy elements with this function call. Doing so may allow your
  530. * code to be forward compatible with later versions of libSRTP that
  531. * include more elements in the crypto_policy_t datatype.
  532. *
  533. * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
  534. * requirement to forego encryption.
  535. *
  536. * @return void.
  537. *
  538. */
  539. void
  540. crypto_policy_set_null_cipher_hmac_sha1_80(crypto_policy_t *p);
  541. /**
  542. * @brief crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto
  543. * policy structure to a encryption and authentication policy using AES-256
  544. * for RTP protection.
  545. *
  546. * @param p is a pointer to the policy structure to be set
  547. *
  548. * The function call crypto_policy_set_aes_cm_256_hmac_sha1_80(&p)
  549. * sets the crypto_policy_t at location p to use policy
  550. * AES_CM_256_HMAC_SHA1_80 as defined in
  551. * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
  552. * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
  553. * authentication tag.
  554. *
  555. * This function is a convenience that helps to avoid dealing directly
  556. * with the policy data structure. You are encouraged to initialize
  557. * policy elements with this function call. Doing so may allow your
  558. * code to be forward compatible with later versions of libSRTP that
  559. * include more elements in the crypto_policy_t datatype.
  560. *
  561. * @return void.
  562. *
  563. */
  564. void crypto_policy_set_aes_cm_256_hmac_sha1_80(crypto_policy_t *p);
  565. /**
  566. * @brief crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto
  567. * policy structure to a short-authentication tag policy using AES-256
  568. * encryption.
  569. *
  570. * @param p is a pointer to the policy structure to be set
  571. *
  572. * The function call crypto_policy_set_aes_cm_256_hmac_sha1_32(&p)
  573. * sets the crypto_policy_t at location p to use policy
  574. * AES_CM_256_HMAC_SHA1_32 as defined in
  575. * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
  576. * Counter Mode encryption and HMAC-SHA1 authentication, with an
  577. * authentication tag that is only 32 bits long. This length is
  578. * considered adequate only for protecting audio and video media that
  579. * use a stateless playback function. See Section 7.5 of RFC 3711
  580. * (http://www.ietf.org/rfc/rfc3711.txt).
  581. *
  582. * This function is a convenience that helps to avoid dealing directly
  583. * with the policy data structure. You are encouraged to initialize
  584. * policy elements with this function call. Doing so may allow your
  585. * code to be forward compatible with later versions of libSRTP that
  586. * include more elements in the crypto_policy_t datatype.
  587. *
  588. * @warning This crypto policy is intended for use in SRTP, but not in
  589. * SRTCP. It is recommended that a policy that uses longer
  590. * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
  591. * (http://www.ietf.org/rfc/rfc3711.txt).
  592. *
  593. * @return void.
  594. *
  595. */
  596. void
  597. crypto_policy_set_aes_cm_256_hmac_sha1_32(crypto_policy_t *p);
  598. /**
  599. * @brief crypto_policy_set_aes_cm_256_null_auth() sets a crypto
  600. * policy structure to an encryption-only policy
  601. *
  602. * @param p is a pointer to the policy structure to be set
  603. *
  604. * The function call crypto_policy_set_aes_cm_256_null_auth(&p) sets
  605. * the crypto_policy_t at location p to use the SRTP default cipher
  606. * (AES-256 Counter Mode), but to use no authentication method. This
  607. * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
  608. * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  609. *
  610. * This function is a convenience that helps to avoid dealing directly
  611. * with the policy data structure. You are encouraged to initialize
  612. * policy elements with this function call. Doing so may allow your
  613. * code to be forward compatible with later versions of libSRTP that
  614. * include more elements in the crypto_policy_t datatype.
  615. *
  616. * @warning This policy is NOT RECOMMENDED for SRTP unless it is
  617. * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
  618. * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  619. *
  620. * @return void.
  621. *
  622. */
  623. void
  624. crypto_policy_set_aes_cm_256_null_auth(crypto_policy_t *p);
  625. /**
  626. * @brief crypto_policy_set_aes_gcm_128_8_auth() sets a crypto
  627. * policy structure to an AEAD encryption policy.
  628. *
  629. * @param p is a pointer to the policy structure to be set
  630. *
  631. * The function call crypto_policy_set_aes_gcm_128_8_auth(&p) sets
  632. * the crypto_policy_t at location p to use the SRTP default cipher
  633. * (AES-128 Galois Counter Mode) with 8 octet auth tag. This
  634. * policy applies confidentiality and authentication to both the
  635. * RTP and RTCP packets.
  636. *
  637. * This function is a convenience that helps to avoid dealing directly
  638. * with the policy data structure. You are encouraged to initialize
  639. * policy elements with this function call. Doing so may allow your
  640. * code to be forward compatible with later versions of libSRTP that
  641. * include more elements in the crypto_policy_t datatype.
  642. *
  643. * @return void.
  644. *
  645. */
  646. void
  647. crypto_policy_set_aes_gcm_128_8_auth(crypto_policy_t *p);
  648. /**
  649. * @brief crypto_policy_set_aes_gcm_256_8_auth() sets a crypto
  650. * policy structure to an AEAD encryption policy
  651. *
  652. * @param p is a pointer to the policy structure to be set
  653. *
  654. * The function call crypto_policy_set_aes_gcm_256_8_auth(&p) sets
  655. * the crypto_policy_t at location p to use the SRTP default cipher
  656. * (AES-256 Galois Counter Mode) with 8 octet auth tag. This
  657. * policy applies confidentiality and authentication to both the
  658. * RTP and RTCP packets.
  659. *
  660. * This function is a convenience that helps to avoid dealing directly
  661. * with the policy data structure. You are encouraged to initialize
  662. * policy elements with this function call. Doing so may allow your
  663. * code to be forward compatible with later versions of libSRTP that
  664. * include more elements in the crypto_policy_t datatype.
  665. *
  666. * @return void.
  667. *
  668. */
  669. void
  670. crypto_policy_set_aes_gcm_256_8_auth(crypto_policy_t *p);
  671. /**
  672. * @brief crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto
  673. * policy structure to an AEAD authentication-only policy
  674. *
  675. * @param p is a pointer to the policy structure to be set
  676. *
  677. * The function call crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets
  678. * the crypto_policy_t at location p to use the SRTP default cipher
  679. * (AES-128 Galois Counter Mode) with 8 octet auth tag. This policy
  680. * applies confidentiality and authentication to the RTP packets,
  681. * but only authentication to the RTCP packets.
  682. *
  683. * This function is a convenience that helps to avoid dealing directly
  684. * with the policy data structure. You are encouraged to initialize
  685. * policy elements with this function call. Doing so may allow your
  686. * code to be forward compatible with later versions of libSRTP that
  687. * include more elements in the crypto_policy_t datatype.
  688. *
  689. * @return void.
  690. *
  691. */
  692. void
  693. crypto_policy_set_aes_gcm_128_8_only_auth(crypto_policy_t *p);
  694. /**
  695. * @brief crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto
  696. * policy structure to an AEAD authentication-only policy
  697. *
  698. * @param p is a pointer to the policy structure to be set
  699. *
  700. * The function call crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets
  701. * the crypto_policy_t at location p to use the SRTP default cipher
  702. * (AES-256 Galois Counter Mode) with 8 octet auth tag. This policy
  703. * applies confidentiality and authentication to the RTP packets,
  704. * but only authentication to the RTCP packets.
  705. *
  706. * This function is a convenience that helps to avoid dealing directly
  707. * with the policy data structure. You are encouraged to initialize
  708. * policy elements with this function call. Doing so may allow your
  709. * code to be forward compatible with later versions of libSRTP that
  710. * include more elements in the crypto_policy_t datatype.
  711. *
  712. * @return void.
  713. *
  714. */
  715. void
  716. crypto_policy_set_aes_gcm_256_8_only_auth(crypto_policy_t *p);
  717. /**
  718. * @brief crypto_policy_set_aes_gcm_128_16_auth() sets a crypto
  719. * policy structure to an AEAD encryption policy.
  720. *
  721. * @param p is a pointer to the policy structure to be set
  722. *
  723. * The function call crypto_policy_set_aes_gcm_128_16_auth(&p) sets
  724. * the crypto_policy_t at location p to use the SRTP default cipher
  725. * (AES-128 Galois Counter Mode) with 16 octet auth tag. This
  726. * policy applies confidentiality and authentication to both the
  727. * RTP and RTCP packets.
  728. *
  729. * This function is a convenience that helps to avoid dealing directly
  730. * with the policy data structure. You are encouraged to initialize
  731. * policy elements with this function call. Doing so may allow your
  732. * code to be forward compatible with later versions of libSRTP that
  733. * include more elements in the crypto_policy_t datatype.
  734. *
  735. * @return void.
  736. *
  737. */
  738. void
  739. crypto_policy_set_aes_gcm_128_16_auth(crypto_policy_t *p);
  740. /**
  741. * @brief crypto_policy_set_aes_gcm_256_16_auth() sets a crypto
  742. * policy structure to an AEAD encryption policy
  743. *
  744. * @param p is a pointer to the policy structure to be set
  745. *
  746. * The function call crypto_policy_set_aes_gcm_256_16_auth(&p) sets
  747. * the crypto_policy_t at location p to use the SRTP default cipher
  748. * (AES-256 Galois Counter Mode) with 16 octet auth tag. This
  749. * policy applies confidentiality and authentication to both the
  750. * RTP and RTCP packets.
  751. *
  752. * This function is a convenience that helps to avoid dealing directly
  753. * with the policy data structure. You are encouraged to initialize
  754. * policy elements with this function call. Doing so may allow your
  755. * code to be forward compatible with later versions of libSRTP that
  756. * include more elements in the crypto_policy_t datatype.
  757. *
  758. * @return void.
  759. *
  760. */
  761. void
  762. crypto_policy_set_aes_gcm_256_16_auth(crypto_policy_t *p);
  763. /**
  764. * @brief srtp_dealloc() deallocates storage for an SRTP session
  765. * context.
  766. *
  767. * The function call srtp_dealloc(s) deallocates storage for the
  768. * SRTP session context s. This function should be called no more
  769. * than one time for each of the contexts allocated by the function
  770. * srtp_create().
  771. *
  772. * @param s is the srtp_t for the session to be deallocated.
  773. *
  774. * @return
  775. * - err_status_ok if there no problems.
  776. * - err_status_dealloc_fail a memory deallocation failure occured.
  777. */
  778. err_status_t
  779. srtp_dealloc(srtp_t s);
  780. /*
  781. * @brief identifies a particular SRTP profile
  782. *
  783. * An srtp_profile_t enumeration is used to identify a particular SRTP
  784. * profile (that is, a set of algorithms and parameters). These
  785. * profiles are defined in the DTLS-SRTP draft.
  786. */
  787. typedef enum {
  788. srtp_profile_reserved = 0,
  789. srtp_profile_aes128_cm_sha1_80 = 1,
  790. srtp_profile_aes128_cm_sha1_32 = 2,
  791. srtp_profile_aes256_cm_sha1_80 = 3,
  792. srtp_profile_aes256_cm_sha1_32 = 4,
  793. srtp_profile_null_sha1_80 = 5,
  794. srtp_profile_null_sha1_32 = 6,
  795. } srtp_profile_t;
  796. /**
  797. * @brief crypto_policy_set_from_profile_for_rtp() sets a crypto policy
  798. * structure to the appropriate value for RTP based on an srtp_profile_t
  799. *
  800. * @param p is a pointer to the policy structure to be set
  801. *
  802. * The function call crypto_policy_set_rtp_default(&policy, profile)
  803. * sets the crypto_policy_t at location policy to the policy for RTP
  804. * protection, as defined by the srtp_profile_t profile.
  805. *
  806. * This function is a convenience that helps to avoid dealing directly
  807. * with the policy data structure. You are encouraged to initialize
  808. * policy elements with this function call. Doing so may allow your
  809. * code to be forward compatible with later versions of libSRTP that
  810. * include more elements in the crypto_policy_t datatype.
  811. *
  812. * @return values
  813. * - err_status_ok no problems were encountered
  814. * - err_status_bad_param the profile is not supported
  815. *
  816. */
  817. err_status_t
  818. crypto_policy_set_from_profile_for_rtp(crypto_policy_t *policy,
  819. srtp_profile_t profile);
  820. /**
  821. * @brief crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
  822. * structure to the appropriate value for RTCP based on an srtp_profile_t
  823. *
  824. * @param p is a pointer to the policy structure to be set
  825. *
  826. * The function call crypto_policy_set_rtcp_default(&policy, profile)
  827. * sets the crypto_policy_t at location policy to the policy for RTCP
  828. * protection, as defined by the srtp_profile_t profile.
  829. *
  830. * This function is a convenience that helps to avoid dealing directly
  831. * with the policy data structure. You are encouraged to initialize
  832. * policy elements with this function call. Doing so may allow your
  833. * code to be forward compatible with later versions of libSRTP that
  834. * include more elements in the crypto_policy_t datatype.
  835. *
  836. * @return values
  837. * - err_status_ok no problems were encountered
  838. * - err_status_bad_param the profile is not supported
  839. *
  840. */
  841. err_status_t
  842. crypto_policy_set_from_profile_for_rtcp(crypto_policy_t *policy,
  843. srtp_profile_t profile);
  844. /**
  845. * @brief returns the master key length for a given SRTP profile
  846. */
  847. unsigned int
  848. srtp_profile_get_master_key_length(srtp_profile_t profile);
  849. /**
  850. * @brief returns the master salt length for a given SRTP profile
  851. */
  852. unsigned int
  853. srtp_profile_get_master_salt_length(srtp_profile_t profile);
  854. /**
  855. * @brief appends the salt to the key
  856. *
  857. * The function call append_salt_to_key(k, klen, s, slen)
  858. * copies the string s to the location at klen bytes following
  859. * the location k.
  860. *
  861. * @warning There must be at least bytes_in_salt + bytes_in_key bytes
  862. * available at the location pointed to by key.
  863. *
  864. */
  865. void
  866. append_salt_to_key(unsigned char *key, unsigned int bytes_in_key,
  867. unsigned char *salt, unsigned int bytes_in_salt);
  868. /**
  869. * @}
  870. */
  871. /**
  872. * @defgroup SRTCP Secure RTCP
  873. * @ingroup SRTP
  874. *
  875. * @brief Secure RTCP functions are used to protect RTCP traffic.
  876. *
  877. * RTCP is the control protocol for RTP. libSRTP protects RTCP
  878. * traffic in much the same way as it does RTP traffic. The function
  879. * srtp_protect_rtcp() applies cryptographic protections to outbound
  880. * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on
  881. * inbound RTCP packets.
  882. *
  883. * A note on the naming convention: srtp_protect_rtcp() has an srtp_t
  884. * as its first argument, and thus has `srtp_' as its prefix. The
  885. * trailing `_rtcp' indicates the protocol on which it acts.
  886. *
  887. * @{
  888. */
  889. /**
  890. * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet
  891. * processing function.
  892. *
  893. * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
  894. * SRTCP protection to the RTCP packet rtcp_hdr (which has length
  895. * *len_ptr) using the SRTP session context ctx. If err_status_ok is
  896. * returned, then rtp_hdr points to the resulting SRTCP packet and
  897. * *len_ptr is the number of octets in that packet; otherwise, no
  898. * assumptions should be made about the value of either data elements.
  899. *
  900. * @warning This function assumes that it can write the authentication
  901. * tag into the location in memory immediately following the RTCP
  902. * packet, and assumes that the RTCP packet is aligned on a 32-bit
  903. * boundary.
  904. *
  905. * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
  906. * into the location in memory immediately following the RTCP packet.
  907. * Callers MUST ensure that this much writable memory is available in
  908. * the buffer that holds the RTCP packet.
  909. *
  910. * @param ctx is the SRTP context to use in processing the packet.
  911. *
  912. * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
  913. * the function returns, it points to the srtp packet.
  914. *
  915. * @param pkt_octet_len is a pointer to the length in octets of the
  916. * complete RTCP packet (header and body) before the function call,
  917. * and of the complete SRTCP packet after the call, if err_status_ok
  918. * was returned. Otherwise, the value of the data to which it points
  919. * is undefined.
  920. *
  921. * @return
  922. * - err_status_ok if there were no problems.
  923. * - [other] if there was a failure in
  924. * the cryptographic mechanisms.
  925. */
  926. err_status_t
  927. srtp_protect_rtcp(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len);
  928. /**
  929. * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
  930. * processing function.
  931. *
  932. * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
  933. * verifies the Secure RTCP protection of the SRTCP packet pointed to
  934. * by srtcp_hdr (which has length *len_ptr), using the SRTP session
  935. * context ctx. If err_status_ok is returned, then srtcp_hdr points
  936. * to the resulting RTCP packet and *len_ptr is the number of octets
  937. * in that packet; otherwise, no assumptions should be made about the
  938. * value of either data elements.
  939. *
  940. * @warning This function assumes that the SRTCP packet is aligned on a
  941. * 32-bit boundary.
  942. *
  943. * @param ctx is a pointer to the srtp_t which applies to the
  944. * particular packet.
  945. *
  946. * @param srtcp_hdr is a pointer to the header of the SRTCP packet
  947. * (before the call). After the function returns, it points to the
  948. * rtp packet if err_status_ok was returned; otherwise, the value of
  949. * the data to which it points is undefined.
  950. *
  951. * @param pkt_octet_len is a pointer to the length in octets of the
  952. * complete SRTCP packet (header and body) before the function call,
  953. * and of the complete rtp packet after the call, if err_status_ok was
  954. * returned. Otherwise, the value of the data to which it points is
  955. * undefined.
  956. *
  957. * @return
  958. * - err_status_ok if the RTCP packet is valid.
  959. * - err_status_auth_fail if the SRTCP packet failed the message
  960. * authentication check.
  961. * - err_status_replay_fail if the SRTCP packet is a replay (e.g. has
  962. * already been processed and accepted).
  963. * - [other] if there has been an error in the cryptographic mechanisms.
  964. *
  965. */
  966. err_status_t
  967. srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len);
  968. /**
  969. * @}
  970. */
  971. /**
  972. * @defgroup SRTPevents SRTP events and callbacks
  973. * @ingroup SRTP
  974. *
  975. * @brief libSRTP can use a user-provided callback function to
  976. * handle events.
  977. *
  978. *
  979. * libSRTP allows a user to provide a callback function to handle
  980. * events that need to be dealt with outside of the data plane (see
  981. * the enum srtp_event_t for a description of these events). Dealing
  982. * with these events is not a strict necessity; they are not
  983. * security-critical, but the application may suffer if they are not
  984. * handled. The function srtp_set_event_handler() is used to provide
  985. * the callback function.
  986. *
  987. * A default event handler that merely reports on the events as they
  988. * happen is included. It is also possible to set the event handler
  989. * function to NULL, in which case all events will just be silently
  990. * ignored.
  991. *
  992. * @{
  993. */
  994. /**
  995. * @brief srtp_event_t defines events that need to be handled
  996. *
  997. * The enum srtp_event_t defines events that need to be handled
  998. * outside the `data plane', such as SSRC collisions and
  999. * key expirations.
  1000. *
  1001. * When a key expires or the maximum number of packets has been
  1002. * reached, an SRTP stream will enter an `expired' state in which no
  1003. * more packets can be protected or unprotected. When this happens,
  1004. * it is likely that you will want to either deallocate the stream
  1005. * (using srtp_stream_dealloc()), and possibly allocate a new one.
  1006. *
  1007. * When an SRTP stream expires, the other streams in the same session
  1008. * are unaffected, unless key sharing is used by that stream. In the
  1009. * latter case, all of the streams in the session will expire.
  1010. */
  1011. typedef enum {
  1012. event_ssrc_collision, /**<
  1013. * An SSRC collision occured.
  1014. */
  1015. event_key_soft_limit, /**< An SRTP stream reached the soft key
  1016. * usage limit and will expire soon.
  1017. */
  1018. event_key_hard_limit, /**< An SRTP stream reached the hard
  1019. * key usage limit and has expired.
  1020. */
  1021. event_packet_index_limit /**< An SRTP stream reached the hard
  1022. * packet limit (2^48 packets).
  1023. */
  1024. } srtp_event_t;
  1025. /**
  1026. * @brief srtp_event_data_t is the structure passed as a callback to
  1027. * the event handler function
  1028. *
  1029. * The struct srtp_event_data_t holds the data passed to the event
  1030. * handler function.
  1031. */
  1032. typedef struct srtp_event_data_t {
  1033. srtp_t session; /**< The session in which the event happend. */
  1034. srtp_stream_t stream; /**< The stream in which the event happend. */
  1035. srtp_event_t event; /**< An enum indicating the type of event. */
  1036. } srtp_event_data_t;
  1037. /**
  1038. * @brief srtp_event_handler_func_t is the function prototype for
  1039. * the event handler.
  1040. *
  1041. * The typedef srtp_event_handler_func_t is the prototype for the
  1042. * event handler function. It has as its only argument an
  1043. * srtp_event_data_t which describes the event that needs to be handled.
  1044. * There can only be a single, global handler for all events in
  1045. * libSRTP.
  1046. */
  1047. typedef void (srtp_event_handler_func_t)(srtp_event_data_t *data);
  1048. /**
  1049. * @brief sets the event handler to the function supplied by the caller.
  1050. *
  1051. * The function call srtp_install_event_handler(func) sets the event
  1052. * handler function to the value func. The value NULL is acceptable
  1053. * as an argument; in this case, events will be ignored rather than
  1054. * handled.
  1055. *
  1056. * @param func is a pointer to a fuction that takes an srtp_event_data_t
  1057. * pointer as an argument and returns void. This function
  1058. * will be used by libSRTP to handle events.
  1059. */
  1060. err_status_t
  1061. srtp_install_event_handler(srtp_event_handler_func_t func);
  1062. /**
  1063. * @}
  1064. */
  1065. /* in host order, so outside the #if */
  1066. #define SRTCP_E_BIT 0x80000000
  1067. /* for byte-access */
  1068. #define SRTCP_E_BYTE_BIT 0x80
  1069. #define SRTCP_INDEX_MASK 0x7fffffff
  1070. #ifdef __cplusplus
  1071. }
  1072. #endif
  1073. #endif /* SRTP_H */