srtp.h 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  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-2017, 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_SRTP_H
  45. #define SRTP_SRTP_H
  46. #include <stdint.h>
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  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 16
  70. /**
  71. * SRTP_MAX_MKI_LEN is the maximum size the MKI could be which is
  72. * 128 bytes
  73. */
  74. #define SRTP_MAX_MKI_LEN 128
  75. /**
  76. * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer
  77. * (authentication tag and MKI) supported by libSRTP. This value is
  78. * the maximum number of octets that will be added to an RTP packet by
  79. * srtp_protect().
  80. *
  81. * @brief the maximum number of octets added by srtp_protect().
  82. */
  83. #define SRTP_MAX_TRAILER_LEN (SRTP_MAX_TAG_LEN + SRTP_MAX_MKI_LEN)
  84. /**
  85. * SRTP_MAX_NUM_MASTER_KEYS is the maximum number of Master keys for
  86. * MKI supported by libSRTP.
  87. *
  88. */
  89. #define SRTP_MAX_NUM_MASTER_KEYS 16
  90. #define SRTP_SALT_LEN 14
  91. /*
  92. * SRTP_AEAD_SALT_LEN is the length of the SALT values used with
  93. * GCM mode. GCM mode requires an IV. The SALT value is used
  94. * as part of the IV formation logic applied to each RTP packet.
  95. */
  96. #define SRTP_AEAD_SALT_LEN 12
  97. #define SRTP_AES_128_KEY_LEN 16
  98. #define SRTP_AES_192_KEY_LEN 24
  99. #define SRTP_AES_256_KEY_LEN 32
  100. #define SRTP_AES_ICM_128_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_128_KEY_LEN)
  101. #define SRTP_AES_ICM_192_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_192_KEY_LEN)
  102. #define SRTP_AES_ICM_256_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_256_KEY_LEN)
  103. #define SRTP_AES_GCM_128_KEY_LEN_WSALT \
  104. (SRTP_AEAD_SALT_LEN + SRTP_AES_128_KEY_LEN)
  105. #define SRTP_AES_GCM_192_KEY_LEN_WSALT \
  106. (SRTP_AEAD_SALT_LEN + SRTP_AES_192_KEY_LEN)
  107. #define SRTP_AES_GCM_256_KEY_LEN_WSALT \
  108. (SRTP_AEAD_SALT_LEN + SRTP_AES_256_KEY_LEN)
  109. /**
  110. * @brief A srtp_cipher_type_id_t is an identifier for a particular cipher
  111. * type.
  112. *
  113. * A srtp_cipher_type_id_t is an integer that represents a particular
  114. * cipher type, e.g. the Advanced Encryption Standard (AES). A
  115. * SRTP_NULL_CIPHER is available; this cipher leaves the data unchanged,
  116. * and can be selected to indicate that no encryption is to take
  117. * place.
  118. *
  119. * @ingroup Ciphers
  120. */
  121. typedef uint32_t srtp_cipher_type_id_t;
  122. /**
  123. * @brief An srtp_auth_type_id_t is an identifier for a particular
  124. * authentication
  125. * function.
  126. *
  127. * An srtp_auth_type_id_t is an integer that represents a particular
  128. * authentication function type, e.g. HMAC-SHA1. A SRTP_NULL_AUTH is
  129. * available; this authentication function performs no computation,
  130. * and can be selected to indicate that no authentication is to take
  131. * place.
  132. *
  133. * @ingroup Authentication
  134. */
  135. typedef uint32_t srtp_auth_type_id_t;
  136. /**
  137. * @brief srtp_err_status_t defines error codes.
  138. *
  139. * The enumeration srtp_err_status_t defines error codes. Note that the
  140. * value of srtp_err_status_ok is equal to zero, which can simplify error
  141. * checking somewhat.
  142. *
  143. */
  144. typedef enum {
  145. srtp_err_status_ok = 0, /**< nothing to report */
  146. srtp_err_status_fail = 1, /**< unspecified failure */
  147. srtp_err_status_bad_param = 2, /**< unsupported parameter */
  148. srtp_err_status_alloc_fail = 3, /**< couldn't allocate memory */
  149. srtp_err_status_dealloc_fail = 4, /**< couldn't deallocate properly */
  150. srtp_err_status_init_fail = 5, /**< couldn't initialize */
  151. srtp_err_status_terminus = 6, /**< can't process as much data as */
  152. /**< requested */
  153. srtp_err_status_auth_fail = 7, /**< authentication failure */
  154. srtp_err_status_cipher_fail = 8, /**< cipher failure */
  155. srtp_err_status_replay_fail = 9, /**< replay check failed (bad index) */
  156. srtp_err_status_replay_old = 10, /**< replay check failed (index too */
  157. /**< old) */
  158. srtp_err_status_algo_fail = 11, /**< algorithm failed test routine */
  159. srtp_err_status_no_such_op = 12, /**< unsupported operation */
  160. srtp_err_status_no_ctx = 13, /**< no appropriate context found */
  161. srtp_err_status_cant_check = 14, /**< unable to perform desired */
  162. /**< validation */
  163. srtp_err_status_key_expired = 15, /**< can't use key any more */
  164. srtp_err_status_socket_err = 16, /**< error in use of socket */
  165. srtp_err_status_signal_err = 17, /**< error in use POSIX signals */
  166. srtp_err_status_nonce_bad = 18, /**< nonce check failed */
  167. srtp_err_status_read_fail = 19, /**< couldn't read data */
  168. srtp_err_status_write_fail = 20, /**< couldn't write data */
  169. srtp_err_status_parse_err = 21, /**< error parsing data */
  170. srtp_err_status_encode_err = 22, /**< error encoding data */
  171. srtp_err_status_semaphore_err = 23, /**< error while using semaphores */
  172. srtp_err_status_pfkey_err = 24, /**< error while using pfkey */
  173. srtp_err_status_bad_mki = 25, /**< error MKI present in packet is */
  174. /**< invalid */
  175. srtp_err_status_pkt_idx_old = 26, /**< packet index is too old to */
  176. /**< consider */
  177. srtp_err_status_pkt_idx_adv = 27 /**< packet index advanced, reset */
  178. /**< needed */
  179. } srtp_err_status_t;
  180. typedef struct srtp_ctx_t_ srtp_ctx_t;
  181. /**
  182. * @brief srtp_sec_serv_t describes a set of security services.
  183. *
  184. * A srtp_sec_serv_t enumeration is used to describe the particular
  185. * security services that will be applied by a particular crypto
  186. * policy (or other mechanism).
  187. */
  188. typedef enum {
  189. sec_serv_none = 0, /**< no services */
  190. sec_serv_conf = 1, /**< confidentiality */
  191. sec_serv_auth = 2, /**< authentication */
  192. sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */
  193. } srtp_sec_serv_t;
  194. /**
  195. * @brief srtp_crypto_policy_t describes a particular crypto policy that
  196. * can be applied to an SRTP stream.
  197. *
  198. * A srtp_crypto_policy_t describes a particular cryptographic policy that
  199. * can be applied to an SRTP or SRTCP stream. An SRTP session policy
  200. * consists of a list of these policies, one for each SRTP stream
  201. * in the session.
  202. */
  203. typedef struct srtp_crypto_policy_t {
  204. srtp_cipher_type_id_t cipher_type; /**< An integer representing */
  205. /**< the type of cipher. */
  206. int cipher_key_len; /**< The length of the cipher key */
  207. /**< in octets. */
  208. srtp_auth_type_id_t auth_type; /**< An integer representing the */
  209. /**< authentication function. */
  210. int auth_key_len; /**< The length of the authentication */
  211. /**< function key in octets. */
  212. int auth_tag_len; /**< The length of the authentication */
  213. /**< tag in octets. */
  214. srtp_sec_serv_t sec_serv; /**< The flag indicating the security */
  215. /**< services to be applied. */
  216. } srtp_crypto_policy_t;
  217. /**
  218. * @brief srtp_ssrc_type_t describes the type of an SSRC.
  219. *
  220. * An srtp_ssrc_type_t enumeration is used to indicate a type of SSRC. See
  221. * @ref srtp_policy_t for more information.
  222. */
  223. typedef enum {
  224. ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */
  225. ssrc_specific = 1, /**< Indicates a specific SSRC value */
  226. ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value */
  227. /**< (i.e. a value that is used in the */
  228. /**< function srtp_unprotect()) */
  229. ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value */
  230. /**< (i.e. a value that is used in the */
  231. /**< function srtp_protect()) */
  232. } srtp_ssrc_type_t;
  233. /**
  234. * @brief An srtp_ssrc_t represents a particular SSRC value, or a `wildcard'
  235. * SSRC.
  236. *
  237. * An srtp_ssrc_t represents a particular SSRC value (if its type is
  238. * ssrc_specific), or a wildcard SSRC value that will match all
  239. * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound
  240. * SSRCs (if its type is ssrc_any_inbound).
  241. */
  242. typedef struct {
  243. srtp_ssrc_type_t type; /**< The type of this particular SSRC */
  244. unsigned int value; /**< The value of this SSRC, if it is not a */
  245. /**< wildcard */
  246. } srtp_ssrc_t;
  247. /**
  248. * @brief srtp_master_key_t represents a master key. There will
  249. * be a Master Key Index and the Master Key associated with the
  250. * Master Key Index. Need to also keep track of the Master Key
  251. * Index Size to correctly read it from a packet.
  252. */
  253. typedef struct srtp_master_key_t {
  254. unsigned char *key;
  255. unsigned char *mki_id;
  256. unsigned int mki_size;
  257. } srtp_master_key_t;
  258. /**
  259. * @brief represents the policy for an SRTP session.
  260. *
  261. * A single srtp_policy_t struct represents the policy for a single
  262. * SRTP stream, and a linked list of these elements represents the
  263. * policy for an entire SRTP session. Each element contains the SRTP
  264. * and SRTCP crypto policies for that stream, a pointer to the SRTP
  265. * master key for that stream, the SSRC describing that stream, or a
  266. * flag indicating a `wildcard' SSRC value, and a `next' field that
  267. * holds a pointer to the next element in the list of policy elements,
  268. * or NULL if it is the last element.
  269. *
  270. * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an
  271. * inbound stream that for which there is no explicit SSRC entry in
  272. * another policy element. Similarly, the value SSRC_ANY_OUTBOUND
  273. * will matches any SSRC from an outbound stream that does not appear
  274. * in another policy element. Note that wildcard SSRCs &b cannot be
  275. * used to match both inbound and outbound traffic. This restriction
  276. * is intentional, and it allows libSRTP to ensure that no security
  277. * lapses result from accidental re-use of SSRC values during key
  278. * sharing.
  279. *
  280. * @warning The final element of the list @b must have its `next' pointer
  281. * set to NULL.
  282. */
  283. typedef struct srtp_policy_t {
  284. srtp_ssrc_t ssrc; /**< The SSRC value of stream, or the */
  285. /**< flags SSRC_ANY_INBOUND or */
  286. /**< SSRC_ANY_OUTBOUND if key sharing */
  287. /**< is used for this policy element. */
  288. srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */
  289. srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */
  290. unsigned char *key; /**< Pointer to the SRTP master key for */
  291. /**< this stream. */
  292. srtp_master_key_t **keys; /** Array of Master Key structures */
  293. unsigned long num_master_keys; /** Number of master keys */
  294. void *deprecated_ekt; /**< DEPRECATED: pointer to the EKT */
  295. /**< policy structure for this stream */
  296. unsigned long window_size; /**< The window size to use for replay */
  297. /**< protection. */
  298. int allow_repeat_tx; /**< Whether retransmissions of */
  299. /**< packets with the same sequence */
  300. /**< number are allowed. */
  301. /**< (Note that such repeated */
  302. /**< transmissions must have the same */
  303. /**< RTP payload, or a severe security */
  304. /**< weakness is introduced!) */
  305. int *enc_xtn_hdr; /**< List of header ids to encrypt. */
  306. int enc_xtn_hdr_count; /**< Number of entries in list of header */
  307. /**< ids. */
  308. struct srtp_policy_t *next; /**< Pointer to next stream policy. */
  309. } srtp_policy_t;
  310. /**
  311. * @brief An srtp_t points to an SRTP session structure.
  312. *
  313. * The typedef srtp_t is a pointer to a structure that represents
  314. * an SRTP session. This datatype is intentionally opaque in
  315. * order to separate the interface from the implementation.
  316. *
  317. * An SRTP session consists of all of the traffic sent to the RTP and
  318. * RTCP destination transport addresses, using the RTP/SAVP (Secure
  319. * Audio/Video Profile). A session can be viewed as a set of SRTP
  320. * streams, each of which originates with a different participant.
  321. */
  322. typedef srtp_ctx_t *srtp_t;
  323. /**
  324. * @brief srtp_init() initializes the srtp library.
  325. *
  326. * @warning This function @b must be called before any other srtp
  327. * functions.
  328. */
  329. srtp_err_status_t srtp_init(void);
  330. /**
  331. * @brief srtp_shutdown() de-initializes the srtp library.
  332. *
  333. * @warning No srtp functions may be called after calling this function.
  334. */
  335. srtp_err_status_t srtp_shutdown(void);
  336. /**
  337. * @brief srtp_protect() is the Secure RTP sender-side packet processing
  338. * function.
  339. *
  340. * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
  341. * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
  342. * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
  343. * points to the resulting SRTP packet and *len_ptr is the number of
  344. * octets in that packet; otherwise, no assumptions should be made
  345. * about the value of either data elements.
  346. *
  347. * The sequence numbers of the RTP packets presented to this function
  348. * need not be consecutive, but they @b must be out of order by less
  349. * than 2^15 = 32,768 packets.
  350. *
  351. * @warning This function assumes that it can write the authentication
  352. * tag into the location in memory immediately following the RTP
  353. * packet, and assumes that the RTP packet is aligned on a 32-bit
  354. * boundary.
  355. *
  356. * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
  357. * into the location in memory immediately following the RTP packet.
  358. * Callers MUST ensure that this much writable memory is available in
  359. * the buffer that holds the RTP packet.
  360. *
  361. * @param ctx is the SRTP context to use in processing the packet.
  362. *
  363. * @param rtp_hdr is a pointer to the RTP packet (before the call); after
  364. * the function returns, it points to the srtp packet.
  365. *
  366. * @param len_ptr is a pointer to the length in octets of the complete
  367. * RTP packet (header and body) before the function call, and of the
  368. * complete SRTP packet after the call, if srtp_err_status_ok was returned.
  369. * Otherwise, the value of the data to which it points is undefined.
  370. *
  371. * @return
  372. * - srtp_err_status_ok no problems
  373. * - srtp_err_status_replay_fail rtp sequence number was non-increasing
  374. * - @e other failure in cryptographic mechanisms
  375. */
  376. srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
  377. /**
  378. * @brief srtp_protect_mki() is the Secure RTP sender-side packet processing
  379. * function that can utilize MKI.
  380. *
  381. * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
  382. * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
  383. * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
  384. * points to the resulting SRTP packet and *len_ptr is the number of
  385. * octets in that packet; otherwise, no assumptions should be made
  386. * about the value of either data elements.
  387. *
  388. * The sequence numbers of the RTP packets presented to this function
  389. * need not be consecutive, but they @b must be out of order by less
  390. * than 2^15 = 32,768 packets.
  391. *
  392. * @warning This function assumes that it can write the authentication
  393. * tag into the location in memory immediately following the RTP
  394. * packet, and assumes that the RTP packet is aligned on a 32-bit
  395. * boundary.
  396. *
  397. * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
  398. * into the location in memory immediately following the RTP packet.
  399. * Callers MUST ensure that this much writable memory is available in
  400. * the buffer that holds the RTP packet.
  401. *
  402. * @param ctx is the SRTP context to use in processing the packet.
  403. *
  404. * @param rtp_hdr is a pointer to the RTP packet (before the call); after
  405. * the function returns, it points to the srtp packet.
  406. *
  407. * @param pkt_octet_len is a pointer to the length in octets of the complete
  408. * RTP packet (header and body) before the function call, and of the
  409. * complete SRTP packet after the call, if srtp_err_status_ok was returned.
  410. * Otherwise, the value of the data to which it points is undefined.
  411. *
  412. * @param use_mki is a boolean to tell the system if mki is being used. If
  413. * set to false then will use the first set of session keys. If set to true
  414. * will
  415. * use the session keys identified by the mki_index
  416. *
  417. * @param mki_index integer value specifying which set of session keys should be
  418. * used if use_mki is set to true.
  419. *
  420. * @return
  421. * - srtp_err_status_ok no problems
  422. * - srtp_err_status_replay_fail rtp sequence number was non-increasing
  423. * - @e other failure in cryptographic mechanisms
  424. */
  425. srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx,
  426. void *rtp_hdr,
  427. int *pkt_octet_len,
  428. unsigned int use_mki,
  429. unsigned int mki_index);
  430. /**
  431. * @brief srtp_unprotect() is the Secure RTP receiver-side packet
  432. * processing function.
  433. *
  434. * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
  435. * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
  436. * (which has length *len_ptr), using the SRTP context ctx. If
  437. * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
  438. * RTP packet and *len_ptr is the number of octets in that packet;
  439. * otherwise, no assumptions should be made about the value of either
  440. * data elements.
  441. *
  442. * The sequence numbers of the RTP packets presented to this function
  443. * need not be consecutive, but they @b must be out of order by less
  444. * than 2^15 = 32,768 packets.
  445. *
  446. * @warning This function assumes that the SRTP packet is aligned on a
  447. * 32-bit boundary.
  448. *
  449. * @param ctx is the SRTP session which applies to the particular packet.
  450. *
  451. * @param srtp_hdr is a pointer to the header of the SRTP packet
  452. * (before the call). after the function returns, it points to the
  453. * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
  454. * the data to which it points is undefined.
  455. *
  456. * @param len_ptr is a pointer to the length in octets of the complete
  457. * srtp packet (header and body) before the function call, and of the
  458. * complete rtp packet after the call, if srtp_err_status_ok was returned.
  459. * Otherwise, the value of the data to which it points is undefined.
  460. *
  461. * @return
  462. * - srtp_err_status_ok if the RTP packet is valid.
  463. * - srtp_err_status_auth_fail if the SRTP packet failed the message
  464. * authentication check.
  465. * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet
  466. * has already been processed and accepted).
  467. * - [other] if there has been an error in the cryptographic mechanisms.
  468. *
  469. */
  470. srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
  471. /**
  472. * @brief srtp_unprotect_mki() is the Secure RTP receiver-side packet
  473. * processing function that checks for MKI.
  474. *
  475. * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
  476. * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
  477. * (which has length *len_ptr), using the SRTP context ctx. If
  478. * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
  479. * RTP packet and *len_ptr is the number of octets in that packet;
  480. * otherwise, no assumptions should be made about the value of either
  481. * data elements.
  482. *
  483. * The sequence numbers of the RTP packets presented to this function
  484. * need not be consecutive, but they @b must be out of order by less
  485. * than 2^15 = 32,768 packets.
  486. *
  487. * @warning This function assumes that the SRTP packet is aligned on a
  488. * 32-bit boundary.
  489. *
  490. * @param ctx is the SRTP session which applies to the particular packet.
  491. *
  492. * @param srtp_hdr is a pointer to the header of the SRTP packet
  493. * (before the call). after the function returns, it points to the
  494. * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
  495. * the data to which it points is undefined.
  496. *
  497. * @param len_ptr is a pointer to the length in octets of the complete
  498. * srtp packet (header and body) before the function call, and of the
  499. * complete rtp packet after the call, if srtp_err_status_ok was returned.
  500. * Otherwise, the value of the data to which it points is undefined.
  501. *
  502. * @param use_mki is a boolean to tell the system if mki is being used. If
  503. * set to false then will use the first set of session keys. If set to true
  504. * will
  505. * use the session keys identified by the mki_index
  506. *
  507. * @return
  508. * - srtp_err_status_ok if the RTP packet is valid.
  509. * - srtp_err_status_auth_fail if the SRTP packet failed the message
  510. * authentication check.
  511. * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet
  512. * has already been processed and accepted).
  513. * - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI id
  514. * - [other] if there has been an error in the cryptographic mechanisms.
  515. *
  516. */
  517. srtp_err_status_t srtp_unprotect_mki(srtp_t ctx,
  518. void *srtp_hdr,
  519. int *len_ptr,
  520. unsigned int use_mki);
  521. /**
  522. * @brief srtp_create() allocates and initializes an SRTP session.
  523. * The function call srtp_create(session, policy) allocates and
  524. * initializes an SRTP session context, applying the given policy.
  525. *
  526. * @param session is a pointer to the SRTP session to which the policy is
  527. * to be added.
  528. *
  529. * @param policy is the srtp_policy_t struct that describes the policy
  530. * for the session. The struct may be a single element, or it may be
  531. * the head of a list, in which case each element of the list is
  532. * processed. It may also be NULL, in which case streams should be added
  533. * later using srtp_add_stream(). The final element of the list @b must
  534. * have its `next' field set to NULL.
  535. *
  536. * @return
  537. * - srtp_err_status_ok if creation succeeded.
  538. * - srtp_err_status_alloc_fail if allocation failed.
  539. * - srtp_err_status_init_fail if initialization failed.
  540. */
  541. srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy);
  542. /**
  543. * @brief srtp_add_stream() allocates and initializes an SRTP stream
  544. * within a given SRTP session.
  545. *
  546. * The function call srtp_add_stream(session, policy) allocates and
  547. * initializes a new SRTP stream within a given, previously created
  548. * session, applying the policy given as the other argument to that
  549. * stream.
  550. *
  551. * @return values:
  552. * - srtp_err_status_ok if stream creation succeeded.
  553. * - srtp_err_status_alloc_fail if stream allocation failed
  554. * - srtp_err_status_init_fail if stream initialization failed.
  555. */
  556. srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy);
  557. /**
  558. * @brief srtp_remove_stream() deallocates an SRTP stream.
  559. *
  560. * The function call srtp_remove_stream(session, ssrc) removes
  561. * the SRTP stream with the SSRC value ssrc from the SRTP session
  562. * context given by the argument session.
  563. *
  564. * @param session is the SRTP session from which the stream
  565. * will be removed.
  566. *
  567. * @param ssrc is the SSRC value of the stream to be removed
  568. * in network byte order.
  569. *
  570. * @warning Wildcard SSRC values cannot be removed from a
  571. * session.
  572. *
  573. * @return
  574. * - srtp_err_status_ok if the stream deallocation succeeded.
  575. * - [other] otherwise.
  576. *
  577. */
  578. srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc);
  579. /**
  580. * @brief srtp_update() updates all streams in the session.
  581. *
  582. * The function call srtp_update(session, policy) updates
  583. * all the streams in the session applying the given policy
  584. * and key. The existing ROC value of all streams will be
  585. * preserved.
  586. *
  587. * @param session is the SRTP session that contains the streams
  588. * to be updated.
  589. *
  590. * @param policy is the srtp_policy_t struct that describes the policy
  591. * for the session. The struct may be a single element, or it may be
  592. * the head of a list, in which case each element of the list is
  593. * processed. The final element of the list @b must
  594. * have its `next' field set to NULL.
  595. *
  596. * @return
  597. * - srtp_err_status_ok if stream creation succeed.
  598. * - srtp_err_status_alloc_fail if stream allocation failed
  599. * - srtp_err_status_init_fail if stream initialization failed.
  600. * - [other] otherwise.
  601. *
  602. */
  603. srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy);
  604. /**
  605. * @brief srtp_update_stream() updates a SRTP stream.
  606. *
  607. * The function call srtp_update_stream(session, policy) updates
  608. * the stream(s) in the session that match applying the given
  609. * policy and key. The existing ROC value of all stream(s) will
  610. * be preserved.
  611. *
  612. * @param session is the SRTP session that contains the streams
  613. * to be updated.
  614. *
  615. * @param policy is the srtp_policy_t struct that describes the policy
  616. * for the session.
  617. *
  618. * @return
  619. * - srtp_err_status_ok if stream creation succeeded.
  620. * - srtp_err_status_alloc_fail if stream allocation failed
  621. * - srtp_err_status_init_fail if stream initialization failed.
  622. * - [other] otherwise.
  623. *
  624. */
  625. srtp_err_status_t srtp_update_stream(srtp_t session,
  626. const srtp_policy_t *policy);
  627. /**
  628. * @brief srtp_crypto_policy_set_rtp_default() sets a crypto policy
  629. * structure to the SRTP default policy for RTP protection.
  630. *
  631. * @param p is a pointer to the policy structure to be set
  632. *
  633. * The function call srtp_crypto_policy_set_rtp_default(&p) sets the
  634. * srtp_crypto_policy_t at location p to the SRTP default policy for RTP
  635. * protection, as defined in the specification. This function is a
  636. * convenience that helps to avoid dealing directly with the policy
  637. * data structure. You are encouraged to initialize policy elements
  638. * with this function call. Doing so may allow your code to be
  639. * forward compatible with later versions of libSRTP that include more
  640. * elements in the srtp_crypto_policy_t datatype.
  641. *
  642. * @return void.
  643. *
  644. */
  645. void srtp_crypto_policy_set_rtp_default(srtp_crypto_policy_t *p);
  646. /**
  647. * @brief srtp_crypto_policy_set_rtcp_default() sets a crypto policy
  648. * structure to the SRTP default policy for RTCP protection.
  649. *
  650. * @param p is a pointer to the policy structure to be set
  651. *
  652. * The function call srtp_crypto_policy_set_rtcp_default(&p) sets the
  653. * srtp_crypto_policy_t at location p to the SRTP default policy for RTCP
  654. * protection, as defined in the specification. This function is a
  655. * convenience that helps to avoid dealing directly with the policy
  656. * data structure. You are encouraged to initialize policy elements
  657. * with this function call. Doing so may allow your code to be
  658. * forward compatible with later versions of libSRTP that include more
  659. * elements in the srtp_crypto_policy_t datatype.
  660. *
  661. * @return void.
  662. *
  663. */
  664. void srtp_crypto_policy_set_rtcp_default(srtp_crypto_policy_t *p);
  665. /**
  666. * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
  667. * policy structure to the SRTP default policy for RTP protection.
  668. *
  669. * @param p is a pointer to the policy structure to be set
  670. *
  671. * The function srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
  672. * synonym for srtp_crypto_policy_set_rtp_default(). It conforms to the
  673. * naming convention used in RFC 4568 (SDP Security Descriptions for
  674. * Media Streams).
  675. *
  676. * @return void.
  677. *
  678. */
  679. #define srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(p) \
  680. srtp_crypto_policy_set_rtp_default(p)
  681. /**
  682. * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
  683. * policy structure to a short-authentication tag policy
  684. *
  685. * @param p is a pointer to the policy structure to be set
  686. *
  687. * The function call srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
  688. * sets the srtp_crypto_policy_t at location p to use policy
  689. * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568.
  690. * This policy uses AES-128
  691. * Counter Mode encryption and HMAC-SHA1 authentication, with an
  692. * authentication tag that is only 32 bits long. This length is
  693. * considered adequate only for protecting audio and video media that
  694. * use a stateless playback function. See Section 7.5 of RFC 3711
  695. * (http://www.ietf.org/rfc/rfc3711.txt).
  696. *
  697. * This function is a convenience that helps to avoid dealing directly
  698. * with the policy data structure. You are encouraged to initialize
  699. * policy elements with this function call. Doing so may allow your
  700. * code to be forward compatible with later versions of libSRTP that
  701. * include more elements in the srtp_crypto_policy_t datatype.
  702. *
  703. * @warning This crypto policy is intended for use in SRTP, but not in
  704. * SRTCP. It is recommended that a policy that uses longer
  705. * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
  706. * (http://www.ietf.org/rfc/rfc3711.txt).
  707. *
  708. * @return void.
  709. *
  710. */
  711. void srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(srtp_crypto_policy_t *p);
  712. /**
  713. * @brief srtp_crypto_policy_set_aes_cm_128_null_auth() sets a crypto
  714. * policy structure to an encryption-only policy
  715. *
  716. * @param p is a pointer to the policy structure to be set
  717. *
  718. * The function call srtp_crypto_policy_set_aes_cm_128_null_auth(&p) sets
  719. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  720. * (AES-128 Counter Mode), but to use no authentication method. This
  721. * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
  722. * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  723. *
  724. * This function is a convenience that helps to avoid dealing directly
  725. * with the policy data structure. You are encouraged to initialize
  726. * policy elements with this function call. Doing so may allow your
  727. * code to be forward compatible with later versions of libSRTP that
  728. * include more elements in the srtp_crypto_policy_t datatype.
  729. *
  730. * @warning This policy is NOT RECOMMENDED for SRTP unless it is
  731. * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
  732. * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  733. *
  734. * @return void.
  735. *
  736. */
  737. void srtp_crypto_policy_set_aes_cm_128_null_auth(srtp_crypto_policy_t *p);
  738. /**
  739. * @brief srtp_crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
  740. * policy structure to an authentication-only policy
  741. *
  742. * @param p is a pointer to the policy structure to be set
  743. *
  744. * The function call srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&p)
  745. * sets the srtp_crypto_policy_t at location p to use HMAC-SHA1 with an 80
  746. * bit authentication tag to provide message authentication, but to
  747. * use no encryption. This policy is NOT RECOMMENDED for SRTP unless
  748. * there is a requirement to forgo encryption.
  749. *
  750. * This function is a convenience that helps to avoid dealing directly
  751. * with the policy data structure. You are encouraged to initialize
  752. * policy elements with this function call. Doing so may allow your
  753. * code to be forward compatible with later versions of libSRTP that
  754. * include more elements in the srtp_crypto_policy_t datatype.
  755. *
  756. * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
  757. * requirement to forgo encryption.
  758. *
  759. * @return void.
  760. *
  761. */
  762. void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p);
  763. /**
  764. * @brief srtp_crypto_policy_set_null_cipher_hmac_null() sets a crypto
  765. * policy structure to use no encryption or authentication.
  766. *
  767. * @param p is a pointer to the policy structure to be set
  768. *
  769. * The function call srtp_crypto_policy_set_null_cipher_hmac_null(&p)
  770. * sets the srtp_crypto_policy_t at location p to use no encryption and
  771. * no authentication. This policy should only be used for testing and
  772. * troubleshooting.
  773. *
  774. * This function is a convenience that helps to avoid dealing directly
  775. * with the policy data structure. You are encouraged to initialize
  776. * policy elements with this function call. Doing so may allow your
  777. * code to be forward compatible with later versions of libSRTP that
  778. * include more elements in the srtp_crypto_policy_t datatype.
  779. *
  780. * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
  781. * requirement to forgo encryption and authentication.
  782. *
  783. * @return void.
  784. *
  785. */
  786. void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p);
  787. /**
  788. * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto
  789. * policy structure to a encryption and authentication policy using AES-256
  790. * for RTP protection.
  791. *
  792. * @param p is a pointer to the policy structure to be set
  793. *
  794. * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&p)
  795. * sets the srtp_crypto_policy_t at location p to use policy
  796. * AES_CM_256_HMAC_SHA1_80 as defined in RFC 6188. This policy uses AES-256
  797. * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
  798. * authentication tag.
  799. *
  800. * This function is a convenience that helps to avoid dealing directly
  801. * with the policy data structure. You are encouraged to initialize
  802. * policy elements with this function call. Doing so may allow your
  803. * code to be forward compatible with later versions of libSRTP that
  804. * include more elements in the srtp_crypto_policy_t datatype.
  805. *
  806. * @return void.
  807. *
  808. */
  809. void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(srtp_crypto_policy_t *p);
  810. /**
  811. * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto
  812. * policy structure to a short-authentication tag policy using AES-256
  813. * encryption.
  814. *
  815. * @param p is a pointer to the policy structure to be set
  816. *
  817. * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&p)
  818. * sets the srtp_crypto_policy_t at location p to use policy
  819. * AES_CM_256_HMAC_SHA1_32 as defined in RFC 6188. This policy uses AES-256
  820. * Counter Mode encryption and HMAC-SHA1 authentication, with an
  821. * authentication tag that is only 32 bits long. This length is
  822. * considered adequate only for protecting audio and video media that
  823. * use a stateless playback function. See Section 7.5 of RFC 3711
  824. * (http://www.ietf.org/rfc/rfc3711.txt).
  825. *
  826. * This function is a convenience that helps to avoid dealing directly
  827. * with the policy data structure. You are encouraged to initialize
  828. * policy elements with this function call. Doing so may allow your
  829. * code to be forward compatible with later versions of libSRTP that
  830. * include more elements in the srtp_crypto_policy_t datatype.
  831. *
  832. * @warning This crypto policy is intended for use in SRTP, but not in
  833. * SRTCP. It is recommended that a policy that uses longer
  834. * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
  835. * (http://www.ietf.org/rfc/rfc3711.txt).
  836. *
  837. * @return void.
  838. *
  839. */
  840. void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(srtp_crypto_policy_t *p);
  841. /**
  842. * @brief srtp_crypto_policy_set_aes_cm_256_null_auth() sets a crypto
  843. * policy structure to an encryption-only policy
  844. *
  845. * @param p is a pointer to the policy structure to be set
  846. *
  847. * The function call srtp_crypto_policy_set_aes_cm_256_null_auth(&p) sets
  848. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  849. * (AES-256 Counter Mode), but to use no authentication method. This
  850. * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
  851. * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  852. *
  853. * This function is a convenience that helps to avoid dealing directly
  854. * with the policy data structure. You are encouraged to initialize
  855. * policy elements with this function call. Doing so may allow your
  856. * code to be forward compatible with later versions of libSRTP that
  857. * include more elements in the srtp_crypto_policy_t datatype.
  858. *
  859. * @warning This policy is NOT RECOMMENDED for SRTP unless it is
  860. * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
  861. * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  862. *
  863. * @return void.
  864. *
  865. */
  866. void srtp_crypto_policy_set_aes_cm_256_null_auth(srtp_crypto_policy_t *p);
  867. /**
  868. * @brief srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80() sets a crypto
  869. * policy structure to a encryption and authentication policy using AES-192
  870. * for RTP protection.
  871. *
  872. * @param p is a pointer to the policy structure to be set
  873. *
  874. * The function call srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&p)
  875. * sets the srtp_crypto_policy_t at location p to use policy
  876. * AES_CM_192_HMAC_SHA1_80 as defined in RFC 6188. This policy uses AES-192
  877. * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
  878. * authentication tag.
  879. *
  880. * This function is a convenience that helps to avoid dealing directly
  881. * with the policy data structure. You are encouraged to initialize
  882. * policy elements with this function call. Doing so may allow your
  883. * code to be forward compatible with later versions of libSRTP that
  884. * include more elements in the srtp_crypto_policy_t datatype.
  885. *
  886. * @return void.
  887. *
  888. */
  889. void srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(srtp_crypto_policy_t *p);
  890. /**
  891. * @brief srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32() sets a crypto
  892. * policy structure to a short-authentication tag policy using AES-192
  893. * encryption.
  894. *
  895. * @param p is a pointer to the policy structure to be set
  896. *
  897. * The function call srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&p)
  898. * sets the srtp_crypto_policy_t at location p to use policy
  899. * AES_CM_192_HMAC_SHA1_32 as defined in RFC 6188. This policy uses AES-192
  900. * Counter Mode encryption and HMAC-SHA1 authentication, with an
  901. * authentication tag that is only 32 bits long. This length is
  902. * considered adequate only for protecting audio and video media that
  903. * use a stateless playback function. See Section 7.5 of RFC 3711
  904. * (http://www.ietf.org/rfc/rfc3711.txt).
  905. *
  906. * This function is a convenience that helps to avoid dealing directly
  907. * with the policy data structure. You are encouraged to initialize
  908. * policy elements with this function call. Doing so may allow your
  909. * code to be forward compatible with later versions of libSRTP that
  910. * include more elements in the srtp_crypto_policy_t datatype.
  911. *
  912. * @warning This crypto policy is intended for use in SRTP, but not in
  913. * SRTCP. It is recommended that a policy that uses longer
  914. * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
  915. * (http://www.ietf.org/rfc/rfc3711.txt).
  916. *
  917. * @return void.
  918. *
  919. */
  920. void srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(srtp_crypto_policy_t *p);
  921. /**
  922. * @brief srtp_crypto_policy_set_aes_cm_192_null_auth() sets a crypto
  923. * policy structure to an encryption-only policy
  924. *
  925. * @param p is a pointer to the policy structure to be set
  926. *
  927. * The function call srtp_crypto_policy_set_aes_cm_192_null_auth(&p) sets
  928. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  929. * (AES-192 Counter Mode), but to use no authentication method. This
  930. * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
  931. * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  932. *
  933. * This function is a convenience that helps to avoid dealing directly
  934. * with the policy data structure. You are encouraged to initialize
  935. * policy elements with this function call. Doing so may allow your
  936. * code to be forward compatible with later versions of libSRTP that
  937. * include more elements in the srtp_crypto_policy_t datatype.
  938. *
  939. * @warning This policy is NOT RECOMMENDED for SRTP unless it is
  940. * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
  941. * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
  942. *
  943. * @return void.
  944. *
  945. */
  946. void srtp_crypto_policy_set_aes_cm_192_null_auth(srtp_crypto_policy_t *p);
  947. /**
  948. * @brief srtp_crypto_policy_set_aes_gcm_128_8_auth() sets a crypto
  949. * policy structure to an AEAD encryption policy.
  950. *
  951. * @param p is a pointer to the policy structure to be set
  952. *
  953. * The function call srtp_crypto_policy_set_aes_gcm_128_8_auth(&p) sets
  954. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  955. * (AES-128 Galois Counter Mode) with 8 octet auth tag. This
  956. * policy applies confidentiality and authentication to both the
  957. * RTP and RTCP packets.
  958. *
  959. * This function is a convenience that helps to avoid dealing directly
  960. * with the policy data structure. You are encouraged to initialize
  961. * policy elements with this function call. Doing so may allow your
  962. * code to be forward compatible with later versions of libSRTP that
  963. * include more elements in the srtp_crypto_policy_t datatype.
  964. *
  965. * @return void.
  966. *
  967. */
  968. void srtp_crypto_policy_set_aes_gcm_128_8_auth(srtp_crypto_policy_t *p);
  969. /**
  970. * @brief srtp_crypto_policy_set_aes_gcm_256_8_auth() sets a crypto
  971. * policy structure to an AEAD encryption policy
  972. *
  973. * @param p is a pointer to the policy structure to be set
  974. *
  975. * The function call srtp_crypto_policy_set_aes_gcm_256_8_auth(&p) sets
  976. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  977. * (AES-256 Galois Counter Mode) with 8 octet auth tag. This
  978. * policy applies confidentiality and authentication to both the
  979. * RTP and RTCP packets.
  980. *
  981. * This function is a convenience that helps to avoid dealing directly
  982. * with the policy data structure. You are encouraged to initialize
  983. * policy elements with this function call. Doing so may allow your
  984. * code to be forward compatible with later versions of libSRTP that
  985. * include more elements in the srtp_crypto_policy_t datatype.
  986. *
  987. * @return void.
  988. *
  989. */
  990. void srtp_crypto_policy_set_aes_gcm_256_8_auth(srtp_crypto_policy_t *p);
  991. /**
  992. * @brief srtp_crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto
  993. * policy structure to an AEAD authentication-only policy
  994. *
  995. * @param p is a pointer to the policy structure to be set
  996. *
  997. * The function call srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets
  998. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  999. * (AES-128 Galois Counter Mode) with 8 octet auth tag. This policy
  1000. * applies confidentiality and authentication to the RTP packets,
  1001. * but only authentication to the RTCP packets.
  1002. *
  1003. * This function is a convenience that helps to avoid dealing directly
  1004. * with the policy data structure. You are encouraged to initialize
  1005. * policy elements with this function call. Doing so may allow your
  1006. * code to be forward compatible with later versions of libSRTP that
  1007. * include more elements in the srtp_crypto_policy_t datatype.
  1008. *
  1009. * @return void.
  1010. *
  1011. */
  1012. void srtp_crypto_policy_set_aes_gcm_128_8_only_auth(srtp_crypto_policy_t *p);
  1013. /**
  1014. * @brief srtp_crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto
  1015. * policy structure to an AEAD authentication-only policy
  1016. *
  1017. * @param p is a pointer to the policy structure to be set
  1018. *
  1019. * The function call srtp_crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets
  1020. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  1021. * (AES-256 Galois Counter Mode) with 8 octet auth tag. This policy
  1022. * applies confidentiality and authentication to the RTP packets,
  1023. * but only authentication to the RTCP packets.
  1024. *
  1025. * This function is a convenience that helps to avoid dealing directly
  1026. * with the policy data structure. You are encouraged to initialize
  1027. * policy elements with this function call. Doing so may allow your
  1028. * code to be forward compatible with later versions of libSRTP that
  1029. * include more elements in the srtp_crypto_policy_t datatype.
  1030. *
  1031. * @return void.
  1032. *
  1033. */
  1034. void srtp_crypto_policy_set_aes_gcm_256_8_only_auth(srtp_crypto_policy_t *p);
  1035. /**
  1036. * @brief srtp_crypto_policy_set_aes_gcm_128_16_auth() sets a crypto
  1037. * policy structure to an AEAD encryption policy.
  1038. *
  1039. * @param p is a pointer to the policy structure to be set
  1040. *
  1041. * The function call srtp_crypto_policy_set_aes_gcm_128_16_auth(&p) sets
  1042. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  1043. * (AES-128 Galois Counter Mode) with 16 octet auth tag. This
  1044. * policy applies confidentiality and authentication to both the
  1045. * RTP and RTCP packets.
  1046. *
  1047. * This function is a convenience that helps to avoid dealing directly
  1048. * with the policy data structure. You are encouraged to initialize
  1049. * policy elements with this function call. Doing so may allow your
  1050. * code to be forward compatible with later versions of libSRTP that
  1051. * include more elements in the srtp_crypto_policy_t datatype.
  1052. *
  1053. * @return void.
  1054. *
  1055. */
  1056. void srtp_crypto_policy_set_aes_gcm_128_16_auth(srtp_crypto_policy_t *p);
  1057. /**
  1058. * @brief srtp_crypto_policy_set_aes_gcm_256_16_auth() sets a crypto
  1059. * policy structure to an AEAD encryption policy
  1060. *
  1061. * @param p is a pointer to the policy structure to be set
  1062. *
  1063. * The function call srtp_crypto_policy_set_aes_gcm_256_16_auth(&p) sets
  1064. * the srtp_crypto_policy_t at location p to use the SRTP default cipher
  1065. * (AES-256 Galois Counter Mode) with 16 octet auth tag. This
  1066. * policy applies confidentiality and authentication to both the
  1067. * RTP and RTCP packets.
  1068. *
  1069. * This function is a convenience that helps to avoid dealing directly
  1070. * with the policy data structure. You are encouraged to initialize
  1071. * policy elements with this function call. Doing so may allow your
  1072. * code to be forward compatible with later versions of libSRTP that
  1073. * include more elements in the srtp_crypto_policy_t datatype.
  1074. *
  1075. * @return void.
  1076. *
  1077. */
  1078. void srtp_crypto_policy_set_aes_gcm_256_16_auth(srtp_crypto_policy_t *p);
  1079. /**
  1080. * @brief srtp_dealloc() deallocates storage for an SRTP session
  1081. * context.
  1082. *
  1083. * The function call srtp_dealloc(s) deallocates storage for the
  1084. * SRTP session context s. This function should be called no more
  1085. * than one time for each of the contexts allocated by the function
  1086. * srtp_create().
  1087. *
  1088. * @param s is the srtp_t for the session to be deallocated.
  1089. *
  1090. * @return
  1091. * - srtp_err_status_ok if there no problems.
  1092. * - srtp_err_status_dealloc_fail a memory deallocation failure occurred.
  1093. */
  1094. srtp_err_status_t srtp_dealloc(srtp_t s);
  1095. /*
  1096. * @brief identifies a particular SRTP profile
  1097. *
  1098. * An srtp_profile_t enumeration is used to identify a particular SRTP
  1099. * profile (that is, a set of algorithms and parameters).
  1100. */
  1101. typedef enum {
  1102. srtp_profile_reserved = 0,
  1103. srtp_profile_aes128_cm_sha1_80 = 1,
  1104. srtp_profile_aes128_cm_sha1_32 = 2,
  1105. srtp_profile_null_sha1_80 = 5,
  1106. srtp_profile_null_sha1_32 = 6,
  1107. srtp_profile_aead_aes_128_gcm = 7,
  1108. srtp_profile_aead_aes_256_gcm = 8,
  1109. } srtp_profile_t;
  1110. /**
  1111. * @brief srtp_crypto_policy_set_from_profile_for_rtp() sets a crypto policy
  1112. * structure to the appropriate value for RTP based on an srtp_profile_t
  1113. *
  1114. * @param policy is a pointer to the policy structure to be set
  1115. *
  1116. * @param profile is an enumeration for the policy to be set
  1117. *
  1118. * The function call srtp_crypto_policy_set_rtp_default(&policy, profile)
  1119. * sets the srtp_crypto_policy_t at location policy to the policy for RTP
  1120. * protection, as defined by the srtp_profile_t profile.
  1121. *
  1122. * This function is a convenience that helps to avoid dealing directly
  1123. * with the policy data structure. You are encouraged to initialize
  1124. * policy elements with this function call. Doing so may allow your
  1125. * code to be forward compatible with later versions of libSRTP that
  1126. * include more elements in the srtp_crypto_policy_t datatype.
  1127. *
  1128. * @return values
  1129. * - srtp_err_status_ok no problems were encountered
  1130. * - srtp_err_status_bad_param the profile is not supported
  1131. *
  1132. */
  1133. srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtp(
  1134. srtp_crypto_policy_t *policy,
  1135. srtp_profile_t profile);
  1136. /**
  1137. * @brief srtp_crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
  1138. * structure to the appropriate value for RTCP based on an srtp_profile_t
  1139. *
  1140. * @param policy is a pointer to the policy structure to be set
  1141. *
  1142. * @param profile is an enumeration for the policy to be set
  1143. *
  1144. * The function call srtp_crypto_policy_set_rtcp_default(&policy, profile)
  1145. * sets the srtp_crypto_policy_t at location policy to the policy for RTCP
  1146. * protection, as defined by the srtp_profile_t profile.
  1147. *
  1148. * This function is a convenience that helps to avoid dealing directly
  1149. * with the policy data structure. You are encouraged to initialize
  1150. * policy elements with this function call. Doing so may allow your
  1151. * code to be forward compatible with later versions of libSRTP that
  1152. * include more elements in the srtp_crypto_policy_t datatype.
  1153. *
  1154. * @return values
  1155. * - srtp_err_status_ok no problems were encountered
  1156. * - srtp_err_status_bad_param the profile is not supported
  1157. *
  1158. */
  1159. srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtcp(
  1160. srtp_crypto_policy_t *policy,
  1161. srtp_profile_t profile);
  1162. /**
  1163. * @brief returns the master key length for a given SRTP profile
  1164. */
  1165. unsigned int srtp_profile_get_master_key_length(srtp_profile_t profile);
  1166. /**
  1167. * @brief returns the master salt length for a given SRTP profile
  1168. */
  1169. unsigned int srtp_profile_get_master_salt_length(srtp_profile_t profile);
  1170. /**
  1171. * @brief appends the salt to the key
  1172. *
  1173. * The function call srtp_append_salt_to_key(k, klen, s, slen)
  1174. * copies the string s to the location at klen bytes following
  1175. * the location k.
  1176. *
  1177. * @warning There must be at least bytes_in_salt + bytes_in_key bytes
  1178. * available at the location pointed to by key.
  1179. *
  1180. */
  1181. void srtp_append_salt_to_key(unsigned char *key,
  1182. unsigned int bytes_in_key,
  1183. unsigned char *salt,
  1184. unsigned int bytes_in_salt);
  1185. /**
  1186. * @}
  1187. */
  1188. /**
  1189. * @defgroup SRTCP Secure RTCP
  1190. * @ingroup SRTP
  1191. *
  1192. * @brief Secure RTCP functions are used to protect RTCP traffic.
  1193. *
  1194. * RTCP is the control protocol for RTP. libSRTP protects RTCP
  1195. * traffic in much the same way as it does RTP traffic. The function
  1196. * srtp_protect_rtcp() applies cryptographic protections to outbound
  1197. * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on
  1198. * inbound RTCP packets.
  1199. *
  1200. * A note on the naming convention: srtp_protect_rtcp() has an srtp_t
  1201. * as its first argument, and thus has `srtp_' as its prefix. The
  1202. * trailing `_rtcp' indicates the protocol on which it acts.
  1203. *
  1204. * @{
  1205. */
  1206. /**
  1207. * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet
  1208. * processing function.
  1209. *
  1210. * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
  1211. * SRTCP protection to the RTCP packet rtcp_hdr (which has length
  1212. * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
  1213. * returned, then rtp_hdr points to the resulting SRTCP packet and
  1214. * *len_ptr is the number of octets in that packet; otherwise, no
  1215. * assumptions should be made about the value of either data elements.
  1216. *
  1217. * @warning This function assumes that it can write the authentication
  1218. * tag into the location in memory immediately following the RTCP
  1219. * packet, and assumes that the RTCP packet is aligned on a 32-bit
  1220. * boundary.
  1221. *
  1222. * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
  1223. * into the location in memory immediately following the RTCP packet.
  1224. * Callers MUST ensure that this much writable memory is available in
  1225. * the buffer that holds the RTCP packet.
  1226. *
  1227. * @param ctx is the SRTP context to use in processing the packet.
  1228. *
  1229. * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
  1230. * the function returns, it points to the srtp packet.
  1231. *
  1232. * @param pkt_octet_len is a pointer to the length in octets of the
  1233. * complete RTCP packet (header and body) before the function call,
  1234. * and of the complete SRTCP packet after the call, if srtp_err_status_ok
  1235. * was returned. Otherwise, the value of the data to which it points
  1236. * is undefined.
  1237. *
  1238. * @return
  1239. * - srtp_err_status_ok if there were no problems.
  1240. * - [other] if there was a failure in
  1241. * the cryptographic mechanisms.
  1242. */
  1243. srtp_err_status_t srtp_protect_rtcp(srtp_t ctx,
  1244. void *rtcp_hdr,
  1245. int *pkt_octet_len);
  1246. /**
  1247. * @brief srtp_protect_rtcp_mki() is the Secure RTCP sender-side packet
  1248. * processing function that can utilize mki.
  1249. *
  1250. * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
  1251. * SRTCP protection to the RTCP packet rtcp_hdr (which has length
  1252. * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
  1253. * returned, then rtp_hdr points to the resulting SRTCP packet and
  1254. * *len_ptr is the number of octets in that packet; otherwise, no
  1255. * assumptions should be made about the value of either data elements.
  1256. *
  1257. * @warning This function assumes that it can write the authentication
  1258. * tag into the location in memory immediately following the RTCP
  1259. * packet, and assumes that the RTCP packet is aligned on a 32-bit
  1260. * boundary.
  1261. *
  1262. * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
  1263. * into the location in memory immediately following the RTCP packet.
  1264. * Callers MUST ensure that this much writable memory is available in
  1265. * the buffer that holds the RTCP packet.
  1266. *
  1267. * @param ctx is the SRTP context to use in processing the packet.
  1268. *
  1269. * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
  1270. * the function returns, it points to the srtp packet.
  1271. *
  1272. * @param pkt_octet_len is a pointer to the length in octets of the
  1273. * complete RTCP packet (header and body) before the function call,
  1274. * and of the complete SRTCP packet after the call, if srtp_err_status_ok
  1275. * was returned. Otherwise, the value of the data to which it points
  1276. * is undefined.
  1277. *
  1278. * @param use_mki is a boolean to tell the system if mki is being used. If
  1279. * set to false then will use the first set of session keys. If set to true
  1280. * will
  1281. * use the session keys identified by the mki_index
  1282. *
  1283. * @param mki_index integer value specifying which set of session keys should be
  1284. * used if use_mki is set to true.
  1285. *
  1286. * @return
  1287. * - srtp_err_status_ok if there were no problems.
  1288. * - [other] if there was a failure in
  1289. * the cryptographic mechanisms.
  1290. */
  1291. srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx,
  1292. void *rtcp_hdr,
  1293. int *pkt_octet_len,
  1294. unsigned int use_mki,
  1295. unsigned int mki_index);
  1296. /**
  1297. * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
  1298. * processing function.
  1299. *
  1300. * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
  1301. * verifies the Secure RTCP protection of the SRTCP packet pointed to
  1302. * by srtcp_hdr (which has length *len_ptr), using the SRTP session
  1303. * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
  1304. * to the resulting RTCP packet and *len_ptr is the number of octets
  1305. * in that packet; otherwise, no assumptions should be made about the
  1306. * value of either data elements.
  1307. *
  1308. * @warning This function assumes that the SRTCP packet is aligned on a
  1309. * 32-bit boundary.
  1310. *
  1311. * @param ctx is a pointer to the srtp_t which applies to the
  1312. * particular packet.
  1313. *
  1314. * @param srtcp_hdr is a pointer to the header of the SRTCP packet
  1315. * (before the call). After the function returns, it points to the
  1316. * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
  1317. * the data to which it points is undefined.
  1318. *
  1319. * @param pkt_octet_len is a pointer to the length in octets of the
  1320. * complete SRTCP packet (header and body) before the function call,
  1321. * and of the complete rtp packet after the call, if srtp_err_status_ok was
  1322. * returned. Otherwise, the value of the data to which it points is
  1323. * undefined.
  1324. *
  1325. * @return
  1326. * - srtp_err_status_ok if the RTCP packet is valid.
  1327. * - srtp_err_status_auth_fail if the SRTCP packet failed the message
  1328. * authentication check.
  1329. * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
  1330. * already been processed and accepted).
  1331. * - [other] if there has been an error in the cryptographic mechanisms.
  1332. *
  1333. */
  1334. srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx,
  1335. void *srtcp_hdr,
  1336. int *pkt_octet_len);
  1337. /**
  1338. * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
  1339. * processing function.
  1340. *
  1341. * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
  1342. * verifies the Secure RTCP protection of the SRTCP packet pointed to
  1343. * by srtcp_hdr (which has length *len_ptr), using the SRTP session
  1344. * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
  1345. * to the resulting RTCP packet and *len_ptr is the number of octets
  1346. * in that packet; otherwise, no assumptions should be made about the
  1347. * value of either data elements.
  1348. *
  1349. * @warning This function assumes that the SRTCP packet is aligned on a
  1350. * 32-bit boundary.
  1351. *
  1352. * @param ctx is a pointer to the srtp_t which applies to the
  1353. * particular packet.
  1354. *
  1355. * @param srtcp_hdr is a pointer to the header of the SRTCP packet
  1356. * (before the call). After the function returns, it points to the
  1357. * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
  1358. * the data to which it points is undefined.
  1359. *
  1360. * @param pkt_octet_len is a pointer to the length in octets of the
  1361. * complete SRTCP packet (header and body) before the function call,
  1362. * and of the complete rtp packet after the call, if srtp_err_status_ok was
  1363. * returned. Otherwise, the value of the data to which it points is
  1364. * undefined.
  1365. *
  1366. * @param use_mki is a boolean to tell the system if mki is being used. If
  1367. * set to false then will use the first set of session keys. If set to true
  1368. * will use the session keys identified by the mki_index
  1369. *
  1370. * @return
  1371. * - srtp_err_status_ok if the RTCP packet is valid.
  1372. * - srtp_err_status_auth_fail if the SRTCP packet failed the message
  1373. * authentication check.
  1374. * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
  1375. * already been processed and accepted).
  1376. * - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI
  1377. * id
  1378. * - [other] if there has been an error in the
  1379. * cryptographic mechanisms.
  1380. *
  1381. */
  1382. srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx,
  1383. void *srtcp_hdr,
  1384. int *pkt_octet_len,
  1385. unsigned int use_mki);
  1386. /**
  1387. * @}
  1388. */
  1389. /**
  1390. * @defgroup User data associated to a SRTP session.
  1391. * @ingroup SRTP
  1392. *
  1393. * @brief Store custom user data within a SRTP session.
  1394. *
  1395. * @{
  1396. */
  1397. /**
  1398. * @brief srtp_set_user_data() stores the given pointer into the SRTP
  1399. * session for later retrieval.
  1400. *
  1401. * @param ctx is the srtp_t context in which the given data pointer is
  1402. * stored.
  1403. *
  1404. * @param data is a pointer to the custom information (struct, function,
  1405. * etc) associated with the SRTP session.
  1406. *
  1407. * @return void.
  1408. *
  1409. */
  1410. void srtp_set_user_data(srtp_t ctx, void *data);
  1411. /**
  1412. * @brief srtp_get_user_data() retrieves the pointer to the custom data
  1413. * previously stored with srtp_set_user_data().
  1414. *
  1415. * This function is mostly useful for retrieving data associated to a
  1416. * SRTP session when an event fires. The user can then get such a custom
  1417. * data by calling this function with the session field of the
  1418. * srtp_event_data_t struct as argument.
  1419. *
  1420. * @param ctx is the srtp_t context in which the given data pointer was
  1421. * stored.
  1422. *
  1423. * @return void* pointer to the user data.
  1424. *
  1425. */
  1426. void *srtp_get_user_data(srtp_t ctx);
  1427. /**
  1428. * @}
  1429. */
  1430. /**
  1431. * @defgroup SRTPevents SRTP events and callbacks
  1432. * @ingroup SRTP
  1433. *
  1434. * @brief libSRTP can use a user-provided callback function to
  1435. * handle events.
  1436. *
  1437. *
  1438. * libSRTP allows a user to provide a callback function to handle
  1439. * events that need to be dealt with outside of the data plane (see
  1440. * the enum srtp_event_t for a description of these events). Dealing
  1441. * with these events is not a strict necessity; they are not
  1442. * security-critical, but the application may suffer if they are not
  1443. * handled. The function srtp_set_event_handler() is used to provide
  1444. * the callback function.
  1445. *
  1446. * A default event handler that merely reports on the events as they
  1447. * happen is included. It is also possible to set the event handler
  1448. * function to NULL, in which case all events will just be silently
  1449. * ignored.
  1450. *
  1451. * @{
  1452. */
  1453. /**
  1454. * @brief srtp_event_t defines events that need to be handled
  1455. *
  1456. * The enum srtp_event_t defines events that need to be handled
  1457. * outside the `data plane', such as SSRC collisions and
  1458. * key expirations.
  1459. *
  1460. * When a key expires or the maximum number of packets has been
  1461. * reached, an SRTP stream will enter an `expired' state in which no
  1462. * more packets can be protected or unprotected. When this happens,
  1463. * it is likely that you will want to either deallocate the stream
  1464. * (using srtp_remove_stream()), and possibly allocate a new one.
  1465. *
  1466. * When an SRTP stream expires, the other streams in the same session
  1467. * are unaffected, unless key sharing is used by that stream. In the
  1468. * latter case, all of the streams in the session will expire.
  1469. */
  1470. typedef enum {
  1471. event_ssrc_collision, /**< An SSRC collision occurred. */
  1472. event_key_soft_limit, /**< An SRTP stream reached the soft key */
  1473. /**< usage limit and will expire soon. */
  1474. event_key_hard_limit, /**< An SRTP stream reached the hard */
  1475. /**< key usage limit and has expired. */
  1476. event_packet_index_limit /**< An SRTP stream reached the hard */
  1477. /**< packet limit (2^48 packets). */
  1478. } srtp_event_t;
  1479. /**
  1480. * @brief srtp_event_data_t is the structure passed as a callback to
  1481. * the event handler function
  1482. *
  1483. * The struct srtp_event_data_t holds the data passed to the event
  1484. * handler function.
  1485. */
  1486. typedef struct srtp_event_data_t {
  1487. srtp_t session; /**< The session in which the event happened. */
  1488. uint32_t ssrc; /**< The ssrc in host order of the stream in which */
  1489. /**< the event happened */
  1490. srtp_event_t event; /**< An enum indicating the type of event. */
  1491. } srtp_event_data_t;
  1492. /**
  1493. * @brief srtp_event_handler_func_t is the function prototype for
  1494. * the event handler.
  1495. *
  1496. * The typedef srtp_event_handler_func_t is the prototype for the
  1497. * event handler function. It has as its only argument an
  1498. * srtp_event_data_t which describes the event that needs to be handled.
  1499. * There can only be a single, global handler for all events in
  1500. * libSRTP.
  1501. */
  1502. typedef void(srtp_event_handler_func_t)(srtp_event_data_t *data);
  1503. /**
  1504. * @brief sets the event handler to the function supplied by the caller.
  1505. *
  1506. * The function call srtp_install_event_handler(func) sets the event
  1507. * handler function to the value func. The value NULL is acceptable
  1508. * as an argument; in this case, events will be ignored rather than
  1509. * handled.
  1510. *
  1511. * @param func is a pointer to a function that takes an srtp_event_data_t
  1512. * pointer as an argument and returns void. This function
  1513. * will be used by libSRTP to handle events.
  1514. */
  1515. srtp_err_status_t srtp_install_event_handler(srtp_event_handler_func_t func);
  1516. /**
  1517. * @brief Returns the version string of the library.
  1518. *
  1519. */
  1520. const char *srtp_get_version_string(void);
  1521. /**
  1522. * @brief Returns the numeric representation of the library version.
  1523. *
  1524. */
  1525. unsigned int srtp_get_version(void);
  1526. /**
  1527. * @brief srtp_set_debug_module(mod_name, v)
  1528. *
  1529. * sets dynamic debugging to the value v (0 for off, 1 for on) for the
  1530. * debug module with the name mod_name
  1531. *
  1532. * returns err_status_ok on success, err_status_fail otherwise
  1533. */
  1534. srtp_err_status_t srtp_set_debug_module(const char *mod_name, int v);
  1535. /**
  1536. * @brief srtp_list_debug_modules() outputs a list of debugging modules
  1537. *
  1538. */
  1539. srtp_err_status_t srtp_list_debug_modules(void);
  1540. /**
  1541. * @brief srtp_log_level_t defines log levels.
  1542. *
  1543. * The enumeration srtp_log_level_t defines log levels reported
  1544. * in the srtp_log_handler_func_t.
  1545. *
  1546. */
  1547. typedef enum {
  1548. srtp_log_level_error, /**< log level is reporting an error message */
  1549. srtp_log_level_warning, /**< log level is reporting a warning message */
  1550. srtp_log_level_info, /**< log level is reporting an info message */
  1551. srtp_log_level_debug /**< log level is reporting a debug message */
  1552. } srtp_log_level_t;
  1553. /**
  1554. * @brief srtp_log_handler_func_t is the function prototype for
  1555. * the log handler.
  1556. *
  1557. * The typedef srtp_event_handler_func_t is the prototype for the
  1558. * event handler function. It has as srtp_log_level_t, log
  1559. * message and data as arguments.
  1560. * There can only be a single, global handler for all log messages in
  1561. * libSRTP.
  1562. */
  1563. typedef void(srtp_log_handler_func_t)(srtp_log_level_t level,
  1564. const char *msg,
  1565. void *data);
  1566. /**
  1567. * @brief sets the log handler to the function supplied by the caller.
  1568. *
  1569. * The function call srtp_install_log_handler(func) sets the log
  1570. * handler function to the value func. The value NULL is acceptable
  1571. * as an argument; in this case, log messages will be ignored.
  1572. * This function can be called before srtp_init() in order to capture
  1573. * any logging during start up.
  1574. *
  1575. * @param func is a pointer to a function of type srtp_log_handler_func_t.
  1576. * This function will be used by libSRTP to output log messages.
  1577. * @param data is a user pointer that will be returned as the data argument in
  1578. * func.
  1579. */
  1580. srtp_err_status_t srtp_install_log_handler(srtp_log_handler_func_t func,
  1581. void *data);
  1582. /**
  1583. * @brief srtp_get_protect_trailer_length(session, use_mki, mki_index, length)
  1584. *
  1585. * Determines the length of the amount of data Lib SRTP will add to the
  1586. * packet during the protect process. The length is returned in the length
  1587. * parameter
  1588. *
  1589. * returns err_status_ok on success, err_status_bad_mki if the MKI index is
  1590. * invalid
  1591. *
  1592. */
  1593. srtp_err_status_t srtp_get_protect_trailer_length(srtp_t session,
  1594. uint32_t use_mki,
  1595. uint32_t mki_index,
  1596. uint32_t *length);
  1597. /**
  1598. * @brief srtp_get_protect_rtcp_trailer_length(session, use_mki, mki_index,
  1599. * length)
  1600. *
  1601. * Determines the length of the amount of data Lib SRTP will add to the
  1602. * packet during the protect process. The length is returned in the length
  1603. * parameter
  1604. *
  1605. * returns err_status_ok on success, err_status_bad_mki if the MKI index is
  1606. * invalid
  1607. *
  1608. */
  1609. srtp_err_status_t srtp_get_protect_rtcp_trailer_length(srtp_t session,
  1610. uint32_t use_mki,
  1611. uint32_t mki_index,
  1612. uint32_t *length);
  1613. /**
  1614. * @brief srtp_set_stream_roc(session, ssrc, roc)
  1615. *
  1616. * Set the roll-over-counter on a session for a given SSRC
  1617. *
  1618. * returns err_status_ok on success, srtp_err_status_bad_param if there is no
  1619. * stream found
  1620. *
  1621. */
  1622. srtp_err_status_t srtp_set_stream_roc(srtp_t session,
  1623. uint32_t ssrc,
  1624. uint32_t roc);
  1625. /**
  1626. * @brief srtp_get_stream_roc(session, ssrc, roc)
  1627. *
  1628. * Get the roll-over-counter on a session for a given SSRC
  1629. *
  1630. * returns err_status_ok on success, srtp_err_status_bad_param if there is no
  1631. * stream found
  1632. *
  1633. */
  1634. srtp_err_status_t srtp_get_stream_roc(srtp_t session,
  1635. uint32_t ssrc,
  1636. uint32_t *roc);
  1637. /**
  1638. * @}
  1639. */
  1640. /* in host order, so outside the #if */
  1641. #define SRTCP_E_BIT 0x80000000
  1642. /* for byte-access */
  1643. #define SRTCP_E_BYTE_BIT 0x80
  1644. #define SRTCP_INDEX_MASK 0x7fffffff
  1645. #ifdef __cplusplus
  1646. }
  1647. #endif
  1648. #endif /* SRTP_SRTP_H */