blob: bb9387f32398725fdbedda6f187bdaa77645a702 [file] [log] [blame]
Benny Prijono8a0ab282008-01-23 20:17:42 +00001/*
2 * srtp.h
3 *
4 * interface to libsrtp
5 *
6 * David A. McGrew
7 * Cisco Systems, Inc.
8 */
9/*
10 *
11 * Copyright (c) 2001-2006, Cisco Systems, Inc.
12 * All rights reserved.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 *
18 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 *
21 * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials provided
24 * with the distribution.
25 *
26 * Neither the name of the Cisco Systems, Inc. nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
34 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
41 * OF THE POSSIBILITY OF SUCH DAMAGE.
42 *
43 */
44
45
46#ifndef SRTP_H
47#define SRTP_H
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53#ifdef _MSC_VER
54#pragma pack(4)
55#endif
56
57#include "crypto_kernel.h"
58
59/**
60 * @defgroup SRTP Secure RTP
61 *
62 * @brief libSRTP provides functions for protecting RTP and RTCP. See
63 * Section @ref Overview for an introduction to the use of the library.
64 *
65 * @{
66 */
67
68/*
69 * SRTP_MASTER_KEY_LEN is the nominal master key length supported by libSRTP
70 */
71
72#define SRTP_MASTER_KEY_LEN 30
73
74/*
75 * SRTP_MAX_KEY_LEN is the maximum key length supported by libSRTP
76 */
77#define SRTP_MAX_KEY_LEN 64
78
79/*
80 * SRTP_MAX_TAG_LEN is the maximum tag length supported by libSRTP
81 */
82
83#define SRTP_MAX_TAG_LEN 12
84
85/**
86 * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer
87 * (authentication tag and MKI) supported by libSRTP. This value is
88 * the maximum number of octets that will be added to an RTP packet by
89 * srtp_protect().
90 *
91 * @brief the maximum number of octets added by srtp_protect().
92 */
93#define SRTP_MAX_TRAILER_LEN SRTP_MAX_TAG_LEN
94
95/*
96 * nota bene: since libSRTP doesn't support the use of the MKI, the
97 * SRTP_MAX_TRAILER_LEN value is just the maximum tag length
98 */
99
100/**
101 * @brief sec_serv_t describes a set of security services.
102 *
103 * A sec_serv_t enumeration is used to describe the particular
104 * security services that will be applied by a particular crypto
105 * policy (or other mechanism).
106 */
107
108typedef enum {
109 sec_serv_none = 0, /**< no services */
110 sec_serv_conf = 1, /**< confidentiality */
111 sec_serv_auth = 2, /**< authentication */
112 sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */
113} sec_serv_t;
114
115/**
116 * @brief crypto_policy_t describes a particular crypto policy that
117 * can be applied to an SRTP stream.
118 *
119 * A crypto_policy_t describes a particular cryptographic policy that
120 * can be applied to an SRTP or SRTCP stream. An SRTP session policy
121 * consists of a list of these policies, one for each SRTP stream
122 * in the session.
123 */
124
125typedef struct crypto_policy_t {
126 cipher_type_id_t cipher_type; /**< An integer representing
127 * the type of cipher. */
128 int cipher_key_len; /**< The length of the cipher key
129 * in octets. */
130 auth_type_id_t auth_type; /**< An integer representing the
131 * authentication function. */
132 int auth_key_len; /**< The length of the authentication
133 * function key in octets. */
134 int auth_tag_len; /**< The length of the authentication
135 * tag in octets. */
136 sec_serv_t sec_serv; /**< The flag indicating the security
137 * services to be applied. */
138} crypto_policy_t;
139
140
141/**
142 * @brief ssrc_type_t describes the type of an SSRC.
143 *
144 * An ssrc_type_t enumeration is used to indicate a type of SSRC. See
145 * @ref srtp_policy_t for more informataion.
146 */
147
148typedef enum {
149 ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */
150 ssrc_specific = 1, /**< Indicates a specific SSRC value */
151 ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value
152 (i.e. a value that is used in the
153 function srtp_unprotect()) */
154 ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value
155 (i.e. a value that is used in the
156 function srtp_protect()) */
157} ssrc_type_t;
158
159/**
160 * @brief An ssrc_t represents a particular SSRC value, or a `wildcard' SSRC.
161 *
162 * An ssrc_t represents a particular SSRC value (if its type is
163 * ssrc_specific), or a wildcard SSRC value that will match all
164 * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound
165 * SSRCs (if its type is ssrc_any_inbound).
166 *
167 */
168
169typedef struct {
170 ssrc_type_t type; /**< The type of this particular SSRC */
171 unsigned int value; /**< The value of this SSRC, if it is not a wildcard */
172} ssrc_t;
173
174
175/**
176 * @brief represents the policy for an SRTP session.
177 *
178 * A single srtp_policy_t struct represents the policy for a single
179 * SRTP stream, and a linked list of these elements represents the
180 * policy for an entire SRTP session. Each element contains the SRTP
181 * and SRTCP crypto policies for that stream, a pointer to the SRTP
182 * master key for that stream, the SSRC describing that stream, or a
183 * flag indicating a `wildcard' SSRC value, and a `next' field that
184 * holds a pointer to the next element in the list of policy elements,
185 * or NULL if it is the last element.
186 *
187 * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an
188 * inbound stream that for which there is no explicit SSRC entry in
189 * another policy element. Similarly, the value SSRC_ANY_OUTBOUND
190 * will matches any SSRC from an outbound stream that does not appear
191 * in another policy element. Note that wildcard SSRCs &b cannot be
192 * used to match both inbound and outbound traffic. This restriction
193 * is intentional, and it allows libSRTP to ensure that no security
194 * lapses result from accidental re-use of SSRC values during key
195 * sharing.
196 *
197 *
198 * @warning The final element of the list @b must have its `next' pointer
199 * set to NULL.
200 */
201
202typedef struct srtp_policy_t {
203 ssrc_t ssrc; /**< The SSRC value of stream, or the
204 * flags SSRC_ANY_INBOUND or
205 * SSRC_ANY_OUTBOUND if key sharing
206 * is used for this policy element.
207 */
208 crypto_policy_t rtp; /**< SRTP crypto policy. */
209 crypto_policy_t rtcp; /**< SRTCP crypto policy. */
210 unsigned char *key; /**< Pointer to the SRTP master key for
211 * this stream. */
212 struct srtp_policy_t *next; /**< Pointer to next stream policy. */
213} srtp_policy_t;
214
215
216
217
218/**
219 * @brief An srtp_t points to an SRTP session structure.
220 *
221 * The typedef srtp_t is a pointer to a structure that represents
222 * an SRTP session. This datatype is intentially opaque in
223 * order to separate the interface from the implementation.
224 *
225 * An SRTP session consists of all of the traffic sent to the RTP and
226 * RTCP destination transport addresses, using the RTP/SAVP (Secure
227 * Audio/Video Profile). A session can be viewed as a set of SRTP
228 * streams, each of which originates with a different participant.
229 */
230
231typedef struct srtp_ctx_t *srtp_t;
232
233
234/**
235 * @brief An srtp_stream_t points to an SRTP stream structure.
236 *
237 * The typedef srtp_stream_t is a pointer to a structure that
238 * represents an SRTP stream. This datatype is intentionally
239 * opaque in order to separate the interface from the implementation.
240 *
241 * An SRTP stream consists of all of the traffic sent to an SRTP
242 * session by a single participant. A session can be viewed as
243 * a set of streams.
244 *
245 */
246typedef struct srtp_stream_ctx_t *srtp_stream_t;
247
248
249
250/**
251 * @brief srtp_init() initializes the srtp library.
252 *
253 * @warning This function @b must be called before any other srtp
254 * functions.
255 */
256
257err_status_t
258srtp_init(void);
259
260/**
261 * @brief srtp_protect() is the Secure RTP sender-side packet processing
262 * function.
263 *
264 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
265 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
266 * the SRTP context ctx. If err_status_ok is returned, then rtp_hdr
267 * points to the resulting SRTP packet and *len_ptr is the number of
268 * octets in that packet; otherwise, no assumptions should be made
269 * about the value of either data elements.
270 *
271 * The sequence numbers of the RTP packets presented to this function
272 * need not be consecutive, but they @b must be out of order by less
273 * than 2^15 = 32,768 packets.
274 *
275 * @warning This function assumes that it can write the authentication
276 * tag into the location in memory immediately following the RTP
277 * packet, and assumes that the RTP packet is aligned on a 32-bit
278 * boundary.
279 *
280 * @param ctx is the SRTP context to use in processing the packet.
281 *
282 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
283 * the function returns, it points to the srtp packet.
284 *
285 * @param len_ptr is a pointer to the length in octets of the complete
286 * RTP packet (header and body) before the function call, and of the
287 * complete SRTP packet after the call, if err_status_ok was returned.
288 * Otherwise, the value of the data to which it points is undefined.
289 *
290 * @return
291 * - err_status_ok no problems
292 * - err_status_replay_fail rtp sequence number was non-increasing
293 * - @e other failure in cryptographic mechanisms
294 */
295
296err_status_t
297srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
298
299/**
300 * @brief srtp_unprotect() is the Secure RTP receiver-side packet
301 * processing function.
302 *
303 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
304 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
305 * (which has length *len_ptr), using the SRTP context ctx. If
306 * err_status_ok is returned, then srtp_hdr points to the resulting
307 * RTP packet and *len_ptr is the number of octets in that packet;
308 * otherwise, no assumptions should be made about the value of either
309 * data elements.
310 *
311 * The sequence numbers of the RTP packets presented to this function
312 * need not be consecutive, but they @b must be out of order by less
313 * than 2^15 = 32,768 packets.
314 *
315 * @warning This function assumes that the SRTP packet is aligned on a
316 * 32-bit boundary.
317 *
318 * @param ctx is a pointer to the srtp_t which applies to the
319 * particular packet.
320 *
321 * @param srtp_hdr is a pointer to the header of the SRTP packet
322 * (before the call). after the function returns, it points to the
323 * rtp packet if err_status_ok was returned; otherwise, the value of
324 * the data to which it points is undefined.
325 *
326 * @param len_ptr is a pointer to the length in octets of the complete
327 * srtp packet (header and body) before the function call, and of the
328 * complete rtp packet after the call, if err_status_ok was returned.
329 * Otherwise, the value of the data to which it points is undefined.
330 *
331 * @return
332 * - err_status_ok if the RTP packet is valid.
333 * - err_status_auth_fail if the SRTP packet failed the message
334 * authentication check.
335 * - err_status_replay_fail if the SRTP packet is a replay (e.g. packet has
336 * already been processed and accepted).
337 * - [other] if there has been an error in the cryptographic mechanisms.
338 *
339 */
340
341err_status_t
342srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
343
344
345/**
346 * @brief srtp_create() allocates and initializes an SRTP session.
347
348 * The function call srtp_create(session, policy, key) allocates and
349 * initializes an SRTP session context, applying the given policy and
350 * key.
351 *
352 * @param session is the SRTP session to which the policy is to be added.
353 *
354 * @param policy is the srtp_policy_t struct that describes the policy
355 * for the session. The struct may be a single element, or it may be
356 * the head of a list, in which case each element of the list is
357 * processed. It may also be NULL, in which case streams should be added
358 * later using srtp_add_stream(). The final element of the list @b must
359 * have its `next' field set to NULL.
360 *
361 * @return
362 * - err_status_ok if creation succeded.
363 * - err_status_alloc_fail if allocation failed.
364 * - err_status_init_fail if initialization failed.
365 */
366
367err_status_t
368srtp_create(srtp_t *session, const srtp_policy_t *policy);
369
370
371/**
372 * @brief srtp_add_stream() allocates and initializes an SRTP stream
373 * within a given SRTP session.
374 *
375 * The function call srtp_add_stream(session, policy) allocates and
376 * initializes a new SRTP stream within a given, previously created
377 * session, applying the policy given as the other argument to that
378 * stream.
379 *
380 * @return values:
381 * - err_status_ok if stream creation succeded.
382 * - err_status_alloc_fail if stream allocation failed
383 * - err_status_init_fail if stream initialization failed.
384 */
385
386err_status_t
387srtp_add_stream(srtp_t session,
388 const srtp_policy_t *policy);
389
390
391/**
392 * @brief srtp_remove_stream() deallocates an SRTP stream.
393 *
394 * The function call srtp_remove_stream(session, ssrc) removes
395 * the SRTP stream with the SSRC value ssrc from the SRTP session
396 * context given by the argument session.
397 *
398 * @param session is the SRTP session from which the stream
399 * will be removed.
400 *
401 * @param ssrc is the SSRC value of the stream to be removed.
402 *
403 * @warning Wildcard SSRC values cannot be removed from a
404 * session.
405 *
406 * @return
407 * - err_status_ok if the stream deallocation succeded.
408 * - [other] otherwise.
409 *
410 */
411
412err_status_t
413srtp_remove_stream(srtp_t session, unsigned int ssrc);
414
415/**
416 * @brief crypto_policy_set_rtp_default() sets a crypto policy
417 * structure to the SRTP default policy for RTP protection.
418 *
419 * @param p is a pointer to the policy structure to be set
420 *
421 * The function call crypto_policy_set_rtp_default(&p) sets the
422 * crypto_policy_t at location p to the SRTP default policy for RTP
423 * protection, as defined in the specification. This function is a
424 * convenience that helps to avoid dealing directly with the policy
425 * data structure. You are encouraged to initialize policy elements
426 * with this function call. Doing so may allow your code to be
427 * forward compatible with later versions of libSRTP that include more
428 * elements in the crypto_policy_t datatype.
429 *
430 * @return void.
431 *
432 */
433
434void
435crypto_policy_set_rtp_default(crypto_policy_t *p);
436
437/**
438 * @brief crypto_policy_set_rtcp_default() sets a crypto policy
439 * structure to the SRTP default policy for RTCP protection.
440 *
441 * @param p is a pointer to the policy structure to be set
442 *
443 * The function call crypto_policy_set_rtcp_default(&p) sets the
444 * crypto_policy_t at location p to the SRTP default policy for RTCP
445 * protection, as defined in the specification. This function is a
446 * convenience that helps to avoid dealing directly with the policy
447 * data structure. You are encouraged to initialize policy elements
448 * with this function call. Doing so may allow your code to be
449 * forward compatible with later versions of libSRTP that include more
450 * elements in the crypto_policy_t datatype.
451 *
452 * @return void.
453 *
454 */
455
456void
457crypto_policy_set_rtcp_default(crypto_policy_t *p);
458
459/**
460 * @brief crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
461 * policy structure to the SRTP default policy for RTP protection.
462 *
463 * @param p is a pointer to the policy structure to be set
464 *
465 * The function crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
466 * synonym for crypto_policy_set_rtp_default(). It conforms to the
467 * naming convention used in
468 * http://www.ietf.org/internet-drafts/draft-ietf-mmusic-sdescriptions-12.txt
469 *
470 * @return void.
471 *
472 */
473
474#define crypto_policy_set_aes_cm_128_hmac_sha1_80(p) crypto_policy_set_rtp_default(p)
475
476
477/**
478 * @brief crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
479 * policy structure to a short-authentication tag policy
480 *
481 * @param p is a pointer to the policy structure to be set
482 *
483 * The function call crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
484 * sets the crypto_policy_t at location p to use policy
485 * AES_CM_128_HMAC_SHA1_32 as defined in
486 * draft-ietf-mmusic-sdescriptions-12.txt. This policy uses AES-128
487 * Counter Mode encryption and HMAC-SHA1 authentication, with an
488 * authentication tag that is only 32 bits long. This length is
489 * considered adequate only for protecting audio and video media that
490 * use a stateless playback function. See Section 7.5 of RFC 3711
491 * (http://www.ietf.org/rfc/rfc3711.txt).
492 *
493 * This function is a convenience that helps to avoid dealing directly
494 * with the policy data structure. You are encouraged to initialize
495 * policy elements with this function call. Doing so may allow your
496 * code to be forward compatible with later versions of libSRTP that
497 * include more elements in the crypto_policy_t datatype.
498 *
499 * @warning This crypto policy is intended for use in SRTP, but not in
500 * SRTCP. It is recommended that a policy that uses longer
501 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
502 * (http://www.ietf.org/rfc/rfc3711.txt).
503 *
504 * @return void.
505 *
506 */
507
508void
509crypto_policy_set_aes_cm_128_hmac_sha1_32(crypto_policy_t *p);
510
511
512
513/**
514 * @brief crypto_policy_set_aes_cm_128_null_auth() sets a crypto
515 * policy structure to an encryption-only policy
516 *
517 * @param p is a pointer to the policy structure to be set
518 *
519 * The function call crypto_policy_set_aes_cm_128_null_auth(&p) sets
520 * the crypto_policy_t at location p to use the SRTP default cipher
521 * (AES-128 Counter Mode), but to use no authentication method. This
522 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
523 * of RFC 3711 (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 policy is NOT RECOMMENDED for SRTP unless it is
532 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
533 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
534 *
535 * @return void.
536 *
537 */
538
539void
540crypto_policy_set_aes_cm_128_null_auth(crypto_policy_t *p);
541
542
543/**
544 * @brief crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
545 * policy structure to an authentication-only policy
546 *
547 * @param p is a pointer to the policy structure to be set
548 *
549 * The function call crypto_policy_set_null_cipher_hmac_sha1_80(&p)
550 * sets the crypto_policy_t at location p to use HMAC-SHA1 with an 80
551 * bit authentication tag to provide message authentication, but to
552 * use no encryption. This policy is NOT RECOMMENDED for SRTP unless
553 * there is a requirement to forego encryption.
554 *
555 * This function is a convenience that helps to avoid dealing directly
556 * with the policy data structure. You are encouraged to initialize
557 * policy elements with this function call. Doing so may allow your
558 * code to be forward compatible with later versions of libSRTP that
559 * include more elements in the crypto_policy_t datatype.
560 *
561 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
562 * requirement to forego encryption.
563 *
564 * @return void.
565 *
566 */
567
568void
569crypto_policy_set_null_cipher_hmac_sha1_80(crypto_policy_t *p);
570
571/**
572 * @brief srtp_dealloc() deallocates storage for an SRTP session
573 * context.
574 *
575 * The function call srtp_dealloc(s) deallocates storage for the
576 * SRTP session context s. This function should be called no more
577 * than one time for each of the contexts allocated by the function
578 * srtp_create().
579 *
580 * @param s is the srtp_t for the session to be deallocated.
581 *
582 * @return
583 * - err_status_ok if there no problems.
584 * - err_status_dealloc_fail a memory deallocation failure occured.
585 */
586
587err_status_t
588srtp_dealloc(srtp_t s);
589
590
591/*
592 * @brief identifies a particular SRTP profile
593 *
594 * An srtp_profile_t enumeration is used to identify a particular SRTP
595 * profile (that is, a set of algorithms and parameters). These
596 * profiles are defined in the DTLS-SRTP draft.
597 */
598
599typedef enum {
600 srtp_profile_reserved = 0,
601 srtp_profile_aes128_cm_sha1_80 = 1,
602 srtp_profile_aes128_cm_sha1_32 = 2,
603 srtp_profile_aes256_cm_sha1_80 = 3,
604 srtp_profile_aes256_cm_sha1_32 = 4,
605 srtp_profile_null_sha1_80 = 5,
606 srtp_profile_null_sha1_32 = 6,
607} srtp_profile_t;
608
609
610/**
611 * @brief crypto_policy_set_from_profile_for_rtp() sets a crypto policy
612 * structure to the appropriate value for RTP based on an srtp_profile_t
613 *
614 * @param p is a pointer to the policy structure to be set
615 *
616 * The function call crypto_policy_set_rtp_default(&policy, profile)
617 * sets the crypto_policy_t at location policy to the policy for RTP
618 * protection, as defined by the srtp_profile_t profile.
619 *
620 * This function is a convenience that helps to avoid dealing directly
621 * with the policy data structure. You are encouraged to initialize
622 * policy elements with this function call. Doing so may allow your
623 * code to be forward compatible with later versions of libSRTP that
624 * include more elements in the crypto_policy_t datatype.
625 *
626 * @return values
627 * - err_status_ok no problems were encountered
628 * - err_status_bad_param the profile is not supported
629 *
630 */
631err_status_t
632crypto_policy_set_from_profile_for_rtp(crypto_policy_t *policy,
633 srtp_profile_t profile);
634
635
636
637
638/**
639 * @brief crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
640 * structure to the appropriate value for RTCP based on an srtp_profile_t
641 *
642 * @param p is a pointer to the policy structure to be set
643 *
644 * The function call crypto_policy_set_rtcp_default(&policy, profile)
645 * sets the crypto_policy_t at location policy to the policy for RTCP
646 * protection, as defined by the srtp_profile_t profile.
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 * @return values
655 * - err_status_ok no problems were encountered
656 * - err_status_bad_param the profile is not supported
657 *
658 */
659err_status_t
660crypto_policy_set_from_profile_for_rtcp(crypto_policy_t *policy,
661 srtp_profile_t profile);
662
663/**
664 * @brief returns the master key length for a given SRTP profile
665 */
666unsigned int
667srtp_profile_get_master_key_length(srtp_profile_t profile);
668
669
670/**
671 * @brief returns the master salt length for a given SRTP profile
672 */
673unsigned int
674srtp_profile_get_master_salt_length(srtp_profile_t profile);
675
676/**
677 * @brief appends the salt to the key
678 *
679 * The function call append_salt_to_key(k, klen, s, slen)
680 * copies the string s to the location at klen bytes following
681 * the location k.
682 *
683 * @warning There must be at least bytes_in_salt + bytes_in_key bytes
684 * available at the location pointed to by key.
685 *
686 */
687
688void
689append_salt_to_key(unsigned char *key, unsigned int bytes_in_key,
690 unsigned char *salt, unsigned int bytes_in_salt);
691
692
693
694/**
695 * @}
696 */
697
698
699
700/**
701 * @defgroup SRTCP Secure RTCP
702 * @ingroup SRTP
703 *
704 * @brief Secure RTCP functions are used to protect RTCP traffic.
705 *
706 * RTCP is the control protocol for RTP. libSRTP protects RTCP
707 * traffic in much the same way as it does RTP traffic. The function
708 * srtp_protect_rtcp() applies cryptographic protections to outbound
709 * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on
710 * inbound RTCP packets.
711 *
712 * A note on the naming convention: srtp_protect_rtcp() has an srtp_t
713 * as its first argument, and thus has `srtp_' as its prefix. The
714 * trailing `_rtcp' indicates the protocol on which it acts.
715 *
716 * @{
717 */
718
719/**
720 * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet
721 * processing function.
722 *
723 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
724 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
725 * *len_ptr) using the SRTP session context ctx. If err_status_ok is
726 * returned, then rtp_hdr points to the resulting SRTCP packet and
727 * *len_ptr is the number of octets in that packet; otherwise, no
728 * assumptions should be made about the value of either data elements.
729 *
730 * @warning This function assumes that it can write the authentication
731 * tag into the location in memory immediately following the RTCP
732 * packet, and assumes that the RTCP packet is aligned on a 32-bit
733 * boundary.
734 *
735 * @param ctx is the SRTP context to use in processing the packet.
736 *
737 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
738 * the function returns, it points to the srtp packet.
739 *
740 * @param pkt_octet_len is a pointer to the length in octets of the
741 * complete RTCP packet (header and body) before the function call,
742 * and of the complete SRTCP packet after the call, if err_status_ok
743 * was returned. Otherwise, the value of the data to which it points
744 * is undefined.
745 *
746 * @return
747 * - err_status_ok if there were no problems.
748 * - [other] if there was a failure in
749 * the cryptographic mechanisms.
750 */
751
752
753err_status_t
754srtp_protect_rtcp(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len);
755
756/**
757 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
758 * processing function.
759 *
760 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
761 * verifies the Secure RTCP protection of the SRTCP packet pointed to
762 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
763 * context ctx. If err_status_ok is returned, then srtcp_hdr points
764 * to the resulting RTCP packet and *len_ptr is the number of octets
765 * in that packet; otherwise, no assumptions should be made about the
766 * value of either data elements.
767 *
768 * @warning This function assumes that the SRTCP packet is aligned on a
769 * 32-bit boundary.
770 *
771 * @param ctx is a pointer to the srtp_t which applies to the
772 * particular packet.
773 *
774 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
775 * (before the call). After the function returns, it points to the
776 * rtp packet if err_status_ok was returned; otherwise, the value of
777 * the data to which it points is undefined.
778 *
779 * @param pkt_octet_len is a pointer to the length in octets of the
780 * complete SRTCP packet (header and body) before the function call,
781 * and of the complete rtp packet after the call, if err_status_ok was
782 * returned. Otherwise, the value of the data to which it points is
783 * undefined.
784 *
785 * @return
786 * - err_status_ok if the RTCP packet is valid.
787 * - err_status_auth_fail if the SRTCP packet failed the message
788 * authentication check.
789 * - err_status_replay_fail if the SRTCP packet is a replay (e.g. has
790 * already been processed and accepted).
791 * - [other] if there has been an error in the cryptographic mechanisms.
792 *
793 */
794
795err_status_t
796srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len);
797
798/**
799 * @}
800 */
801
802/**
803 * @defgroup SRTPevents SRTP events and callbacks
804 * @ingroup SRTP
805 *
806 * @brief libSRTP can use a user-provided callback function to
807 * handle events.
808 *
809 *
810 * libSRTP allows a user to provide a callback function to handle
811 * events that need to be dealt with outside of the data plane (see
812 * the enum srtp_event_t for a description of these events). Dealing
813 * with these events is not a strict necessity; they are not
814 * security-critical, but the application may suffer if they are not
815 * handled. The function srtp_set_event_handler() is used to provide
816 * the callback function.
817 *
818 * A default event handler that merely reports on the events as they
819 * happen is included. It is also possible to set the event handler
820 * function to NULL, in which case all events will just be silently
821 * ignored.
822 *
823 * @{
824 */
825
826/**
827 * @brief srtp_event_t defines events that need to be handled
828 *
829 * The enum srtp_event_t defines events that need to be handled
830 * outside the `data plane', such as SSRC collisions and
831 * key expirations.
832 *
833 * When a key expires or the maximum number of packets has been
834 * reached, an SRTP stream will enter an `expired' state in which no
835 * more packets can be protected or unprotected. When this happens,
836 * it is likely that you will want to either deallocate the stream
837 * (using srtp_stream_dealloc()), and possibly allocate a new one.
838 *
839 * When an SRTP stream expires, the other streams in the same session
840 * are unaffected, unless key sharing is used by that stream. In the
841 * latter case, all of the streams in the session will expire.
842 */
843
844typedef enum {
845 event_ssrc_collision, /**<
846 * An SSRC collision occured.
847 */
848 event_key_soft_limit, /**< An SRTP stream reached the soft key
849 * usage limit and will expire soon.
850 */
851 event_key_hard_limit, /**< An SRTP stream reached the hard
852 * key usage limit and has expired.
853 */
854 event_packet_index_limit /**< An SRTP stream reached the hard
855 * packet limit (2^48 packets).
856 */
857} srtp_event_t;
858
859/**
860 * @brief srtp_event_data_t is the structure passed as a callback to
861 * the event handler function
862 *
863 * The struct srtp_event_data_t holds the data passed to the event
864 * handler function.
865 */
866
867typedef struct srtp_event_data_t {
868 srtp_t session; /**< The session in which the event happend. */
869 srtp_stream_t stream; /**< The stream in which the event happend. */
870 srtp_event_t event; /**< An enum indicating the type of event. */
871} srtp_event_data_t;
872
873/**
874 * @brief srtp_event_handler_func_t is the function prototype for
875 * the event handler.
876 *
877 * The typedef srtp_event_handler_func_t is the prototype for the
878 * event handler function. It has as its only argument an
879 * srtp_event_data_t which describes the event that needs to be handled.
880 * There can only be a single, global handler for all events in
881 * libSRTP.
882 */
883
884typedef void (srtp_event_handler_func_t)(srtp_event_data_t *data);
885
886/**
887 * @brief sets the event handler to the function supplied by the caller.
888 *
889 * The function call srtp_install_event_handler(func) sets the event
890 * handler function to the value func. The value NULL is acceptable
891 * as an argument; in this case, events will be ignored rather than
892 * handled.
893 *
894 * @param func is a pointer to a fuction that takes an srtp_event_data_t
895 * pointer as an argument and returns void. This function
896 * will be used by libSRTP to handle events.
897 */
898
899err_status_t
900srtp_install_event_handler(srtp_event_handler_func_t func);
901
902/**
903 * @}
904 */
905/* in host order, so outside the #if */
906#define SRTCP_E_BIT 0x80000000
907/* for byte-access */
908#define SRTCP_E_BYTE_BIT 0x80
909#define SRTCP_INDEX_MASK 0x7fffffff
910
911#ifdef _MSC_VER
912#pragma pack()
913#endif
914
915#ifdef __cplusplus
916}
917#endif
918
919#endif /* SRTP_H */