blob: 9b939296477e1fc760feee0cf27b3340a46c3a97 [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
104
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
288typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t;
289typedef struct srtp_ctx_t_ srtp_ctx_t;
jfigus44947602014-10-08 13:08:52 -0400290
Cullen Jennings235513a2005-09-21 22:51:36 +0000291/*
292 * nota bene: since libSRTP doesn't support the use of the MKI, the
293 * SRTP_MAX_TRAILER_LEN value is just the maximum tag length
294 */
295
296/**
jfigus857009c2014-11-05 11:17:43 -0500297 * @brief srtp_sec_serv_t describes a set of security services.
Cullen Jennings235513a2005-09-21 22:51:36 +0000298 *
jfigus857009c2014-11-05 11:17:43 -0500299 * A srtp_sec_serv_t enumeration is used to describe the particular
Cullen Jennings235513a2005-09-21 22:51:36 +0000300 * security services that will be applied by a particular crypto
301 * policy (or other mechanism).
302 */
303
304typedef enum {
305 sec_serv_none = 0, /**< no services */
306 sec_serv_conf = 1, /**< confidentiality */
307 sec_serv_auth = 2, /**< authentication */
308 sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */
jfigus857009c2014-11-05 11:17:43 -0500309} srtp_sec_serv_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000310
311/**
jfigus857009c2014-11-05 11:17:43 -0500312 * @brief srtp_crypto_policy_t describes a particular crypto policy that
Cullen Jennings235513a2005-09-21 22:51:36 +0000313 * can be applied to an SRTP stream.
314 *
jfigus857009c2014-11-05 11:17:43 -0500315 * A srtp_crypto_policy_t describes a particular cryptographic policy that
Cullen Jennings235513a2005-09-21 22:51:36 +0000316 * can be applied to an SRTP or SRTCP stream. An SRTP session policy
317 * consists of a list of these policies, one for each SRTP stream
318 * in the session.
319 */
320
jfigus857009c2014-11-05 11:17:43 -0500321typedef struct srtp_crypto_policy_t {
322 srtp_cipher_type_id_t cipher_type; /**< An integer representing
323 * the type of cipher. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000324 int cipher_key_len; /**< The length of the cipher key
325 * in octets. */
jfigus857009c2014-11-05 11:17:43 -0500326 srtp_auth_type_id_t auth_type; /**< An integer representing the
327 * authentication function. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000328 int auth_key_len; /**< The length of the authentication
329 * function key in octets. */
330 int auth_tag_len; /**< The length of the authentication
331 * tag in octets. */
jfigus857009c2014-11-05 11:17:43 -0500332 srtp_sec_serv_t sec_serv; /**< The flag indicating the security
Cullen Jennings235513a2005-09-21 22:51:36 +0000333 * services to be applied. */
jfigus857009c2014-11-05 11:17:43 -0500334} srtp_crypto_policy_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000335
336
337/**
jfigus857009c2014-11-05 11:17:43 -0500338 * @brief srtp_ssrc_type_t describes the type of an SSRC.
Cullen Jennings235513a2005-09-21 22:51:36 +0000339 *
jfigus857009c2014-11-05 11:17:43 -0500340 * An srtp_ssrc_type_t enumeration is used to indicate a type of SSRC. See
Cullen Jennings235513a2005-09-21 22:51:36 +0000341 * @ref srtp_policy_t for more informataion.
342 */
343
344typedef enum {
345 ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */
346 ssrc_specific = 1, /**< Indicates a specific SSRC value */
347 ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value
348 (i.e. a value that is used in the
349 function srtp_unprotect()) */
350 ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value
351 (i.e. a value that is used in the
352 function srtp_protect()) */
jfigus857009c2014-11-05 11:17:43 -0500353} srtp_ssrc_type_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000354
355/**
jfigus857009c2014-11-05 11:17:43 -0500356 * @brief An srtp_ssrc_t represents a particular SSRC value, or a `wildcard' SSRC.
Cullen Jennings235513a2005-09-21 22:51:36 +0000357 *
jfigus857009c2014-11-05 11:17:43 -0500358 * An srtp_ssrc_t represents a particular SSRC value (if its type is
Cullen Jennings235513a2005-09-21 22:51:36 +0000359 * ssrc_specific), or a wildcard SSRC value that will match all
360 * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound
361 * SSRCs (if its type is ssrc_any_inbound).
362 *
363 */
364
365typedef struct {
jfigus857009c2014-11-05 11:17:43 -0500366 srtp_ssrc_type_t type; /**< The type of this particular SSRC */
367 unsigned int value; /**< The value of this SSRC, if it is not a wildcard */
368} srtp_ssrc_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000369
370
David McGrew79870d62007-06-15 18:17:39 +0000371/**
372 * @brief points to an EKT policy
373 */
jfigusc5887e72014-11-06 09:46:18 -0500374typedef struct srtp_ekt_policy_ctx_t *srtp_ekt_policy_t;
David McGrew79870d62007-06-15 18:17:39 +0000375
376
377/**
378 * @brief points to EKT stream data
379 */
jfigusc5887e72014-11-06 09:46:18 -0500380typedef struct srtp_ekt_stream_ctx_t *srtp_ekt_stream_t;
David McGrew79870d62007-06-15 18:17:39 +0000381
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500382/**
383 * @brief srtp_master_key_t represents a master key. There will
384 * be a Master Key Index and the Master Key associated with the
385 * Master Key Index. Need to also keep track of the Master Key
386 * Index Size to correctly read it from a packet.
387 */
388typedef struct srtp_master_key_t {
389 unsigned char *key;
390 unsigned char *mki_id;
391 unsigned int mki_size;
392} srtp_master_key_t;
David McGrew79870d62007-06-15 18:17:39 +0000393
Cullen Jennings235513a2005-09-21 22:51:36 +0000394/**
395 * @brief represents the policy for an SRTP session.
396 *
397 * A single srtp_policy_t struct represents the policy for a single
398 * SRTP stream, and a linked list of these elements represents the
399 * policy for an entire SRTP session. Each element contains the SRTP
400 * and SRTCP crypto policies for that stream, a pointer to the SRTP
401 * master key for that stream, the SSRC describing that stream, or a
402 * flag indicating a `wildcard' SSRC value, and a `next' field that
403 * holds a pointer to the next element in the list of policy elements,
404 * or NULL if it is the last element.
405 *
406 * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an
407 * inbound stream that for which there is no explicit SSRC entry in
408 * another policy element. Similarly, the value SSRC_ANY_OUTBOUND
409 * will matches any SSRC from an outbound stream that does not appear
410 * in another policy element. Note that wildcard SSRCs &b cannot be
411 * used to match both inbound and outbound traffic. This restriction
412 * is intentional, and it allows libSRTP to ensure that no security
413 * lapses result from accidental re-use of SSRC values during key
414 * sharing.
415 *
416 *
417 * @warning The final element of the list @b must have its `next' pointer
418 * set to NULL.
419 */
420
421typedef struct srtp_policy_t {
jfigus857009c2014-11-05 11:17:43 -0500422 srtp_ssrc_t ssrc; /**< The SSRC value of stream, or the
Cullen Jennings235513a2005-09-21 22:51:36 +0000423 * flags SSRC_ANY_INBOUND or
424 * SSRC_ANY_OUTBOUND if key sharing
425 * is used for this policy element.
426 */
jfigus857009c2014-11-05 11:17:43 -0500427 srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */
428 srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */
Ryan Hooper89a288b2016-12-22 16:22:47 -0500429 unsigned char *key; /**< Pointer to the SRTP master key for
430 * this stream. */
431 srtp_master_key_t **keys; /** Array of Master Key structures */
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500432 unsigned long num_master_keys; /** Number of master keys */
jfigusc5887e72014-11-06 09:46:18 -0500433 srtp_ekt_policy_t ekt; /**< Pointer to the EKT policy structure
David McGrew79870d62007-06-15 18:17:39 +0000434 * for this stream (if any) */
Jonathan Lennoxa1242f82010-05-17 21:46:04 +0000435 unsigned long window_size; /**< The window size to use for replay
436 * protection. */
Jonathan Lennoxdcee5c62010-05-17 22:08:40 +0000437 int allow_repeat_tx; /**< Whether retransmissions of
438 * packets with the same sequence number
439 * are allowed. (Note that such repeated
440 * transmissions must have the same RTP
441 * payload, or a severe security weakness
442 * is introduced!) */
Joachim Bauch99a74822015-11-17 00:08:19 +0100443 int *enc_xtn_hdr; /**< List of header ids to encrypt. */
444 int enc_xtn_hdr_count; /**< Number of entries in list of header ids. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000445 struct srtp_policy_t *next; /**< Pointer to next stream policy. */
446} srtp_policy_t;
447
448
449
450
451/**
452 * @brief An srtp_t points to an SRTP session structure.
453 *
454 * The typedef srtp_t is a pointer to a structure that represents
455 * an SRTP session. This datatype is intentially opaque in
456 * order to separate the interface from the implementation.
457 *
458 * An SRTP session consists of all of the traffic sent to the RTP and
459 * RTCP destination transport addresses, using the RTP/SAVP (Secure
460 * Audio/Video Profile). A session can be viewed as a set of SRTP
461 * streams, each of which originates with a different participant.
462 */
463
jfigusa9ac8982014-10-31 14:49:31 -0400464typedef srtp_ctx_t *srtp_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000465
466
467/**
468 * @brief An srtp_stream_t points to an SRTP stream structure.
469 *
470 * The typedef srtp_stream_t is a pointer to a structure that
471 * represents an SRTP stream. This datatype is intentionally
472 * opaque in order to separate the interface from the implementation.
473 *
474 * An SRTP stream consists of all of the traffic sent to an SRTP
475 * session by a single participant. A session can be viewed as
476 * a set of streams.
477 *
478 */
jfigusa9ac8982014-10-31 14:49:31 -0400479typedef srtp_stream_ctx_t *srtp_stream_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000480
481
482
483/**
484 * @brief srtp_init() initializes the srtp library.
485 *
486 * @warning This function @b must be called before any other srtp
487 * functions.
488 */
489
jfigus857009c2014-11-05 11:17:43 -0500490srtp_err_status_t srtp_init(void);
Cullen Jennings235513a2005-09-21 22:51:36 +0000491
492/**
Jonathan Lennox5ae76332010-05-15 04:48:59 +0000493 * @brief srtp_shutdown() de-initializes the srtp library.
494 *
495 * @warning No srtp functions may be called after calling this function.
496 */
497
jfigus857009c2014-11-05 11:17:43 -0500498srtp_err_status_t srtp_shutdown(void);
Jonathan Lennox5ae76332010-05-15 04:48:59 +0000499
500/**
Cullen Jennings235513a2005-09-21 22:51:36 +0000501 * @brief srtp_protect() is the Secure RTP sender-side packet processing
502 * function.
503 *
504 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
505 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
jfigus857009c2014-11-05 11:17:43 -0500506 * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
Cullen Jennings235513a2005-09-21 22:51:36 +0000507 * points to the resulting SRTP packet and *len_ptr is the number of
508 * octets in that packet; otherwise, no assumptions should be made
509 * about the value of either data elements.
510 *
511 * The sequence numbers of the RTP packets presented to this function
512 * need not be consecutive, but they @b must be out of order by less
513 * than 2^15 = 32,768 packets.
514 *
515 * @warning This function assumes that it can write the authentication
516 * tag into the location in memory immediately following the RTP
517 * packet, and assumes that the RTP packet is aligned on a 32-bit
518 * boundary.
519 *
jfigusdfe68ea2013-05-28 09:00:14 -0400520 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
521 * into the location in memory immediately following the RTP packet.
522 * Callers MUST ensure that this much writable memory is available in
523 * the buffer that holds the RTP packet.
jfigus5e337292013-05-28 13:57:47 -0400524 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000525 * @param ctx is the SRTP context to use in processing the packet.
526 *
527 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
528 * the function returns, it points to the srtp packet.
529 *
530 * @param len_ptr is a pointer to the length in octets of the complete
531 * RTP packet (header and body) before the function call, and of the
jfigus857009c2014-11-05 11:17:43 -0500532 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
Cullen Jennings235513a2005-09-21 22:51:36 +0000533 * Otherwise, the value of the data to which it points is undefined.
534 *
535 * @return
jfigus857009c2014-11-05 11:17:43 -0500536 * - srtp_err_status_ok no problems
537 * - srtp_err_status_replay_fail rtp sequence number was non-increasing
Cullen Jennings235513a2005-09-21 22:51:36 +0000538 * - @e other failure in cryptographic mechanisms
539 */
540
jfigus857009c2014-11-05 11:17:43 -0500541srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500542
543/**
544 * @brief srtp_protect_mki() is the Secure RTP sender-side packet processing
545 * function that can utilize MKI.
546 *
547 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
548 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
549 * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
550 * points to the resulting SRTP packet and *len_ptr is the number of
551 * octets in that packet; otherwise, no assumptions should be made
552 * about the value of either data elements.
553 *
554 * The sequence numbers of the RTP packets presented to this function
555 * need not be consecutive, but they @b must be out of order by less
556 * than 2^15 = 32,768 packets.
557 *
558 * @warning This function assumes that it can write the authentication
559 * tag into the location in memory immediately following the RTP
560 * packet, and assumes that the RTP packet is aligned on a 32-bit
561 * boundary.
562 *
563 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
564 * into the location in memory immediately following the RTP packet.
565 * Callers MUST ensure that this much writable memory is available in
566 * the buffer that holds the RTP packet.
567 *
568 * @param ctx is the SRTP context to use in processing the packet.
569 *
570 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
571 * the function returns, it points to the srtp packet.
572 *
573 * @param len_ptr is a pointer to the length in octets of the complete
574 * RTP packet (header and body) before the function call, and of the
575 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
576 * Otherwise, the value of the data to which it points is undefined.
577 *
578 * @param use_mki is a boolean to tell the system if mki is being used. If
579 * set to false then will use the first set of session keys. If set to true will
580 * use the session keys identified by the mki_index
581 *
582 * @param mki_index integer value specifying which set of session kesy should be
583 * used if use_mki is set to true.
584 *
585 * @return
586 * - srtp_err_status_ok no problems
587 * - srtp_err_status_replay_fail rtp sequence number was non-increasing
588 * - @e other failure in cryptographic mechanisms
589 */
590
Geir Istad626e9e82017-02-20 18:15:05 +0100591srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx, void *rtp_hdr,
592 int *pkt_octet_len, unsigned int use_mki,
593 unsigned int mki_index);
594
Cullen Jennings235513a2005-09-21 22:51:36 +0000595/**
596 * @brief srtp_unprotect() is the Secure RTP receiver-side packet
597 * processing function.
598 *
599 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
600 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
601 * (which has length *len_ptr), using the SRTP context ctx. If
jfigus857009c2014-11-05 11:17:43 -0500602 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
Cullen Jennings235513a2005-09-21 22:51:36 +0000603 * RTP packet and *len_ptr is the number of octets in that packet;
604 * otherwise, no assumptions should be made about the value of either
605 * data elements.
606 *
607 * The sequence numbers of the RTP packets presented to this function
608 * need not be consecutive, but they @b must be out of order by less
609 * than 2^15 = 32,768 packets.
610 *
611 * @warning This function assumes that the SRTP packet is aligned on a
612 * 32-bit boundary.
613 *
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +0200614 * @param ctx is the SRTP session which applies to the particular packet.
Cullen Jennings235513a2005-09-21 22:51:36 +0000615 *
616 * @param srtp_hdr is a pointer to the header of the SRTP packet
617 * (before the call). after the function returns, it points to the
jfigus857009c2014-11-05 11:17:43 -0500618 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
Cullen Jennings235513a2005-09-21 22:51:36 +0000619 * the data to which it points is undefined.
620 *
621 * @param len_ptr is a pointer to the length in octets of the complete
622 * srtp packet (header and body) before the function call, and of the
jfigus857009c2014-11-05 11:17:43 -0500623 * complete rtp packet after the call, if srtp_err_status_ok was returned.
Cullen Jennings235513a2005-09-21 22:51:36 +0000624 * Otherwise, the value of the data to which it points is undefined.
625 *
626 * @return
jfigus857009c2014-11-05 11:17:43 -0500627 * - srtp_err_status_ok if the RTP packet is valid.
628 * - srtp_err_status_auth_fail if the SRTP packet failed the message
Cullen Jennings235513a2005-09-21 22:51:36 +0000629 * authentication check.
jfigus857009c2014-11-05 11:17:43 -0500630 * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet has
Cullen Jennings235513a2005-09-21 22:51:36 +0000631 * already been processed and accepted).
632 * - [other] if there has been an error in the cryptographic mechanisms.
633 *
634 */
635
jfigus857009c2014-11-05 11:17:43 -0500636srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
Cullen Jennings235513a2005-09-21 22:51:36 +0000637
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500638/**
639 * @brief srtp_unprotect_mki() is the Secure RTP receiver-side packet
640 * processing function that checks for MKI.
641 *
642 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
643 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
644 * (which has length *len_ptr), using the SRTP context ctx. If
645 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
646 * RTP packet and *len_ptr is the number of octets in that packet;
647 * otherwise, no assumptions should be made about the value of either
648 * data elements.
649 *
650 * The sequence numbers of the RTP packets presented to this function
651 * need not be consecutive, but they @b must be out of order by less
652 * than 2^15 = 32,768 packets.
653 *
654 * @warning This function assumes that the SRTP packet is aligned on a
655 * 32-bit boundary.
656 *
657 * @param ctx is the SRTP session which applies to the particular packet.
658 *
659 * @param srtp_hdr is a pointer to the header of the SRTP packet
660 * (before the call). after the function returns, it points to the
661 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
662 * the data to which it points is undefined.
663 *
664 * @param len_ptr is a pointer to the length in octets of the complete
665 * srtp packet (header and body) before the function call, and of the
666 * complete rtp packet after the call, if srtp_err_status_ok was returned.
667 * Otherwise, the value of the data to which it points is undefined.
668 *
669 * @return
670 * - srtp_err_status_ok if the RTP packet is valid.
671 * - srtp_err_status_auth_fail if the SRTP packet failed the message
672 * authentication check.
673 * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet has
674 * already been processed and accepted).
675 * - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI id
676 * - [other] if there has been an error in the cryptographic mechanisms.
677 *
678 */
679
Geir Istad626e9e82017-02-20 18:15:05 +0100680srtp_err_status_t srtp_unprotect_mki(srtp_t ctx, void *srtp_hdr, int *len_ptr,
681 unsigned int use_mki);
Cullen Jennings235513a2005-09-21 22:51:36 +0000682
683/**
684 * @brief srtp_create() allocates and initializes an SRTP session.
685
jfigus92c3de32016-02-02 13:44:39 -0500686 * The function call srtp_create(session, policy) allocates and
687 * initializes an SRTP session context, applying the given policy.
Cullen Jennings235513a2005-09-21 22:51:36 +0000688 *
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +0200689 * @param session is a pointer to the SRTP session to which the policy is
690 * to be added.
Cullen Jennings235513a2005-09-21 22:51:36 +0000691 *
692 * @param policy is the srtp_policy_t struct that describes the policy
693 * for the session. The struct may be a single element, or it may be
694 * the head of a list, in which case each element of the list is
Marcus Sundberg75d92122005-10-05 12:40:31 +0000695 * processed. It may also be NULL, in which case streams should be added
696 * later using srtp_add_stream(). The final element of the list @b must
697 * have its `next' field set to NULL.
Cullen Jennings235513a2005-09-21 22:51:36 +0000698 *
699 * @return
jfigus857009c2014-11-05 11:17:43 -0500700 * - srtp_err_status_ok if creation succeded.
701 * - srtp_err_status_alloc_fail if allocation failed.
702 * - srtp_err_status_init_fail if initialization failed.
Cullen Jennings235513a2005-09-21 22:51:36 +0000703 */
704
jfigus857009c2014-11-05 11:17:43 -0500705srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000706
707
708/**
709 * @brief srtp_add_stream() allocates and initializes an SRTP stream
710 * within a given SRTP session.
711 *
712 * The function call srtp_add_stream(session, policy) allocates and
713 * initializes a new SRTP stream within a given, previously created
714 * session, applying the policy given as the other argument to that
715 * stream.
716 *
717 * @return values:
jfigus857009c2014-11-05 11:17:43 -0500718 * - srtp_err_status_ok if stream creation succeded.
719 * - srtp_err_status_alloc_fail if stream allocation failed
720 * - srtp_err_status_init_fail if stream initialization failed.
Cullen Jennings235513a2005-09-21 22:51:36 +0000721 */
722
jfigus857009c2014-11-05 11:17:43 -0500723srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000724
725
726/**
727 * @brief srtp_remove_stream() deallocates an SRTP stream.
728 *
729 * The function call srtp_remove_stream(session, ssrc) removes
730 * the SRTP stream with the SSRC value ssrc from the SRTP session
731 * context given by the argument session.
732 *
733 * @param session is the SRTP session from which the stream
734 * will be removed.
735 *
jfigus68f8a882016-02-03 12:48:23 -0500736 * @param ssrc is the SSRC value of the stream to be removed
737 * in network byte order.
Cullen Jennings235513a2005-09-21 22:51:36 +0000738 *
739 * @warning Wildcard SSRC values cannot be removed from a
740 * session.
741 *
742 * @return
jfigus857009c2014-11-05 11:17:43 -0500743 * - srtp_err_status_ok if the stream deallocation succeded.
Cullen Jennings235513a2005-09-21 22:51:36 +0000744 * - [other] otherwise.
745 *
746 */
747
jfigus857009c2014-11-05 11:17:43 -0500748srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc);
Cullen Jennings235513a2005-09-21 22:51:36 +0000749
750/**
Pascal Bühlerbd3112a2015-11-06 20:29:15 +0100751 * @brief srtp_update() udpates all streams in the session.
752 *
753 * The function call srtp_update(session, policy) updates
754 * all the streams in the session applying the given policy
755 * and key. The exsisting ROC value of all streams will be
756 * preserved.
757 *
758 * @param session is the SRTP session that contains the streams
759 * to be updated.
760 *
761 * @param policy is the srtp_policy_t struct that describes the policy
762 * for the session. The struct may be a single element, or it may be
763 * the head of a list, in which case each element of the list is
764 * processed. The final element of the list @b must
765 * have its `next' field set to NULL.
766 *
767 * @return
768 * - srtp_err_status_ok if stream creation succeded.
769 * - srtp_err_status_alloc_fail if stream allocation failed
770 * - srtp_err_status_init_fail if stream initialization failed.
771 * - [other] otherwise.
772 *
773 */
774
775srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy);
776
777/**
778 * @brief srtp_update_stream() udpates a SRTP stream.
779 *
780 * The function call srtp_update_stream(session, policy) updates
781 * the stream(s) in the session that match applying the given
782 * policy and key. The exsisting ROC value of all stream(s) will
783 * be preserved.
784 *
785 * @param session is the SRTP session that contains the streams
786 * to be updated.
787 *
788 * @param policy is the srtp_policy_t struct that describes the policy
789 * for the session.
790 *
791 * @return
792 * - srtp_err_status_ok if stream creation succeded.
793 * - srtp_err_status_alloc_fail if stream allocation failed
794 * - srtp_err_status_init_fail if stream initialization failed.
795 * - [other] otherwise.
796 *
797 */
798
799srtp_err_status_t srtp_update_stream(srtp_t session, const srtp_policy_t *policy);
800
801/**
jfigus857009c2014-11-05 11:17:43 -0500802 * @brief srtp_crypto_policy_set_rtp_default() sets a crypto policy
Cullen Jennings235513a2005-09-21 22:51:36 +0000803 * structure to the SRTP default policy for RTP 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 *
807 * The function call crypto_policy_set_rtp_default(&p) sets the
808 * crypto_policy_t at location p to the SRTP default policy for RTP
809 * 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
814 * elements in the crypto_policy_t datatype.
815 *
816 * @return void.
817 *
818 */
819
jfigus857009c2014-11-05 11:17:43 -0500820void srtp_crypto_policy_set_rtp_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_rtcp_default() sets a crypto policy
Cullen Jennings235513a2005-09-21 22:51:36 +0000824 * structure to the SRTP default policy for RTCP protection.
825 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000826 * @param p is a pointer to the policy structure to be set
Cullen Jennings235513a2005-09-21 22:51:36 +0000827 *
jfigus857009c2014-11-05 11:17:43 -0500828 * The function call srtp_crypto_policy_set_rtcp_default(&p) sets the
829 * srtp_crypto_policy_t at location p to the SRTP default policy for RTCP
Cullen Jennings235513a2005-09-21 22:51:36 +0000830 * protection, as defined in the specification. This function is a
831 * convenience that helps to avoid dealing directly with the policy
832 * data structure. You are encouraged to initialize policy elements
833 * with this function call. Doing so may allow your code to be
834 * forward compatible with later versions of libSRTP that include more
jfigus857009c2014-11-05 11:17:43 -0500835 * elements in the srtp_crypto_policy_t datatype.
Cullen Jennings235513a2005-09-21 22:51:36 +0000836 *
837 * @return void.
838 *
839 */
840
jfigus857009c2014-11-05 11:17:43 -0500841void srtp_crypto_policy_set_rtcp_default(srtp_crypto_policy_t *p);
Cullen Jennings235513a2005-09-21 22:51:36 +0000842
843/**
jfigus857009c2014-11-05 11:17:43 -0500844 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000845 * policy structure to the SRTP default policy for RTP protection.
846 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000847 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000848 *
jfigus857009c2014-11-05 11:17:43 -0500849 * The function srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
850 * synonym for srtp_crypto_policy_set_rtp_default(). It conforms to the
Jonathan Lennoxd8d5cd02010-05-17 20:08:17 +0000851 * naming convention used in RFC 4568 (SDP Security Descriptions for
852 * Media Streams).
David McGrewa8546882006-01-12 17:56:02 +0000853 *
854 * @return void.
855 *
856 */
857
jfigus857009c2014-11-05 11:17:43 -0500858#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 +0000859
860
861/**
jfigus857009c2014-11-05 11:17:43 -0500862 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000863 * policy structure to a short-authentication tag policy
864 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000865 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000866 *
jfigus857009c2014-11-05 11:17:43 -0500867 * The function call srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
868 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennoxd8d5cd02010-05-17 20:08:17 +0000869 * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568.
870 * This policy uses AES-128
David McGrewa8546882006-01-12 17:56:02 +0000871 * Counter Mode encryption and HMAC-SHA1 authentication, with an
872 * authentication tag that is only 32 bits long. This length is
873 * considered adequate only for protecting audio and video media that
874 * use a stateless playback function. See Section 7.5 of RFC 3711
875 * (http://www.ietf.org/rfc/rfc3711.txt).
876 *
877 * This function is a convenience that helps to avoid dealing directly
878 * with the policy data structure. You are encouraged to initialize
879 * policy elements with this function call. Doing so may allow your
880 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500881 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000882 *
883 * @warning This crypto policy is intended for use in SRTP, but not in
884 * SRTCP. It is recommended that a policy that uses longer
885 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
886 * (http://www.ietf.org/rfc/rfc3711.txt).
887 *
888 * @return void.
889 *
890 */
891
jfigus857009c2014-11-05 11:17:43 -0500892void srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000893
894
895
896/**
jfigus857009c2014-11-05 11:17:43 -0500897 * @brief srtp_crypto_policy_set_aes_cm_128_null_auth() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000898 * policy structure to an encryption-only policy
899 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000900 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000901 *
jfigus857009c2014-11-05 11:17:43 -0500902 * The function call srtp_crypto_policy_set_aes_cm_128_null_auth(&p) sets
903 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
David McGrewa8546882006-01-12 17:56:02 +0000904 * (AES-128 Counter Mode), but to use no authentication method. This
905 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
906 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
907 *
908 * This function is a convenience that helps to avoid dealing directly
909 * with the policy data structure. You are encouraged to initialize
910 * policy elements with this function call. Doing so may allow your
911 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500912 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000913 *
914 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
915 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
916 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
917 *
918 * @return void.
919 *
920 */
921
jfigus857009c2014-11-05 11:17:43 -0500922void srtp_crypto_policy_set_aes_cm_128_null_auth(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000923
924
925/**
jfigus857009c2014-11-05 11:17:43 -0500926 * @brief srtp_crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000927 * policy structure to an authentication-only policy
928 *
David McGrewc4fc00b2006-06-08 18:51:27 +0000929 * @param p is a pointer to the policy structure to be set
David McGrewa8546882006-01-12 17:56:02 +0000930 *
jfigus857009c2014-11-05 11:17:43 -0500931 * The function call srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&p)
932 * sets the srtp_crypto_policy_t at location p to use HMAC-SHA1 with an 80
David McGrewa8546882006-01-12 17:56:02 +0000933 * bit authentication tag to provide message authentication, but to
934 * use no encryption. This policy is NOT RECOMMENDED for SRTP unless
935 * there is a requirement to forego encryption.
936 *
937 * This function is a convenience that helps to avoid dealing directly
938 * with the policy data structure. You are encouraged to initialize
939 * policy elements with this function call. Doing so may allow your
940 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500941 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000942 *
943 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
944 * requirement to forego encryption.
945 *
946 * @return void.
947 *
948 */
jfigus857009c2014-11-05 11:17:43 -0500949void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000950
jfigus267956d2014-11-06 10:49:21 -0500951/**
952 * @brief srtp_crypto_policy_set_null_cipher_hmac_null() sets a crypto
953 * policy structure to use no encryption or authentication.
954 *
955 * @param p is a pointer to the policy structure to be set
956 *
957 * The function call srtp_crypto_policy_set_null_cipher_hmac_null(&p)
958 * sets the srtp_crypto_policy_t at location p to use no encryption and
959 * no authentication. This policy should only be used for testing and
960 * troubleshootingl.
961 *
962 * This function is a convenience that helps to avoid dealing directly
963 * with the policy data structure. You are encouraged to initialize
964 * policy elements with this function call. Doing so may allow your
965 * code to be forward compatible with later versions of libSRTP that
966 * include more elements in the srtp_crypto_policy_t datatype.
967 *
968 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
969 * requirement to forego encryption and authentication.
970 *
971 * @return void.
972 *
973 */
974void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p);
975
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000976
977/**
jfigus857009c2014-11-05 11:17:43 -0500978 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000979 * policy structure to a encryption and authentication policy using AES-256
980 * for RTP protection.
981 *
982 * @param p is a pointer to the policy structure to be set
983 *
jfigus857009c2014-11-05 11:17:43 -0500984 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&p)
985 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000986 * AES_CM_256_HMAC_SHA1_80 as defined in
987 * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
988 * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
989 * authentication tag.
990 *
991 * This function is a convenience that helps to avoid dealing directly
992 * with the policy data structure. You are encouraged to initialize
993 * policy elements with this function call. Doing so may allow your
994 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500995 * include more elements in the srtp_crypto_policy_t datatype.
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000996 *
997 * @return void.
998 *
999 */
1000
jfigus857009c2014-11-05 11:17:43 -05001001void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(srtp_crypto_policy_t *p);
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001002
1003
1004/**
jfigus857009c2014-11-05 11:17:43 -05001005 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001006 * policy structure to a short-authentication tag policy using AES-256
1007 * encryption.
1008 *
1009 * @param p is a pointer to the policy structure to be set
1010 *
jfigus857009c2014-11-05 11:17:43 -05001011 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&p)
1012 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001013 * AES_CM_256_HMAC_SHA1_32 as defined in
1014 * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
1015 * Counter Mode encryption and HMAC-SHA1 authentication, with an
1016 * authentication tag that is only 32 bits long. This length is
1017 * considered adequate only for protecting audio and video media that
1018 * use a stateless playback function. See Section 7.5 of RFC 3711
1019 * (http://www.ietf.org/rfc/rfc3711.txt).
1020 *
1021 * This function is a convenience that helps to avoid dealing directly
1022 * with the policy data structure. You are encouraged to initialize
1023 * policy elements with this function call. Doing so may allow your
1024 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001025 * include more elements in the srtp_crypto_policy_t datatype.
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001026 *
1027 * @warning This crypto policy is intended for use in SRTP, but not in
1028 * SRTCP. It is recommended that a policy that uses longer
1029 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
1030 * (http://www.ietf.org/rfc/rfc3711.txt).
1031 *
1032 * @return void.
1033 *
1034 */
1035
jfigus857009c2014-11-05 11:17:43 -05001036void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(srtp_crypto_policy_t *p);
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001037
jfigus8c36da22013-10-01 16:41:19 -04001038/**
jfigus857009c2014-11-05 11:17:43 -05001039 * @brief srtp_crypto_policy_set_aes_cm_256_null_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001040 * policy structure to an encryption-only policy
1041 *
1042 * @param p is a pointer to the policy structure to be set
1043 *
jfigus857009c2014-11-05 11:17:43 -05001044 * The function call srtp_crypto_policy_set_aes_cm_256_null_auth(&p) sets
1045 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001046 * (AES-256 Counter Mode), but to use no authentication method. This
1047 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
1048 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
1049 *
1050 * This function is a convenience that helps to avoid dealing directly
1051 * with the policy data structure. You are encouraged to initialize
1052 * policy elements with this function call. Doing so may allow your
1053 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001054 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001055 *
1056 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
1057 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
1058 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
1059 *
1060 * @return void.
1061 *
1062 */
jfigus857009c2014-11-05 11:17:43 -05001063void srtp_crypto_policy_set_aes_cm_256_null_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001064
1065/**
jfigus857009c2014-11-05 11:17:43 -05001066 * @brief srtp_crypto_policy_set_aes_gcm_128_8_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001067 * policy structure to an AEAD encryption policy.
1068 *
1069 * @param p is a pointer to the policy structure to be set
1070 *
jfigus857009c2014-11-05 11:17:43 -05001071 * The function call srtp_crypto_policy_set_aes_gcm_128_8_auth(&p) sets
1072 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001073 * (AES-128 Galois Counter Mode) with 8 octet auth tag. This
1074 * policy applies confidentiality and authentication to both the
1075 * RTP and RTCP packets.
1076 *
1077 * This function is a convenience that helps to avoid dealing directly
1078 * with the policy data structure. You are encouraged to initialize
1079 * policy elements with this function call. Doing so may allow your
1080 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001081 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001082 *
1083 * @return void.
1084 *
1085 */
jfigus857009c2014-11-05 11:17:43 -05001086void srtp_crypto_policy_set_aes_gcm_128_8_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001087
1088/**
jfigus857009c2014-11-05 11:17:43 -05001089 * @brief srtp_crypto_policy_set_aes_gcm_256_8_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001090 * policy structure to an AEAD encryption policy
1091 *
1092 * @param p is a pointer to the policy structure to be set
1093 *
jfigus857009c2014-11-05 11:17:43 -05001094 * The function call srtp_crypto_policy_set_aes_gcm_256_8_auth(&p) sets
1095 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001096 * (AES-256 Galois Counter Mode) with 8 octet auth tag. This
1097 * policy applies confidentiality and authentication to both the
1098 * RTP and RTCP packets.
1099 *
1100 * This function is a convenience that helps to avoid dealing directly
1101 * with the policy data structure. You are encouraged to initialize
1102 * policy elements with this function call. Doing so may allow your
1103 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001104 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001105 *
1106 * @return void.
1107 *
1108 */
jfigus857009c2014-11-05 11:17:43 -05001109void srtp_crypto_policy_set_aes_gcm_256_8_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001110
1111/**
jfigus857009c2014-11-05 11:17:43 -05001112 * @brief srtp_crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001113 * policy structure to an AEAD authentication-only policy
1114 *
1115 * @param p is a pointer to the policy structure to be set
1116 *
jfigus857009c2014-11-05 11:17:43 -05001117 * The function call srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets
1118 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001119 * (AES-128 Galois Counter Mode) with 8 octet auth tag. This policy
1120 * applies confidentiality and authentication to the RTP packets,
1121 * but only authentication to the RTCP packets.
1122 *
1123 * This function is a convenience that helps to avoid dealing directly
1124 * with the policy data structure. You are encouraged to initialize
1125 * policy elements with this function call. Doing so may allow your
1126 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001127 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001128 *
1129 * @return void.
1130 *
1131 */
jfigus857009c2014-11-05 11:17:43 -05001132void srtp_crypto_policy_set_aes_gcm_128_8_only_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001133
1134/**
jfigus857009c2014-11-05 11:17:43 -05001135 * @brief srtp_crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001136 * policy structure to an AEAD authentication-only policy
1137 *
1138 * @param p is a pointer to the policy structure to be set
1139 *
jfigus857009c2014-11-05 11:17:43 -05001140 * The function call srtp_crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets
1141 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001142 * (AES-256 Galois Counter Mode) with 8 octet auth tag. This policy
1143 * applies confidentiality and authentication to the RTP packets,
1144 * but only authentication to the RTCP packets.
1145 *
1146 * This function is a convenience that helps to avoid dealing directly
1147 * with the policy data structure. You are encouraged to initialize
1148 * policy elements with this function call. Doing so may allow your
1149 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001150 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001151 *
1152 * @return void.
1153 *
1154 */
jfigus857009c2014-11-05 11:17:43 -05001155void srtp_crypto_policy_set_aes_gcm_256_8_only_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001156
jfigusc13c1002014-05-08 13:34:53 -04001157/**
jfigus857009c2014-11-05 11:17:43 -05001158 * @brief srtp_crypto_policy_set_aes_gcm_128_16_auth() sets a crypto
jfigusc13c1002014-05-08 13:34:53 -04001159 * policy structure to an AEAD encryption policy.
1160 *
1161 * @param p is a pointer to the policy structure to be set
1162 *
jfigus857009c2014-11-05 11:17:43 -05001163 * The function call srtp_crypto_policy_set_aes_gcm_128_16_auth(&p) sets
1164 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigusc13c1002014-05-08 13:34:53 -04001165 * (AES-128 Galois Counter Mode) with 16 octet auth tag. This
1166 * policy applies confidentiality and authentication to both the
1167 * RTP and RTCP packets.
1168 *
1169 * This function is a convenience that helps to avoid dealing directly
1170 * with the policy data structure. You are encouraged to initialize
1171 * policy elements with this function call. Doing so may allow your
1172 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001173 * include more elements in the srtp_crypto_policy_t datatype.
jfigusc13c1002014-05-08 13:34:53 -04001174 *
1175 * @return void.
1176 *
1177 */
jfigus857009c2014-11-05 11:17:43 -05001178void srtp_crypto_policy_set_aes_gcm_128_16_auth(srtp_crypto_policy_t *p);
jfigusc13c1002014-05-08 13:34:53 -04001179
1180/**
jfigus857009c2014-11-05 11:17:43 -05001181 * @brief srtp_crypto_policy_set_aes_gcm_256_16_auth() sets a crypto
jfigusc13c1002014-05-08 13:34:53 -04001182 * policy structure to an AEAD encryption policy
1183 *
1184 * @param p is a pointer to the policy structure to be set
1185 *
jfigus857009c2014-11-05 11:17:43 -05001186 * The function call srtp_crypto_policy_set_aes_gcm_256_16_auth(&p) sets
1187 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigusc13c1002014-05-08 13:34:53 -04001188 * (AES-256 Galois Counter Mode) with 16 octet auth tag. This
1189 * policy applies confidentiality and authentication to both the
1190 * RTP and RTCP packets.
1191 *
1192 * This function is a convenience that helps to avoid dealing directly
1193 * with the policy data structure. You are encouraged to initialize
1194 * policy elements with this function call. Doing so may allow your
1195 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001196 * include more elements in the srtp_crypto_policy_t datatype.
jfigusc13c1002014-05-08 13:34:53 -04001197 *
1198 * @return void.
1199 *
1200 */
jfigus857009c2014-11-05 11:17:43 -05001201void srtp_crypto_policy_set_aes_gcm_256_16_auth(srtp_crypto_policy_t *p);
jfigusc13c1002014-05-08 13:34:53 -04001202
Jonathan Lennox5df951a2010-05-20 20:55:54 +00001203
David McGrewa8546882006-01-12 17:56:02 +00001204/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001205 * @brief srtp_dealloc() deallocates storage for an SRTP session
1206 * context.
1207 *
1208 * The function call srtp_dealloc(s) deallocates storage for the
1209 * SRTP session context s. This function should be called no more
1210 * than one time for each of the contexts allocated by the function
1211 * srtp_create().
1212 *
1213 * @param s is the srtp_t for the session to be deallocated.
1214 *
1215 * @return
jfigus857009c2014-11-05 11:17:43 -05001216 * - srtp_err_status_ok if there no problems.
1217 * - srtp_err_status_dealloc_fail a memory deallocation failure occured.
Cullen Jennings235513a2005-09-21 22:51:36 +00001218 */
1219
jfigus857009c2014-11-05 11:17:43 -05001220srtp_err_status_t srtp_dealloc(srtp_t s);
Cullen Jennings235513a2005-09-21 22:51:36 +00001221
1222
David McGrew0cb86ee2006-07-07 15:46:57 +00001223/*
1224 * @brief identifies a particular SRTP profile
1225 *
1226 * An srtp_profile_t enumeration is used to identify a particular SRTP
1227 * profile (that is, a set of algorithms and parameters). These
1228 * profiles are defined in the DTLS-SRTP draft.
1229 */
1230
1231typedef enum {
1232 srtp_profile_reserved = 0,
1233 srtp_profile_aes128_cm_sha1_80 = 1,
1234 srtp_profile_aes128_cm_sha1_32 = 2,
1235 srtp_profile_aes256_cm_sha1_80 = 3,
1236 srtp_profile_aes256_cm_sha1_32 = 4,
1237 srtp_profile_null_sha1_80 = 5,
1238 srtp_profile_null_sha1_32 = 6,
1239} srtp_profile_t;
1240
1241
1242/**
jfigus857009c2014-11-05 11:17:43 -05001243 * @brief srtp_crypto_policy_set_from_profile_for_rtp() sets a crypto policy
David McGrew0cb86ee2006-07-07 15:46:57 +00001244 * structure to the appropriate value for RTP based on an srtp_profile_t
1245 *
1246 * @param p is a pointer to the policy structure to be set
1247 *
jfigus857009c2014-11-05 11:17:43 -05001248 * The function call srtp_crypto_policy_set_rtp_default(&policy, profile)
1249 * sets the srtp_crypto_policy_t at location policy to the policy for RTP
David McGrew0cb86ee2006-07-07 15:46:57 +00001250 * protection, as defined by the srtp_profile_t profile.
1251 *
1252 * This function is a convenience that helps to avoid dealing directly
1253 * with the policy data structure. You are encouraged to initialize
1254 * policy elements with this function call. Doing so may allow your
1255 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001256 * include more elements in the srtp_crypto_policy_t datatype.
David McGrew0cb86ee2006-07-07 15:46:57 +00001257 *
1258 * @return values
jfigus857009c2014-11-05 11:17:43 -05001259 * - srtp_err_status_ok no problems were encountered
1260 * - srtp_err_status_bad_param the profile is not supported
David McGrew0cb86ee2006-07-07 15:46:57 +00001261 *
1262 */
jfigus857009c2014-11-05 11:17:43 -05001263srtp_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 +00001264
1265
1266
1267
1268/**
jfigus857009c2014-11-05 11:17:43 -05001269 * @brief srtp_crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
David McGrew0cb86ee2006-07-07 15:46:57 +00001270 * structure to the appropriate value for RTCP based on an srtp_profile_t
1271 *
1272 * @param p is a pointer to the policy structure to be set
1273 *
jfigus857009c2014-11-05 11:17:43 -05001274 * The function call srtp_crypto_policy_set_rtcp_default(&policy, profile)
1275 * sets the srtp_crypto_policy_t at location policy to the policy for RTCP
David McGrew0cb86ee2006-07-07 15:46:57 +00001276 * protection, as defined by the srtp_profile_t profile.
1277 *
1278 * This function is a convenience that helps to avoid dealing directly
1279 * with the policy data structure. You are encouraged to initialize
1280 * policy elements with this function call. Doing so may allow your
1281 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001282 * include more elements in the srtp_crypto_policy_t datatype.
David McGrew0cb86ee2006-07-07 15:46:57 +00001283 *
1284 * @return values
jfigus857009c2014-11-05 11:17:43 -05001285 * - srtp_err_status_ok no problems were encountered
1286 * - srtp_err_status_bad_param the profile is not supported
David McGrew0cb86ee2006-07-07 15:46:57 +00001287 *
1288 */
jfigus857009c2014-11-05 11:17:43 -05001289srtp_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 +00001290
1291/**
1292 * @brief returns the master key length for a given SRTP profile
1293 */
1294unsigned int
1295srtp_profile_get_master_key_length(srtp_profile_t profile);
1296
1297
1298/**
1299 * @brief returns the master salt length for a given SRTP profile
1300 */
1301unsigned int
1302srtp_profile_get_master_salt_length(srtp_profile_t profile);
1303
1304/**
1305 * @brief appends the salt to the key
1306 *
jfigus857009c2014-11-05 11:17:43 -05001307 * The function call srtp_append_salt_to_key(k, klen, s, slen)
David McGrew0cb86ee2006-07-07 15:46:57 +00001308 * copies the string s to the location at klen bytes following
1309 * the location k.
1310 *
1311 * @warning There must be at least bytes_in_salt + bytes_in_key bytes
1312 * available at the location pointed to by key.
1313 *
1314 */
1315
1316void
jfigus857009c2014-11-05 11:17:43 -05001317srtp_append_salt_to_key(unsigned char *key, unsigned int bytes_in_key,
1318 unsigned char *salt, unsigned int bytes_in_salt);
David McGrew0cb86ee2006-07-07 15:46:57 +00001319
1320
Cullen Jennings235513a2005-09-21 22:51:36 +00001321
1322/**
1323 * @}
1324 */
1325
1326
Cullen Jennings235513a2005-09-21 22:51:36 +00001327
1328/**
1329 * @defgroup SRTCP Secure RTCP
1330 * @ingroup SRTP
1331 *
1332 * @brief Secure RTCP functions are used to protect RTCP traffic.
1333 *
1334 * RTCP is the control protocol for RTP. libSRTP protects RTCP
1335 * traffic in much the same way as it does RTP traffic. The function
1336 * srtp_protect_rtcp() applies cryptographic protections to outbound
1337 * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on
1338 * inbound RTCP packets.
1339 *
1340 * A note on the naming convention: srtp_protect_rtcp() has an srtp_t
1341 * as its first argument, and thus has `srtp_' as its prefix. The
1342 * trailing `_rtcp' indicates the protocol on which it acts.
1343 *
1344 * @{
1345 */
1346
1347/**
1348 * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet
1349 * processing function.
1350 *
1351 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
1352 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
jfigus857009c2014-11-05 11:17:43 -05001353 * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
Cullen Jennings235513a2005-09-21 22:51:36 +00001354 * returned, then rtp_hdr points to the resulting SRTCP packet and
1355 * *len_ptr is the number of octets in that packet; otherwise, no
1356 * assumptions should be made about the value of either data elements.
1357 *
1358 * @warning This function assumes that it can write the authentication
1359 * tag into the location in memory immediately following the RTCP
1360 * packet, and assumes that the RTCP packet is aligned on a 32-bit
1361 * boundary.
1362 *
jfigus5e337292013-05-28 13:57:47 -04001363 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
1364 * into the location in memory immediately following the RTCP packet.
1365 * Callers MUST ensure that this much writable memory is available in
1366 * the buffer that holds the RTCP packet.
1367 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001368 * @param ctx is the SRTP context to use in processing the packet.
1369 *
1370 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
1371 * the function returns, it points to the srtp packet.
1372 *
1373 * @param pkt_octet_len is a pointer to the length in octets of the
1374 * complete RTCP packet (header and body) before the function call,
jfigus857009c2014-11-05 11:17:43 -05001375 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
Cullen Jennings235513a2005-09-21 22:51:36 +00001376 * was returned. Otherwise, the value of the data to which it points
1377 * is undefined.
1378 *
1379 * @return
jfigus857009c2014-11-05 11:17:43 -05001380 * - srtp_err_status_ok if there were no problems.
Cullen Jennings235513a2005-09-21 22:51:36 +00001381 * - [other] if there was a failure in
1382 * the cryptographic mechanisms.
1383 */
1384
1385
jfigus857009c2014-11-05 11:17:43 -05001386srtp_err_status_t srtp_protect_rtcp(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001387
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001388
1389/**
1390 * @brief srtp_protect_rtcp_mki() is the Secure RTCP sender-side packet
1391 * processing function that can utilize mki.
1392 *
1393 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
1394 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
1395 * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
1396 * returned, then rtp_hdr points to the resulting SRTCP packet and
1397 * *len_ptr is the number of octets in that packet; otherwise, no
1398 * assumptions should be made about the value of either data elements.
1399 *
1400 * @warning This function assumes that it can write the authentication
1401 * tag into the location in memory immediately following the RTCP
1402 * packet, and assumes that the RTCP packet is aligned on a 32-bit
1403 * boundary.
1404 *
1405 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
1406 * into the location in memory immediately following the RTCP packet.
1407 * Callers MUST ensure that this much writable memory is available in
1408 * the buffer that holds the RTCP packet.
1409 *
1410 * @param ctx is the SRTP context to use in processing the packet.
1411 *
1412 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
1413 * the function returns, it points to the srtp packet.
1414 *
1415 * @param pkt_octet_len is a pointer to the length in octets of the
1416 * complete RTCP packet (header and body) before the function call,
1417 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
1418 * was returned. Otherwise, the value of the data to which it points
1419 * is undefined.
1420 *
1421 * @param use_mki is a boolean to tell the system if mki is being used. If
1422 * set to false then will use the first set of session keys. If set to true will
1423 * use the session keys identified by the mki_index
1424 *
1425 * @param mki_index integer value specifying which set of session kesy should be
1426 * used if use_mki is set to true.
1427 *
1428 * @return
1429 * - srtp_err_status_ok if there were no problems.
1430 * - [other] if there was a failure in
1431 * the cryptographic mechanisms.
1432 */
1433
1434srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len,
1435 unsigned int use_mki, unsigned int mki_index);
1436
Cullen Jennings235513a2005-09-21 22:51:36 +00001437/**
1438 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
1439 * processing function.
1440 *
1441 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
1442 * verifies the Secure RTCP protection of the SRTCP packet pointed to
1443 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
jfigus857009c2014-11-05 11:17:43 -05001444 * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
Cullen Jennings235513a2005-09-21 22:51:36 +00001445 * to the resulting RTCP packet and *len_ptr is the number of octets
1446 * in that packet; otherwise, no assumptions should be made about the
1447 * value of either data elements.
1448 *
1449 * @warning This function assumes that the SRTCP packet is aligned on a
1450 * 32-bit boundary.
1451 *
1452 * @param ctx is a pointer to the srtp_t which applies to the
1453 * particular packet.
1454 *
1455 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
1456 * (before the call). After the function returns, it points to the
jfigus857009c2014-11-05 11:17:43 -05001457 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
Cullen Jennings235513a2005-09-21 22:51:36 +00001458 * the data to which it points is undefined.
1459 *
1460 * @param pkt_octet_len is a pointer to the length in octets of the
1461 * complete SRTCP packet (header and body) before the function call,
jfigus857009c2014-11-05 11:17:43 -05001462 * and of the complete rtp packet after the call, if srtp_err_status_ok was
Cullen Jennings235513a2005-09-21 22:51:36 +00001463 * returned. Otherwise, the value of the data to which it points is
1464 * undefined.
1465 *
1466 * @return
jfigus857009c2014-11-05 11:17:43 -05001467 * - srtp_err_status_ok if the RTCP packet is valid.
1468 * - srtp_err_status_auth_fail if the SRTCP packet failed the message
Cullen Jennings235513a2005-09-21 22:51:36 +00001469 * authentication check.
jfigus857009c2014-11-05 11:17:43 -05001470 * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
Cullen Jennings235513a2005-09-21 22:51:36 +00001471 * already been processed and accepted).
1472 * - [other] if there has been an error in the cryptographic mechanisms.
1473 *
1474 */
1475
jfigus857009c2014-11-05 11:17:43 -05001476srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001477
1478/**
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001479 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
1480 * processing function.
1481 *
1482 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
1483 * verifies the Secure RTCP protection of the SRTCP packet pointed to
1484 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
1485 * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
1486 * to the resulting RTCP packet and *len_ptr is the number of octets
1487 * in that packet; otherwise, no assumptions should be made about the
1488 * value of either data elements.
1489 *
1490 * @warning This function assumes that the SRTCP packet is aligned on a
1491 * 32-bit boundary.
1492 *
1493 * @param ctx is a pointer to the srtp_t which applies to the
1494 * particular packet.
1495 *
1496 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
1497 * (before the call). After the function returns, it points to the
1498 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
1499 * the data to which it points is undefined.
1500 *
1501 * @param pkt_octet_len is a pointer to the length in octets of the
1502 * complete SRTCP packet (header and body) before the function call,
1503 * and of the complete rtp packet after the call, if srtp_err_status_ok was
1504 * returned. Otherwise, the value of the data to which it points is
1505 * undefined.
1506 *
1507 * @return
1508 * - srtp_err_status_ok if the RTCP packet is valid.
1509 * - srtp_err_status_auth_fail if the SRTCP packet failed the message
1510 * authentication check.
1511 * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
1512 * already been processed and accepted).
1513 * - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI id
1514 * - [other] if there has been an error in the cryptographic mechanisms.
1515 *
1516 */
1517
Geir Istad626e9e82017-02-20 18:15:05 +01001518srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx, void *srtcp_hdr,
1519 int *pkt_octet_len,
1520 unsigned int use_mki);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001521
1522/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001523 * @}
1524 */
1525
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +02001526
1527/**
1528 * @defgroup User data associated to a SRTP session.
1529 * @ingroup SRTP
1530 *
1531 * @brief Store custom user data within a SRTP session.
1532 *
1533 * @{
1534 */
1535
1536/**
1537 * @brief srtp_set_user_data() stores the given pointer into the SRTP
1538 * session for later retrieval.
1539 *
1540 * @param ctx is the srtp_t context in which the given data pointer is
1541 * stored.
1542 *
1543 * @param data is a pointer to the custom information (struct, function,
1544 * etc) associated with the SRTP session.
1545 *
1546 * @return void.
1547 *
1548 */
1549
1550void
1551srtp_set_user_data(srtp_t ctx, void *data);
1552
1553/**
1554 * @brief srtp_get_user_data() retrieves the pointer to the custom data
1555 * previously stored with srtp_set_user_data().
1556 *
1557 * This function is mostly useful for retrieving data associated to a
1558 * SRTP session when an event fires. The user can then get such a custom
1559 * data by calling this function with the session field of the
1560 * srtp_event_data_t struct as argument.
1561 *
1562 * @param ctx is the srtp_t context in which the given data pointer was
1563 * stored.
1564 *
1565 * @return void* pointer to the user data.
1566 *
1567 */
1568
1569void*
1570srtp_get_user_data(srtp_t ctx);
1571
1572/**
1573 * @}
1574 */
1575
1576
Cullen Jennings235513a2005-09-21 22:51:36 +00001577/**
1578 * @defgroup SRTPevents SRTP events and callbacks
1579 * @ingroup SRTP
1580 *
1581 * @brief libSRTP can use a user-provided callback function to
1582 * handle events.
1583 *
1584 *
1585 * libSRTP allows a user to provide a callback function to handle
1586 * events that need to be dealt with outside of the data plane (see
1587 * the enum srtp_event_t for a description of these events). Dealing
1588 * with these events is not a strict necessity; they are not
1589 * security-critical, but the application may suffer if they are not
1590 * handled. The function srtp_set_event_handler() is used to provide
1591 * the callback function.
1592 *
1593 * A default event handler that merely reports on the events as they
1594 * happen is included. It is also possible to set the event handler
1595 * function to NULL, in which case all events will just be silently
1596 * ignored.
1597 *
1598 * @{
1599 */
1600
1601/**
1602 * @brief srtp_event_t defines events that need to be handled
1603 *
1604 * The enum srtp_event_t defines events that need to be handled
1605 * outside the `data plane', such as SSRC collisions and
1606 * key expirations.
1607 *
1608 * When a key expires or the maximum number of packets has been
1609 * reached, an SRTP stream will enter an `expired' state in which no
1610 * more packets can be protected or unprotected. When this happens,
1611 * it is likely that you will want to either deallocate the stream
jfigus92c3de32016-02-02 13:44:39 -05001612 * (using srtp_remove_stream()), and possibly allocate a new one.
Cullen Jennings235513a2005-09-21 22:51:36 +00001613 *
1614 * When an SRTP stream expires, the other streams in the same session
1615 * are unaffected, unless key sharing is used by that stream. In the
1616 * latter case, all of the streams in the session will expire.
1617 */
1618
1619typedef enum {
1620 event_ssrc_collision, /**<
1621 * An SSRC collision occured.
1622 */
1623 event_key_soft_limit, /**< An SRTP stream reached the soft key
1624 * usage limit and will expire soon.
1625 */
1626 event_key_hard_limit, /**< An SRTP stream reached the hard
1627 * key usage limit and has expired.
1628 */
1629 event_packet_index_limit /**< An SRTP stream reached the hard
1630 * packet limit (2^48 packets).
1631 */
1632} srtp_event_t;
1633
1634/**
1635 * @brief srtp_event_data_t is the structure passed as a callback to
1636 * the event handler function
1637 *
1638 * The struct srtp_event_data_t holds the data passed to the event
1639 * handler function.
1640 */
1641
1642typedef struct srtp_event_data_t {
1643 srtp_t session; /**< The session in which the event happend. */
1644 srtp_stream_t stream; /**< The stream in which the event happend. */
1645 srtp_event_t event; /**< An enum indicating the type of event. */
1646} srtp_event_data_t;
1647
1648/**
1649 * @brief srtp_event_handler_func_t is the function prototype for
1650 * the event handler.
1651 *
1652 * The typedef srtp_event_handler_func_t is the prototype for the
1653 * event handler function. It has as its only argument an
1654 * srtp_event_data_t which describes the event that needs to be handled.
1655 * There can only be a single, global handler for all events in
1656 * libSRTP.
1657 */
1658
1659typedef void (srtp_event_handler_func_t)(srtp_event_data_t *data);
1660
1661/**
1662 * @brief sets the event handler to the function supplied by the caller.
1663 *
1664 * The function call srtp_install_event_handler(func) sets the event
1665 * handler function to the value func. The value NULL is acceptable
1666 * as an argument; in this case, events will be ignored rather than
1667 * handled.
1668 *
1669 * @param func is a pointer to a fuction that takes an srtp_event_data_t
1670 * pointer as an argument and returns void. This function
1671 * will be used by libSRTP to handle events.
1672 */
1673
jfigus857009c2014-11-05 11:17:43 -05001674srtp_err_status_t srtp_install_event_handler(srtp_event_handler_func_t func);
Cullen Jennings235513a2005-09-21 22:51:36 +00001675
1676/**
jfigusf62b64d2014-10-08 13:53:57 -04001677 * @brief Returns the version string of the library.
1678 *
1679 */
Christian Oiend4e3eec2014-10-24 10:14:08 +02001680const char *srtp_get_version_string(void);
jfigusf62b64d2014-10-08 13:53:57 -04001681
1682/**
1683 * @brief Returns the numeric representation of the library version.
1684 *
1685 */
1686unsigned int srtp_get_version(void);
1687
1688/**
jfigus46d6b472014-11-14 16:42:01 -05001689 * @brief srtp_set_debug_module(mod_name, v)
1690 *
1691 * sets dynamic debugging to the value v (0 for off, 1 for on) for the
1692 * debug module with the name mod_name
1693 *
1694 * returns err_status_ok on success, err_status_fail otherwise
1695 */
1696srtp_err_status_t srtp_set_debug_module(char *mod_name, int v);
1697
1698/**
1699 * @brief srtp_list_debug_modules() outputs a list of debugging modules
1700 *
1701 */
1702srtp_err_status_t srtp_list_debug_modules(void);
1703
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001704/**
Ryan Hooperab0345b2017-02-07 16:07:59 -05001705 * @brief srtp_get_protect_trailer_length(session, use_mki, mki_index, length)
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001706 *
1707 * Determines the length of the amount of data Lib SRTP will add to the
1708 * packet during the protect process. The length is returned in the length parameter
1709 *
1710 * returns err_status_ok on success, err_status_bad_mki if the MKI index is invalid
1711 *
1712 */
Ryan Hooperab0345b2017-02-07 16:07:59 -05001713srtp_err_status_t srtp_get_protect_trailer_length(srtp_t session, uint32_t use_mki,
1714 uint32_t mki_index, uint32_t *length);
1715
1716/**
1717 * @brief srtp_get_protect_rtcp_trailer_length(session, use_mki, mki_index, length)
1718 *
1719 * Determines the length of the amount of data Lib SRTP will add to the
1720 * packet during the protect process. The length is returned in the length parameter
1721 *
1722 * returns err_status_ok on success, err_status_bad_mki if the MKI index is invalid
1723 *
1724 */
1725srtp_err_status_t srtp_get_protect_rtcp_trailer_length(srtp_t session, uint32_t use_mki,
1726 uint32_t mki_index, uint32_t *length);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001727
jfigus46d6b472014-11-14 16:42:01 -05001728
1729/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001730 * @}
1731 */
Cullen Jennings235513a2005-09-21 22:51:36 +00001732/* in host order, so outside the #if */
1733#define SRTCP_E_BIT 0x80000000
1734/* for byte-access */
1735#define SRTCP_E_BYTE_BIT 0x80
1736#define SRTCP_INDEX_MASK 0x7fffffff
1737
Marcus Sundbergcb60bf82005-10-17 17:23:05 +00001738#ifdef __cplusplus
1739}
1740#endif
1741
Pascal Bühlerc3655db2017-02-01 09:11:27 +01001742#endif /* SRTP_SRTP_H */