blob: 1745bbe7aa8aa6d95449e60f5cc9da464659efba [file] [log] [blame]
Cullen Jennings235513a2005-09-21 22:51:36 +00001/*
2 * srtp.h
3 *
4 * interface to libsrtp
5 *
6 * David A. McGrew
7 * Cisco Systems, Inc.
8 */
9/*
10 *
David McGrew7629bf22006-06-08 17:00:25 +000011 * Copyright (c) 2001-2006, Cisco Systems, Inc.
Cullen Jennings235513a2005-09-21 22:51:36 +000012 * 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
45
46#ifndef SRTP_H
47#define SRTP_H
48
Marcus Sundbergcb60bf82005-10-17 17:23:05 +000049#ifdef __cplusplus
50extern "C" {
51#endif
52
jfigus45ab5332014-10-01 19:47:46 -040053#include <stdint.h>
Cullen Jennings235513a2005-09-21 22:51:36 +000054
55/**
56 * @defgroup SRTP Secure RTP
57 *
58 * @brief libSRTP provides functions for protecting RTP and RTCP. See
59 * Section @ref Overview for an introduction to the use of the library.
60 *
61 * @{
62 */
63
64/*
65 * SRTP_MASTER_KEY_LEN is the nominal master key length supported by libSRTP
66 */
67
68#define SRTP_MASTER_KEY_LEN 30
69
70/*
71 * SRTP_MAX_KEY_LEN is the maximum key length supported by libSRTP
72 */
73#define SRTP_MAX_KEY_LEN 64
74
75/*
76 * SRTP_MAX_TAG_LEN is the maximum tag length supported by libSRTP
77 */
78
jfigused221292015-05-15 13:39:08 -040079#define SRTP_MAX_TAG_LEN 16
Cullen Jennings235513a2005-09-21 22:51:36 +000080
81/**
82 * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer
83 * (authentication tag and MKI) supported by libSRTP. This value is
84 * the maximum number of octets that will be added to an RTP packet by
85 * srtp_protect().
86 *
87 * @brief the maximum number of octets added by srtp_protect().
88 */
89#define SRTP_MAX_TRAILER_LEN SRTP_MAX_TAG_LEN
90
jfigus8c36da22013-10-01 16:41:19 -040091/*
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
jfigus857009c2014-11-05 11:17:43 -050097#define SRTP_AES_128_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 16
98#define SRTP_AES_192_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 24
99#define SRTP_AES_256_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 32
jfigus8719f952014-04-08 09:15:49 -0400100
jfigusa9ac8982014-10-31 14:49:31 -0400101/*
102 * an srtp_hdr_t represents the srtp header
103 *
104 * in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
105 *
106 * (note that this definition follows that of RFC 1889 Appendix A, but
107 * is not identical)
108 */
109
110#ifndef WORDS_BIGENDIAN
jfigus8c36da22013-10-01 16:41:19 -0400111
jfigusa9ac8982014-10-31 14:49:31 -0400112/*
113 * srtp_hdr_t represents an RTP or SRTP header. The bit-fields in
114 * this structure should be declared "unsigned int" instead of
115 * "unsigned char", but doing so causes the MS compiler to not
116 * fully pack the bit fields.
117 */
118
119typedef struct {
120 unsigned char cc:4; /* CSRC count */
121 unsigned char x:1; /* header extension flag */
122 unsigned char p:1; /* padding flag */
123 unsigned char version:2; /* protocol version */
124 unsigned char pt:7; /* payload type */
125 unsigned char m:1; /* marker bit */
126 uint16_t seq; /* sequence number */
127 uint32_t ts; /* timestamp */
128 uint32_t ssrc; /* synchronization source */
129} srtp_hdr_t;
130
131#else /* BIG_ENDIAN */
132
133typedef struct {
134 unsigned char version:2; /* protocol version */
135 unsigned char p:1; /* padding flag */
136 unsigned char x:1; /* header extension flag */
137 unsigned char cc:4; /* CSRC count */
138 unsigned char m:1; /* marker bit */
139 unsigned char pt:7; /* payload type */
140 uint16_t seq; /* sequence number */
141 uint32_t ts; /* timestamp */
142 uint32_t ssrc; /* synchronization source */
143} srtp_hdr_t;
144
145#endif
146
147typedef struct {
148 uint16_t profile_specific; /* profile-specific info */
149 uint16_t length; /* number of 32-bit words in extension */
150} srtp_hdr_xtnd_t;
151
152
153/*
154 * srtcp_hdr_t represents a secure rtcp header
155 *
156 * in this implementation, an srtcp header is assumed to be 32-bit
157 * alinged
158 */
159
160#ifndef WORDS_BIGENDIAN
161
162typedef struct {
163 unsigned char rc:5; /* reception report count */
164 unsigned char p:1; /* padding flag */
165 unsigned char version:2; /* protocol version */
166 unsigned char pt:8; /* payload type */
167 uint16_t len; /* length */
168 uint32_t ssrc; /* synchronization source */
169} srtcp_hdr_t;
170
171typedef struct {
172 unsigned int index:31; /* srtcp packet index in network order! */
173 unsigned int e:1; /* encrypted? 1=yes */
174 /* optional mikey/etc go here */
175 /* and then the variable-length auth tag */
176} srtcp_trailer_t;
177
178
179#else /* BIG_ENDIAN */
180
181typedef struct {
182 unsigned char version:2; /* protocol version */
183 unsigned char p:1; /* padding flag */
184 unsigned char rc:5; /* reception report count */
185 unsigned char pt:8; /* payload type */
186 uint16_t len; /* length */
187 uint32_t ssrc; /* synchronization source */
188} srtcp_hdr_t;
189
190typedef struct {
191 unsigned int version:2; /* protocol version */
192 unsigned int p:1; /* padding flag */
193 unsigned int count:5; /* varies by packet type */
194 unsigned int pt:8; /* payload type */
195 uint16_t length; /* len of uint32s of packet less header */
196} rtcp_common_t;
197
198typedef struct {
199 unsigned int e:1; /* encrypted? 1=yes */
200 unsigned int index:31; /* srtcp packet index */
201 /* optional mikey/etc go here */
202 /* and then the variable-length auth tag */
203} srtcp_trailer_t;
204
205#endif
206
207
208
209/**
jfigus857009c2014-11-05 11:17:43 -0500210 * @brief A srtp_cipher_type_id_t is an identifier for a particular cipher
jfigusa9ac8982014-10-31 14:49:31 -0400211 * type.
212 *
jfigus857009c2014-11-05 11:17:43 -0500213 * A srtp_cipher_type_id_t is an integer that represents a particular
jfigusa9ac8982014-10-31 14:49:31 -0400214 * cipher type, e.g. the Advanced Encryption Standard (AES). A
jfigus67b9c732014-11-20 10:17:21 -0500215 * SRTP_NULL_CIPHER is avaliable; this cipher leaves the data unchanged,
jfigusa9ac8982014-10-31 14:49:31 -0400216 * and can be selected to indicate that no encryption is to take
217 * place.
218 *
219 * @ingroup Ciphers
220 */
jfigus857009c2014-11-05 11:17:43 -0500221typedef uint32_t srtp_cipher_type_id_t;
jfigusa9ac8982014-10-31 14:49:31 -0400222
223/**
jfigus857009c2014-11-05 11:17:43 -0500224 * @brief An srtp_auth_type_id_t is an identifier for a particular authentication
jfigusa9ac8982014-10-31 14:49:31 -0400225 * function.
226 *
jfigus857009c2014-11-05 11:17:43 -0500227 * An srtp_auth_type_id_t is an integer that represents a particular
jfigus67b9c732014-11-20 10:17:21 -0500228 * authentication function type, e.g. HMAC-SHA1. A SRTP_NULL_AUTH is
jfigusa9ac8982014-10-31 14:49:31 -0400229 * avaliable; this authentication function performs no computation,
230 * and can be selected to indicate that no authentication is to take
231 * place.
232 *
233 * @ingroup Authentication
234 */
jfigus857009c2014-11-05 11:17:43 -0500235typedef uint32_t srtp_auth_type_id_t;
jfigusa9ac8982014-10-31 14:49:31 -0400236
237/*
jfigus857009c2014-11-05 11:17:43 -0500238 * @brief srtp_err_status_t defines error codes.
jfigusa9ac8982014-10-31 14:49:31 -0400239 *
jfigus857009c2014-11-05 11:17:43 -0500240 * The enumeration srtp_err_status_t defines error codes. Note that the
241 * value of srtp_err_status_ok is equal to zero, which can simplify error
jfigusa9ac8982014-10-31 14:49:31 -0400242 * checking somewhat.
243 *
244 */
245typedef enum {
jfigus857009c2014-11-05 11:17:43 -0500246 srtp_err_status_ok = 0, /**< nothing to report */
247 srtp_err_status_fail = 1, /**< unspecified failure */
248 srtp_err_status_bad_param = 2, /**< unsupported parameter */
249 srtp_err_status_alloc_fail = 3, /**< couldn't allocate memory */
250 srtp_err_status_dealloc_fail = 4, /**< couldn't deallocate properly */
251 srtp_err_status_init_fail = 5, /**< couldn't initialize */
252 srtp_err_status_terminus = 6, /**< can't process as much data as requested */
253 srtp_err_status_auth_fail = 7, /**< authentication failure */
254 srtp_err_status_cipher_fail = 8, /**< cipher failure */
255 srtp_err_status_replay_fail = 9, /**< replay check failed (bad index) */
256 srtp_err_status_replay_old = 10, /**< replay check failed (index too old) */
257 srtp_err_status_algo_fail = 11, /**< algorithm failed test routine */
258 srtp_err_status_no_such_op = 12, /**< unsupported operation */
259 srtp_err_status_no_ctx = 13, /**< no appropriate context found */
260 srtp_err_status_cant_check = 14, /**< unable to perform desired validation */
261 srtp_err_status_key_expired = 15, /**< can't use key any more */
262 srtp_err_status_socket_err = 16, /**< error in use of socket */
263 srtp_err_status_signal_err = 17, /**< error in use POSIX signals */
264 srtp_err_status_nonce_bad = 18, /**< nonce check failed */
265 srtp_err_status_read_fail = 19, /**< couldn't read data */
266 srtp_err_status_write_fail = 20, /**< couldn't write data */
267 srtp_err_status_parse_err = 21, /**< error parsing data */
268 srtp_err_status_encode_err = 22, /**< error encoding data */
269 srtp_err_status_semaphore_err = 23,/**< error while using semaphores */
270 srtp_err_status_pfkey_err = 24 /**< error while using pfkey */
271} srtp_err_status_t;
jfigusa9ac8982014-10-31 14:49:31 -0400272
273typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t;
274typedef struct srtp_ctx_t_ srtp_ctx_t;
jfigus44947602014-10-08 13:08:52 -0400275
Cullen Jennings235513a2005-09-21 22:51:36 +0000276/*
277 * nota bene: since libSRTP doesn't support the use of the MKI, the
278 * SRTP_MAX_TRAILER_LEN value is just the maximum tag length
279 */
280
281/**
jfigus857009c2014-11-05 11:17:43 -0500282 * @brief srtp_sec_serv_t describes a set of security services.
Cullen Jennings235513a2005-09-21 22:51:36 +0000283 *
jfigus857009c2014-11-05 11:17:43 -0500284 * A srtp_sec_serv_t enumeration is used to describe the particular
Cullen Jennings235513a2005-09-21 22:51:36 +0000285 * security services that will be applied by a particular crypto
286 * policy (or other mechanism).
287 */
288
289typedef enum {
290 sec_serv_none = 0, /**< no services */
291 sec_serv_conf = 1, /**< confidentiality */
292 sec_serv_auth = 2, /**< authentication */
293 sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */
jfigus857009c2014-11-05 11:17:43 -0500294} srtp_sec_serv_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000295
296/**
jfigus857009c2014-11-05 11:17:43 -0500297 * @brief srtp_crypto_policy_t describes a particular crypto policy that
Cullen Jennings235513a2005-09-21 22:51:36 +0000298 * can be applied to an SRTP stream.
299 *
jfigus857009c2014-11-05 11:17:43 -0500300 * A srtp_crypto_policy_t describes a particular cryptographic policy that
Cullen Jennings235513a2005-09-21 22:51:36 +0000301 * can be applied to an SRTP or SRTCP stream. An SRTP session policy
302 * consists of a list of these policies, one for each SRTP stream
303 * in the session.
304 */
305
jfigus857009c2014-11-05 11:17:43 -0500306typedef struct srtp_crypto_policy_t {
307 srtp_cipher_type_id_t cipher_type; /**< An integer representing
308 * the type of cipher. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000309 int cipher_key_len; /**< The length of the cipher key
310 * in octets. */
jfigus857009c2014-11-05 11:17:43 -0500311 srtp_auth_type_id_t auth_type; /**< An integer representing the
312 * authentication function. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000313 int auth_key_len; /**< The length of the authentication
314 * function key in octets. */
315 int auth_tag_len; /**< The length of the authentication
316 * tag in octets. */
jfigus857009c2014-11-05 11:17:43 -0500317 srtp_sec_serv_t sec_serv; /**< The flag indicating the security
Cullen Jennings235513a2005-09-21 22:51:36 +0000318 * services to be applied. */
jfigus857009c2014-11-05 11:17:43 -0500319} srtp_crypto_policy_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000320
321
322/**
jfigus857009c2014-11-05 11:17:43 -0500323 * @brief srtp_ssrc_type_t describes the type of an SSRC.
Cullen Jennings235513a2005-09-21 22:51:36 +0000324 *
jfigus857009c2014-11-05 11:17:43 -0500325 * An srtp_ssrc_type_t enumeration is used to indicate a type of SSRC. See
Cullen Jennings235513a2005-09-21 22:51:36 +0000326 * @ref srtp_policy_t for more informataion.
327 */
328
329typedef enum {
330 ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */
331 ssrc_specific = 1, /**< Indicates a specific SSRC value */
332 ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value
333 (i.e. a value that is used in the
334 function srtp_unprotect()) */
335 ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value
336 (i.e. a value that is used in the
337 function srtp_protect()) */
jfigus857009c2014-11-05 11:17:43 -0500338} srtp_ssrc_type_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000339
340/**
jfigus857009c2014-11-05 11:17:43 -0500341 * @brief An srtp_ssrc_t represents a particular SSRC value, or a `wildcard' SSRC.
Cullen Jennings235513a2005-09-21 22:51:36 +0000342 *
jfigus857009c2014-11-05 11:17:43 -0500343 * An srtp_ssrc_t represents a particular SSRC value (if its type is
Cullen Jennings235513a2005-09-21 22:51:36 +0000344 * ssrc_specific), or a wildcard SSRC value that will match all
345 * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound
346 * SSRCs (if its type is ssrc_any_inbound).
347 *
348 */
349
350typedef struct {
jfigus857009c2014-11-05 11:17:43 -0500351 srtp_ssrc_type_t type; /**< The type of this particular SSRC */
352 unsigned int value; /**< The value of this SSRC, if it is not a wildcard */
353} srtp_ssrc_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000354
355
David McGrew79870d62007-06-15 18:17:39 +0000356/**
357 * @brief points to an EKT policy
358 */
jfigusc5887e72014-11-06 09:46:18 -0500359typedef struct srtp_ekt_policy_ctx_t *srtp_ekt_policy_t;
David McGrew79870d62007-06-15 18:17:39 +0000360
361
362/**
363 * @brief points to EKT stream data
364 */
jfigusc5887e72014-11-06 09:46:18 -0500365typedef struct srtp_ekt_stream_ctx_t *srtp_ekt_stream_t;
David McGrew79870d62007-06-15 18:17:39 +0000366
367
Cullen Jennings235513a2005-09-21 22:51:36 +0000368/**
369 * @brief represents the policy for an SRTP session.
370 *
371 * A single srtp_policy_t struct represents the policy for a single
372 * SRTP stream, and a linked list of these elements represents the
373 * policy for an entire SRTP session. Each element contains the SRTP
374 * and SRTCP crypto policies for that stream, a pointer to the SRTP
375 * master key for that stream, the SSRC describing that stream, or a
376 * flag indicating a `wildcard' SSRC value, and a `next' field that
377 * holds a pointer to the next element in the list of policy elements,
378 * or NULL if it is the last element.
379 *
380 * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an
381 * inbound stream that for which there is no explicit SSRC entry in
382 * another policy element. Similarly, the value SSRC_ANY_OUTBOUND
383 * will matches any SSRC from an outbound stream that does not appear
384 * in another policy element. Note that wildcard SSRCs &b cannot be
385 * used to match both inbound and outbound traffic. This restriction
386 * is intentional, and it allows libSRTP to ensure that no security
387 * lapses result from accidental re-use of SSRC values during key
388 * sharing.
389 *
390 *
391 * @warning The final element of the list @b must have its `next' pointer
392 * set to NULL.
393 */
394
395typedef struct srtp_policy_t {
jfigus857009c2014-11-05 11:17:43 -0500396 srtp_ssrc_t ssrc; /**< The SSRC value of stream, or the
Cullen Jennings235513a2005-09-21 22:51:36 +0000397 * flags SSRC_ANY_INBOUND or
398 * SSRC_ANY_OUTBOUND if key sharing
399 * is used for this policy element.
400 */
jfigus857009c2014-11-05 11:17:43 -0500401 srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */
402 srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */
David McGrew3c45e0c2006-07-12 00:50:56 +0000403 unsigned char *key; /**< Pointer to the SRTP master key for
Cullen Jennings235513a2005-09-21 22:51:36 +0000404 * this stream. */
jfigusc5887e72014-11-06 09:46:18 -0500405 srtp_ekt_policy_t ekt; /**< Pointer to the EKT policy structure
David McGrew79870d62007-06-15 18:17:39 +0000406 * for this stream (if any) */
Jonathan Lennoxa1242f82010-05-17 21:46:04 +0000407 unsigned long window_size; /**< The window size to use for replay
408 * protection. */
Jonathan Lennoxdcee5c62010-05-17 22:08:40 +0000409 int allow_repeat_tx; /**< Whether retransmissions of
410 * packets with the same sequence number
411 * are allowed. (Note that such repeated
412 * transmissions must have the same RTP
413 * payload, or a severe security weakness
414 * is introduced!) */
Joachim Bauch99a74822015-11-17 00:08:19 +0100415 int *enc_xtn_hdr; /**< List of header ids to encrypt. */
416 int enc_xtn_hdr_count; /**< Number of entries in list of header ids. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000417 struct srtp_policy_t *next; /**< Pointer to next stream policy. */
418} srtp_policy_t;
419
420
421
422
423/**
424 * @brief An srtp_t points to an SRTP session structure.
425 *
426 * The typedef srtp_t is a pointer to a structure that represents
427 * an SRTP session. This datatype is intentially opaque in
428 * order to separate the interface from the implementation.
429 *
430 * An SRTP session consists of all of the traffic sent to the RTP and
431 * RTCP destination transport addresses, using the RTP/SAVP (Secure
432 * Audio/Video Profile). A session can be viewed as a set of SRTP
433 * streams, each of which originates with a different participant.
434 */
435
jfigusa9ac8982014-10-31 14:49:31 -0400436typedef srtp_ctx_t *srtp_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000437
438
439/**
440 * @brief An srtp_stream_t points to an SRTP stream structure.
441 *
442 * The typedef srtp_stream_t is a pointer to a structure that
443 * represents an SRTP stream. This datatype is intentionally
444 * opaque in order to separate the interface from the implementation.
445 *
446 * An SRTP stream consists of all of the traffic sent to an SRTP
447 * session by a single participant. A session can be viewed as
448 * a set of streams.
449 *
450 */
jfigusa9ac8982014-10-31 14:49:31 -0400451typedef srtp_stream_ctx_t *srtp_stream_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000452
453
454
455/**
456 * @brief srtp_init() initializes the srtp library.
457 *
458 * @warning This function @b must be called before any other srtp
459 * functions.
460 */
461
jfigus857009c2014-11-05 11:17:43 -0500462srtp_err_status_t srtp_init(void);
Cullen Jennings235513a2005-09-21 22:51:36 +0000463
464/**
Jonathan Lennox5ae76332010-05-15 04:48:59 +0000465 * @brief srtp_shutdown() de-initializes the srtp library.
466 *
467 * @warning No srtp functions may be called after calling this function.
468 */
469
jfigus857009c2014-11-05 11:17:43 -0500470srtp_err_status_t srtp_shutdown(void);
Jonathan Lennox5ae76332010-05-15 04:48:59 +0000471
472/**
Cullen Jennings235513a2005-09-21 22:51:36 +0000473 * @brief srtp_protect() is the Secure RTP sender-side packet processing
474 * function.
475 *
476 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
477 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
jfigus857009c2014-11-05 11:17:43 -0500478 * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
Cullen Jennings235513a2005-09-21 22:51:36 +0000479 * points to the resulting SRTP packet and *len_ptr is the number of
480 * octets in that packet; otherwise, no assumptions should be made
481 * about the value of either 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 it can write the authentication
488 * tag into the location in memory immediately following the RTP
489 * packet, and assumes that the RTP packet is aligned on a 32-bit
490 * boundary.
491 *
jfigusdfe68ea2013-05-28 09:00:14 -0400492 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
493 * into the location in memory immediately following the RTP packet.
494 * Callers MUST ensure that this much writable memory is available in
495 * the buffer that holds the RTP packet.
jfigus5e337292013-05-28 13:57:47 -0400496 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000497 * @param ctx is the SRTP context to use in processing the packet.
498 *
499 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
500 * the function returns, it points to the srtp packet.
501 *
502 * @param len_ptr is a pointer to the length in octets of the complete
503 * RTP packet (header and body) before the function call, and of the
jfigus857009c2014-11-05 11:17:43 -0500504 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
Cullen Jennings235513a2005-09-21 22:51:36 +0000505 * Otherwise, the value of the data to which it points is undefined.
506 *
507 * @return
jfigus857009c2014-11-05 11:17:43 -0500508 * - srtp_err_status_ok no problems
509 * - srtp_err_status_replay_fail rtp sequence number was non-increasing
Cullen Jennings235513a2005-09-21 22:51:36 +0000510 * - @e other failure in cryptographic mechanisms
511 */
512
jfigus857009c2014-11-05 11:17:43 -0500513srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
Cullen Jennings235513a2005-09-21 22:51:36 +0000514
515/**
516 * @brief srtp_unprotect() is the Secure RTP receiver-side packet
517 * processing function.
518 *
519 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
520 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
521 * (which has length *len_ptr), using the SRTP context ctx. If
jfigus857009c2014-11-05 11:17:43 -0500522 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
Cullen Jennings235513a2005-09-21 22:51:36 +0000523 * RTP packet and *len_ptr is the number of octets in that packet;
524 * otherwise, no assumptions should be made about the value of either
525 * data elements.
526 *
527 * The sequence numbers of the RTP packets presented to this function
528 * need not be consecutive, but they @b must be out of order by less
529 * than 2^15 = 32,768 packets.
530 *
531 * @warning This function assumes that the SRTP packet is aligned on a
532 * 32-bit boundary.
533 *
IƱaki Baz Castillo241fec32014-08-21 00:51:00 +0200534 * @param ctx is the SRTP session which applies to the particular packet.
Cullen Jennings235513a2005-09-21 22:51:36 +0000535 *
536 * @param srtp_hdr is a pointer to the header of the SRTP packet
537 * (before the call). after the function returns, it points to the
jfigus857009c2014-11-05 11:17:43 -0500538 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
Cullen Jennings235513a2005-09-21 22:51:36 +0000539 * the data to which it points is undefined.
540 *
541 * @param len_ptr is a pointer to the length in octets of the complete
542 * srtp packet (header and body) before the function call, and of the
jfigus857009c2014-11-05 11:17:43 -0500543 * complete rtp packet after the call, if srtp_err_status_ok was returned.
Cullen Jennings235513a2005-09-21 22:51:36 +0000544 * Otherwise, the value of the data to which it points is undefined.
545 *
546 * @return
jfigus857009c2014-11-05 11:17:43 -0500547 * - srtp_err_status_ok if the RTP packet is valid.
548 * - srtp_err_status_auth_fail if the SRTP packet failed the message
Cullen Jennings235513a2005-09-21 22:51:36 +0000549 * authentication check.
jfigus857009c2014-11-05 11:17:43 -0500550 * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet has
Cullen Jennings235513a2005-09-21 22:51:36 +0000551 * already been processed and accepted).
552 * - [other] if there has been an error in the cryptographic mechanisms.
553 *
554 */
555
jfigus857009c2014-11-05 11:17:43 -0500556srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
Cullen Jennings235513a2005-09-21 22:51:36 +0000557
558
559/**
560 * @brief srtp_create() allocates and initializes an SRTP session.
561
jfigus92c3de32016-02-02 13:44:39 -0500562 * The function call srtp_create(session, policy) allocates and
563 * initializes an SRTP session context, applying the given policy.
Cullen Jennings235513a2005-09-21 22:51:36 +0000564 *
IƱaki Baz Castillo241fec32014-08-21 00:51:00 +0200565 * @param session is a pointer to the SRTP session to which the policy is
566 * to be added.
Cullen Jennings235513a2005-09-21 22:51:36 +0000567 *
568 * @param policy is the srtp_policy_t struct that describes the policy
569 * for the session. The struct may be a single element, or it may be
570 * the head of a list, in which case each element of the list is
Marcus Sundberg75d92122005-10-05 12:40:31 +0000571 * processed. It may also be NULL, in which case streams should be added
572 * later using srtp_add_stream(). The final element of the list @b must
573 * have its `next' field set to NULL.
Cullen Jennings235513a2005-09-21 22:51:36 +0000574 *
575 * @return
jfigus857009c2014-11-05 11:17:43 -0500576 * - srtp_err_status_ok if creation succeded.
577 * - srtp_err_status_alloc_fail if allocation failed.
578 * - srtp_err_status_init_fail if initialization failed.
Cullen Jennings235513a2005-09-21 22:51:36 +0000579 */
580
jfigus857009c2014-11-05 11:17:43 -0500581srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000582
583
584/**
585 * @brief srtp_add_stream() allocates and initializes an SRTP stream
586 * within a given SRTP session.
587 *
588 * The function call srtp_add_stream(session, policy) allocates and
589 * initializes a new SRTP stream within a given, previously created
590 * session, applying the policy given as the other argument to that
591 * stream.
592 *
593 * @return values:
jfigus857009c2014-11-05 11:17:43 -0500594 * - srtp_err_status_ok if stream creation succeded.
595 * - srtp_err_status_alloc_fail if stream allocation failed
596 * - srtp_err_status_init_fail if stream initialization failed.
Cullen Jennings235513a2005-09-21 22:51:36 +0000597 */
598
jfigus857009c2014-11-05 11:17:43 -0500599srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000600
601
602/**
603 * @brief srtp_remove_stream() deallocates an SRTP stream.
604 *
605 * The function call srtp_remove_stream(session, ssrc) removes
606 * the SRTP stream with the SSRC value ssrc from the SRTP session
607 * context given by the argument session.
608 *
609 * @param session is the SRTP session from which the stream
610 * will be removed.
611 *
jfigus68f8a882016-02-03 12:48:23 -0500612 * @param ssrc is the SSRC value of the stream to be removed
613 * in network byte order.
Cullen Jennings235513a2005-09-21 22:51:36 +0000614 *
615 * @warning Wildcard SSRC values cannot be removed from a
616 * session.
617 *
618 * @return
jfigus857009c2014-11-05 11:17:43 -0500619 * - srtp_err_status_ok if the stream deallocation succeded.
Cullen Jennings235513a2005-09-21 22:51:36 +0000620 * - [other] otherwise.
621 *
622 */
623
jfigus857009c2014-11-05 11:17:43 -0500624srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc);
Cullen Jennings235513a2005-09-21 22:51:36 +0000625
626/**
Pascal BĆ¼hlerbd3112a2015-11-06 20:29:15 +0100627 * @brief srtp_update() udpates all streams in the session.
628 *
629 * The function call srtp_update(session, policy) updates
630 * all the streams in the session applying the given policy
631 * and key. The exsisting ROC value of all streams will be
632 * preserved.
633 *
634 * @param session is the SRTP session that contains the streams
635 * to be updated.
636 *
637 * @param policy is the srtp_policy_t struct that describes the policy
638 * for the session. The struct may be a single element, or it may be
639 * the head of a list, in which case each element of the list is
640 * processed. The final element of the list @b must
641 * have its `next' field set to NULL.
642 *
643 * @return
644 * - srtp_err_status_ok if stream creation succeded.
645 * - srtp_err_status_alloc_fail if stream allocation failed
646 * - srtp_err_status_init_fail if stream initialization failed.
647 * - [other] otherwise.
648 *
649 */
650
651srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy);
652
653/**
654 * @brief srtp_update_stream() udpates a SRTP stream.
655 *
656 * The function call srtp_update_stream(session, policy) updates
657 * the stream(s) in the session that match applying the given
658 * policy and key. The exsisting ROC value of all stream(s) will
659 * be preserved.
660 *
661 * @param session is the SRTP session that contains the streams
662 * to be updated.
663 *
664 * @param policy is the srtp_policy_t struct that describes the policy
665 * for the session.
666 *
667 * @return
668 * - srtp_err_status_ok if stream creation succeded.
669 * - srtp_err_status_alloc_fail if stream allocation failed
670 * - srtp_err_status_init_fail if stream initialization failed.
671 * - [other] otherwise.
672 *
673 */
674
675srtp_err_status_t srtp_update_stream(srtp_t session, const srtp_policy_t *policy);
676
677/**
jfigus857009c2014-11-05 11:17:43 -0500678 * @brief srtp_crypto_policy_set_rtp_default() sets a crypto policy
Cullen Jennings235513a2005-09-21 22:51:36 +0000679 * structure to the SRTP default policy for RTP protection.
680 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000681 * @param p is a pointer to the policy structure to be set
Cullen Jennings235513a2005-09-21 22:51:36 +0000682 *
683 * The function call crypto_policy_set_rtp_default(&p) sets the
684 * crypto_policy_t at location p to the SRTP default policy for RTP
685 * protection, as defined in the specification. This function is a
686 * convenience that helps to avoid dealing directly with the policy
687 * data structure. You are encouraged to initialize policy elements
688 * with this function call. Doing so may allow your code to be
689 * forward compatible with later versions of libSRTP that include more
690 * elements in the crypto_policy_t datatype.
691 *
692 * @return void.
693 *
694 */
695
jfigus857009c2014-11-05 11:17:43 -0500696void srtp_crypto_policy_set_rtp_default(srtp_crypto_policy_t *p);
Cullen Jennings235513a2005-09-21 22:51:36 +0000697
698/**
jfigus857009c2014-11-05 11:17:43 -0500699 * @brief srtp_crypto_policy_set_rtcp_default() sets a crypto policy
Cullen Jennings235513a2005-09-21 22:51:36 +0000700 * structure to the SRTP default policy for RTCP protection.
701 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000702 * @param p is a pointer to the policy structure to be set
Cullen Jennings235513a2005-09-21 22:51:36 +0000703 *
jfigus857009c2014-11-05 11:17:43 -0500704 * The function call srtp_crypto_policy_set_rtcp_default(&p) sets the
705 * srtp_crypto_policy_t at location p to the SRTP default policy for RTCP
Cullen Jennings235513a2005-09-21 22:51:36 +0000706 * protection, as defined in the specification. This function is a
707 * convenience that helps to avoid dealing directly with the policy
708 * data structure. You are encouraged to initialize policy elements
709 * with this function call. Doing so may allow your code to be
710 * forward compatible with later versions of libSRTP that include more
jfigus857009c2014-11-05 11:17:43 -0500711 * elements in the srtp_crypto_policy_t datatype.
Cullen Jennings235513a2005-09-21 22:51:36 +0000712 *
713 * @return void.
714 *
715 */
716
jfigus857009c2014-11-05 11:17:43 -0500717void srtp_crypto_policy_set_rtcp_default(srtp_crypto_policy_t *p);
Cullen Jennings235513a2005-09-21 22:51:36 +0000718
719/**
jfigus857009c2014-11-05 11:17:43 -0500720 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000721 * policy structure to the SRTP default policy for RTP protection.
722 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000723 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000724 *
jfigus857009c2014-11-05 11:17:43 -0500725 * The function srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
726 * synonym for srtp_crypto_policy_set_rtp_default(). It conforms to the
Jonathan Lennoxd8d5cd02010-05-17 20:08:17 +0000727 * naming convention used in RFC 4568 (SDP Security Descriptions for
728 * Media Streams).
David McGrewa8546882006-01-12 17:56:02 +0000729 *
730 * @return void.
731 *
732 */
733
jfigus857009c2014-11-05 11:17:43 -0500734#define srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(p) srtp_crypto_policy_set_rtp_default(p)
David McGrewa8546882006-01-12 17:56:02 +0000735
736
737/**
jfigus857009c2014-11-05 11:17:43 -0500738 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000739 * policy structure to a short-authentication tag policy
740 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000741 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000742 *
jfigus857009c2014-11-05 11:17:43 -0500743 * The function call srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
744 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennoxd8d5cd02010-05-17 20:08:17 +0000745 * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568.
746 * This policy uses AES-128
David McGrewa8546882006-01-12 17:56:02 +0000747 * Counter Mode encryption and HMAC-SHA1 authentication, with an
748 * authentication tag that is only 32 bits long. This length is
749 * considered adequate only for protecting audio and video media that
750 * use a stateless playback function. See Section 7.5 of RFC 3711
751 * (http://www.ietf.org/rfc/rfc3711.txt).
752 *
753 * This function is a convenience that helps to avoid dealing directly
754 * with the policy data structure. You are encouraged to initialize
755 * policy elements with this function call. Doing so may allow your
756 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500757 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000758 *
759 * @warning This crypto policy is intended for use in SRTP, but not in
760 * SRTCP. It is recommended that a policy that uses longer
761 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
762 * (http://www.ietf.org/rfc/rfc3711.txt).
763 *
764 * @return void.
765 *
766 */
767
jfigus857009c2014-11-05 11:17:43 -0500768void srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000769
770
771
772/**
jfigus857009c2014-11-05 11:17:43 -0500773 * @brief srtp_crypto_policy_set_aes_cm_128_null_auth() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000774 * policy structure to an encryption-only policy
775 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000776 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000777 *
jfigus857009c2014-11-05 11:17:43 -0500778 * The function call srtp_crypto_policy_set_aes_cm_128_null_auth(&p) sets
779 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
David McGrewa8546882006-01-12 17:56:02 +0000780 * (AES-128 Counter Mode), but to use no authentication method. This
781 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
782 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
783 *
784 * This function is a convenience that helps to avoid dealing directly
785 * with the policy data structure. You are encouraged to initialize
786 * policy elements with this function call. Doing so may allow your
787 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500788 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000789 *
790 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
791 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
792 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
793 *
794 * @return void.
795 *
796 */
797
jfigus857009c2014-11-05 11:17:43 -0500798void srtp_crypto_policy_set_aes_cm_128_null_auth(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000799
800
801/**
jfigus857009c2014-11-05 11:17:43 -0500802 * @brief srtp_crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000803 * policy structure to an authentication-only policy
804 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000805 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000806 *
jfigus857009c2014-11-05 11:17:43 -0500807 * The function call srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&p)
808 * sets the srtp_crypto_policy_t at location p to use HMAC-SHA1 with an 80
David McGrewa8546882006-01-12 17:56:02 +0000809 * bit authentication tag to provide message authentication, but to
810 * use no encryption. This policy is NOT RECOMMENDED for SRTP unless
811 * there is a requirement to forego encryption.
812 *
813 * This function is a convenience that helps to avoid dealing directly
814 * with the policy data structure. You are encouraged to initialize
815 * policy elements with this function call. Doing so may allow your
816 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500817 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000818 *
819 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
820 * requirement to forego encryption.
821 *
822 * @return void.
823 *
824 */
jfigus857009c2014-11-05 11:17:43 -0500825void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000826
jfigus267956d2014-11-06 10:49:21 -0500827/**
828 * @brief srtp_crypto_policy_set_null_cipher_hmac_null() sets a crypto
829 * policy structure to use no encryption or authentication.
830 *
831 * @param p is a pointer to the policy structure to be set
832 *
833 * The function call srtp_crypto_policy_set_null_cipher_hmac_null(&p)
834 * sets the srtp_crypto_policy_t at location p to use no encryption and
835 * no authentication. This policy should only be used for testing and
836 * troubleshootingl.
837 *
838 * This function is a convenience that helps to avoid dealing directly
839 * with the policy data structure. You are encouraged to initialize
840 * policy elements with this function call. Doing so may allow your
841 * code to be forward compatible with later versions of libSRTP that
842 * include more elements in the srtp_crypto_policy_t datatype.
843 *
844 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
845 * requirement to forego encryption and authentication.
846 *
847 * @return void.
848 *
849 */
850void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p);
851
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000852
853/**
jfigus857009c2014-11-05 11:17:43 -0500854 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000855 * policy structure to a encryption and authentication policy using AES-256
856 * for RTP protection.
857 *
858 * @param p is a pointer to the policy structure to be set
859 *
jfigus857009c2014-11-05 11:17:43 -0500860 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&p)
861 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000862 * AES_CM_256_HMAC_SHA1_80 as defined in
863 * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
864 * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
865 * authentication tag.
866 *
867 * This function is a convenience that helps to avoid dealing directly
868 * with the policy data structure. You are encouraged to initialize
869 * policy elements with this function call. Doing so may allow your
870 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500871 * include more elements in the srtp_crypto_policy_t datatype.
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000872 *
873 * @return void.
874 *
875 */
876
jfigus857009c2014-11-05 11:17:43 -0500877void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(srtp_crypto_policy_t *p);
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000878
879
880/**
jfigus857009c2014-11-05 11:17:43 -0500881 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000882 * policy structure to a short-authentication tag policy using AES-256
883 * encryption.
884 *
885 * @param p is a pointer to the policy structure to be set
886 *
jfigus857009c2014-11-05 11:17:43 -0500887 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&p)
888 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000889 * AES_CM_256_HMAC_SHA1_32 as defined in
890 * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
891 * Counter Mode encryption and HMAC-SHA1 authentication, with an
892 * authentication tag that is only 32 bits long. This length is
893 * considered adequate only for protecting audio and video media that
894 * use a stateless playback function. See Section 7.5 of RFC 3711
895 * (http://www.ietf.org/rfc/rfc3711.txt).
896 *
897 * This function is a convenience that helps to avoid dealing directly
898 * with the policy data structure. You are encouraged to initialize
899 * policy elements with this function call. Doing so may allow your
900 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500901 * include more elements in the srtp_crypto_policy_t datatype.
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000902 *
903 * @warning This crypto policy is intended for use in SRTP, but not in
904 * SRTCP. It is recommended that a policy that uses longer
905 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
906 * (http://www.ietf.org/rfc/rfc3711.txt).
907 *
908 * @return void.
909 *
910 */
911
jfigus857009c2014-11-05 11:17:43 -0500912void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(srtp_crypto_policy_t *p);
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000913
jfigus8c36da22013-10-01 16:41:19 -0400914/**
jfigus857009c2014-11-05 11:17:43 -0500915 * @brief srtp_crypto_policy_set_aes_cm_256_null_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -0400916 * policy structure to an encryption-only policy
917 *
918 * @param p is a pointer to the policy structure to be set
919 *
jfigus857009c2014-11-05 11:17:43 -0500920 * The function call srtp_crypto_policy_set_aes_cm_256_null_auth(&p) sets
921 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -0400922 * (AES-256 Counter Mode), but to use no authentication method. This
923 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
924 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
925 *
926 * This function is a convenience that helps to avoid dealing directly
927 * with the policy data structure. You are encouraged to initialize
928 * policy elements with this function call. Doing so may allow your
929 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500930 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -0400931 *
932 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
933 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
934 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
935 *
936 * @return void.
937 *
938 */
jfigus857009c2014-11-05 11:17:43 -0500939void srtp_crypto_policy_set_aes_cm_256_null_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -0400940
941/**
jfigus857009c2014-11-05 11:17:43 -0500942 * @brief srtp_crypto_policy_set_aes_gcm_128_8_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -0400943 * policy structure to an AEAD encryption policy.
944 *
945 * @param p is a pointer to the policy structure to be set
946 *
jfigus857009c2014-11-05 11:17:43 -0500947 * The function call srtp_crypto_policy_set_aes_gcm_128_8_auth(&p) sets
948 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -0400949 * (AES-128 Galois Counter Mode) with 8 octet auth tag. This
950 * policy applies confidentiality and authentication to both the
951 * RTP and RTCP packets.
952 *
953 * This function is a convenience that helps to avoid dealing directly
954 * with the policy data structure. You are encouraged to initialize
955 * policy elements with this function call. Doing so may allow your
956 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500957 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -0400958 *
959 * @return void.
960 *
961 */
jfigus857009c2014-11-05 11:17:43 -0500962void srtp_crypto_policy_set_aes_gcm_128_8_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -0400963
964/**
jfigus857009c2014-11-05 11:17:43 -0500965 * @brief srtp_crypto_policy_set_aes_gcm_256_8_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -0400966 * policy structure to an AEAD encryption policy
967 *
968 * @param p is a pointer to the policy structure to be set
969 *
jfigus857009c2014-11-05 11:17:43 -0500970 * The function call srtp_crypto_policy_set_aes_gcm_256_8_auth(&p) sets
971 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -0400972 * (AES-256 Galois Counter Mode) with 8 octet auth tag. This
973 * policy applies confidentiality and authentication to both the
974 * RTP and RTCP packets.
975 *
976 * This function is a convenience that helps to avoid dealing directly
977 * with the policy data structure. You are encouraged to initialize
978 * policy elements with this function call. Doing so may allow your
979 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500980 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -0400981 *
982 * @return void.
983 *
984 */
jfigus857009c2014-11-05 11:17:43 -0500985void srtp_crypto_policy_set_aes_gcm_256_8_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -0400986
987/**
jfigus857009c2014-11-05 11:17:43 -0500988 * @brief srtp_crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -0400989 * policy structure to an AEAD authentication-only policy
990 *
991 * @param p is a pointer to the policy structure to be set
992 *
jfigus857009c2014-11-05 11:17:43 -0500993 * The function call srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets
994 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -0400995 * (AES-128 Galois Counter Mode) with 8 octet auth tag. This policy
996 * applies confidentiality and authentication to the RTP packets,
997 * but only authentication to the RTCP packets.
998 *
999 * This function is a convenience that helps to avoid dealing directly
1000 * with the policy data structure. You are encouraged to initialize
1001 * policy elements with this function call. Doing so may allow your
1002 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001003 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001004 *
1005 * @return void.
1006 *
1007 */
jfigus857009c2014-11-05 11:17:43 -05001008void srtp_crypto_policy_set_aes_gcm_128_8_only_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001009
1010/**
jfigus857009c2014-11-05 11:17:43 -05001011 * @brief srtp_crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001012 * policy structure to an AEAD authentication-only policy
1013 *
1014 * @param p is a pointer to the policy structure to be set
1015 *
jfigus857009c2014-11-05 11:17:43 -05001016 * The function call srtp_crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets
1017 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001018 * (AES-256 Galois Counter Mode) with 8 octet auth tag. This policy
1019 * applies confidentiality and authentication to the RTP packets,
1020 * but only authentication to the RTCP packets.
1021 *
1022 * This function is a convenience that helps to avoid dealing directly
1023 * with the policy data structure. You are encouraged to initialize
1024 * policy elements with this function call. Doing so may allow your
1025 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001026 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001027 *
1028 * @return void.
1029 *
1030 */
jfigus857009c2014-11-05 11:17:43 -05001031void srtp_crypto_policy_set_aes_gcm_256_8_only_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001032
jfigusc13c1002014-05-08 13:34:53 -04001033/**
jfigus857009c2014-11-05 11:17:43 -05001034 * @brief srtp_crypto_policy_set_aes_gcm_128_16_auth() sets a crypto
jfigusc13c1002014-05-08 13:34:53 -04001035 * policy structure to an AEAD encryption policy.
1036 *
1037 * @param p is a pointer to the policy structure to be set
1038 *
jfigus857009c2014-11-05 11:17:43 -05001039 * The function call srtp_crypto_policy_set_aes_gcm_128_16_auth(&p) sets
1040 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigusc13c1002014-05-08 13:34:53 -04001041 * (AES-128 Galois Counter Mode) with 16 octet auth tag. This
1042 * policy applies confidentiality and authentication to both the
1043 * RTP and RTCP packets.
1044 *
1045 * This function is a convenience that helps to avoid dealing directly
1046 * with the policy data structure. You are encouraged to initialize
1047 * policy elements with this function call. Doing so may allow your
1048 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001049 * include more elements in the srtp_crypto_policy_t datatype.
jfigusc13c1002014-05-08 13:34:53 -04001050 *
1051 * @return void.
1052 *
1053 */
jfigus857009c2014-11-05 11:17:43 -05001054void srtp_crypto_policy_set_aes_gcm_128_16_auth(srtp_crypto_policy_t *p);
jfigusc13c1002014-05-08 13:34:53 -04001055
1056/**
jfigus857009c2014-11-05 11:17:43 -05001057 * @brief srtp_crypto_policy_set_aes_gcm_256_16_auth() sets a crypto
jfigusc13c1002014-05-08 13:34:53 -04001058 * policy structure to an AEAD encryption policy
1059 *
1060 * @param p is a pointer to the policy structure to be set
1061 *
jfigus857009c2014-11-05 11:17:43 -05001062 * The function call srtp_crypto_policy_set_aes_gcm_256_16_auth(&p) sets
1063 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigusc13c1002014-05-08 13:34:53 -04001064 * (AES-256 Galois Counter Mode) with 16 octet auth tag. This
1065 * policy applies confidentiality and authentication to both the
1066 * RTP and RTCP packets.
1067 *
1068 * This function is a convenience that helps to avoid dealing directly
1069 * with the policy data structure. You are encouraged to initialize
1070 * policy elements with this function call. Doing so may allow your
1071 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001072 * include more elements in the srtp_crypto_policy_t datatype.
jfigusc13c1002014-05-08 13:34:53 -04001073 *
1074 * @return void.
1075 *
1076 */
jfigus857009c2014-11-05 11:17:43 -05001077void srtp_crypto_policy_set_aes_gcm_256_16_auth(srtp_crypto_policy_t *p);
jfigusc13c1002014-05-08 13:34:53 -04001078
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001079
David McGrewa8546882006-01-12 17:56:02 +00001080/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001081 * @brief srtp_dealloc() deallocates storage for an SRTP session
1082 * context.
1083 *
1084 * The function call srtp_dealloc(s) deallocates storage for the
1085 * SRTP session context s. This function should be called no more
1086 * than one time for each of the contexts allocated by the function
1087 * srtp_create().
1088 *
1089 * @param s is the srtp_t for the session to be deallocated.
1090 *
1091 * @return
jfigus857009c2014-11-05 11:17:43 -05001092 * - srtp_err_status_ok if there no problems.
1093 * - srtp_err_status_dealloc_fail a memory deallocation failure occured.
Cullen Jennings235513a2005-09-21 22:51:36 +00001094 */
1095
jfigus857009c2014-11-05 11:17:43 -05001096srtp_err_status_t srtp_dealloc(srtp_t s);
Cullen Jennings235513a2005-09-21 22:51:36 +00001097
1098
David McGrew0cb86ee2006-07-07 15:46:57 +00001099/*
1100 * @brief identifies a particular SRTP profile
1101 *
1102 * An srtp_profile_t enumeration is used to identify a particular SRTP
1103 * profile (that is, a set of algorithms and parameters). These
1104 * profiles are defined in the DTLS-SRTP draft.
1105 */
1106
1107typedef enum {
1108 srtp_profile_reserved = 0,
1109 srtp_profile_aes128_cm_sha1_80 = 1,
1110 srtp_profile_aes128_cm_sha1_32 = 2,
1111 srtp_profile_aes256_cm_sha1_80 = 3,
1112 srtp_profile_aes256_cm_sha1_32 = 4,
1113 srtp_profile_null_sha1_80 = 5,
1114 srtp_profile_null_sha1_32 = 6,
1115} srtp_profile_t;
1116
1117
1118/**
jfigus857009c2014-11-05 11:17:43 -05001119 * @brief srtp_crypto_policy_set_from_profile_for_rtp() sets a crypto policy
David McGrew0cb86ee2006-07-07 15:46:57 +00001120 * structure to the appropriate value for RTP based on an srtp_profile_t
1121 *
1122 * @param p is a pointer to the policy structure to be set
1123 *
jfigus857009c2014-11-05 11:17:43 -05001124 * The function call srtp_crypto_policy_set_rtp_default(&policy, profile)
1125 * sets the srtp_crypto_policy_t at location policy to the policy for RTP
David McGrew0cb86ee2006-07-07 15:46:57 +00001126 * protection, as defined by the srtp_profile_t profile.
1127 *
1128 * This function is a convenience that helps to avoid dealing directly
1129 * with the policy data structure. You are encouraged to initialize
1130 * policy elements with this function call. Doing so may allow your
1131 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001132 * include more elements in the srtp_crypto_policy_t datatype.
David McGrew0cb86ee2006-07-07 15:46:57 +00001133 *
1134 * @return values
jfigus857009c2014-11-05 11:17:43 -05001135 * - srtp_err_status_ok no problems were encountered
1136 * - srtp_err_status_bad_param the profile is not supported
David McGrew0cb86ee2006-07-07 15:46:57 +00001137 *
1138 */
jfigus857009c2014-11-05 11:17:43 -05001139srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtp(srtp_crypto_policy_t *policy, srtp_profile_t profile);
David McGrew0cb86ee2006-07-07 15:46:57 +00001140
1141
1142
1143
1144/**
jfigus857009c2014-11-05 11:17:43 -05001145 * @brief srtp_crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
David McGrew0cb86ee2006-07-07 15:46:57 +00001146 * structure to the appropriate value for RTCP based on an srtp_profile_t
1147 *
1148 * @param p is a pointer to the policy structure to be set
1149 *
jfigus857009c2014-11-05 11:17:43 -05001150 * The function call srtp_crypto_policy_set_rtcp_default(&policy, profile)
1151 * sets the srtp_crypto_policy_t at location policy to the policy for RTCP
David McGrew0cb86ee2006-07-07 15:46:57 +00001152 * protection, as defined by the srtp_profile_t profile.
1153 *
1154 * This function is a convenience that helps to avoid dealing directly
1155 * with the policy data structure. You are encouraged to initialize
1156 * policy elements with this function call. Doing so may allow your
1157 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001158 * include more elements in the srtp_crypto_policy_t datatype.
David McGrew0cb86ee2006-07-07 15:46:57 +00001159 *
1160 * @return values
jfigus857009c2014-11-05 11:17:43 -05001161 * - srtp_err_status_ok no problems were encountered
1162 * - srtp_err_status_bad_param the profile is not supported
David McGrew0cb86ee2006-07-07 15:46:57 +00001163 *
1164 */
jfigus857009c2014-11-05 11:17:43 -05001165srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtcp(srtp_crypto_policy_t *policy, srtp_profile_t profile);
David McGrew0cb86ee2006-07-07 15:46:57 +00001166
1167/**
1168 * @brief returns the master key length for a given SRTP profile
1169 */
1170unsigned int
1171srtp_profile_get_master_key_length(srtp_profile_t profile);
1172
1173
1174/**
1175 * @brief returns the master salt length for a given SRTP profile
1176 */
1177unsigned int
1178srtp_profile_get_master_salt_length(srtp_profile_t profile);
1179
1180/**
1181 * @brief appends the salt to the key
1182 *
jfigus857009c2014-11-05 11:17:43 -05001183 * The function call srtp_append_salt_to_key(k, klen, s, slen)
David McGrew0cb86ee2006-07-07 15:46:57 +00001184 * copies the string s to the location at klen bytes following
1185 * the location k.
1186 *
1187 * @warning There must be at least bytes_in_salt + bytes_in_key bytes
1188 * available at the location pointed to by key.
1189 *
1190 */
1191
1192void
jfigus857009c2014-11-05 11:17:43 -05001193srtp_append_salt_to_key(unsigned char *key, unsigned int bytes_in_key,
1194 unsigned char *salt, unsigned int bytes_in_salt);
David McGrew0cb86ee2006-07-07 15:46:57 +00001195
1196
Cullen Jennings235513a2005-09-21 22:51:36 +00001197
1198/**
1199 * @}
1200 */
1201
1202
Cullen Jennings235513a2005-09-21 22:51:36 +00001203
1204/**
1205 * @defgroup SRTCP Secure RTCP
1206 * @ingroup SRTP
1207 *
1208 * @brief Secure RTCP functions are used to protect RTCP traffic.
1209 *
1210 * RTCP is the control protocol for RTP. libSRTP protects RTCP
1211 * traffic in much the same way as it does RTP traffic. The function
1212 * srtp_protect_rtcp() applies cryptographic protections to outbound
1213 * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on
1214 * inbound RTCP packets.
1215 *
1216 * A note on the naming convention: srtp_protect_rtcp() has an srtp_t
1217 * as its first argument, and thus has `srtp_' as its prefix. The
1218 * trailing `_rtcp' indicates the protocol on which it acts.
1219 *
1220 * @{
1221 */
1222
1223/**
1224 * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet
1225 * processing function.
1226 *
1227 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
1228 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
jfigus857009c2014-11-05 11:17:43 -05001229 * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
Cullen Jennings235513a2005-09-21 22:51:36 +00001230 * returned, then rtp_hdr points to the resulting SRTCP packet and
1231 * *len_ptr is the number of octets in that packet; otherwise, no
1232 * assumptions should be made about the value of either data elements.
1233 *
1234 * @warning This function assumes that it can write the authentication
1235 * tag into the location in memory immediately following the RTCP
1236 * packet, and assumes that the RTCP packet is aligned on a 32-bit
1237 * boundary.
1238 *
jfigus5e337292013-05-28 13:57:47 -04001239 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
1240 * into the location in memory immediately following the RTCP packet.
1241 * Callers MUST ensure that this much writable memory is available in
1242 * the buffer that holds the RTCP packet.
1243 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001244 * @param ctx is the SRTP context to use in processing the packet.
1245 *
1246 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
1247 * the function returns, it points to the srtp packet.
1248 *
1249 * @param pkt_octet_len is a pointer to the length in octets of the
1250 * complete RTCP packet (header and body) before the function call,
jfigus857009c2014-11-05 11:17:43 -05001251 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
Cullen Jennings235513a2005-09-21 22:51:36 +00001252 * was returned. Otherwise, the value of the data to which it points
1253 * is undefined.
1254 *
1255 * @return
jfigus857009c2014-11-05 11:17:43 -05001256 * - srtp_err_status_ok if there were no problems.
Cullen Jennings235513a2005-09-21 22:51:36 +00001257 * - [other] if there was a failure in
1258 * the cryptographic mechanisms.
1259 */
1260
1261
jfigus857009c2014-11-05 11:17:43 -05001262srtp_err_status_t srtp_protect_rtcp(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001263
1264/**
1265 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
1266 * processing function.
1267 *
1268 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
1269 * verifies the Secure RTCP protection of the SRTCP packet pointed to
1270 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
jfigus857009c2014-11-05 11:17:43 -05001271 * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
Cullen Jennings235513a2005-09-21 22:51:36 +00001272 * to the resulting RTCP packet and *len_ptr is the number of octets
1273 * in that packet; otherwise, no assumptions should be made about the
1274 * value of either data elements.
1275 *
1276 * @warning This function assumes that the SRTCP packet is aligned on a
1277 * 32-bit boundary.
1278 *
1279 * @param ctx is a pointer to the srtp_t which applies to the
1280 * particular packet.
1281 *
1282 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
1283 * (before the call). After the function returns, it points to the
jfigus857009c2014-11-05 11:17:43 -05001284 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
Cullen Jennings235513a2005-09-21 22:51:36 +00001285 * the data to which it points is undefined.
1286 *
1287 * @param pkt_octet_len is a pointer to the length in octets of the
1288 * complete SRTCP packet (header and body) before the function call,
jfigus857009c2014-11-05 11:17:43 -05001289 * and of the complete rtp packet after the call, if srtp_err_status_ok was
Cullen Jennings235513a2005-09-21 22:51:36 +00001290 * returned. Otherwise, the value of the data to which it points is
1291 * undefined.
1292 *
1293 * @return
jfigus857009c2014-11-05 11:17:43 -05001294 * - srtp_err_status_ok if the RTCP packet is valid.
1295 * - srtp_err_status_auth_fail if the SRTCP packet failed the message
Cullen Jennings235513a2005-09-21 22:51:36 +00001296 * authentication check.
jfigus857009c2014-11-05 11:17:43 -05001297 * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
Cullen Jennings235513a2005-09-21 22:51:36 +00001298 * already been processed and accepted).
1299 * - [other] if there has been an error in the cryptographic mechanisms.
1300 *
1301 */
1302
jfigus857009c2014-11-05 11:17:43 -05001303srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001304
1305/**
1306 * @}
1307 */
1308
IƱaki Baz Castillo241fec32014-08-21 00:51:00 +02001309
1310/**
1311 * @defgroup User data associated to a SRTP session.
1312 * @ingroup SRTP
1313 *
1314 * @brief Store custom user data within a SRTP session.
1315 *
1316 * @{
1317 */
1318
1319/**
1320 * @brief srtp_set_user_data() stores the given pointer into the SRTP
1321 * session for later retrieval.
1322 *
1323 * @param ctx is the srtp_t context in which the given data pointer is
1324 * stored.
1325 *
1326 * @param data is a pointer to the custom information (struct, function,
1327 * etc) associated with the SRTP session.
1328 *
1329 * @return void.
1330 *
1331 */
1332
1333void
1334srtp_set_user_data(srtp_t ctx, void *data);
1335
1336/**
1337 * @brief srtp_get_user_data() retrieves the pointer to the custom data
1338 * previously stored with srtp_set_user_data().
1339 *
1340 * This function is mostly useful for retrieving data associated to a
1341 * SRTP session when an event fires. The user can then get such a custom
1342 * data by calling this function with the session field of the
1343 * srtp_event_data_t struct as argument.
1344 *
1345 * @param ctx is the srtp_t context in which the given data pointer was
1346 * stored.
1347 *
1348 * @return void* pointer to the user data.
1349 *
1350 */
1351
1352void*
1353srtp_get_user_data(srtp_t ctx);
1354
1355/**
1356 * @}
1357 */
1358
1359
Cullen Jennings235513a2005-09-21 22:51:36 +00001360/**
1361 * @defgroup SRTPevents SRTP events and callbacks
1362 * @ingroup SRTP
1363 *
1364 * @brief libSRTP can use a user-provided callback function to
1365 * handle events.
1366 *
1367 *
1368 * libSRTP allows a user to provide a callback function to handle
1369 * events that need to be dealt with outside of the data plane (see
1370 * the enum srtp_event_t for a description of these events). Dealing
1371 * with these events is not a strict necessity; they are not
1372 * security-critical, but the application may suffer if they are not
1373 * handled. The function srtp_set_event_handler() is used to provide
1374 * the callback function.
1375 *
1376 * A default event handler that merely reports on the events as they
1377 * happen is included. It is also possible to set the event handler
1378 * function to NULL, in which case all events will just be silently
1379 * ignored.
1380 *
1381 * @{
1382 */
1383
1384/**
1385 * @brief srtp_event_t defines events that need to be handled
1386 *
1387 * The enum srtp_event_t defines events that need to be handled
1388 * outside the `data plane', such as SSRC collisions and
1389 * key expirations.
1390 *
1391 * When a key expires or the maximum number of packets has been
1392 * reached, an SRTP stream will enter an `expired' state in which no
1393 * more packets can be protected or unprotected. When this happens,
1394 * it is likely that you will want to either deallocate the stream
jfigus92c3de32016-02-02 13:44:39 -05001395 * (using srtp_remove_stream()), and possibly allocate a new one.
Cullen Jennings235513a2005-09-21 22:51:36 +00001396 *
1397 * When an SRTP stream expires, the other streams in the same session
1398 * are unaffected, unless key sharing is used by that stream. In the
1399 * latter case, all of the streams in the session will expire.
1400 */
1401
1402typedef enum {
1403 event_ssrc_collision, /**<
1404 * An SSRC collision occured.
1405 */
1406 event_key_soft_limit, /**< An SRTP stream reached the soft key
1407 * usage limit and will expire soon.
1408 */
1409 event_key_hard_limit, /**< An SRTP stream reached the hard
1410 * key usage limit and has expired.
1411 */
1412 event_packet_index_limit /**< An SRTP stream reached the hard
1413 * packet limit (2^48 packets).
1414 */
1415} srtp_event_t;
1416
1417/**
1418 * @brief srtp_event_data_t is the structure passed as a callback to
1419 * the event handler function
1420 *
1421 * The struct srtp_event_data_t holds the data passed to the event
1422 * handler function.
1423 */
1424
1425typedef struct srtp_event_data_t {
1426 srtp_t session; /**< The session in which the event happend. */
1427 srtp_stream_t stream; /**< The stream in which the event happend. */
1428 srtp_event_t event; /**< An enum indicating the type of event. */
1429} srtp_event_data_t;
1430
1431/**
1432 * @brief srtp_event_handler_func_t is the function prototype for
1433 * the event handler.
1434 *
1435 * The typedef srtp_event_handler_func_t is the prototype for the
1436 * event handler function. It has as its only argument an
1437 * srtp_event_data_t which describes the event that needs to be handled.
1438 * There can only be a single, global handler for all events in
1439 * libSRTP.
1440 */
1441
1442typedef void (srtp_event_handler_func_t)(srtp_event_data_t *data);
1443
1444/**
1445 * @brief sets the event handler to the function supplied by the caller.
1446 *
1447 * The function call srtp_install_event_handler(func) sets the event
1448 * handler function to the value func. The value NULL is acceptable
1449 * as an argument; in this case, events will be ignored rather than
1450 * handled.
1451 *
1452 * @param func is a pointer to a fuction that takes an srtp_event_data_t
1453 * pointer as an argument and returns void. This function
1454 * will be used by libSRTP to handle events.
1455 */
1456
jfigus857009c2014-11-05 11:17:43 -05001457srtp_err_status_t srtp_install_event_handler(srtp_event_handler_func_t func);
Cullen Jennings235513a2005-09-21 22:51:36 +00001458
1459/**
jfigusf62b64d2014-10-08 13:53:57 -04001460 * @brief Returns the version string of the library.
1461 *
1462 */
Christian Oiend4e3eec2014-10-24 10:14:08 +02001463const char *srtp_get_version_string(void);
jfigusf62b64d2014-10-08 13:53:57 -04001464
1465/**
1466 * @brief Returns the numeric representation of the library version.
1467 *
1468 */
1469unsigned int srtp_get_version(void);
1470
1471/**
jfigus46d6b472014-11-14 16:42:01 -05001472 * @brief srtp_set_debug_module(mod_name, v)
1473 *
1474 * sets dynamic debugging to the value v (0 for off, 1 for on) for the
1475 * debug module with the name mod_name
1476 *
1477 * returns err_status_ok on success, err_status_fail otherwise
1478 */
1479srtp_err_status_t srtp_set_debug_module(char *mod_name, int v);
1480
1481/**
1482 * @brief srtp_list_debug_modules() outputs a list of debugging modules
1483 *
1484 */
1485srtp_err_status_t srtp_list_debug_modules(void);
1486
1487
1488/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001489 * @}
1490 */
Cullen Jennings235513a2005-09-21 22:51:36 +00001491/* in host order, so outside the #if */
1492#define SRTCP_E_BIT 0x80000000
1493/* for byte-access */
1494#define SRTCP_E_BYTE_BIT 0x80
1495#define SRTCP_INDEX_MASK 0x7fffffff
1496
Marcus Sundbergcb60bf82005-10-17 17:23:05 +00001497#ifdef __cplusplus
1498}
1499#endif
1500
Cullen Jennings235513a2005-09-21 22:51:36 +00001501#endif /* SRTP_H */