blob: 66e15e01a795c7c3fdd89d145094831564a184ff [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
Pascal Bühlerc3655db2017-02-01 09:11:27 +010046#ifndef SRTP_SRTP_H
47#define SRTP_SRTP_H
Cullen Jennings235513a2005-09-21 22:51:36 +000048
David Benjamin5f1b9822016-07-26 18:18:01 -040049#include <stdint.h>
50
Marcus Sundbergcb60bf82005-10-17 17:23:05 +000051#ifdef __cplusplus
52extern "C" {
53#endif
54
Cullen Jennings235513a2005-09-21 22:51:36 +000055/**
56 * @defgroup SRTP Secure RTP
57 *
58 * @brief libSRTP provides functions for protecting RTP and RTCP. See
59 * Section @ref Overview for an introduction to the use of the library.
60 *
61 * @{
62 */
63
64/*
65 * SRTP_MASTER_KEY_LEN is the nominal master key length supported by libSRTP
66 */
67
68#define SRTP_MASTER_KEY_LEN 30
69
70/*
71 * SRTP_MAX_KEY_LEN is the maximum key length supported by libSRTP
72 */
73#define SRTP_MAX_KEY_LEN 64
74
75/*
76 * SRTP_MAX_TAG_LEN is the maximum tag length supported by libSRTP
77 */
78
jfigused221292015-05-15 13:39:08 -040079#define SRTP_MAX_TAG_LEN 16
Cullen Jennings235513a2005-09-21 22:51:36 +000080
81/**
Ryan Hooperab0345b2017-02-07 16:07:59 -050082 * SRTP_MAX_MKI_LEN is the maximum size the MKI could be which is
83 * 128 bytes
84 */
85#define SRTP_MAX_MKI_LEN 128
86
87
88/**
Cullen Jennings235513a2005-09-21 22:51:36 +000089 * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer
90 * (authentication tag and MKI) supported by libSRTP. This value is
Ryan Hooperab0345b2017-02-07 16:07:59 -050091 * the maixmum number of octets that will be added to an RTP packet by
Cullen Jennings235513a2005-09-21 22:51:36 +000092 * srtp_protect().
93 *
94 * @brief the maximum number of octets added by srtp_protect().
95 */
Ryan Hooperab0345b2017-02-07 16:07:59 -050096#define SRTP_MAX_TRAILER_LEN SRTP_MAX_TAG_LEN + SRTP_MAX_MKI_LEN
Cullen Jennings235513a2005-09-21 22:51:36 +000097
Ryan Hooperfe5d8b82016-12-15 14:53:58 -050098/**
99 * SRTP_MAX_NUM_MASTER_KEYS is the maximum number of Master keys for
Ryan Hooper89a288b2016-12-22 16:22:47 -0500100 * MKI supported by libSRTP.
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500101 *
102 */
Ryan Hooper89a288b2016-12-22 16:22:47 -0500103#define SRTP_MAX_NUM_MASTER_KEYS 16
Cullen Jennings235513a2005-09-21 22:51:36 +0000104
jfigus8c36da22013-10-01 16:41:19 -0400105/*
106 * SRTP_AEAD_SALT_LEN is the length of the SALT values used with
107 * GCM mode. GCM mode requires an IV. The SALT value is used
108 * as part of the IV formation logic applied to each RTP packet.
109 */
110#define SRTP_AEAD_SALT_LEN 12
jfigus857009c2014-11-05 11:17:43 -0500111#define SRTP_AES_128_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 16
112#define SRTP_AES_192_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 24
113#define SRTP_AES_256_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 32
jfigus8719f952014-04-08 09:15:49 -0400114
jfigusa9ac8982014-10-31 14:49:31 -0400115/*
116 * an srtp_hdr_t represents the srtp header
117 *
118 * in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
119 *
120 * (note that this definition follows that of RFC 1889 Appendix A, but
121 * is not identical)
122 */
123
124#ifndef WORDS_BIGENDIAN
jfigus8c36da22013-10-01 16:41:19 -0400125
jfigusa9ac8982014-10-31 14:49:31 -0400126/*
127 * srtp_hdr_t represents an RTP or SRTP header. The bit-fields in
128 * this structure should be declared "unsigned int" instead of
129 * "unsigned char", but doing so causes the MS compiler to not
130 * fully pack the bit fields.
131 */
132
133typedef struct {
134 unsigned char cc:4; /* CSRC count */
135 unsigned char x:1; /* header extension flag */
136 unsigned char p:1; /* padding flag */
137 unsigned char version:2; /* protocol version */
138 unsigned char pt:7; /* payload type */
139 unsigned char m:1; /* marker bit */
140 uint16_t seq; /* sequence number */
141 uint32_t ts; /* timestamp */
142 uint32_t ssrc; /* synchronization source */
143} srtp_hdr_t;
144
145#else /* BIG_ENDIAN */
146
147typedef struct {
148 unsigned char version:2; /* protocol version */
149 unsigned char p:1; /* padding flag */
150 unsigned char x:1; /* header extension flag */
151 unsigned char cc:4; /* CSRC count */
152 unsigned char m:1; /* marker bit */
153 unsigned char pt:7; /* payload type */
154 uint16_t seq; /* sequence number */
155 uint32_t ts; /* timestamp */
156 uint32_t ssrc; /* synchronization source */
157} srtp_hdr_t;
158
159#endif
160
161typedef struct {
162 uint16_t profile_specific; /* profile-specific info */
163 uint16_t length; /* number of 32-bit words in extension */
164} srtp_hdr_xtnd_t;
165
166
167/*
168 * srtcp_hdr_t represents a secure rtcp header
169 *
170 * in this implementation, an srtcp header is assumed to be 32-bit
171 * alinged
172 */
173
174#ifndef WORDS_BIGENDIAN
175
176typedef struct {
177 unsigned char rc:5; /* reception report count */
178 unsigned char p:1; /* padding flag */
179 unsigned char version:2; /* protocol version */
180 unsigned char pt:8; /* payload type */
181 uint16_t len; /* length */
182 uint32_t ssrc; /* synchronization source */
183} srtcp_hdr_t;
184
185typedef struct {
186 unsigned int index:31; /* srtcp packet index in network order! */
187 unsigned int e:1; /* encrypted? 1=yes */
188 /* optional mikey/etc go here */
189 /* and then the variable-length auth tag */
190} srtcp_trailer_t;
191
192
193#else /* BIG_ENDIAN */
194
195typedef struct {
196 unsigned char version:2; /* protocol version */
197 unsigned char p:1; /* padding flag */
198 unsigned char rc:5; /* reception report count */
199 unsigned char pt:8; /* payload type */
200 uint16_t len; /* length */
201 uint32_t ssrc; /* synchronization source */
202} srtcp_hdr_t;
203
204typedef struct {
205 unsigned int version:2; /* protocol version */
206 unsigned int p:1; /* padding flag */
207 unsigned int count:5; /* varies by packet type */
208 unsigned int pt:8; /* payload type */
209 uint16_t length; /* len of uint32s of packet less header */
210} rtcp_common_t;
211
212typedef struct {
213 unsigned int e:1; /* encrypted? 1=yes */
214 unsigned int index:31; /* srtcp packet index */
215 /* optional mikey/etc go here */
216 /* and then the variable-length auth tag */
217} srtcp_trailer_t;
218
219#endif
220
221
222
223/**
jfigus857009c2014-11-05 11:17:43 -0500224 * @brief A srtp_cipher_type_id_t is an identifier for a particular cipher
jfigusa9ac8982014-10-31 14:49:31 -0400225 * type.
226 *
jfigus857009c2014-11-05 11:17:43 -0500227 * A srtp_cipher_type_id_t is an integer that represents a particular
jfigusa9ac8982014-10-31 14:49:31 -0400228 * cipher type, e.g. the Advanced Encryption Standard (AES). A
jfigus67b9c732014-11-20 10:17:21 -0500229 * SRTP_NULL_CIPHER is avaliable; this cipher leaves the data unchanged,
jfigusa9ac8982014-10-31 14:49:31 -0400230 * and can be selected to indicate that no encryption is to take
231 * place.
232 *
233 * @ingroup Ciphers
234 */
jfigus857009c2014-11-05 11:17:43 -0500235typedef uint32_t srtp_cipher_type_id_t;
jfigusa9ac8982014-10-31 14:49:31 -0400236
237/**
jfigus857009c2014-11-05 11:17:43 -0500238 * @brief An srtp_auth_type_id_t is an identifier for a particular authentication
jfigusa9ac8982014-10-31 14:49:31 -0400239 * function.
240 *
jfigus857009c2014-11-05 11:17:43 -0500241 * An srtp_auth_type_id_t is an integer that represents a particular
jfigus67b9c732014-11-20 10:17:21 -0500242 * authentication function type, e.g. HMAC-SHA1. A SRTP_NULL_AUTH is
jfigusa9ac8982014-10-31 14:49:31 -0400243 * avaliable; this authentication function performs no computation,
244 * and can be selected to indicate that no authentication is to take
245 * place.
246 *
247 * @ingroup Authentication
248 */
jfigus857009c2014-11-05 11:17:43 -0500249typedef uint32_t srtp_auth_type_id_t;
jfigusa9ac8982014-10-31 14:49:31 -0400250
251/*
jfigus857009c2014-11-05 11:17:43 -0500252 * @brief srtp_err_status_t defines error codes.
jfigusa9ac8982014-10-31 14:49:31 -0400253 *
jfigus857009c2014-11-05 11:17:43 -0500254 * The enumeration srtp_err_status_t defines error codes. Note that the
255 * value of srtp_err_status_ok is equal to zero, which can simplify error
jfigusa9ac8982014-10-31 14:49:31 -0400256 * checking somewhat.
257 *
258 */
259typedef enum {
jfigus857009c2014-11-05 11:17:43 -0500260 srtp_err_status_ok = 0, /**< nothing to report */
261 srtp_err_status_fail = 1, /**< unspecified failure */
262 srtp_err_status_bad_param = 2, /**< unsupported parameter */
263 srtp_err_status_alloc_fail = 3, /**< couldn't allocate memory */
264 srtp_err_status_dealloc_fail = 4, /**< couldn't deallocate properly */
265 srtp_err_status_init_fail = 5, /**< couldn't initialize */
266 srtp_err_status_terminus = 6, /**< can't process as much data as requested */
267 srtp_err_status_auth_fail = 7, /**< authentication failure */
268 srtp_err_status_cipher_fail = 8, /**< cipher failure */
269 srtp_err_status_replay_fail = 9, /**< replay check failed (bad index) */
270 srtp_err_status_replay_old = 10, /**< replay check failed (index too old) */
271 srtp_err_status_algo_fail = 11, /**< algorithm failed test routine */
272 srtp_err_status_no_such_op = 12, /**< unsupported operation */
273 srtp_err_status_no_ctx = 13, /**< no appropriate context found */
274 srtp_err_status_cant_check = 14, /**< unable to perform desired validation */
275 srtp_err_status_key_expired = 15, /**< can't use key any more */
276 srtp_err_status_socket_err = 16, /**< error in use of socket */
277 srtp_err_status_signal_err = 17, /**< error in use POSIX signals */
278 srtp_err_status_nonce_bad = 18, /**< nonce check failed */
279 srtp_err_status_read_fail = 19, /**< couldn't read data */
280 srtp_err_status_write_fail = 20, /**< couldn't write data */
281 srtp_err_status_parse_err = 21, /**< error parsing data */
282 srtp_err_status_encode_err = 22, /**< error encoding data */
283 srtp_err_status_semaphore_err = 23,/**< error while using semaphores */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500284 srtp_err_status_pfkey_err = 24, /**< error while using pfkey */
285 srtp_err_status_bad_mki = 25 /**< error MKI present in packet is invalid */
jfigus857009c2014-11-05 11:17:43 -0500286} srtp_err_status_t;
jfigusa9ac8982014-10-31 14:49:31 -0400287
Pascal Bühlerf15c7e02017-01-25 13:15:21 +0100288
jfigusa9ac8982014-10-31 14:49:31 -0400289typedef struct srtp_ctx_t_ srtp_ctx_t;
jfigus44947602014-10-08 13:08:52 -0400290
Cullen Jennings235513a2005-09-21 22:51:36 +0000291/**
jfigus857009c2014-11-05 11:17:43 -0500292 * @brief srtp_sec_serv_t describes a set of security services.
Cullen Jennings235513a2005-09-21 22:51:36 +0000293 *
jfigus857009c2014-11-05 11:17:43 -0500294 * A srtp_sec_serv_t enumeration is used to describe the particular
Cullen Jennings235513a2005-09-21 22:51:36 +0000295 * security services that will be applied by a particular crypto
296 * policy (or other mechanism).
297 */
298
299typedef enum {
300 sec_serv_none = 0, /**< no services */
301 sec_serv_conf = 1, /**< confidentiality */
302 sec_serv_auth = 2, /**< authentication */
303 sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */
jfigus857009c2014-11-05 11:17:43 -0500304} srtp_sec_serv_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000305
306/**
jfigus857009c2014-11-05 11:17:43 -0500307 * @brief srtp_crypto_policy_t describes a particular crypto policy that
Cullen Jennings235513a2005-09-21 22:51:36 +0000308 * can be applied to an SRTP stream.
309 *
jfigus857009c2014-11-05 11:17:43 -0500310 * A srtp_crypto_policy_t describes a particular cryptographic policy that
Cullen Jennings235513a2005-09-21 22:51:36 +0000311 * can be applied to an SRTP or SRTCP stream. An SRTP session policy
312 * consists of a list of these policies, one for each SRTP stream
313 * in the session.
314 */
315
jfigus857009c2014-11-05 11:17:43 -0500316typedef struct srtp_crypto_policy_t {
317 srtp_cipher_type_id_t cipher_type; /**< An integer representing
318 * the type of cipher. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000319 int cipher_key_len; /**< The length of the cipher key
320 * in octets. */
jfigus857009c2014-11-05 11:17:43 -0500321 srtp_auth_type_id_t auth_type; /**< An integer representing the
322 * authentication function. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000323 int auth_key_len; /**< The length of the authentication
324 * function key in octets. */
325 int auth_tag_len; /**< The length of the authentication
326 * tag in octets. */
jfigus857009c2014-11-05 11:17:43 -0500327 srtp_sec_serv_t sec_serv; /**< The flag indicating the security
Cullen Jennings235513a2005-09-21 22:51:36 +0000328 * services to be applied. */
jfigus857009c2014-11-05 11:17:43 -0500329} srtp_crypto_policy_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000330
331
332/**
jfigus857009c2014-11-05 11:17:43 -0500333 * @brief srtp_ssrc_type_t describes the type of an SSRC.
Cullen Jennings235513a2005-09-21 22:51:36 +0000334 *
jfigus857009c2014-11-05 11:17:43 -0500335 * An srtp_ssrc_type_t enumeration is used to indicate a type of SSRC. See
Cullen Jennings235513a2005-09-21 22:51:36 +0000336 * @ref srtp_policy_t for more informataion.
337 */
338
339typedef enum {
340 ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */
341 ssrc_specific = 1, /**< Indicates a specific SSRC value */
342 ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value
343 (i.e. a value that is used in the
344 function srtp_unprotect()) */
345 ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value
346 (i.e. a value that is used in the
347 function srtp_protect()) */
jfigus857009c2014-11-05 11:17:43 -0500348} srtp_ssrc_type_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000349
350/**
jfigus857009c2014-11-05 11:17:43 -0500351 * @brief An srtp_ssrc_t represents a particular SSRC value, or a `wildcard' SSRC.
Cullen Jennings235513a2005-09-21 22:51:36 +0000352 *
jfigus857009c2014-11-05 11:17:43 -0500353 * An srtp_ssrc_t represents a particular SSRC value (if its type is
Cullen Jennings235513a2005-09-21 22:51:36 +0000354 * ssrc_specific), or a wildcard SSRC value that will match all
355 * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound
356 * SSRCs (if its type is ssrc_any_inbound).
357 *
358 */
359
360typedef struct {
jfigus857009c2014-11-05 11:17:43 -0500361 srtp_ssrc_type_t type; /**< The type of this particular SSRC */
362 unsigned int value; /**< The value of this SSRC, if it is not a wildcard */
363} srtp_ssrc_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000364
365
David McGrew79870d62007-06-15 18:17:39 +0000366/**
367 * @brief points to an EKT policy
368 */
jfigusc5887e72014-11-06 09:46:18 -0500369typedef struct srtp_ekt_policy_ctx_t *srtp_ekt_policy_t;
David McGrew79870d62007-06-15 18:17:39 +0000370
371
372/**
373 * @brief points to EKT stream data
374 */
jfigusc5887e72014-11-06 09:46:18 -0500375typedef struct srtp_ekt_stream_ctx_t *srtp_ekt_stream_t;
David McGrew79870d62007-06-15 18:17:39 +0000376
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500377/**
378 * @brief srtp_master_key_t represents a master key. There will
379 * be a Master Key Index and the Master Key associated with the
380 * Master Key Index. Need to also keep track of the Master Key
381 * Index Size to correctly read it from a packet.
382 */
383typedef struct srtp_master_key_t {
384 unsigned char *key;
385 unsigned char *mki_id;
386 unsigned int mki_size;
387} srtp_master_key_t;
David McGrew79870d62007-06-15 18:17:39 +0000388
Cullen Jennings235513a2005-09-21 22:51:36 +0000389/**
390 * @brief represents the policy for an SRTP session.
391 *
392 * A single srtp_policy_t struct represents the policy for a single
393 * SRTP stream, and a linked list of these elements represents the
394 * policy for an entire SRTP session. Each element contains the SRTP
395 * and SRTCP crypto policies for that stream, a pointer to the SRTP
396 * master key for that stream, the SSRC describing that stream, or a
397 * flag indicating a `wildcard' SSRC value, and a `next' field that
398 * holds a pointer to the next element in the list of policy elements,
399 * or NULL if it is the last element.
400 *
401 * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an
402 * inbound stream that for which there is no explicit SSRC entry in
403 * another policy element. Similarly, the value SSRC_ANY_OUTBOUND
404 * will matches any SSRC from an outbound stream that does not appear
405 * in another policy element. Note that wildcard SSRCs &b cannot be
406 * used to match both inbound and outbound traffic. This restriction
407 * is intentional, and it allows libSRTP to ensure that no security
408 * lapses result from accidental re-use of SSRC values during key
409 * sharing.
410 *
411 *
412 * @warning The final element of the list @b must have its `next' pointer
413 * set to NULL.
414 */
415
416typedef struct srtp_policy_t {
jfigus857009c2014-11-05 11:17:43 -0500417 srtp_ssrc_t ssrc; /**< The SSRC value of stream, or the
Cullen Jennings235513a2005-09-21 22:51:36 +0000418 * flags SSRC_ANY_INBOUND or
419 * SSRC_ANY_OUTBOUND if key sharing
420 * is used for this policy element.
421 */
jfigus857009c2014-11-05 11:17:43 -0500422 srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */
423 srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */
David McGrew3c45e0c2006-07-12 00:50:56 +0000424 unsigned char *key; /**< Pointer to the SRTP master key for
Ryan Hooper89a288b2016-12-22 16:22:47 -0500425 * this stream. */
426 srtp_master_key_t **keys; /** Array of Master Key structures */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500427 unsigned long num_master_keys; /** Number of master keys */
jfigusc5887e72014-11-06 09:46:18 -0500428 srtp_ekt_policy_t ekt; /**< Pointer to the EKT policy structure
David McGrew79870d62007-06-15 18:17:39 +0000429 * for this stream (if any) */
Jonathan Lennoxa1242f82010-05-17 21:46:04 +0000430 unsigned long window_size; /**< The window size to use for replay
431 * protection. */
Jonathan Lennoxdcee5c62010-05-17 22:08:40 +0000432 int allow_repeat_tx; /**< Whether retransmissions of
433 * packets with the same sequence number
434 * are allowed. (Note that such repeated
435 * transmissions must have the same RTP
436 * payload, or a severe security weakness
437 * is introduced!) */
Joachim Bauch99a74822015-11-17 00:08:19 +0100438 int *enc_xtn_hdr; /**< List of header ids to encrypt. */
439 int enc_xtn_hdr_count; /**< Number of entries in list of header ids. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000440 struct srtp_policy_t *next; /**< Pointer to next stream policy. */
441} srtp_policy_t;
442
443
444
445
446/**
447 * @brief An srtp_t points to an SRTP session structure.
448 *
449 * The typedef srtp_t is a pointer to a structure that represents
450 * an SRTP session. This datatype is intentially opaque in
451 * order to separate the interface from the implementation.
452 *
453 * An SRTP session consists of all of the traffic sent to the RTP and
454 * RTCP destination transport addresses, using the RTP/SAVP (Secure
455 * Audio/Video Profile). A session can be viewed as a set of SRTP
456 * streams, each of which originates with a different participant.
457 */
458
jfigusa9ac8982014-10-31 14:49:31 -0400459typedef srtp_ctx_t *srtp_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000460
461
462/**
Cullen Jennings235513a2005-09-21 22:51:36 +0000463 * @brief srtp_init() initializes the srtp library.
464 *
465 * @warning This function @b must be called before any other srtp
466 * functions.
467 */
468
jfigus857009c2014-11-05 11:17:43 -0500469srtp_err_status_t srtp_init(void);
Cullen Jennings235513a2005-09-21 22:51:36 +0000470
471/**
Jonathan Lennox5ae76332010-05-15 04:48:59 +0000472 * @brief srtp_shutdown() de-initializes the srtp library.
473 *
474 * @warning No srtp functions may be called after calling this function.
475 */
476
jfigus857009c2014-11-05 11:17:43 -0500477srtp_err_status_t srtp_shutdown(void);
Jonathan Lennox5ae76332010-05-15 04:48:59 +0000478
479/**
Cullen Jennings235513a2005-09-21 22:51:36 +0000480 * @brief srtp_protect() is the Secure RTP sender-side packet processing
481 * function.
482 *
483 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
484 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
jfigus857009c2014-11-05 11:17:43 -0500485 * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
Cullen Jennings235513a2005-09-21 22:51:36 +0000486 * points to the resulting SRTP packet and *len_ptr is the number of
487 * octets in that packet; otherwise, no assumptions should be made
488 * about the value of either data elements.
489 *
490 * The sequence numbers of the RTP packets presented to this function
491 * need not be consecutive, but they @b must be out of order by less
492 * than 2^15 = 32,768 packets.
493 *
494 * @warning This function assumes that it can write the authentication
495 * tag into the location in memory immediately following the RTP
496 * packet, and assumes that the RTP packet is aligned on a 32-bit
497 * boundary.
498 *
jfigusdfe68ea2013-05-28 09:00:14 -0400499 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
500 * into the location in memory immediately following the RTP packet.
501 * Callers MUST ensure that this much writable memory is available in
502 * the buffer that holds the RTP packet.
jfigus5e337292013-05-28 13:57:47 -0400503 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000504 * @param ctx is the SRTP context to use in processing the packet.
505 *
506 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
507 * the function returns, it points to the srtp packet.
508 *
509 * @param len_ptr is a pointer to the length in octets of the complete
510 * RTP packet (header and body) before the function call, and of the
jfigus857009c2014-11-05 11:17:43 -0500511 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
Cullen Jennings235513a2005-09-21 22:51:36 +0000512 * Otherwise, the value of the data to which it points is undefined.
513 *
514 * @return
jfigus857009c2014-11-05 11:17:43 -0500515 * - srtp_err_status_ok no problems
516 * - srtp_err_status_replay_fail rtp sequence number was non-increasing
Cullen Jennings235513a2005-09-21 22:51:36 +0000517 * - @e other failure in cryptographic mechanisms
518 */
519
jfigus857009c2014-11-05 11:17:43 -0500520srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500521
522/**
523 * @brief srtp_protect_mki() is the Secure RTP sender-side packet processing
524 * function that can utilize MKI.
525 *
526 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
527 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
528 * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
529 * points to the resulting SRTP packet and *len_ptr is the number of
530 * octets in that packet; otherwise, no assumptions should be made
531 * about the value of either data elements.
532 *
533 * The sequence numbers of the RTP packets presented to this function
534 * need not be consecutive, but they @b must be out of order by less
535 * than 2^15 = 32,768 packets.
536 *
537 * @warning This function assumes that it can write the authentication
538 * tag into the location in memory immediately following the RTP
539 * packet, and assumes that the RTP packet is aligned on a 32-bit
540 * boundary.
541 *
542 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
543 * into the location in memory immediately following the RTP packet.
544 * Callers MUST ensure that this much writable memory is available in
545 * the buffer that holds the RTP packet.
546 *
547 * @param ctx is the SRTP context to use in processing the packet.
548 *
549 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
550 * the function returns, it points to the srtp packet.
551 *
552 * @param len_ptr is a pointer to the length in octets of the complete
553 * RTP packet (header and body) before the function call, and of the
554 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
555 * Otherwise, the value of the data to which it points is undefined.
556 *
557 * @param use_mki is a boolean to tell the system if mki is being used. If
558 * set to false then will use the first set of session keys. If set to true will
559 * use the session keys identified by the mki_index
560 *
561 * @param mki_index integer value specifying which set of session kesy should be
562 * used if use_mki is set to true.
563 *
564 * @return
565 * - srtp_err_status_ok no problems
566 * - srtp_err_status_replay_fail rtp sequence number was non-increasing
567 * - @e other failure in cryptographic mechanisms
568 */
569
Geir Istad626e9e82017-02-20 18:15:05 +0100570srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, void *rtp_hdr,
571 int *pkt_octet_len, unsigned int use_mki,
572 unsigned int mki_index);
573
Cullen Jennings235513a2005-09-21 22:51:36 +0000574/**
575 * @brief srtp_unprotect() is the Secure RTP receiver-side packet
576 * processing function.
577 *
578 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
579 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
580 * (which has length *len_ptr), using the SRTP context ctx. If
jfigus857009c2014-11-05 11:17:43 -0500581 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
Cullen Jennings235513a2005-09-21 22:51:36 +0000582 * RTP packet and *len_ptr is the number of octets in that packet;
583 * otherwise, no assumptions should be made about the value of either
584 * data elements.
585 *
586 * The sequence numbers of the RTP packets presented to this function
587 * need not be consecutive, but they @b must be out of order by less
588 * than 2^15 = 32,768 packets.
589 *
590 * @warning This function assumes that the SRTP packet is aligned on a
591 * 32-bit boundary.
592 *
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +0200593 * @param ctx is the SRTP session which applies to the particular packet.
Cullen Jennings235513a2005-09-21 22:51:36 +0000594 *
595 * @param srtp_hdr is a pointer to the header of the SRTP packet
596 * (before the call). after the function returns, it points to the
jfigus857009c2014-11-05 11:17:43 -0500597 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
Cullen Jennings235513a2005-09-21 22:51:36 +0000598 * the data to which it points is undefined.
599 *
600 * @param len_ptr is a pointer to the length in octets of the complete
601 * srtp packet (header and body) before the function call, and of the
jfigus857009c2014-11-05 11:17:43 -0500602 * complete rtp packet after the call, if srtp_err_status_ok was returned.
Cullen Jennings235513a2005-09-21 22:51:36 +0000603 * Otherwise, the value of the data to which it points is undefined.
604 *
605 * @return
jfigus857009c2014-11-05 11:17:43 -0500606 * - srtp_err_status_ok if the RTP packet is valid.
607 * - srtp_err_status_auth_fail if the SRTP packet failed the message
Cullen Jennings235513a2005-09-21 22:51:36 +0000608 * authentication check.
jfigus857009c2014-11-05 11:17:43 -0500609 * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet has
Cullen Jennings235513a2005-09-21 22:51:36 +0000610 * already been processed and accepted).
611 * - [other] if there has been an error in the cryptographic mechanisms.
612 *
613 */
614
jfigus857009c2014-11-05 11:17:43 -0500615srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
Cullen Jennings235513a2005-09-21 22:51:36 +0000616
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500617/**
618 * @brief srtp_unprotect_mki() is the Secure RTP receiver-side packet
619 * processing function that checks for MKI.
620 *
621 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
622 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
623 * (which has length *len_ptr), using the SRTP context ctx. If
624 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
625 * RTP packet and *len_ptr is the number of octets in that packet;
626 * otherwise, no assumptions should be made about the value of either
627 * data elements.
628 *
629 * The sequence numbers of the RTP packets presented to this function
630 * need not be consecutive, but they @b must be out of order by less
631 * than 2^15 = 32,768 packets.
632 *
633 * @warning This function assumes that the SRTP packet is aligned on a
634 * 32-bit boundary.
635 *
636 * @param ctx is the SRTP session which applies to the particular packet.
637 *
638 * @param srtp_hdr is a pointer to the header of the SRTP packet
639 * (before the call). after the function returns, it points to the
640 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
641 * the data to which it points is undefined.
642 *
643 * @param len_ptr is a pointer to the length in octets of the complete
644 * srtp packet (header and body) before the function call, and of the
645 * complete rtp packet after the call, if srtp_err_status_ok was returned.
646 * Otherwise, the value of the data to which it points is undefined.
647 *
648 * @return
649 * - srtp_err_status_ok if the RTP packet is valid.
650 * - srtp_err_status_auth_fail if the SRTP packet failed the message
651 * authentication check.
652 * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet has
653 * already been processed and accepted).
654 * - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI id
655 * - [other] if there has been an error in the cryptographic mechanisms.
656 *
657 */
658
Geir Istad626e9e82017-02-20 18:15:05 +0100659srtp_err_status_t srtp_unprotect_mki(srtp_t ctx, void *srtp_hdr, int *len_ptr,
660 unsigned int use_mki);
Cullen Jennings235513a2005-09-21 22:51:36 +0000661
662/**
663 * @brief srtp_create() allocates and initializes an SRTP session.
664
jfigus92c3de32016-02-02 13:44:39 -0500665 * The function call srtp_create(session, policy) allocates and
666 * initializes an SRTP session context, applying the given policy.
Cullen Jennings235513a2005-09-21 22:51:36 +0000667 *
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +0200668 * @param session is a pointer to the SRTP session to which the policy is
669 * to be added.
Cullen Jennings235513a2005-09-21 22:51:36 +0000670 *
671 * @param policy is the srtp_policy_t struct that describes the policy
672 * for the session. The struct may be a single element, or it may be
673 * the head of a list, in which case each element of the list is
Marcus Sundberg75d92122005-10-05 12:40:31 +0000674 * processed. It may also be NULL, in which case streams should be added
675 * later using srtp_add_stream(). The final element of the list @b must
676 * have its `next' field set to NULL.
Cullen Jennings235513a2005-09-21 22:51:36 +0000677 *
678 * @return
jfigus857009c2014-11-05 11:17:43 -0500679 * - srtp_err_status_ok if creation succeded.
680 * - srtp_err_status_alloc_fail if allocation failed.
681 * - srtp_err_status_init_fail if initialization failed.
Cullen Jennings235513a2005-09-21 22:51:36 +0000682 */
683
jfigus857009c2014-11-05 11:17:43 -0500684srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000685
686
687/**
688 * @brief srtp_add_stream() allocates and initializes an SRTP stream
689 * within a given SRTP session.
690 *
691 * The function call srtp_add_stream(session, policy) allocates and
692 * initializes a new SRTP stream within a given, previously created
693 * session, applying the policy given as the other argument to that
694 * stream.
695 *
696 * @return values:
jfigus857009c2014-11-05 11:17:43 -0500697 * - srtp_err_status_ok if stream creation succeded.
698 * - srtp_err_status_alloc_fail if stream allocation failed
699 * - srtp_err_status_init_fail if stream initialization failed.
Cullen Jennings235513a2005-09-21 22:51:36 +0000700 */
701
jfigus857009c2014-11-05 11:17:43 -0500702srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000703
704
705/**
706 * @brief srtp_remove_stream() deallocates an SRTP stream.
707 *
708 * The function call srtp_remove_stream(session, ssrc) removes
709 * the SRTP stream with the SSRC value ssrc from the SRTP session
710 * context given by the argument session.
711 *
712 * @param session is the SRTP session from which the stream
713 * will be removed.
714 *
jfigus68f8a882016-02-03 12:48:23 -0500715 * @param ssrc is the SSRC value of the stream to be removed
716 * in network byte order.
Cullen Jennings235513a2005-09-21 22:51:36 +0000717 *
718 * @warning Wildcard SSRC values cannot be removed from a
719 * session.
720 *
721 * @return
jfigus857009c2014-11-05 11:17:43 -0500722 * - srtp_err_status_ok if the stream deallocation succeded.
Cullen Jennings235513a2005-09-21 22:51:36 +0000723 * - [other] otherwise.
724 *
725 */
726
jfigus857009c2014-11-05 11:17:43 -0500727srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc);
Cullen Jennings235513a2005-09-21 22:51:36 +0000728
729/**
Pascal Bühlerbd3112a2015-11-06 20:29:15 +0100730 * @brief srtp_update() udpates all streams in the session.
731 *
732 * The function call srtp_update(session, policy) updates
733 * all the streams in the session applying the given policy
734 * and key. The exsisting ROC value of all streams will be
735 * preserved.
736 *
737 * @param session is the SRTP session that contains the streams
738 * to be updated.
739 *
740 * @param policy is the srtp_policy_t struct that describes the policy
741 * for the session. The struct may be a single element, or it may be
742 * the head of a list, in which case each element of the list is
743 * processed. The final element of the list @b must
744 * have its `next' field set to NULL.
745 *
746 * @return
747 * - srtp_err_status_ok if stream creation succeded.
748 * - srtp_err_status_alloc_fail if stream allocation failed
749 * - srtp_err_status_init_fail if stream initialization failed.
750 * - [other] otherwise.
751 *
752 */
753
754srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy);
755
756/**
757 * @brief srtp_update_stream() udpates a SRTP stream.
758 *
759 * The function call srtp_update_stream(session, policy) updates
760 * the stream(s) in the session that match applying the given
761 * policy and key. The exsisting ROC value of all stream(s) will
762 * be preserved.
763 *
764 * @param session is the SRTP session that contains the streams
765 * to be updated.
766 *
767 * @param policy is the srtp_policy_t struct that describes the policy
768 * for the session.
769 *
770 * @return
771 * - srtp_err_status_ok if stream creation succeded.
772 * - srtp_err_status_alloc_fail if stream allocation failed
773 * - srtp_err_status_init_fail if stream initialization failed.
774 * - [other] otherwise.
775 *
776 */
777
778srtp_err_status_t srtp_update_stream(srtp_t session, const srtp_policy_t *policy);
779
780/**
jfigus857009c2014-11-05 11:17:43 -0500781 * @brief srtp_crypto_policy_set_rtp_default() sets a crypto policy
Cullen Jennings235513a2005-09-21 22:51:36 +0000782 * structure to the SRTP default policy for RTP protection.
783 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000784 * @param p is a pointer to the policy structure to be set
Cullen Jennings235513a2005-09-21 22:51:36 +0000785 *
786 * The function call crypto_policy_set_rtp_default(&p) sets the
787 * crypto_policy_t at location p to the SRTP default policy for RTP
788 * protection, as defined in the specification. This function is a
789 * convenience that helps to avoid dealing directly with the policy
790 * data structure. You are encouraged to initialize policy elements
791 * with this function call. Doing so may allow your code to be
792 * forward compatible with later versions of libSRTP that include more
793 * elements in the crypto_policy_t datatype.
794 *
795 * @return void.
796 *
797 */
798
jfigus857009c2014-11-05 11:17:43 -0500799void srtp_crypto_policy_set_rtp_default(srtp_crypto_policy_t *p);
Cullen Jennings235513a2005-09-21 22:51:36 +0000800
801/**
jfigus857009c2014-11-05 11:17:43 -0500802 * @brief srtp_crypto_policy_set_rtcp_default() sets a crypto policy
Cullen Jennings235513a2005-09-21 22:51:36 +0000803 * structure to the SRTP default policy for RTCP protection.
804 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000805 * @param p is a pointer to the policy structure to be set
Cullen Jennings235513a2005-09-21 22:51:36 +0000806 *
jfigus857009c2014-11-05 11:17:43 -0500807 * The function call srtp_crypto_policy_set_rtcp_default(&p) sets the
808 * srtp_crypto_policy_t at location p to the SRTP default policy for RTCP
Cullen Jennings235513a2005-09-21 22:51:36 +0000809 * protection, as defined in the specification. This function is a
810 * convenience that helps to avoid dealing directly with the policy
811 * data structure. You are encouraged to initialize policy elements
812 * with this function call. Doing so may allow your code to be
813 * forward compatible with later versions of libSRTP that include more
jfigus857009c2014-11-05 11:17:43 -0500814 * elements in the srtp_crypto_policy_t datatype.
Cullen Jennings235513a2005-09-21 22:51:36 +0000815 *
816 * @return void.
817 *
818 */
819
jfigus857009c2014-11-05 11:17:43 -0500820void srtp_crypto_policy_set_rtcp_default(srtp_crypto_policy_t *p);
Cullen Jennings235513a2005-09-21 22:51:36 +0000821
822/**
jfigus857009c2014-11-05 11:17:43 -0500823 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000824 * policy structure to the SRTP default policy for RTP protection.
825 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000826 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000827 *
jfigus857009c2014-11-05 11:17:43 -0500828 * The function srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
829 * synonym for srtp_crypto_policy_set_rtp_default(). It conforms to the
Jonathan Lennoxd8d5cd02010-05-17 20:08:17 +0000830 * naming convention used in RFC 4568 (SDP Security Descriptions for
831 * Media Streams).
David McGrewa8546882006-01-12 17:56:02 +0000832 *
833 * @return void.
834 *
835 */
836
jfigus857009c2014-11-05 11:17:43 -0500837#define srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(p) srtp_crypto_policy_set_rtp_default(p)
David McGrewa8546882006-01-12 17:56:02 +0000838
839
840/**
jfigus857009c2014-11-05 11:17:43 -0500841 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000842 * policy structure to a short-authentication tag policy
843 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000844 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000845 *
jfigus857009c2014-11-05 11:17:43 -0500846 * The function call srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
847 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennoxd8d5cd02010-05-17 20:08:17 +0000848 * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568.
849 * This policy uses AES-128
David McGrewa8546882006-01-12 17:56:02 +0000850 * Counter Mode encryption and HMAC-SHA1 authentication, with an
851 * authentication tag that is only 32 bits long. This length is
852 * considered adequate only for protecting audio and video media that
853 * use a stateless playback function. See Section 7.5 of RFC 3711
854 * (http://www.ietf.org/rfc/rfc3711.txt).
855 *
856 * This function is a convenience that helps to avoid dealing directly
857 * with the policy data structure. You are encouraged to initialize
858 * policy elements with this function call. Doing so may allow your
859 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500860 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000861 *
862 * @warning This crypto policy is intended for use in SRTP, but not in
863 * SRTCP. It is recommended that a policy that uses longer
864 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
865 * (http://www.ietf.org/rfc/rfc3711.txt).
866 *
867 * @return void.
868 *
869 */
870
jfigus857009c2014-11-05 11:17:43 -0500871void srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000872
873
874
875/**
jfigus857009c2014-11-05 11:17:43 -0500876 * @brief srtp_crypto_policy_set_aes_cm_128_null_auth() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000877 * policy structure to an encryption-only policy
878 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000879 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000880 *
jfigus857009c2014-11-05 11:17:43 -0500881 * The function call srtp_crypto_policy_set_aes_cm_128_null_auth(&p) sets
882 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
David McGrewa8546882006-01-12 17:56:02 +0000883 * (AES-128 Counter Mode), but to use no authentication method. This
884 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
885 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
886 *
887 * This function is a convenience that helps to avoid dealing directly
888 * with the policy data structure. You are encouraged to initialize
889 * policy elements with this function call. Doing so may allow your
890 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500891 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000892 *
893 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
894 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
895 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
896 *
897 * @return void.
898 *
899 */
900
jfigus857009c2014-11-05 11:17:43 -0500901void srtp_crypto_policy_set_aes_cm_128_null_auth(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000902
903
904/**
jfigus857009c2014-11-05 11:17:43 -0500905 * @brief srtp_crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000906 * policy structure to an authentication-only policy
907 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000908 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000909 *
jfigus857009c2014-11-05 11:17:43 -0500910 * The function call srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&p)
911 * sets the srtp_crypto_policy_t at location p to use HMAC-SHA1 with an 80
David McGrewa8546882006-01-12 17:56:02 +0000912 * bit authentication tag to provide message authentication, but to
913 * use no encryption. This policy is NOT RECOMMENDED for SRTP unless
914 * there is a requirement to forego encryption.
915 *
916 * This function is a convenience that helps to avoid dealing directly
917 * with the policy data structure. You are encouraged to initialize
918 * policy elements with this function call. Doing so may allow your
919 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500920 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000921 *
922 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
923 * requirement to forego encryption.
924 *
925 * @return void.
926 *
927 */
jfigus857009c2014-11-05 11:17:43 -0500928void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000929
jfigus267956d2014-11-06 10:49:21 -0500930/**
931 * @brief srtp_crypto_policy_set_null_cipher_hmac_null() sets a crypto
932 * policy structure to use no encryption or authentication.
933 *
934 * @param p is a pointer to the policy structure to be set
935 *
936 * The function call srtp_crypto_policy_set_null_cipher_hmac_null(&p)
937 * sets the srtp_crypto_policy_t at location p to use no encryption and
938 * no authentication. This policy should only be used for testing and
939 * troubleshootingl.
940 *
941 * This function is a convenience that helps to avoid dealing directly
942 * with the policy data structure. You are encouraged to initialize
943 * policy elements with this function call. Doing so may allow your
944 * code to be forward compatible with later versions of libSRTP that
945 * include more elements in the srtp_crypto_policy_t datatype.
946 *
947 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
948 * requirement to forego encryption and authentication.
949 *
950 * @return void.
951 *
952 */
953void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p);
954
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000955
956/**
jfigus857009c2014-11-05 11:17:43 -0500957 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000958 * policy structure to a encryption and authentication policy using AES-256
959 * for RTP protection.
960 *
961 * @param p is a pointer to the policy structure to be set
962 *
jfigus857009c2014-11-05 11:17:43 -0500963 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&p)
964 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000965 * AES_CM_256_HMAC_SHA1_80 as defined in
966 * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
967 * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
968 * authentication tag.
969 *
970 * This function is a convenience that helps to avoid dealing directly
971 * with the policy data structure. You are encouraged to initialize
972 * policy elements with this function call. Doing so may allow your
973 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500974 * include more elements in the srtp_crypto_policy_t datatype.
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000975 *
976 * @return void.
977 *
978 */
979
jfigus857009c2014-11-05 11:17:43 -0500980void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(srtp_crypto_policy_t *p);
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000981
982
983/**
jfigus857009c2014-11-05 11:17:43 -0500984 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000985 * policy structure to a short-authentication tag policy using AES-256
986 * encryption.
987 *
988 * @param p is a pointer to the policy structure to be set
989 *
jfigus857009c2014-11-05 11:17:43 -0500990 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&p)
991 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000992 * AES_CM_256_HMAC_SHA1_32 as defined in
993 * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
994 * Counter Mode encryption and HMAC-SHA1 authentication, with an
995 * authentication tag that is only 32 bits long. This length is
996 * considered adequate only for protecting audio and video media that
997 * use a stateless playback function. See Section 7.5 of RFC 3711
998 * (http://www.ietf.org/rfc/rfc3711.txt).
999 *
1000 * This function is a convenience that helps to avoid dealing directly
1001 * with the policy data structure. You are encouraged to initialize
1002 * policy elements with this function call. Doing so may allow your
1003 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001004 * include more elements in the srtp_crypto_policy_t datatype.
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001005 *
1006 * @warning This crypto policy is intended for use in SRTP, but not in
1007 * SRTCP. It is recommended that a policy that uses longer
1008 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
1009 * (http://www.ietf.org/rfc/rfc3711.txt).
1010 *
1011 * @return void.
1012 *
1013 */
1014
jfigus857009c2014-11-05 11:17:43 -05001015void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(srtp_crypto_policy_t *p);
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001016
jfigus8c36da22013-10-01 16:41:19 -04001017/**
jfigus857009c2014-11-05 11:17:43 -05001018 * @brief srtp_crypto_policy_set_aes_cm_256_null_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001019 * policy structure to an encryption-only policy
1020 *
1021 * @param p is a pointer to the policy structure to be set
1022 *
jfigus857009c2014-11-05 11:17:43 -05001023 * The function call srtp_crypto_policy_set_aes_cm_256_null_auth(&p) sets
1024 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001025 * (AES-256 Counter Mode), but to use no authentication method. This
1026 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
1027 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
1028 *
1029 * This function is a convenience that helps to avoid dealing directly
1030 * with the policy data structure. You are encouraged to initialize
1031 * policy elements with this function call. Doing so may allow your
1032 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001033 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001034 *
1035 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
1036 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
1037 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
1038 *
1039 * @return void.
1040 *
1041 */
jfigus857009c2014-11-05 11:17:43 -05001042void srtp_crypto_policy_set_aes_cm_256_null_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001043
1044/**
jfigus857009c2014-11-05 11:17:43 -05001045 * @brief srtp_crypto_policy_set_aes_gcm_128_8_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001046 * policy structure to an AEAD encryption policy.
1047 *
1048 * @param p is a pointer to the policy structure to be set
1049 *
jfigus857009c2014-11-05 11:17:43 -05001050 * The function call srtp_crypto_policy_set_aes_gcm_128_8_auth(&p) sets
1051 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001052 * (AES-128 Galois Counter Mode) with 8 octet auth tag. This
1053 * policy applies confidentiality and authentication to both the
1054 * RTP and RTCP packets.
1055 *
1056 * This function is a convenience that helps to avoid dealing directly
1057 * with the policy data structure. You are encouraged to initialize
1058 * policy elements with this function call. Doing so may allow your
1059 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001060 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001061 *
1062 * @return void.
1063 *
1064 */
jfigus857009c2014-11-05 11:17:43 -05001065void srtp_crypto_policy_set_aes_gcm_128_8_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001066
1067/**
jfigus857009c2014-11-05 11:17:43 -05001068 * @brief srtp_crypto_policy_set_aes_gcm_256_8_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001069 * policy structure to an AEAD encryption policy
1070 *
1071 * @param p is a pointer to the policy structure to be set
1072 *
jfigus857009c2014-11-05 11:17:43 -05001073 * The function call srtp_crypto_policy_set_aes_gcm_256_8_auth(&p) sets
1074 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001075 * (AES-256 Galois Counter Mode) with 8 octet auth tag. This
1076 * policy applies confidentiality and authentication to both the
1077 * RTP and RTCP packets.
1078 *
1079 * This function is a convenience that helps to avoid dealing directly
1080 * with the policy data structure. You are encouraged to initialize
1081 * policy elements with this function call. Doing so may allow your
1082 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001083 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001084 *
1085 * @return void.
1086 *
1087 */
jfigus857009c2014-11-05 11:17:43 -05001088void srtp_crypto_policy_set_aes_gcm_256_8_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001089
1090/**
jfigus857009c2014-11-05 11:17:43 -05001091 * @brief srtp_crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001092 * policy structure to an AEAD authentication-only policy
1093 *
1094 * @param p is a pointer to the policy structure to be set
1095 *
jfigus857009c2014-11-05 11:17:43 -05001096 * The function call srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets
1097 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001098 * (AES-128 Galois Counter Mode) with 8 octet auth tag. This policy
1099 * applies confidentiality and authentication to the RTP packets,
1100 * but only authentication to the RTCP packets.
1101 *
1102 * This function is a convenience that helps to avoid dealing directly
1103 * with the policy data structure. You are encouraged to initialize
1104 * policy elements with this function call. Doing so may allow your
1105 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001106 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001107 *
1108 * @return void.
1109 *
1110 */
jfigus857009c2014-11-05 11:17:43 -05001111void srtp_crypto_policy_set_aes_gcm_128_8_only_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001112
1113/**
jfigus857009c2014-11-05 11:17:43 -05001114 * @brief srtp_crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001115 * policy structure to an AEAD authentication-only policy
1116 *
1117 * @param p is a pointer to the policy structure to be set
1118 *
jfigus857009c2014-11-05 11:17:43 -05001119 * The function call srtp_crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets
1120 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001121 * (AES-256 Galois Counter Mode) with 8 octet auth tag. This policy
1122 * applies confidentiality and authentication to the RTP packets,
1123 * but only authentication to the RTCP packets.
1124 *
1125 * This function is a convenience that helps to avoid dealing directly
1126 * with the policy data structure. You are encouraged to initialize
1127 * policy elements with this function call. Doing so may allow your
1128 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001129 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001130 *
1131 * @return void.
1132 *
1133 */
jfigus857009c2014-11-05 11:17:43 -05001134void srtp_crypto_policy_set_aes_gcm_256_8_only_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001135
jfigusc13c1002014-05-08 13:34:53 -04001136/**
jfigus857009c2014-11-05 11:17:43 -05001137 * @brief srtp_crypto_policy_set_aes_gcm_128_16_auth() sets a crypto
jfigusc13c1002014-05-08 13:34:53 -04001138 * policy structure to an AEAD encryption policy.
1139 *
1140 * @param p is a pointer to the policy structure to be set
1141 *
jfigus857009c2014-11-05 11:17:43 -05001142 * The function call srtp_crypto_policy_set_aes_gcm_128_16_auth(&p) sets
1143 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigusc13c1002014-05-08 13:34:53 -04001144 * (AES-128 Galois Counter Mode) with 16 octet auth tag. This
1145 * policy applies confidentiality and authentication to both the
1146 * RTP and RTCP packets.
1147 *
1148 * This function is a convenience that helps to avoid dealing directly
1149 * with the policy data structure. You are encouraged to initialize
1150 * policy elements with this function call. Doing so may allow your
1151 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001152 * include more elements in the srtp_crypto_policy_t datatype.
jfigusc13c1002014-05-08 13:34:53 -04001153 *
1154 * @return void.
1155 *
1156 */
jfigus857009c2014-11-05 11:17:43 -05001157void srtp_crypto_policy_set_aes_gcm_128_16_auth(srtp_crypto_policy_t *p);
jfigusc13c1002014-05-08 13:34:53 -04001158
1159/**
jfigus857009c2014-11-05 11:17:43 -05001160 * @brief srtp_crypto_policy_set_aes_gcm_256_16_auth() sets a crypto
jfigusc13c1002014-05-08 13:34:53 -04001161 * policy structure to an AEAD encryption policy
1162 *
1163 * @param p is a pointer to the policy structure to be set
1164 *
jfigus857009c2014-11-05 11:17:43 -05001165 * The function call srtp_crypto_policy_set_aes_gcm_256_16_auth(&p) sets
1166 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigusc13c1002014-05-08 13:34:53 -04001167 * (AES-256 Galois Counter Mode) with 16 octet auth tag. This
1168 * policy applies confidentiality and authentication to both the
1169 * RTP and RTCP packets.
1170 *
1171 * This function is a convenience that helps to avoid dealing directly
1172 * with the policy data structure. You are encouraged to initialize
1173 * policy elements with this function call. Doing so may allow your
1174 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001175 * include more elements in the srtp_crypto_policy_t datatype.
jfigusc13c1002014-05-08 13:34:53 -04001176 *
1177 * @return void.
1178 *
1179 */
jfigus857009c2014-11-05 11:17:43 -05001180void srtp_crypto_policy_set_aes_gcm_256_16_auth(srtp_crypto_policy_t *p);
jfigusc13c1002014-05-08 13:34:53 -04001181
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001182
David McGrewa8546882006-01-12 17:56:02 +00001183/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001184 * @brief srtp_dealloc() deallocates storage for an SRTP session
1185 * context.
1186 *
1187 * The function call srtp_dealloc(s) deallocates storage for the
1188 * SRTP session context s. This function should be called no more
1189 * than one time for each of the contexts allocated by the function
1190 * srtp_create().
1191 *
1192 * @param s is the srtp_t for the session to be deallocated.
1193 *
1194 * @return
jfigus857009c2014-11-05 11:17:43 -05001195 * - srtp_err_status_ok if there no problems.
1196 * - srtp_err_status_dealloc_fail a memory deallocation failure occured.
Cullen Jennings235513a2005-09-21 22:51:36 +00001197 */
1198
jfigus857009c2014-11-05 11:17:43 -05001199srtp_err_status_t srtp_dealloc(srtp_t s);
Cullen Jennings235513a2005-09-21 22:51:36 +00001200
1201
David McGrew0cb86ee2006-07-07 15:46:57 +00001202/*
1203 * @brief identifies a particular SRTP profile
1204 *
1205 * An srtp_profile_t enumeration is used to identify a particular SRTP
1206 * profile (that is, a set of algorithms and parameters). These
1207 * profiles are defined in the DTLS-SRTP draft.
1208 */
1209
1210typedef enum {
1211 srtp_profile_reserved = 0,
1212 srtp_profile_aes128_cm_sha1_80 = 1,
1213 srtp_profile_aes128_cm_sha1_32 = 2,
1214 srtp_profile_aes256_cm_sha1_80 = 3,
1215 srtp_profile_aes256_cm_sha1_32 = 4,
1216 srtp_profile_null_sha1_80 = 5,
1217 srtp_profile_null_sha1_32 = 6,
1218} srtp_profile_t;
1219
1220
1221/**
jfigus857009c2014-11-05 11:17:43 -05001222 * @brief srtp_crypto_policy_set_from_profile_for_rtp() sets a crypto policy
David McGrew0cb86ee2006-07-07 15:46:57 +00001223 * structure to the appropriate value for RTP based on an srtp_profile_t
1224 *
1225 * @param p is a pointer to the policy structure to be set
1226 *
jfigus857009c2014-11-05 11:17:43 -05001227 * The function call srtp_crypto_policy_set_rtp_default(&policy, profile)
1228 * sets the srtp_crypto_policy_t at location policy to the policy for RTP
David McGrew0cb86ee2006-07-07 15:46:57 +00001229 * protection, as defined by the srtp_profile_t profile.
1230 *
1231 * This function is a convenience that helps to avoid dealing directly
1232 * with the policy data structure. You are encouraged to initialize
1233 * policy elements with this function call. Doing so may allow your
1234 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001235 * include more elements in the srtp_crypto_policy_t datatype.
David McGrew0cb86ee2006-07-07 15:46:57 +00001236 *
1237 * @return values
jfigus857009c2014-11-05 11:17:43 -05001238 * - srtp_err_status_ok no problems were encountered
1239 * - srtp_err_status_bad_param the profile is not supported
David McGrew0cb86ee2006-07-07 15:46:57 +00001240 *
1241 */
jfigus857009c2014-11-05 11:17:43 -05001242srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtp(srtp_crypto_policy_t *policy, srtp_profile_t profile);
David McGrew0cb86ee2006-07-07 15:46:57 +00001243
1244
1245
1246
1247/**
jfigus857009c2014-11-05 11:17:43 -05001248 * @brief srtp_crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
David McGrew0cb86ee2006-07-07 15:46:57 +00001249 * structure to the appropriate value for RTCP based on an srtp_profile_t
1250 *
1251 * @param p is a pointer to the policy structure to be set
1252 *
jfigus857009c2014-11-05 11:17:43 -05001253 * The function call srtp_crypto_policy_set_rtcp_default(&policy, profile)
1254 * sets the srtp_crypto_policy_t at location policy to the policy for RTCP
David McGrew0cb86ee2006-07-07 15:46:57 +00001255 * protection, as defined by the srtp_profile_t profile.
1256 *
1257 * This function is a convenience that helps to avoid dealing directly
1258 * with the policy data structure. You are encouraged to initialize
1259 * policy elements with this function call. Doing so may allow your
1260 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001261 * include more elements in the srtp_crypto_policy_t datatype.
David McGrew0cb86ee2006-07-07 15:46:57 +00001262 *
1263 * @return values
jfigus857009c2014-11-05 11:17:43 -05001264 * - srtp_err_status_ok no problems were encountered
1265 * - srtp_err_status_bad_param the profile is not supported
David McGrew0cb86ee2006-07-07 15:46:57 +00001266 *
1267 */
jfigus857009c2014-11-05 11:17:43 -05001268srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtcp(srtp_crypto_policy_t *policy, srtp_profile_t profile);
David McGrew0cb86ee2006-07-07 15:46:57 +00001269
1270/**
1271 * @brief returns the master key length for a given SRTP profile
1272 */
1273unsigned int
1274srtp_profile_get_master_key_length(srtp_profile_t profile);
1275
1276
1277/**
1278 * @brief returns the master salt length for a given SRTP profile
1279 */
1280unsigned int
1281srtp_profile_get_master_salt_length(srtp_profile_t profile);
1282
1283/**
1284 * @brief appends the salt to the key
1285 *
jfigus857009c2014-11-05 11:17:43 -05001286 * The function call srtp_append_salt_to_key(k, klen, s, slen)
David McGrew0cb86ee2006-07-07 15:46:57 +00001287 * copies the string s to the location at klen bytes following
1288 * the location k.
1289 *
1290 * @warning There must be at least bytes_in_salt + bytes_in_key bytes
1291 * available at the location pointed to by key.
1292 *
1293 */
1294
1295void
jfigus857009c2014-11-05 11:17:43 -05001296srtp_append_salt_to_key(unsigned char *key, unsigned int bytes_in_key,
1297 unsigned char *salt, unsigned int bytes_in_salt);
David McGrew0cb86ee2006-07-07 15:46:57 +00001298
1299
Cullen Jennings235513a2005-09-21 22:51:36 +00001300
1301/**
1302 * @}
1303 */
1304
1305
Cullen Jennings235513a2005-09-21 22:51:36 +00001306
1307/**
1308 * @defgroup SRTCP Secure RTCP
1309 * @ingroup SRTP
1310 *
1311 * @brief Secure RTCP functions are used to protect RTCP traffic.
1312 *
1313 * RTCP is the control protocol for RTP. libSRTP protects RTCP
1314 * traffic in much the same way as it does RTP traffic. The function
1315 * srtp_protect_rtcp() applies cryptographic protections to outbound
1316 * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on
1317 * inbound RTCP packets.
1318 *
1319 * A note on the naming convention: srtp_protect_rtcp() has an srtp_t
1320 * as its first argument, and thus has `srtp_' as its prefix. The
1321 * trailing `_rtcp' indicates the protocol on which it acts.
1322 *
1323 * @{
1324 */
1325
1326/**
1327 * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet
1328 * processing function.
1329 *
1330 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
1331 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
jfigus857009c2014-11-05 11:17:43 -05001332 * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
Cullen Jennings235513a2005-09-21 22:51:36 +00001333 * returned, then rtp_hdr points to the resulting SRTCP packet and
1334 * *len_ptr is the number of octets in that packet; otherwise, no
1335 * assumptions should be made about the value of either data elements.
1336 *
1337 * @warning This function assumes that it can write the authentication
1338 * tag into the location in memory immediately following the RTCP
1339 * packet, and assumes that the RTCP packet is aligned on a 32-bit
1340 * boundary.
1341 *
jfigus5e337292013-05-28 13:57:47 -04001342 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
1343 * into the location in memory immediately following the RTCP packet.
1344 * Callers MUST ensure that this much writable memory is available in
1345 * the buffer that holds the RTCP packet.
1346 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001347 * @param ctx is the SRTP context to use in processing the packet.
1348 *
1349 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
1350 * the function returns, it points to the srtp packet.
1351 *
1352 * @param pkt_octet_len is a pointer to the length in octets of the
1353 * complete RTCP packet (header and body) before the function call,
jfigus857009c2014-11-05 11:17:43 -05001354 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
Cullen Jennings235513a2005-09-21 22:51:36 +00001355 * was returned. Otherwise, the value of the data to which it points
1356 * is undefined.
1357 *
1358 * @return
jfigus857009c2014-11-05 11:17:43 -05001359 * - srtp_err_status_ok if there were no problems.
Cullen Jennings235513a2005-09-21 22:51:36 +00001360 * - [other] if there was a failure in
1361 * the cryptographic mechanisms.
1362 */
1363
1364
jfigus857009c2014-11-05 11:17:43 -05001365srtp_err_status_t srtp_protect_rtcp(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001366
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001367
1368/**
1369 * @brief srtp_protect_rtcp_mki() is the Secure RTCP sender-side packet
1370 * processing function that can utilize mki.
1371 *
1372 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
1373 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
1374 * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
1375 * returned, then rtp_hdr points to the resulting SRTCP packet and
1376 * *len_ptr is the number of octets in that packet; otherwise, no
1377 * assumptions should be made about the value of either data elements.
1378 *
1379 * @warning This function assumes that it can write the authentication
1380 * tag into the location in memory immediately following the RTCP
1381 * packet, and assumes that the RTCP packet is aligned on a 32-bit
1382 * boundary.
1383 *
1384 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
1385 * into the location in memory immediately following the RTCP packet.
1386 * Callers MUST ensure that this much writable memory is available in
1387 * the buffer that holds the RTCP packet.
1388 *
1389 * @param ctx is the SRTP context to use in processing the packet.
1390 *
1391 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
1392 * the function returns, it points to the srtp packet.
1393 *
1394 * @param pkt_octet_len is a pointer to the length in octets of the
1395 * complete RTCP packet (header and body) before the function call,
1396 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
1397 * was returned. Otherwise, the value of the data to which it points
1398 * is undefined.
1399 *
1400 * @param use_mki is a boolean to tell the system if mki is being used. If
1401 * set to false then will use the first set of session keys. If set to true will
1402 * use the session keys identified by the mki_index
1403 *
1404 * @param mki_index integer value specifying which set of session kesy should be
1405 * used if use_mki is set to true.
1406 *
1407 * @return
1408 * - srtp_err_status_ok if there were no problems.
1409 * - [other] if there was a failure in
1410 * the cryptographic mechanisms.
1411 */
1412
1413srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len,
1414 unsigned int use_mki, unsigned int mki_index);
1415
Cullen Jennings235513a2005-09-21 22:51:36 +00001416/**
1417 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
1418 * processing function.
1419 *
1420 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
1421 * verifies the Secure RTCP protection of the SRTCP packet pointed to
1422 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
jfigus857009c2014-11-05 11:17:43 -05001423 * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
Cullen Jennings235513a2005-09-21 22:51:36 +00001424 * to the resulting RTCP packet and *len_ptr is the number of octets
1425 * in that packet; otherwise, no assumptions should be made about the
1426 * value of either data elements.
1427 *
1428 * @warning This function assumes that the SRTCP packet is aligned on a
1429 * 32-bit boundary.
1430 *
1431 * @param ctx is a pointer to the srtp_t which applies to the
1432 * particular packet.
1433 *
1434 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
1435 * (before the call). After the function returns, it points to the
jfigus857009c2014-11-05 11:17:43 -05001436 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
Cullen Jennings235513a2005-09-21 22:51:36 +00001437 * the data to which it points is undefined.
1438 *
1439 * @param pkt_octet_len is a pointer to the length in octets of the
1440 * complete SRTCP packet (header and body) before the function call,
jfigus857009c2014-11-05 11:17:43 -05001441 * and of the complete rtp packet after the call, if srtp_err_status_ok was
Cullen Jennings235513a2005-09-21 22:51:36 +00001442 * returned. Otherwise, the value of the data to which it points is
1443 * undefined.
1444 *
1445 * @return
jfigus857009c2014-11-05 11:17:43 -05001446 * - srtp_err_status_ok if the RTCP packet is valid.
1447 * - srtp_err_status_auth_fail if the SRTCP packet failed the message
Cullen Jennings235513a2005-09-21 22:51:36 +00001448 * authentication check.
jfigus857009c2014-11-05 11:17:43 -05001449 * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
Cullen Jennings235513a2005-09-21 22:51:36 +00001450 * already been processed and accepted).
1451 * - [other] if there has been an error in the cryptographic mechanisms.
1452 *
1453 */
1454
jfigus857009c2014-11-05 11:17:43 -05001455srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001456
1457/**
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001458 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
1459 * processing function.
1460 *
1461 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
1462 * verifies the Secure RTCP protection of the SRTCP packet pointed to
1463 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
1464 * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
1465 * to the resulting RTCP packet and *len_ptr is the number of octets
1466 * in that packet; otherwise, no assumptions should be made about the
1467 * value of either data elements.
1468 *
1469 * @warning This function assumes that the SRTCP packet is aligned on a
1470 * 32-bit boundary.
1471 *
1472 * @param ctx is a pointer to the srtp_t which applies to the
1473 * particular packet.
1474 *
1475 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
1476 * (before the call). After the function returns, it points to the
1477 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
1478 * the data to which it points is undefined.
1479 *
1480 * @param pkt_octet_len is a pointer to the length in octets of the
1481 * complete SRTCP packet (header and body) before the function call,
1482 * and of the complete rtp packet after the call, if srtp_err_status_ok was
1483 * returned. Otherwise, the value of the data to which it points is
1484 * undefined.
1485 *
1486 * @return
1487 * - srtp_err_status_ok if the RTCP packet is valid.
1488 * - srtp_err_status_auth_fail if the SRTCP packet failed the message
1489 * authentication check.
1490 * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
1491 * already been processed and accepted).
1492 * - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI id
1493 * - [other] if there has been an error in the cryptographic mechanisms.
1494 *
1495 */
1496
Geir Istad626e9e82017-02-20 18:15:05 +01001497srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, void *srtcp_hdr,
1498 int *pkt_octet_len,
1499 unsigned int use_mki);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001500
1501/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001502 * @}
1503 */
1504
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +02001505
1506/**
1507 * @defgroup User data associated to a SRTP session.
1508 * @ingroup SRTP
1509 *
1510 * @brief Store custom user data within a SRTP session.
1511 *
1512 * @{
1513 */
1514
1515/**
1516 * @brief srtp_set_user_data() stores the given pointer into the SRTP
1517 * session for later retrieval.
1518 *
1519 * @param ctx is the srtp_t context in which the given data pointer is
1520 * stored.
1521 *
1522 * @param data is a pointer to the custom information (struct, function,
1523 * etc) associated with the SRTP session.
1524 *
1525 * @return void.
1526 *
1527 */
1528
1529void
1530srtp_set_user_data(srtp_t ctx, void *data);
1531
1532/**
1533 * @brief srtp_get_user_data() retrieves the pointer to the custom data
1534 * previously stored with srtp_set_user_data().
1535 *
1536 * This function is mostly useful for retrieving data associated to a
1537 * SRTP session when an event fires. The user can then get such a custom
1538 * data by calling this function with the session field of the
1539 * srtp_event_data_t struct as argument.
1540 *
1541 * @param ctx is the srtp_t context in which the given data pointer was
1542 * stored.
1543 *
1544 * @return void* pointer to the user data.
1545 *
1546 */
1547
1548void*
1549srtp_get_user_data(srtp_t ctx);
1550
1551/**
1552 * @}
1553 */
1554
1555
Cullen Jennings235513a2005-09-21 22:51:36 +00001556/**
1557 * @defgroup SRTPevents SRTP events and callbacks
1558 * @ingroup SRTP
1559 *
1560 * @brief libSRTP can use a user-provided callback function to
1561 * handle events.
1562 *
1563 *
1564 * libSRTP allows a user to provide a callback function to handle
1565 * events that need to be dealt with outside of the data plane (see
1566 * the enum srtp_event_t for a description of these events). Dealing
1567 * with these events is not a strict necessity; they are not
1568 * security-critical, but the application may suffer if they are not
1569 * handled. The function srtp_set_event_handler() is used to provide
1570 * the callback function.
1571 *
1572 * A default event handler that merely reports on the events as they
1573 * happen is included. It is also possible to set the event handler
1574 * function to NULL, in which case all events will just be silently
1575 * ignored.
1576 *
1577 * @{
1578 */
1579
1580/**
1581 * @brief srtp_event_t defines events that need to be handled
1582 *
1583 * The enum srtp_event_t defines events that need to be handled
1584 * outside the `data plane', such as SSRC collisions and
1585 * key expirations.
1586 *
1587 * When a key expires or the maximum number of packets has been
1588 * reached, an SRTP stream will enter an `expired' state in which no
1589 * more packets can be protected or unprotected. When this happens,
1590 * it is likely that you will want to either deallocate the stream
jfigus92c3de32016-02-02 13:44:39 -05001591 * (using srtp_remove_stream()), and possibly allocate a new one.
Cullen Jennings235513a2005-09-21 22:51:36 +00001592 *
1593 * When an SRTP stream expires, the other streams in the same session
1594 * are unaffected, unless key sharing is used by that stream. In the
1595 * latter case, all of the streams in the session will expire.
1596 */
1597
1598typedef enum {
1599 event_ssrc_collision, /**<
1600 * An SSRC collision occured.
1601 */
1602 event_key_soft_limit, /**< An SRTP stream reached the soft key
1603 * usage limit and will expire soon.
1604 */
1605 event_key_hard_limit, /**< An SRTP stream reached the hard
1606 * key usage limit and has expired.
1607 */
1608 event_packet_index_limit /**< An SRTP stream reached the hard
1609 * packet limit (2^48 packets).
1610 */
1611} srtp_event_t;
1612
1613/**
1614 * @brief srtp_event_data_t is the structure passed as a callback to
1615 * the event handler function
1616 *
1617 * The struct srtp_event_data_t holds the data passed to the event
1618 * handler function.
1619 */
1620
1621typedef struct srtp_event_data_t {
1622 srtp_t session; /**< The session in which the event happend. */
Pascal Bühleref54b902017-02-16 09:39:13 +01001623 uint32_t ssrc; /**< The ssrc in host order of the stream in which the event happend */
Cullen Jennings235513a2005-09-21 22:51:36 +00001624 srtp_event_t event; /**< An enum indicating the type of event. */
1625} srtp_event_data_t;
1626
1627/**
1628 * @brief srtp_event_handler_func_t is the function prototype for
1629 * the event handler.
1630 *
1631 * The typedef srtp_event_handler_func_t is the prototype for the
1632 * event handler function. It has as its only argument an
1633 * srtp_event_data_t which describes the event that needs to be handled.
1634 * There can only be a single, global handler for all events in
1635 * libSRTP.
1636 */
1637
1638typedef void (srtp_event_handler_func_t)(srtp_event_data_t *data);
1639
1640/**
1641 * @brief sets the event handler to the function supplied by the caller.
1642 *
1643 * The function call srtp_install_event_handler(func) sets the event
1644 * handler function to the value func. The value NULL is acceptable
1645 * as an argument; in this case, events will be ignored rather than
1646 * handled.
1647 *
1648 * @param func is a pointer to a fuction that takes an srtp_event_data_t
1649 * pointer as an argument and returns void. This function
1650 * will be used by libSRTP to handle events.
1651 */
1652
jfigus857009c2014-11-05 11:17:43 -05001653srtp_err_status_t srtp_install_event_handler(srtp_event_handler_func_t func);
Cullen Jennings235513a2005-09-21 22:51:36 +00001654
1655/**
jfigusf62b64d2014-10-08 13:53:57 -04001656 * @brief Returns the version string of the library.
1657 *
1658 */
Christian Oiend4e3eec2014-10-24 10:14:08 +02001659const char *srtp_get_version_string(void);
jfigusf62b64d2014-10-08 13:53:57 -04001660
1661/**
1662 * @brief Returns the numeric representation of the library version.
1663 *
1664 */
1665unsigned int srtp_get_version(void);
1666
1667/**
jfigus46d6b472014-11-14 16:42:01 -05001668 * @brief srtp_set_debug_module(mod_name, v)
1669 *
1670 * sets dynamic debugging to the value v (0 for off, 1 for on) for the
1671 * debug module with the name mod_name
1672 *
1673 * returns err_status_ok on success, err_status_fail otherwise
1674 */
1675srtp_err_status_t srtp_set_debug_module(char *mod_name, int v);
1676
1677/**
1678 * @brief srtp_list_debug_modules() outputs a list of debugging modules
1679 *
1680 */
1681srtp_err_status_t srtp_list_debug_modules(void);
1682
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001683/**
Pascal Bühleraf151782017-02-24 10:51:52 +01001684 * @brief srtp_log_level_t defines log levels.
1685 *
1686 * The enumeration srtp_log_level_t defines log levels reported
1687 * in the srtp_log_handler_func_t.
1688 *
1689 */
1690typedef enum {
1691 srtp_log_level_error, /**< log level is reporting an error message */
1692 srtp_log_level_warning, /**< log level is reporting a warning message */
1693 srtp_log_level_info, /**< log level is reporting an info message */
1694 srtp_log_level_debug /**< log level is reporting a debug message */
1695} srtp_log_level_t;
1696
1697/**
1698 * @brief srtp_log_handler_func_t is the function prototype for
1699 * the log handler.
1700 *
1701 * The typedef srtp_event_handler_func_t is the prototype for the
1702 * event handler function. It has as srtp_log_level_t and log
1703 * message as arguments.
1704 * There can only be a single, global handler for all log messages in
1705 * libSRTP.
1706 */
1707typedef void (srtp_log_handler_func_t)(srtp_log_level_t level, const char * msg);
1708
1709/**
1710 * @brief sets the log handler to the function supplied by the caller.
1711 *
1712 * The function call srtp_install_log_handler(func) sets the log
1713 * handler function to the value func. The value NULL is acceptable
1714 * as an argument; in this case, log messages will be ignored.
1715 * This function can be called before srtp_init() inorder to capture
1716 * any logging during start up.
1717 *
1718 * @param func is a pointer to a fuction of type srtp_log_handler_func_t.
1719 * This function will be used by libSRTP to output log messages.
1720 */
1721srtp_err_status_t srtp_install_log_handler(srtp_log_handler_func_t func);
1722
1723/**
Ryan Hooperab0345b2017-02-07 16:07:59 -05001724 * @brief srtp_get_protect_trailer_length(session, use_mki, mki_index, length)
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001725 *
1726 * Determines the length of the amount of data Lib SRTP will add to the
1727 * packet during the protect process. The length is returned in the length parameter
1728 *
1729 * returns err_status_ok on success, err_status_bad_mki if the MKI index is invalid
1730 *
1731 */
Ryan Hooperab0345b2017-02-07 16:07:59 -05001732srtp_err_status_t srtp_get_protect_trailer_length(srtp_t session, uint32_t use_mki,
1733 uint32_t mki_index, uint32_t *length);
1734
1735/**
1736 * @brief srtp_get_protect_rtcp_trailer_length(session, use_mki, mki_index, length)
1737 *
1738 * Determines the length of the amount of data Lib SRTP will add to the
1739 * packet during the protect process. The length is returned in the length parameter
1740 *
1741 * returns err_status_ok on success, err_status_bad_mki if the MKI index is invalid
1742 *
1743 */
1744srtp_err_status_t srtp_get_protect_rtcp_trailer_length(srtp_t session, uint32_t use_mki,
1745 uint32_t mki_index, uint32_t *length);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001746
jfigus46d6b472014-11-14 16:42:01 -05001747
1748/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001749 * @}
1750 */
Cullen Jennings235513a2005-09-21 22:51:36 +00001751/* in host order, so outside the #if */
1752#define SRTCP_E_BIT 0x80000000
1753/* for byte-access */
1754#define SRTCP_E_BYTE_BIT 0x80
1755#define SRTCP_INDEX_MASK 0x7fffffff
1756
Marcus Sundbergcb60bf82005-10-17 17:23:05 +00001757#ifdef __cplusplus
1758}
1759#endif
1760
Pascal Bühlerc3655db2017-02-01 09:11:27 +01001761#endif /* SRTP_SRTP_H */