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