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