srtp.h 42 KB

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