blob: c86b9ee7473e48f44efeaca5a1e77f25a10bb8f7 [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/*
Geir Istadb6109682017-07-10 19:01:17 +020010 *
Geir Istad445c1c92017-03-27 08:13:49 +020011 * Copyright (c) 2001-2017, Cisco Systems, Inc.
Cullen Jennings235513a2005-09-21 22:51:36 +000012 * All rights reserved.
Geir Istadb6109682017-07-10 19:01:17 +020013 *
Cullen Jennings235513a2005-09-21 22:51:36 +000014 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
Geir Istadb6109682017-07-10 19:01:17 +020017 *
Cullen Jennings235513a2005-09-21 22:51:36 +000018 * Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
Geir Istadb6109682017-07-10 19:01:17 +020020 *
Cullen Jennings235513a2005-09-21 22:51:36 +000021 * 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.
Geir Istadb6109682017-07-10 19:01:17 +020025 *
Cullen Jennings235513a2005-09-21 22:51:36 +000026 * 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.
Geir Istadb6109682017-07-10 19:01:17 +020029 *
Cullen Jennings235513a2005-09-21 22:51:36 +000030 * 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
Pascal Bühlerc3655db2017-02-01 09:11:27 +010045#ifndef SRTP_SRTP_H
46#define SRTP_SRTP_H
Cullen Jennings235513a2005-09-21 22:51:36 +000047
David Benjamin5f1b9822016-07-26 18:18:01 -040048#include <stdint.h>
49
Marcus Sundbergcb60bf82005-10-17 17:23:05 +000050#ifdef __cplusplus
51extern "C" {
52#endif
53
Cullen Jennings235513a2005-09-21 22:51:36 +000054/**
55 * @defgroup SRTP Secure RTP
56 *
57 * @brief libSRTP provides functions for protecting RTP and RTCP. See
58 * Section @ref Overview for an introduction to the use of the library.
59 *
60 * @{
61 */
62
63/*
64 * SRTP_MASTER_KEY_LEN is the nominal master key length supported by libSRTP
65 */
66
67#define SRTP_MASTER_KEY_LEN 30
68
69/*
70 * SRTP_MAX_KEY_LEN is the maximum key length supported by libSRTP
71 */
Geir Istadb6109682017-07-10 19:01:17 +020072#define SRTP_MAX_KEY_LEN 64
Cullen Jennings235513a2005-09-21 22:51:36 +000073
74/*
75 * SRTP_MAX_TAG_LEN is the maximum tag length supported by libSRTP
76 */
77
Geir Istadb6109682017-07-10 19:01:17 +020078#define SRTP_MAX_TAG_LEN 16
Cullen Jennings235513a2005-09-21 22:51:36 +000079
80/**
Ryan Hooperab0345b2017-02-07 16:07:59 -050081 * SRTP_MAX_MKI_LEN is the maximum size the MKI could be which is
82 * 128 bytes
83 */
84#define SRTP_MAX_MKI_LEN 128
85
Ryan Hooperab0345b2017-02-07 16:07:59 -050086/**
Cullen Jennings235513a2005-09-21 22:51:36 +000087 * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer
88 * (authentication tag and MKI) supported by libSRTP. This value is
Ryan Hooperab0345b2017-02-07 16:07:59 -050089 * the maixmum number of octets that will be added to an RTP packet by
Cullen Jennings235513a2005-09-21 22:51:36 +000090 * srtp_protect().
91 *
92 * @brief the maximum number of octets added by srtp_protect().
93 */
Pascal Bühler20e66122017-03-13 09:09:36 +010094#define SRTP_MAX_TRAILER_LEN (SRTP_MAX_TAG_LEN + SRTP_MAX_MKI_LEN)
Cullen Jennings235513a2005-09-21 22:51:36 +000095
Ryan Hooperfe5d8b82016-12-15 14:53:58 -050096/**
97 * SRTP_MAX_NUM_MASTER_KEYS is the maximum number of Master keys for
Geir Istadb6109682017-07-10 19:01:17 +020098 * MKI supported by libSRTP.
99 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500100 */
Ryan Hooper89a288b2016-12-22 16:22:47 -0500101#define SRTP_MAX_NUM_MASTER_KEYS 16
Cullen Jennings235513a2005-09-21 22:51:36 +0000102
Geir Istadb6109682017-07-10 19:01:17 +0200103#define SRTP_SALT_LEN 14
104
jfigus8c36da22013-10-01 16:41:19 -0400105/*
Pascal Bühler20e66122017-03-13 09:09:36 +0100106 * SRTP_AEAD_SALT_LEN is the length of the SALT values used with
jfigus8c36da22013-10-01 16:41:19 -0400107 * 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 */
Geir Istadb6109682017-07-10 19:01:17 +0200110#define SRTP_AEAD_SALT_LEN 12
Pascal Bühler20e66122017-03-13 09:09:36 +0100111
Geir Istadb6109682017-07-10 19:01:17 +0200112#define SRTP_AES_128_KEY_LEN 16
113#define SRTP_AES_192_KEY_LEN 24
114#define SRTP_AES_256_KEY_LEN 32
Pascal Bühler20e66122017-03-13 09:09:36 +0100115
Geir Istadb6109682017-07-10 19:01:17 +0200116#define SRTP_AES_ICM_128_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_128_KEY_LEN)
117#define SRTP_AES_ICM_192_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_192_KEY_LEN)
118#define SRTP_AES_ICM_256_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_256_KEY_LEN)
Pascal Bühler20e66122017-03-13 09:09:36 +0100119
Geir Istadb6109682017-07-10 19:01:17 +0200120#define SRTP_AES_GCM_128_KEY_LEN_WSALT \
121 (SRTP_AEAD_SALT_LEN + SRTP_AES_128_KEY_LEN)
122#define SRTP_AES_GCM_192_KEY_LEN_WSALT \
123 (SRTP_AEAD_SALT_LEN + SRTP_AES_192_KEY_LEN)
124#define SRTP_AES_GCM_256_KEY_LEN_WSALT \
125 (SRTP_AEAD_SALT_LEN + SRTP_AES_256_KEY_LEN)
jfigus8719f952014-04-08 09:15:49 -0400126
Geir Istadb6109682017-07-10 19:01:17 +0200127/**
jfigus857009c2014-11-05 11:17:43 -0500128 * @brief A srtp_cipher_type_id_t is an identifier for a particular cipher
jfigusa9ac8982014-10-31 14:49:31 -0400129 * type.
130 *
jfigus857009c2014-11-05 11:17:43 -0500131 * A srtp_cipher_type_id_t is an integer that represents a particular
jfigusa9ac8982014-10-31 14:49:31 -0400132 * cipher type, e.g. the Advanced Encryption Standard (AES). A
jfigus67b9c732014-11-20 10:17:21 -0500133 * SRTP_NULL_CIPHER is avaliable; this cipher leaves the data unchanged,
jfigusa9ac8982014-10-31 14:49:31 -0400134 * and can be selected to indicate that no encryption is to take
135 * place.
Geir Istadb6109682017-07-10 19:01:17 +0200136 *
jfigusa9ac8982014-10-31 14:49:31 -0400137 * @ingroup Ciphers
138 */
Geir Istadb6109682017-07-10 19:01:17 +0200139typedef uint32_t srtp_cipher_type_id_t;
jfigusa9ac8982014-10-31 14:49:31 -0400140
141/**
Geir Istadb6109682017-07-10 19:01:17 +0200142 * @brief An srtp_auth_type_id_t is an identifier for a particular
143 * authentication
jfigusa9ac8982014-10-31 14:49:31 -0400144 * function.
145 *
jfigus857009c2014-11-05 11:17:43 -0500146 * An srtp_auth_type_id_t is an integer that represents a particular
jfigus67b9c732014-11-20 10:17:21 -0500147 * authentication function type, e.g. HMAC-SHA1. A SRTP_NULL_AUTH is
jfigusa9ac8982014-10-31 14:49:31 -0400148 * avaliable; this authentication function performs no computation,
149 * and can be selected to indicate that no authentication is to take
150 * place.
Geir Istadb6109682017-07-10 19:01:17 +0200151 *
jfigusa9ac8982014-10-31 14:49:31 -0400152 * @ingroup Authentication
153 */
jfigus857009c2014-11-05 11:17:43 -0500154typedef uint32_t srtp_auth_type_id_t;
jfigusa9ac8982014-10-31 14:49:31 -0400155
Geir Istad1aa0f432017-03-29 07:07:28 +0200156/**
jfigus857009c2014-11-05 11:17:43 -0500157 * @brief srtp_err_status_t defines error codes.
jfigusa9ac8982014-10-31 14:49:31 -0400158 *
jfigus857009c2014-11-05 11:17:43 -0500159 * The enumeration srtp_err_status_t defines error codes. Note that the
160 * value of srtp_err_status_ok is equal to zero, which can simplify error
jfigusa9ac8982014-10-31 14:49:31 -0400161 * checking somewhat.
162 *
163 */
164typedef enum {
Geir Istadb6109682017-07-10 19:01:17 +0200165 srtp_err_status_ok = 0, /**< nothing to report */
166 srtp_err_status_fail = 1, /**< unspecified failure */
167 srtp_err_status_bad_param = 2, /**< unsupported parameter */
168 srtp_err_status_alloc_fail = 3, /**< couldn't allocate memory */
169 srtp_err_status_dealloc_fail = 4, /**< couldn't deallocate properly */
170 srtp_err_status_init_fail = 5, /**< couldn't initialize */
171 srtp_err_status_terminus = 6, /**< can't process as much data as */
172 /**< requested */
173 srtp_err_status_auth_fail = 7, /**< authentication failure */
174 srtp_err_status_cipher_fail = 8, /**< cipher failure */
175 srtp_err_status_replay_fail = 9, /**< replay check failed (bad index) */
176 srtp_err_status_replay_old = 10, /**< replay check failed (index too */
177 /**< old) */
178 srtp_err_status_algo_fail = 11, /**< algorithm failed test routine */
179 srtp_err_status_no_such_op = 12, /**< unsupported operation */
180 srtp_err_status_no_ctx = 13, /**< no appropriate context found */
181 srtp_err_status_cant_check = 14, /**< unable to perform desired */
182 /**< validation */
183 srtp_err_status_key_expired = 15, /**< can't use key any more */
184 srtp_err_status_socket_err = 16, /**< error in use of socket */
185 srtp_err_status_signal_err = 17, /**< error in use POSIX signals */
186 srtp_err_status_nonce_bad = 18, /**< nonce check failed */
187 srtp_err_status_read_fail = 19, /**< couldn't read data */
188 srtp_err_status_write_fail = 20, /**< couldn't write data */
189 srtp_err_status_parse_err = 21, /**< error parsing data */
190 srtp_err_status_encode_err = 22, /**< error encoding data */
191 srtp_err_status_semaphore_err = 23, /**< error while using semaphores */
192 srtp_err_status_pfkey_err = 24, /**< error while using pfkey */
193 srtp_err_status_bad_mki = 25, /**< error MKI present in packet is */
194 /**< invalid */
195 srtp_err_status_pkt_idx_old = 26, /**< packet index is too old to */
196 /**< consider */
197 srtp_err_status_pkt_idx_adv = 27 /**< packet index advanced, reset */
198 /**< needed */
jfigus857009c2014-11-05 11:17:43 -0500199} srtp_err_status_t;
jfigusa9ac8982014-10-31 14:49:31 -0400200
jfigusa9ac8982014-10-31 14:49:31 -0400201typedef struct srtp_ctx_t_ srtp_ctx_t;
jfigus44947602014-10-08 13:08:52 -0400202
Cullen Jennings235513a2005-09-21 22:51:36 +0000203/**
Geir Istadb6109682017-07-10 19:01:17 +0200204 * @brief srtp_sec_serv_t describes a set of security services.
Cullen Jennings235513a2005-09-21 22:51:36 +0000205 *
jfigus857009c2014-11-05 11:17:43 -0500206 * A srtp_sec_serv_t enumeration is used to describe the particular
Cullen Jennings235513a2005-09-21 22:51:36 +0000207 * security services that will be applied by a particular crypto
Geir Istadb6109682017-07-10 19:01:17 +0200208 * policy (or other mechanism).
Cullen Jennings235513a2005-09-21 22:51:36 +0000209 */
Cullen Jennings235513a2005-09-21 22:51:36 +0000210typedef enum {
Geir Istadb6109682017-07-10 19:01:17 +0200211 sec_serv_none = 0, /**< no services */
212 sec_serv_conf = 1, /**< confidentiality */
213 sec_serv_auth = 2, /**< authentication */
214 sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */
jfigus857009c2014-11-05 11:17:43 -0500215} srtp_sec_serv_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000216
Geir Istadb6109682017-07-10 19:01:17 +0200217/**
jfigus857009c2014-11-05 11:17:43 -0500218 * @brief srtp_crypto_policy_t describes a particular crypto policy that
Cullen Jennings235513a2005-09-21 22:51:36 +0000219 * can be applied to an SRTP stream.
220 *
jfigus857009c2014-11-05 11:17:43 -0500221 * A srtp_crypto_policy_t describes a particular cryptographic policy that
Cullen Jennings235513a2005-09-21 22:51:36 +0000222 * can be applied to an SRTP or SRTCP stream. An SRTP session policy
Geir Istadb6109682017-07-10 19:01:17 +0200223 * consists of a list of these policies, one for each SRTP stream
Cullen Jennings235513a2005-09-21 22:51:36 +0000224 * in the session.
225 */
jfigus857009c2014-11-05 11:17:43 -0500226typedef struct srtp_crypto_policy_t {
Geir Istadb6109682017-07-10 19:01:17 +0200227 srtp_cipher_type_id_t cipher_type; /**< An integer representing */
228 /**< the type of cipher. */
229 int cipher_key_len; /**< The length of the cipher key */
230 /**< in octets. */
231 srtp_auth_type_id_t auth_type; /**< An integer representing the */
232 /**< authentication function. */
233 int auth_key_len; /**< The length of the authentication */
234 /**< function key in octets. */
235 int auth_tag_len; /**< The length of the authentication */
236 /**< tag in octets. */
237 srtp_sec_serv_t sec_serv; /**< The flag indicating the security */
238 /**< services to be applied. */
jfigus857009c2014-11-05 11:17:43 -0500239} srtp_crypto_policy_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000240
Geir Istadb6109682017-07-10 19:01:17 +0200241/**
jfigus857009c2014-11-05 11:17:43 -0500242 * @brief srtp_ssrc_type_t describes the type of an SSRC.
Geir Istadb6109682017-07-10 19:01:17 +0200243 *
jfigus857009c2014-11-05 11:17:43 -0500244 * An srtp_ssrc_type_t enumeration is used to indicate a type of SSRC. See
Cullen Jennings235513a2005-09-21 22:51:36 +0000245 * @ref srtp_policy_t for more informataion.
246 */
Geir Istadb6109682017-07-10 19:01:17 +0200247typedef enum {
248 ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */
249 ssrc_specific = 1, /**< Indicates a specific SSRC value */
250 ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value */
251 /**< (i.e. a value that is used in the */
252 /**< function srtp_unprotect()) */
253 ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value */
254 /**< (i.e. a value that is used in the */
255 /**< function srtp_protect()) */
jfigus857009c2014-11-05 11:17:43 -0500256} srtp_ssrc_type_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000257
258/**
Geir Istadb6109682017-07-10 19:01:17 +0200259 * @brief An srtp_ssrc_t represents a particular SSRC value, or a `wildcard'
260 * SSRC.
261 *
jfigus857009c2014-11-05 11:17:43 -0500262 * An srtp_ssrc_t represents a particular SSRC value (if its type is
Cullen Jennings235513a2005-09-21 22:51:36 +0000263 * ssrc_specific), or a wildcard SSRC value that will match all
264 * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound
Geir Istadb6109682017-07-10 19:01:17 +0200265 * SSRCs (if its type is ssrc_any_inbound).
Cullen Jennings235513a2005-09-21 22:51:36 +0000266 */
Geir Istadb6109682017-07-10 19:01:17 +0200267typedef struct {
268 srtp_ssrc_type_t type; /**< The type of this particular SSRC */
269 unsigned int value; /**< The value of this SSRC, if it is not a */
270 /**< wildcard */
jfigus857009c2014-11-05 11:17:43 -0500271} srtp_ssrc_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000272
David McGrew79870d62007-06-15 18:17:39 +0000273/**
274 * @brief points to an EKT policy
275 */
jfigusc5887e72014-11-06 09:46:18 -0500276typedef struct srtp_ekt_policy_ctx_t *srtp_ekt_policy_t;
David McGrew79870d62007-06-15 18:17:39 +0000277
David McGrew79870d62007-06-15 18:17:39 +0000278/**
279 * @brief points to EKT stream data
280 */
jfigusc5887e72014-11-06 09:46:18 -0500281typedef struct srtp_ekt_stream_ctx_t *srtp_ekt_stream_t;
David McGrew79870d62007-06-15 18:17:39 +0000282
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500283/**
284 * @brief srtp_master_key_t represents a master key. There will
285 * be a Master Key Index and the Master Key associated with the
286 * Master Key Index. Need to also keep track of the Master Key
287 * Index Size to correctly read it from a packet.
288 */
289typedef struct srtp_master_key_t {
Geir Istadb6109682017-07-10 19:01:17 +0200290 unsigned char *key;
291 unsigned char *mki_id;
292 unsigned int mki_size;
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500293} srtp_master_key_t;
David McGrew79870d62007-06-15 18:17:39 +0000294
Geir Istadb6109682017-07-10 19:01:17 +0200295/**
296 * @brief represents the policy for an SRTP session.
Cullen Jennings235513a2005-09-21 22:51:36 +0000297 *
298 * A single srtp_policy_t struct represents the policy for a single
299 * SRTP stream, and a linked list of these elements represents the
300 * policy for an entire SRTP session. Each element contains the SRTP
301 * and SRTCP crypto policies for that stream, a pointer to the SRTP
302 * master key for that stream, the SSRC describing that stream, or a
303 * flag indicating a `wildcard' SSRC value, and a `next' field that
304 * holds a pointer to the next element in the list of policy elements,
Geir Istadb6109682017-07-10 19:01:17 +0200305 * or NULL if it is the last element.
Cullen Jennings235513a2005-09-21 22:51:36 +0000306 *
307 * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an
308 * inbound stream that for which there is no explicit SSRC entry in
309 * another policy element. Similarly, the value SSRC_ANY_OUTBOUND
310 * will matches any SSRC from an outbound stream that does not appear
311 * in another policy element. Note that wildcard SSRCs &b cannot be
312 * used to match both inbound and outbound traffic. This restriction
313 * is intentional, and it allows libSRTP to ensure that no security
314 * lapses result from accidental re-use of SSRC values during key
315 * sharing.
Geir Istadb6109682017-07-10 19:01:17 +0200316 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000317 * @warning The final element of the list @b must have its `next' pointer
318 * set to NULL.
319 */
320
321typedef struct srtp_policy_t {
Geir Istadb6109682017-07-10 19:01:17 +0200322 srtp_ssrc_t ssrc; /**< The SSRC value of stream, or the */
323 /**< flags SSRC_ANY_INBOUND or */
324 /**< SSRC_ANY_OUTBOUND if key sharing */
325 /**< is used for this policy element. */
326 srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */
327 srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */
328 unsigned char *key; /**< Pointer to the SRTP master key for */
329 /**< this stream. */
330 srtp_master_key_t **keys; /** Array of Master Key structures */
331 unsigned long num_master_keys; /** Number of master keys */
332 srtp_ekt_policy_t ekt; /**< Pointer to the EKT policy structure */
333 /**< for this stream (if any) */
334 unsigned long window_size; /**< The window size to use for replay */
335 /**< protection. */
336 int allow_repeat_tx; /**< Whether retransmissions of */
337 /**< packets with the same sequence */
338 /**< number are allowed. */
339 /**< (Note that such repeated */
340 /**< transmissions must have the same */
341 /**< RTP payload, or a severe security */
342 /**< weakness is introduced!) */
343 int *enc_xtn_hdr; /**< List of header ids to encrypt. */
344 int enc_xtn_hdr_count; /**< Number of entries in list of header */
345 /**< ids. */
346 struct srtp_policy_t *next; /**< Pointer to next stream policy. */
Cullen Jennings235513a2005-09-21 22:51:36 +0000347} srtp_policy_t;
348
Cullen Jennings235513a2005-09-21 22:51:36 +0000349/**
350 * @brief An srtp_t points to an SRTP session structure.
351 *
352 * The typedef srtp_t is a pointer to a structure that represents
Geir Istadb6109682017-07-10 19:01:17 +0200353 * an SRTP session. This datatype is intentially opaque in
Cullen Jennings235513a2005-09-21 22:51:36 +0000354 * order to separate the interface from the implementation.
355 *
356 * An SRTP session consists of all of the traffic sent to the RTP and
357 * RTCP destination transport addresses, using the RTP/SAVP (Secure
358 * Audio/Video Profile). A session can be viewed as a set of SRTP
359 * streams, each of which originates with a different participant.
360 */
jfigusa9ac8982014-10-31 14:49:31 -0400361typedef srtp_ctx_t *srtp_t;
Cullen Jennings235513a2005-09-21 22:51:36 +0000362
Cullen Jennings235513a2005-09-21 22:51:36 +0000363/**
Geir Istadb6109682017-07-10 19:01:17 +0200364 * @brief srtp_init() initializes the srtp library.
Cullen Jennings235513a2005-09-21 22:51:36 +0000365 *
366 * @warning This function @b must be called before any other srtp
367 * functions.
368 */
jfigus857009c2014-11-05 11:17:43 -0500369srtp_err_status_t srtp_init(void);
Cullen Jennings235513a2005-09-21 22:51:36 +0000370
371/**
Jonathan Lennox5ae76332010-05-15 04:48:59 +0000372 * @brief srtp_shutdown() de-initializes the srtp library.
373 *
374 * @warning No srtp functions may be called after calling this function.
375 */
jfigus857009c2014-11-05 11:17:43 -0500376srtp_err_status_t srtp_shutdown(void);
Jonathan Lennox5ae76332010-05-15 04:48:59 +0000377
378/**
Cullen Jennings235513a2005-09-21 22:51:36 +0000379 * @brief srtp_protect() is the Secure RTP sender-side packet processing
380 * function.
Geir Istadb6109682017-07-10 19:01:17 +0200381 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000382 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
383 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
jfigus857009c2014-11-05 11:17:43 -0500384 * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
Cullen Jennings235513a2005-09-21 22:51:36 +0000385 * points to the resulting SRTP packet and *len_ptr is the number of
386 * octets in that packet; otherwise, no assumptions should be made
387 * about the value of either data elements.
Geir Istadb6109682017-07-10 19:01:17 +0200388 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000389 * The sequence numbers of the RTP packets presented to this function
390 * need not be consecutive, but they @b must be out of order by less
391 * than 2^15 = 32,768 packets.
392 *
393 * @warning This function assumes that it can write the authentication
394 * tag into the location in memory immediately following the RTP
395 * packet, and assumes that the RTP packet is aligned on a 32-bit
396 * boundary.
397 *
Geir Istadb6109682017-07-10 19:01:17 +0200398 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
399 * into the location in memory immediately following the RTP packet.
400 * Callers MUST ensure that this much writable memory is available in
jfigusdfe68ea2013-05-28 09:00:14 -0400401 * the buffer that holds the RTP packet.
Geir Istadb6109682017-07-10 19:01:17 +0200402 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000403 * @param ctx is the SRTP context to use in processing the packet.
404 *
405 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
406 * the function returns, it points to the srtp packet.
407 *
408 * @param len_ptr is a pointer to the length in octets of the complete
409 * RTP packet (header and body) before the function call, and of the
jfigus857009c2014-11-05 11:17:43 -0500410 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
Cullen Jennings235513a2005-09-21 22:51:36 +0000411 * Otherwise, the value of the data to which it points is undefined.
412 *
Geir Istadb6109682017-07-10 19:01:17 +0200413 * @return
jfigus857009c2014-11-05 11:17:43 -0500414 * - srtp_err_status_ok no problems
415 * - srtp_err_status_replay_fail rtp sequence number was non-increasing
Cullen Jennings235513a2005-09-21 22:51:36 +0000416 * - @e other failure in cryptographic mechanisms
417 */
jfigus857009c2014-11-05 11:17:43 -0500418srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500419
420/**
421 * @brief srtp_protect_mki() is the Secure RTP sender-side packet processing
422 * function that can utilize MKI.
Geir Istadb6109682017-07-10 19:01:17 +0200423 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500424 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
425 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
426 * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr
427 * points to the resulting SRTP packet and *len_ptr is the number of
428 * octets in that packet; otherwise, no assumptions should be made
429 * about the value of either data elements.
Geir Istadb6109682017-07-10 19:01:17 +0200430 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500431 * The sequence numbers of the RTP packets presented to this function
432 * need not be consecutive, but they @b must be out of order by less
433 * than 2^15 = 32,768 packets.
434 *
435 * @warning This function assumes that it can write the authentication
436 * tag into the location in memory immediately following the RTP
437 * packet, and assumes that the RTP packet is aligned on a 32-bit
438 * boundary.
439 *
Geir Istadb6109682017-07-10 19:01:17 +0200440 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
441 * into the location in memory immediately following the RTP packet.
442 * Callers MUST ensure that this much writable memory is available in
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500443 * the buffer that holds the RTP packet.
Geir Istadb6109682017-07-10 19:01:17 +0200444 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500445 * @param ctx is the SRTP context to use in processing the packet.
446 *
447 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
448 * the function returns, it points to the srtp packet.
449 *
Geir Istad6d3729a2017-03-29 06:51:37 +0200450 * @param pkt_octet_len is a pointer to the length in octets of the complete
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500451 * RTP packet (header and body) before the function call, and of the
452 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
453 * Otherwise, the value of the data to which it points is undefined.
454 *
Geir Istadb6109682017-07-10 19:01:17 +0200455 * @param use_mki is a boolean to tell the system if mki is being used. If
456 * set to false then will use the first set of session keys. If set to true
457 * will
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500458 * use the session keys identified by the mki_index
459 *
Geir Istadad8e9182017-03-29 06:46:07 +0200460 * @param mki_index integer value specifying which set of session keys should be
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500461 * used if use_mki is set to true.
462 *
Geir Istadb6109682017-07-10 19:01:17 +0200463 * @return
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500464 * - srtp_err_status_ok no problems
465 * - srtp_err_status_replay_fail rtp sequence number was non-increasing
466 * - @e other failure in cryptographic mechanisms
467 */
Geir Istadb6109682017-07-10 19:01:17 +0200468srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx,
469 void *rtp_hdr,
470 int *pkt_octet_len,
471 unsigned int use_mki,
Geir Istad626e9e82017-02-20 18:15:05 +0100472 unsigned int mki_index);
473
Cullen Jennings235513a2005-09-21 22:51:36 +0000474/**
475 * @brief srtp_unprotect() is the Secure RTP receiver-side packet
476 * processing function.
477 *
478 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
479 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
480 * (which has length *len_ptr), using the SRTP context ctx. If
jfigus857009c2014-11-05 11:17:43 -0500481 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
Cullen Jennings235513a2005-09-21 22:51:36 +0000482 * RTP packet and *len_ptr is the number of octets in that packet;
483 * otherwise, no assumptions should be made about the value of either
Geir Istadb6109682017-07-10 19:01:17 +0200484 * data elements.
485 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000486 * The sequence numbers of the RTP packets presented to this function
487 * need not be consecutive, but they @b must be out of order by less
488 * than 2^15 = 32,768 packets.
Geir Istadb6109682017-07-10 19:01:17 +0200489 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000490 * @warning This function assumes that the SRTP packet is aligned on a
491 * 32-bit boundary.
492 *
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +0200493 * @param ctx is the SRTP session which applies to the particular packet.
Cullen Jennings235513a2005-09-21 22:51:36 +0000494 *
495 * @param srtp_hdr is a pointer to the header of the SRTP packet
496 * (before the call). after the function returns, it points to the
jfigus857009c2014-11-05 11:17:43 -0500497 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
Cullen Jennings235513a2005-09-21 22:51:36 +0000498 * the data to which it points is undefined.
499 *
500 * @param len_ptr is a pointer to the length in octets of the complete
501 * srtp packet (header and body) before the function call, and of the
jfigus857009c2014-11-05 11:17:43 -0500502 * complete rtp packet after the call, if srtp_err_status_ok was returned.
Cullen Jennings235513a2005-09-21 22:51:36 +0000503 * Otherwise, the value of the data to which it points is undefined.
504 *
Geir Istadb6109682017-07-10 19:01:17 +0200505 * @return
jfigus857009c2014-11-05 11:17:43 -0500506 * - srtp_err_status_ok if the RTP packet is valid.
Geir Istadb6109682017-07-10 19:01:17 +0200507 * - srtp_err_status_auth_fail if the SRTP packet failed the message
508 * authentication check.
509 * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet
510 * has already been processed and accepted).
Cullen Jennings235513a2005-09-21 22:51:36 +0000511 * - [other] if there has been an error in the cryptographic mechanisms.
512 *
513 */
jfigus857009c2014-11-05 11:17:43 -0500514srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
Cullen Jennings235513a2005-09-21 22:51:36 +0000515
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500516/**
517 * @brief srtp_unprotect_mki() is the Secure RTP receiver-side packet
518 * processing function that checks for MKI.
519 *
520 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
521 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
522 * (which has length *len_ptr), using the SRTP context ctx. If
523 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
524 * RTP packet and *len_ptr is the number of octets in that packet;
525 * otherwise, no assumptions should be made about the value of either
Geir Istadb6109682017-07-10 19:01:17 +0200526 * data elements.
527 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500528 * The sequence numbers of the RTP packets presented to this function
529 * need not be consecutive, but they @b must be out of order by less
530 * than 2^15 = 32,768 packets.
Geir Istadb6109682017-07-10 19:01:17 +0200531 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500532 * @warning This function assumes that the SRTP packet is aligned on a
533 * 32-bit boundary.
534 *
535 * @param ctx is the SRTP session which applies to the particular packet.
536 *
537 * @param srtp_hdr is a pointer to the header of the SRTP packet
538 * (before the call). after the function returns, it points to the
539 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
540 * the data to which it points is undefined.
541 *
542 * @param len_ptr is a pointer to the length in octets of the complete
543 * srtp packet (header and body) before the function call, and of the
544 * complete rtp packet after the call, if srtp_err_status_ok was returned.
545 * Otherwise, the value of the data to which it points is undefined.
546 *
Geir Istad659419e2017-03-29 06:53:40 +0200547 * @param use_mki is a boolean to tell the system if mki is being used. If
Geir Istadb6109682017-07-10 19:01:17 +0200548 * set to false then will use the first set of session keys. If set to true
549 * will
Geir Istad659419e2017-03-29 06:53:40 +0200550 * use the session keys identified by the mki_index
551 *
Geir Istadb6109682017-07-10 19:01:17 +0200552 * @return
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500553 * - srtp_err_status_ok if the RTP packet is valid.
Geir Istadb6109682017-07-10 19:01:17 +0200554 * - srtp_err_status_auth_fail if the SRTP packet failed the message
555 * authentication check.
556 * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet
557 * has already been processed and accepted).
Ryan Hooperfe5d8b82016-12-15 14:53:58 -0500558 * - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI id
559 * - [other] if there has been an error in the cryptographic mechanisms.
560 *
561 */
Geir Istadb6109682017-07-10 19:01:17 +0200562srtp_err_status_t srtp_unprotect_mki(srtp_t ctx,
563 void *srtp_hdr,
564 int *len_ptr,
Geir Istad626e9e82017-02-20 18:15:05 +0100565 unsigned int use_mki);
Cullen Jennings235513a2005-09-21 22:51:36 +0000566
567/**
568 * @brief srtp_create() allocates and initializes an SRTP session.
569
jfigus92c3de32016-02-02 13:44:39 -0500570 * The function call srtp_create(session, policy) allocates and
Geir Istadb6109682017-07-10 19:01:17 +0200571 * initializes an SRTP session context, applying the given policy.
Cullen Jennings235513a2005-09-21 22:51:36 +0000572 *
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +0200573 * @param session is a pointer to the SRTP session to which the policy is
574 * to be added.
Geir Istadb6109682017-07-10 19:01:17 +0200575 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000576 * @param policy is the srtp_policy_t struct that describes the policy
577 * for the session. The struct may be a single element, or it may be
578 * the head of a list, in which case each element of the list is
Marcus Sundberg75d92122005-10-05 12:40:31 +0000579 * processed. It may also be NULL, in which case streams should be added
580 * later using srtp_add_stream(). The final element of the list @b must
581 * have its `next' field set to NULL.
Geir Istadb6109682017-07-10 19:01:17 +0200582 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000583 * @return
jfigus857009c2014-11-05 11:17:43 -0500584 * - srtp_err_status_ok if creation succeded.
585 * - srtp_err_status_alloc_fail if allocation failed.
586 * - srtp_err_status_init_fail if initialization failed.
Cullen Jennings235513a2005-09-21 22:51:36 +0000587 */
jfigus857009c2014-11-05 11:17:43 -0500588srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000589
Cullen Jennings235513a2005-09-21 22:51:36 +0000590/**
591 * @brief srtp_add_stream() allocates and initializes an SRTP stream
592 * within a given SRTP session.
Geir Istadb6109682017-07-10 19:01:17 +0200593 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000594 * The function call srtp_add_stream(session, policy) allocates and
595 * initializes a new SRTP stream within a given, previously created
596 * session, applying the policy given as the other argument to that
597 * stream.
598 *
599 * @return values:
jfigus857009c2014-11-05 11:17:43 -0500600 * - srtp_err_status_ok if stream creation succeded.
601 * - srtp_err_status_alloc_fail if stream allocation failed
602 * - srtp_err_status_init_fail if stream initialization failed.
Cullen Jennings235513a2005-09-21 22:51:36 +0000603 */
jfigus857009c2014-11-05 11:17:43 -0500604srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy);
Cullen Jennings235513a2005-09-21 22:51:36 +0000605
Cullen Jennings235513a2005-09-21 22:51:36 +0000606/**
607 * @brief srtp_remove_stream() deallocates an SRTP stream.
Geir Istadb6109682017-07-10 19:01:17 +0200608 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000609 * The function call srtp_remove_stream(session, ssrc) removes
610 * the SRTP stream with the SSRC value ssrc from the SRTP session
611 * context given by the argument session.
612 *
613 * @param session is the SRTP session from which the stream
614 * will be removed.
615 *
jfigus68f8a882016-02-03 12:48:23 -0500616 * @param ssrc is the SSRC value of the stream to be removed
617 * in network byte order.
Cullen Jennings235513a2005-09-21 22:51:36 +0000618 *
619 * @warning Wildcard SSRC values cannot be removed from a
620 * session.
Geir Istadb6109682017-07-10 19:01:17 +0200621 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000622 * @return
jfigus857009c2014-11-05 11:17:43 -0500623 * - srtp_err_status_ok if the stream deallocation succeded.
Cullen Jennings235513a2005-09-21 22:51:36 +0000624 * - [other] otherwise.
625 *
626 */
jfigus857009c2014-11-05 11:17:43 -0500627srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc);
Cullen Jennings235513a2005-09-21 22:51:36 +0000628
629/**
Pascal Bühlerbd3112a2015-11-06 20:29:15 +0100630 * @brief srtp_update() udpates all streams in the session.
631 *
632 * The function call srtp_update(session, policy) updates
633 * all the streams in the session applying the given policy
634 * and key. The exsisting ROC value of all streams will be
635 * preserved.
636 *
637 * @param session is the SRTP session that contains the streams
638 * to be updated.
639 *
640 * @param policy is the srtp_policy_t struct that describes the policy
641 * for the session. The struct may be a single element, or it may be
642 * the head of a list, in which case each element of the list is
643 * processed. The final element of the list @b must
644 * have its `next' field set to NULL.
645 *
646 * @return
647 * - srtp_err_status_ok if stream creation succeded.
648 * - srtp_err_status_alloc_fail if stream allocation failed
649 * - srtp_err_status_init_fail if stream initialization failed.
650 * - [other] otherwise.
651 *
652 */
Pascal Bühlerbd3112a2015-11-06 20:29:15 +0100653srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy);
654
655/**
656 * @brief srtp_update_stream() udpates a SRTP stream.
657 *
658 * The function call srtp_update_stream(session, policy) updates
659 * the stream(s) in the session that match applying the given
660 * policy and key. The exsisting ROC value of all stream(s) will
661 * be preserved.
662 *
663 * @param session is the SRTP session that contains the streams
664 * to be updated.
665 *
666 * @param policy is the srtp_policy_t struct that describes the policy
667 * for the session.
668 *
669 * @return
670 * - srtp_err_status_ok if stream creation succeded.
671 * - srtp_err_status_alloc_fail if stream allocation failed
672 * - srtp_err_status_init_fail if stream initialization failed.
673 * - [other] otherwise.
674 *
675 */
Geir Istadb6109682017-07-10 19:01:17 +0200676srtp_err_status_t srtp_update_stream(srtp_t session,
677 const srtp_policy_t *policy);
Pascal Bühlerbd3112a2015-11-06 20:29:15 +0100678
679/**
jfigus857009c2014-11-05 11:17:43 -0500680 * @brief srtp_crypto_policy_set_rtp_default() sets a crypto policy
Cullen Jennings235513a2005-09-21 22:51:36 +0000681 * structure to the SRTP default policy for RTP protection.
682 *
Geir Istadb6109682017-07-10 19:01:17 +0200683 * @param p is a pointer to the policy structure to be set
684 *
Sean DuBoisb173a642019-07-11 08:24:41 +0100685 * The function call srtp_crypto_policy_set_rtp_default(&p) sets the
686 * srtp_crypto_policy_t at location p to the SRTP default policy for RTP
Cullen Jennings235513a2005-09-21 22:51:36 +0000687 * protection, as defined in the specification. This function is a
688 * convenience that helps to avoid dealing directly with the policy
689 * data structure. You are encouraged to initialize policy elements
690 * with this function call. Doing so may allow your code to be
691 * forward compatible with later versions of libSRTP that include more
Sean DuBoisb173a642019-07-11 08:24:41 +0100692 * elements in the srtp_crypto_policy_t datatype.
Geir Istadb6109682017-07-10 19:01:17 +0200693 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000694 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200695 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000696 */
jfigus857009c2014-11-05 11:17:43 -0500697void srtp_crypto_policy_set_rtp_default(srtp_crypto_policy_t *p);
Cullen Jennings235513a2005-09-21 22:51:36 +0000698
699/**
jfigus857009c2014-11-05 11:17:43 -0500700 * @brief srtp_crypto_policy_set_rtcp_default() sets a crypto policy
Cullen Jennings235513a2005-09-21 22:51:36 +0000701 * structure to the SRTP default policy for RTCP protection.
702 *
Geir Istadb6109682017-07-10 19:01:17 +0200703 * @param p is a pointer to the policy structure to be set
704 *
jfigus857009c2014-11-05 11:17:43 -0500705 * The function call srtp_crypto_policy_set_rtcp_default(&p) sets the
706 * srtp_crypto_policy_t at location p to the SRTP default policy for RTCP
Cullen Jennings235513a2005-09-21 22:51:36 +0000707 * protection, as defined in the specification. This function is a
708 * convenience that helps to avoid dealing directly with the policy
709 * data structure. You are encouraged to initialize policy elements
710 * with this function call. Doing so may allow your code to be
711 * forward compatible with later versions of libSRTP that include more
jfigus857009c2014-11-05 11:17:43 -0500712 * elements in the srtp_crypto_policy_t datatype.
Geir Istadb6109682017-07-10 19:01:17 +0200713 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000714 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200715 *
Cullen Jennings235513a2005-09-21 22:51:36 +0000716 */
jfigus857009c2014-11-05 11:17:43 -0500717void srtp_crypto_policy_set_rtcp_default(srtp_crypto_policy_t *p);
Cullen Jennings235513a2005-09-21 22:51:36 +0000718
719/**
jfigus857009c2014-11-05 11:17:43 -0500720 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000721 * policy structure to the SRTP default policy for RTP protection.
722 *
Geir Istadb6109682017-07-10 19:01:17 +0200723 * @param p is a pointer to the policy structure to be set
724 *
jfigus857009c2014-11-05 11:17:43 -0500725 * The function srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
726 * synonym for srtp_crypto_policy_set_rtp_default(). It conforms to the
Jonathan Lennoxd8d5cd02010-05-17 20:08:17 +0000727 * naming convention used in RFC 4568 (SDP Security Descriptions for
728 * Media Streams).
Geir Istadb6109682017-07-10 19:01:17 +0200729 *
David McGrewa8546882006-01-12 17:56:02 +0000730 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200731 *
David McGrewa8546882006-01-12 17:56:02 +0000732 */
Geir Istadb6109682017-07-10 19:01:17 +0200733#define srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(p) \
734 srtp_crypto_policy_set_rtp_default(p)
David McGrewa8546882006-01-12 17:56:02 +0000735
736/**
jfigus857009c2014-11-05 11:17:43 -0500737 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000738 * policy structure to a short-authentication tag policy
739 *
Geir Istadb6109682017-07-10 19:01:17 +0200740 * @param p is a pointer to the policy structure to be set
741 *
jfigus857009c2014-11-05 11:17:43 -0500742 * The function call srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
743 * sets the srtp_crypto_policy_t at location p to use policy
Jonathan Lennoxd8d5cd02010-05-17 20:08:17 +0000744 * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568.
745 * This policy uses AES-128
David McGrewa8546882006-01-12 17:56:02 +0000746 * Counter Mode encryption and HMAC-SHA1 authentication, with an
747 * authentication tag that is only 32 bits long. This length is
748 * considered adequate only for protecting audio and video media that
749 * use a stateless playback function. See Section 7.5 of RFC 3711
750 * (http://www.ietf.org/rfc/rfc3711.txt).
Geir Istadb6109682017-07-10 19:01:17 +0200751 *
David McGrewa8546882006-01-12 17:56:02 +0000752 * This function is a convenience that helps to avoid dealing directly
753 * with the policy data structure. You are encouraged to initialize
754 * policy elements with this function call. Doing so may allow your
755 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500756 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000757 *
758 * @warning This crypto policy is intended for use in SRTP, but not in
759 * SRTCP. It is recommended that a policy that uses longer
760 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
761 * (http://www.ietf.org/rfc/rfc3711.txt).
762 *
763 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200764 *
David McGrewa8546882006-01-12 17:56:02 +0000765 */
jfigus857009c2014-11-05 11:17:43 -0500766void srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000767
David McGrewa8546882006-01-12 17:56:02 +0000768/**
jfigus857009c2014-11-05 11:17:43 -0500769 * @brief srtp_crypto_policy_set_aes_cm_128_null_auth() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000770 * policy structure to an encryption-only policy
771 *
Geir Istadb6109682017-07-10 19:01:17 +0200772 * @param p is a pointer to the policy structure to be set
773 *
jfigus857009c2014-11-05 11:17:43 -0500774 * The function call srtp_crypto_policy_set_aes_cm_128_null_auth(&p) sets
775 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
David McGrewa8546882006-01-12 17:56:02 +0000776 * (AES-128 Counter Mode), but to use no authentication method. This
777 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
778 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
Geir Istadb6109682017-07-10 19:01:17 +0200779 *
David McGrewa8546882006-01-12 17:56:02 +0000780 * This function is a convenience that helps to avoid dealing directly
781 * with the policy data structure. You are encouraged to initialize
782 * policy elements with this function call. Doing so may allow your
783 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500784 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000785 *
786 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
787 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
788 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
789 *
790 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200791 *
David McGrewa8546882006-01-12 17:56:02 +0000792 */
jfigus857009c2014-11-05 11:17:43 -0500793void srtp_crypto_policy_set_aes_cm_128_null_auth(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000794
David McGrewa8546882006-01-12 17:56:02 +0000795/**
jfigus857009c2014-11-05 11:17:43 -0500796 * @brief srtp_crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
David McGrewa8546882006-01-12 17:56:02 +0000797 * policy structure to an authentication-only policy
798 *
Geir Istadb6109682017-07-10 19:01:17 +0200799 * @param p is a pointer to the policy structure to be set
800 *
jfigus857009c2014-11-05 11:17:43 -0500801 * The function call srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&p)
802 * sets the srtp_crypto_policy_t at location p to use HMAC-SHA1 with an 80
David McGrewa8546882006-01-12 17:56:02 +0000803 * bit authentication tag to provide message authentication, but to
804 * use no encryption. This policy is NOT RECOMMENDED for SRTP unless
Geir Istadb6109682017-07-10 19:01:17 +0200805 * there is a requirement to forego encryption.
806 *
David McGrewa8546882006-01-12 17:56:02 +0000807 * This function is a convenience that helps to avoid dealing directly
808 * with the policy data structure. You are encouraged to initialize
809 * policy elements with this function call. Doing so may allow your
810 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500811 * include more elements in the srtp_crypto_policy_t datatype.
David McGrewa8546882006-01-12 17:56:02 +0000812 *
813 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
Geir Istadb6109682017-07-10 19:01:17 +0200814 * requirement to forego encryption.
David McGrewa8546882006-01-12 17:56:02 +0000815 *
816 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200817 *
David McGrewa8546882006-01-12 17:56:02 +0000818 */
jfigus857009c2014-11-05 11:17:43 -0500819void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p);
David McGrewa8546882006-01-12 17:56:02 +0000820
jfigus267956d2014-11-06 10:49:21 -0500821/**
822 * @brief srtp_crypto_policy_set_null_cipher_hmac_null() sets a crypto
Geir Istadb6109682017-07-10 19:01:17 +0200823 * policy structure to use no encryption or authentication.
jfigus267956d2014-11-06 10:49:21 -0500824 *
Geir Istadb6109682017-07-10 19:01:17 +0200825 * @param p is a pointer to the policy structure to be set
826 *
jfigus267956d2014-11-06 10:49:21 -0500827 * The function call srtp_crypto_policy_set_null_cipher_hmac_null(&p)
828 * sets the srtp_crypto_policy_t at location p to use no encryption and
829 * no authentication. This policy should only be used for testing and
Geir Istadb6109682017-07-10 19:01:17 +0200830 * troubleshootingl.
831 *
jfigus267956d2014-11-06 10:49:21 -0500832 * This function is a convenience that helps to avoid dealing directly
833 * with the policy data structure. You are encouraged to initialize
834 * policy elements with this function call. Doing so may allow your
835 * code to be forward compatible with later versions of libSRTP that
836 * include more elements in the srtp_crypto_policy_t datatype.
837 *
838 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
Geir Istadb6109682017-07-10 19:01:17 +0200839 * requirement to forego encryption and authentication.
jfigus267956d2014-11-06 10:49:21 -0500840 *
841 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200842 *
jfigus267956d2014-11-06 10:49:21 -0500843 */
844void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p);
845
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000846/**
jfigus857009c2014-11-05 11:17:43 -0500847 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto
Geir Istadb6109682017-07-10 19:01:17 +0200848 * policy structure to a encryption and authentication policy using AES-256
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000849 * for RTP protection.
850 *
Geir Istadb6109682017-07-10 19:01:17 +0200851 * @param p is a pointer to the policy structure to be set
852 *
jfigus857009c2014-11-05 11:17:43 -0500853 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&p)
854 * sets the srtp_crypto_policy_t at location p to use policy
Geir Istad23020812017-03-22 20:10:55 +0100855 * AES_CM_256_HMAC_SHA1_80 as defined in RFC 6188. This policy uses AES-256
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000856 * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
857 * authentication tag.
Geir Istadb6109682017-07-10 19:01:17 +0200858 *
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000859 * This function is a convenience that helps to avoid dealing directly
860 * with the policy data structure. You are encouraged to initialize
861 * policy elements with this function call. Doing so may allow your
862 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500863 * include more elements in the srtp_crypto_policy_t datatype.
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000864 *
865 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200866 *
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000867 */
jfigus857009c2014-11-05 11:17:43 -0500868void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(srtp_crypto_policy_t *p);
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000869
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000870/**
jfigus857009c2014-11-05 11:17:43 -0500871 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000872 * policy structure to a short-authentication tag policy using AES-256
873 * encryption.
874 *
Geir Istadb6109682017-07-10 19:01:17 +0200875 * @param p is a pointer to the policy structure to be set
876 *
jfigus857009c2014-11-05 11:17:43 -0500877 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&p)
878 * sets the srtp_crypto_policy_t at location p to use policy
Geir Istad23020812017-03-22 20:10:55 +0100879 * AES_CM_256_HMAC_SHA1_32 as defined in RFC 6188. This policy uses AES-256
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000880 * Counter Mode encryption and HMAC-SHA1 authentication, with an
881 * authentication tag that is only 32 bits long. This length is
882 * considered adequate only for protecting audio and video media that
883 * use a stateless playback function. See Section 7.5 of RFC 3711
884 * (http://www.ietf.org/rfc/rfc3711.txt).
Geir Istadb6109682017-07-10 19:01:17 +0200885 *
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000886 * This function is a convenience that helps to avoid dealing directly
887 * with the policy data structure. You are encouraged to initialize
888 * policy elements with this function call. Doing so may allow your
889 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500890 * include more elements in the srtp_crypto_policy_t datatype.
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000891 *
892 * @warning This crypto policy is intended for use in SRTP, but not in
893 * SRTCP. It is recommended that a policy that uses longer
894 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
895 * (http://www.ietf.org/rfc/rfc3711.txt).
896 *
897 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +0200898 *
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000899 */
jfigus857009c2014-11-05 11:17:43 -0500900void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(srtp_crypto_policy_t *p);
Jonathan Lennox5df951a2010-05-20 20:55:54 +0000901
jfigus8c36da22013-10-01 16:41:19 -0400902/**
jfigus857009c2014-11-05 11:17:43 -0500903 * @brief srtp_crypto_policy_set_aes_cm_256_null_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -0400904 * policy structure to an encryption-only policy
905 *
906 * @param p is a pointer to the policy structure to be set
907 *
jfigus857009c2014-11-05 11:17:43 -0500908 * The function call srtp_crypto_policy_set_aes_cm_256_null_auth(&p) sets
909 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -0400910 * (AES-256 Counter Mode), but to use no authentication method. This
911 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
912 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
913 *
914 * This function is a convenience that helps to avoid dealing directly
915 * with the policy data structure. You are encouraged to initialize
916 * policy elements with this function call. Doing so may allow your
917 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -0500918 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -0400919 *
920 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
921 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
922 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
923 *
924 * @return void.
925 *
926 */
jfigus857009c2014-11-05 11:17:43 -0500927void srtp_crypto_policy_set_aes_cm_256_null_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -0400928
Alexander Traud8872f712017-02-21 12:55:24 +0100929/**
930 * @brief srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80() sets a crypto
931 * policy structure to a encryption and authentication policy using AES-192
932 * for RTP protection.
933 *
934 * @param p is a pointer to the policy structure to be set
935 *
936 * The function call srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&p)
Sean DuBoisb173a642019-07-11 08:24:41 +0100937 * sets the srtp_crypto_policy_t at location p to use policy
Geir Istad23020812017-03-22 20:10:55 +0100938 * AES_CM_192_HMAC_SHA1_80 as defined in RFC 6188. This policy uses AES-192
Alexander Traud8872f712017-02-21 12:55:24 +0100939 * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
940 * authentication tag.
941 *
942 * This function is a convenience that helps to avoid dealing directly
943 * with the policy data structure. You are encouraged to initialize
944 * policy elements with this function call. Doing so may allow your
945 * code to be forward compatible with later versions of libSRTP that
Sean DuBoisb173a642019-07-11 08:24:41 +0100946 * include more elements in the srtp_crypto_policy_t datatype.
Alexander Traud8872f712017-02-21 12:55:24 +0100947 *
948 * @return void.
949 *
950 */
951void srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(srtp_crypto_policy_t *p);
952
Alexander Traud8872f712017-02-21 12:55:24 +0100953/**
954 * @brief srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32() sets a crypto
955 * policy structure to a short-authentication tag policy using AES-192
956 * encryption.
957 *
958 * @param p is a pointer to the policy structure to be set
959 *
960 * The function call srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&p)
Sean DuBoisb173a642019-07-11 08:24:41 +0100961 * sets the srtp_crypto_policy_t at location p to use policy
Geir Istad23020812017-03-22 20:10:55 +0100962 * AES_CM_192_HMAC_SHA1_32 as defined in RFC 6188. This policy uses AES-192
Alexander Traud8872f712017-02-21 12:55:24 +0100963 * Counter Mode encryption and HMAC-SHA1 authentication, with an
964 * authentication tag that is only 32 bits long. This length is
965 * considered adequate only for protecting audio and video media that
966 * use a stateless playback function. See Section 7.5 of RFC 3711
967 * (http://www.ietf.org/rfc/rfc3711.txt).
968 *
969 * This function is a convenience that helps to avoid dealing directly
970 * with the policy data structure. You are encouraged to initialize
971 * policy elements with this function call. Doing so may allow your
972 * code to be forward compatible with later versions of libSRTP that
Sean DuBoisb173a642019-07-11 08:24:41 +0100973 * include more elements in the srtp_crypto_policy_t datatype.
Alexander Traud8872f712017-02-21 12:55:24 +0100974 *
975 * @warning This crypto policy is intended for use in SRTP, but not in
976 * SRTCP. It is recommended that a policy that uses longer
977 * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
978 * (http://www.ietf.org/rfc/rfc3711.txt).
979 *
980 * @return void.
981 *
982 */
983void srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(srtp_crypto_policy_t *p);
984
Alexander Traud8872f712017-02-21 12:55:24 +0100985/**
986 * @brief srtp_crypto_policy_set_aes_cm_192_null_auth() sets a crypto
987 * policy structure to an encryption-only policy
988 *
989 * @param p is a pointer to the policy structure to be set
990 *
991 * The function call srtp_crypto_policy_set_aes_cm_192_null_auth(&p) sets
Sean DuBoisb173a642019-07-11 08:24:41 +0100992 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
Alexander Traud8872f712017-02-21 12:55:24 +0100993 * (AES-192 Counter Mode), but to use no authentication method. This
994 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
995 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
996 *
997 * This function is a convenience that helps to avoid dealing directly
998 * with the policy data structure. You are encouraged to initialize
999 * policy elements with this function call. Doing so may allow your
1000 * code to be forward compatible with later versions of libSRTP that
Sean DuBoisb173a642019-07-11 08:24:41 +01001001 * include more elements in the srtp_crypto_policy_t datatype.
Alexander Traud8872f712017-02-21 12:55:24 +01001002 *
1003 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
1004 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
1005 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
1006 *
1007 * @return void.
1008 *
1009 */
1010void srtp_crypto_policy_set_aes_cm_192_null_auth(srtp_crypto_policy_t *p);
1011
jfigus8c36da22013-10-01 16:41:19 -04001012/**
jfigus857009c2014-11-05 11:17:43 -05001013 * @brief srtp_crypto_policy_set_aes_gcm_128_8_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001014 * policy structure to an AEAD encryption policy.
1015 *
Geir Istadb6109682017-07-10 19:01:17 +02001016 * @param p is a pointer to the policy structure to be set
1017 *
jfigus857009c2014-11-05 11:17:43 -05001018 * The function call srtp_crypto_policy_set_aes_gcm_128_8_auth(&p) sets
1019 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigus8c36da22013-10-01 16:41:19 -04001020 * (AES-128 Galois Counter Mode) with 8 octet auth tag. This
1021 * policy applies confidentiality and authentication to both the
1022 * RTP and RTCP packets.
Geir Istadb6109682017-07-10 19:01:17 +02001023 *
jfigus8c36da22013-10-01 16:41:19 -04001024 * This function is a convenience that helps to avoid dealing directly
1025 * with the policy data structure. You are encouraged to initialize
1026 * policy elements with this function call. Doing so may allow your
1027 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001028 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001029 *
1030 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +02001031 *
jfigus8c36da22013-10-01 16:41:19 -04001032 */
jfigus857009c2014-11-05 11:17:43 -05001033void srtp_crypto_policy_set_aes_gcm_128_8_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001034
1035/**
jfigus857009c2014-11-05 11:17:43 -05001036 * @brief srtp_crypto_policy_set_aes_gcm_256_8_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001037 * policy structure to an AEAD encryption policy
1038 *
Geir Istadb6109682017-07-10 19:01:17 +02001039 * @param p is a pointer to the policy structure to be set
1040 *
jfigus857009c2014-11-05 11:17:43 -05001041 * The function call srtp_crypto_policy_set_aes_gcm_256_8_auth(&p) sets
1042 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
Geir Istadb6109682017-07-10 19:01:17 +02001043 * (AES-256 Galois Counter Mode) with 8 octet auth tag. This
jfigus8c36da22013-10-01 16:41:19 -04001044 * policy applies confidentiality and authentication to both the
1045 * RTP and RTCP packets.
Geir Istadb6109682017-07-10 19:01:17 +02001046 *
jfigus8c36da22013-10-01 16:41:19 -04001047 * This function is a convenience that helps to avoid dealing directly
1048 * with the policy data structure. You are encouraged to initialize
1049 * policy elements with this function call. Doing so may allow your
1050 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001051 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001052 *
1053 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +02001054 *
jfigus8c36da22013-10-01 16:41:19 -04001055 */
jfigus857009c2014-11-05 11:17:43 -05001056void srtp_crypto_policy_set_aes_gcm_256_8_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001057
1058/**
jfigus857009c2014-11-05 11:17:43 -05001059 * @brief srtp_crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001060 * policy structure to an AEAD authentication-only policy
1061 *
Geir Istadb6109682017-07-10 19:01:17 +02001062 * @param p is a pointer to the policy structure to be set
1063 *
jfigus857009c2014-11-05 11:17:43 -05001064 * The function call srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets
1065 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
Geir Istadb6109682017-07-10 19:01:17 +02001066 * (AES-128 Galois Counter Mode) with 8 octet auth tag. This policy
1067 * applies confidentiality and authentication to the RTP packets,
jfigus8c36da22013-10-01 16:41:19 -04001068 * but only authentication to the RTCP packets.
Geir Istadb6109682017-07-10 19:01:17 +02001069 *
jfigus8c36da22013-10-01 16:41:19 -04001070 * This function is a convenience that helps to avoid dealing directly
1071 * with the policy data structure. You are encouraged to initialize
1072 * policy elements with this function call. Doing so may allow your
1073 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001074 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001075 *
1076 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +02001077 *
jfigus8c36da22013-10-01 16:41:19 -04001078 */
jfigus857009c2014-11-05 11:17:43 -05001079void srtp_crypto_policy_set_aes_gcm_128_8_only_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001080
1081/**
jfigus857009c2014-11-05 11:17:43 -05001082 * @brief srtp_crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto
jfigus8c36da22013-10-01 16:41:19 -04001083 * policy structure to an AEAD authentication-only policy
1084 *
Geir Istadb6109682017-07-10 19:01:17 +02001085 * @param p is a pointer to the policy structure to be set
1086 *
jfigus857009c2014-11-05 11:17:43 -05001087 * The function call srtp_crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets
1088 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
Geir Istadb6109682017-07-10 19:01:17 +02001089 * (AES-256 Galois Counter Mode) with 8 octet auth tag. This policy
1090 * applies confidentiality and authentication to the RTP packets,
jfigus8c36da22013-10-01 16:41:19 -04001091 * but only authentication to the RTCP packets.
Geir Istadb6109682017-07-10 19:01:17 +02001092 *
jfigus8c36da22013-10-01 16:41:19 -04001093 * This function is a convenience that helps to avoid dealing directly
1094 * with the policy data structure. You are encouraged to initialize
1095 * policy elements with this function call. Doing so may allow your
1096 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001097 * include more elements in the srtp_crypto_policy_t datatype.
jfigus8c36da22013-10-01 16:41:19 -04001098 *
1099 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +02001100 *
jfigus8c36da22013-10-01 16:41:19 -04001101 */
jfigus857009c2014-11-05 11:17:43 -05001102void srtp_crypto_policy_set_aes_gcm_256_8_only_auth(srtp_crypto_policy_t *p);
jfigus8c36da22013-10-01 16:41:19 -04001103
jfigusc13c1002014-05-08 13:34:53 -04001104/**
jfigus857009c2014-11-05 11:17:43 -05001105 * @brief srtp_crypto_policy_set_aes_gcm_128_16_auth() sets a crypto
jfigusc13c1002014-05-08 13:34:53 -04001106 * policy structure to an AEAD encryption policy.
1107 *
Geir Istadb6109682017-07-10 19:01:17 +02001108 * @param p is a pointer to the policy structure to be set
1109 *
jfigus857009c2014-11-05 11:17:43 -05001110 * The function call srtp_crypto_policy_set_aes_gcm_128_16_auth(&p) sets
1111 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
jfigusc13c1002014-05-08 13:34:53 -04001112 * (AES-128 Galois Counter Mode) with 16 octet auth tag. This
1113 * policy applies confidentiality and authentication to both the
1114 * RTP and RTCP packets.
Geir Istadb6109682017-07-10 19:01:17 +02001115 *
jfigusc13c1002014-05-08 13:34:53 -04001116 * This function is a convenience that helps to avoid dealing directly
1117 * with the policy data structure. You are encouraged to initialize
1118 * policy elements with this function call. Doing so may allow your
1119 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001120 * include more elements in the srtp_crypto_policy_t datatype.
jfigusc13c1002014-05-08 13:34:53 -04001121 *
1122 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +02001123 *
jfigusc13c1002014-05-08 13:34:53 -04001124 */
jfigus857009c2014-11-05 11:17:43 -05001125void srtp_crypto_policy_set_aes_gcm_128_16_auth(srtp_crypto_policy_t *p);
jfigusc13c1002014-05-08 13:34:53 -04001126
1127/**
jfigus857009c2014-11-05 11:17:43 -05001128 * @brief srtp_crypto_policy_set_aes_gcm_256_16_auth() sets a crypto
jfigusc13c1002014-05-08 13:34:53 -04001129 * policy structure to an AEAD encryption policy
1130 *
Geir Istadb6109682017-07-10 19:01:17 +02001131 * @param p is a pointer to the policy structure to be set
1132 *
jfigus857009c2014-11-05 11:17:43 -05001133 * The function call srtp_crypto_policy_set_aes_gcm_256_16_auth(&p) sets
1134 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
Geir Istadb6109682017-07-10 19:01:17 +02001135 * (AES-256 Galois Counter Mode) with 16 octet auth tag. This
jfigusc13c1002014-05-08 13:34:53 -04001136 * policy applies confidentiality and authentication to both the
1137 * RTP and RTCP packets.
Geir Istadb6109682017-07-10 19:01:17 +02001138 *
jfigusc13c1002014-05-08 13:34:53 -04001139 * This function is a convenience that helps to avoid dealing directly
1140 * with the policy data structure. You are encouraged to initialize
1141 * policy elements with this function call. Doing so may allow your
1142 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001143 * include more elements in the srtp_crypto_policy_t datatype.
jfigusc13c1002014-05-08 13:34:53 -04001144 *
1145 * @return void.
Geir Istadb6109682017-07-10 19:01:17 +02001146 *
jfigusc13c1002014-05-08 13:34:53 -04001147 */
jfigus857009c2014-11-05 11:17:43 -05001148void srtp_crypto_policy_set_aes_gcm_256_16_auth(srtp_crypto_policy_t *p);
jfigusc13c1002014-05-08 13:34:53 -04001149
David McGrewa8546882006-01-12 17:56:02 +00001150/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001151 * @brief srtp_dealloc() deallocates storage for an SRTP session
1152 * context.
Geir Istadb6109682017-07-10 19:01:17 +02001153 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001154 * The function call srtp_dealloc(s) deallocates storage for the
1155 * SRTP session context s. This function should be called no more
1156 * than one time for each of the contexts allocated by the function
1157 * srtp_create().
1158 *
1159 * @param s is the srtp_t for the session to be deallocated.
1160 *
1161 * @return
jfigus857009c2014-11-05 11:17:43 -05001162 * - srtp_err_status_ok if there no problems.
1163 * - srtp_err_status_dealloc_fail a memory deallocation failure occured.
Cullen Jennings235513a2005-09-21 22:51:36 +00001164 */
jfigus857009c2014-11-05 11:17:43 -05001165srtp_err_status_t srtp_dealloc(srtp_t s);
Cullen Jennings235513a2005-09-21 22:51:36 +00001166
David McGrew0cb86ee2006-07-07 15:46:57 +00001167/*
Geir Istadb6109682017-07-10 19:01:17 +02001168 * @brief identifies a particular SRTP profile
David McGrew0cb86ee2006-07-07 15:46:57 +00001169 *
1170 * An srtp_profile_t enumeration is used to identify a particular SRTP
Alexander Traud97ba0212016-07-11 12:20:29 +02001171 * profile (that is, a set of algorithms and parameters). These profiles
1172 * are defined for DTLS-SRTP:
1173 * https://www.iana.org/assignments/srtp-protection/srtp-protection.xhtml
David McGrew0cb86ee2006-07-07 15:46:57 +00001174 */
David McGrew0cb86ee2006-07-07 15:46:57 +00001175typedef enum {
Geir Istadb6109682017-07-10 19:01:17 +02001176 srtp_profile_reserved = 0,
1177 srtp_profile_aes128_cm_sha1_80 = 1,
1178 srtp_profile_aes128_cm_sha1_32 = 2,
1179 srtp_profile_null_sha1_80 = 5,
1180 srtp_profile_null_sha1_32 = 6,
1181 srtp_profile_aead_aes_128_gcm = 7,
1182 srtp_profile_aead_aes_256_gcm = 8,
David McGrew0cb86ee2006-07-07 15:46:57 +00001183} srtp_profile_t;
1184
David McGrew0cb86ee2006-07-07 15:46:57 +00001185/**
jfigus857009c2014-11-05 11:17:43 -05001186 * @brief srtp_crypto_policy_set_from_profile_for_rtp() sets a crypto policy
David McGrew0cb86ee2006-07-07 15:46:57 +00001187 * structure to the appropriate value for RTP based on an srtp_profile_t
1188 *
Geir Istadb6a4a792017-03-29 06:34:35 +02001189 * @param policy is a pointer to the policy structure to be set
1190 *
1191 * @param profile is an enumeration for the policy to be set
1192 *
jfigus857009c2014-11-05 11:17:43 -05001193 * The function call srtp_crypto_policy_set_rtp_default(&policy, profile)
1194 * sets the srtp_crypto_policy_t at location policy to the policy for RTP
David McGrew0cb86ee2006-07-07 15:46:57 +00001195 * protection, as defined by the srtp_profile_t profile.
Geir Istadb6a4a792017-03-29 06:34:35 +02001196 *
David McGrew0cb86ee2006-07-07 15:46:57 +00001197 * This function is a convenience that helps to avoid dealing directly
1198 * with the policy data structure. You are encouraged to initialize
1199 * policy elements with this function call. Doing so may allow your
1200 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001201 * include more elements in the srtp_crypto_policy_t datatype.
Geir Istadb6a4a792017-03-29 06:34:35 +02001202 *
David McGrew0cb86ee2006-07-07 15:46:57 +00001203 * @return values
jfigus857009c2014-11-05 11:17:43 -05001204 * - srtp_err_status_ok no problems were encountered
Geir Istadb6109682017-07-10 19:01:17 +02001205 * - srtp_err_status_bad_param the profile is not supported
Geir Istadb6a4a792017-03-29 06:34:35 +02001206 *
David McGrew0cb86ee2006-07-07 15:46:57 +00001207 */
Geir Istad013228a2017-09-29 07:06:22 +02001208srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtp(
1209 srtp_crypto_policy_t *policy,
1210 srtp_profile_t profile);
David McGrew0cb86ee2006-07-07 15:46:57 +00001211
1212/**
jfigus857009c2014-11-05 11:17:43 -05001213 * @brief srtp_crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
David McGrew0cb86ee2006-07-07 15:46:57 +00001214 * structure to the appropriate value for RTCP based on an srtp_profile_t
1215 *
Geir Istad8124b762017-03-29 06:32:39 +02001216 * @param policy is a pointer to the policy structure to be set
1217 *
1218 * @param profile is an enumeration for the policy to be set
1219 *
jfigus857009c2014-11-05 11:17:43 -05001220 * The function call srtp_crypto_policy_set_rtcp_default(&policy, profile)
1221 * sets the srtp_crypto_policy_t at location policy to the policy for RTCP
David McGrew0cb86ee2006-07-07 15:46:57 +00001222 * protection, as defined by the srtp_profile_t profile.
Geir Istad8124b762017-03-29 06:32:39 +02001223 *
David McGrew0cb86ee2006-07-07 15:46:57 +00001224 * This function is a convenience that helps to avoid dealing directly
1225 * with the policy data structure. You are encouraged to initialize
1226 * policy elements with this function call. Doing so may allow your
1227 * code to be forward compatible with later versions of libSRTP that
jfigus857009c2014-11-05 11:17:43 -05001228 * include more elements in the srtp_crypto_policy_t datatype.
Geir Istad8124b762017-03-29 06:32:39 +02001229 *
David McGrew0cb86ee2006-07-07 15:46:57 +00001230 * @return values
jfigus857009c2014-11-05 11:17:43 -05001231 * - srtp_err_status_ok no problems were encountered
Geir Istad8124b762017-03-29 06:32:39 +02001232 * - srtp_err_status_bad_param the profile is not supported
1233 *
David McGrew0cb86ee2006-07-07 15:46:57 +00001234 */
Geir Istad013228a2017-09-29 07:06:22 +02001235srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtcp(
1236 srtp_crypto_policy_t *policy,
1237 srtp_profile_t profile);
David McGrew0cb86ee2006-07-07 15:46:57 +00001238
1239/**
1240 * @brief returns the master key length for a given SRTP profile
1241 */
Geir Istadb6109682017-07-10 19:01:17 +02001242unsigned int srtp_profile_get_master_key_length(srtp_profile_t profile);
David McGrew0cb86ee2006-07-07 15:46:57 +00001243
1244/**
1245 * @brief returns the master salt length for a given SRTP profile
1246 */
Geir Istadb6109682017-07-10 19:01:17 +02001247unsigned int srtp_profile_get_master_salt_length(srtp_profile_t profile);
David McGrew0cb86ee2006-07-07 15:46:57 +00001248
1249/**
1250 * @brief appends the salt to the key
1251 *
Geir Istadb6109682017-07-10 19:01:17 +02001252 * The function call srtp_append_salt_to_key(k, klen, s, slen)
David McGrew0cb86ee2006-07-07 15:46:57 +00001253 * copies the string s to the location at klen bytes following
Geir Istadb6109682017-07-10 19:01:17 +02001254 * the location k.
David McGrew0cb86ee2006-07-07 15:46:57 +00001255 *
1256 * @warning There must be at least bytes_in_salt + bytes_in_key bytes
1257 * available at the location pointed to by key.
Geir Istadb6109682017-07-10 19:01:17 +02001258 *
David McGrew0cb86ee2006-07-07 15:46:57 +00001259 */
Geir Istadb6109682017-07-10 19:01:17 +02001260void srtp_append_salt_to_key(unsigned char *key,
1261 unsigned int bytes_in_key,
1262 unsigned char *salt,
1263 unsigned int bytes_in_salt);
Cullen Jennings235513a2005-09-21 22:51:36 +00001264
1265/**
1266 * @}
1267 */
1268
Cullen Jennings235513a2005-09-21 22:51:36 +00001269/**
1270 * @defgroup SRTCP Secure RTCP
Geir Istadb6109682017-07-10 19:01:17 +02001271 * @ingroup SRTP
Cullen Jennings235513a2005-09-21 22:51:36 +00001272 *
1273 * @brief Secure RTCP functions are used to protect RTCP traffic.
1274 *
1275 * RTCP is the control protocol for RTP. libSRTP protects RTCP
1276 * traffic in much the same way as it does RTP traffic. The function
1277 * srtp_protect_rtcp() applies cryptographic protections to outbound
1278 * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on
Geir Istadb6109682017-07-10 19:01:17 +02001279 * inbound RTCP packets.
Cullen Jennings235513a2005-09-21 22:51:36 +00001280 *
1281 * A note on the naming convention: srtp_protect_rtcp() has an srtp_t
1282 * as its first argument, and thus has `srtp_' as its prefix. The
Geir Istadb6109682017-07-10 19:01:17 +02001283 * trailing `_rtcp' indicates the protocol on which it acts.
1284 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001285 * @{
1286 */
1287
1288/**
1289 * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet
1290 * processing function.
Geir Istadb6109682017-07-10 19:01:17 +02001291 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001292 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
1293 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
jfigus857009c2014-11-05 11:17:43 -05001294 * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
Cullen Jennings235513a2005-09-21 22:51:36 +00001295 * returned, then rtp_hdr points to the resulting SRTCP packet and
1296 * *len_ptr is the number of octets in that packet; otherwise, no
1297 * assumptions should be made about the value of either data elements.
Geir Istadb6109682017-07-10 19:01:17 +02001298 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001299 * @warning This function assumes that it can write the authentication
1300 * tag into the location in memory immediately following the RTCP
1301 * packet, and assumes that the RTCP packet is aligned on a 32-bit
1302 * boundary.
1303 *
Geir Istadb6109682017-07-10 19:01:17 +02001304 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
1305 * into the location in memory immediately following the RTCP packet.
1306 * Callers MUST ensure that this much writable memory is available in
jfigus5e337292013-05-28 13:57:47 -04001307 * the buffer that holds the RTCP packet.
Geir Istadb6109682017-07-10 19:01:17 +02001308 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001309 * @param ctx is the SRTP context to use in processing the packet.
1310 *
1311 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
1312 * the function returns, it points to the srtp packet.
1313 *
1314 * @param pkt_octet_len is a pointer to the length in octets of the
1315 * complete RTCP packet (header and body) before the function call,
jfigus857009c2014-11-05 11:17:43 -05001316 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
Cullen Jennings235513a2005-09-21 22:51:36 +00001317 * was returned. Otherwise, the value of the data to which it points
1318 * is undefined.
1319 *
Geir Istadb6109682017-07-10 19:01:17 +02001320 * @return
jfigus857009c2014-11-05 11:17:43 -05001321 * - srtp_err_status_ok if there were no problems.
Geir Istadb6109682017-07-10 19:01:17 +02001322 * - [other] if there was a failure in
Cullen Jennings235513a2005-09-21 22:51:36 +00001323 * the cryptographic mechanisms.
1324 */
Geir Istad013228a2017-09-29 07:06:22 +02001325srtp_err_status_t srtp_protect_rtcp(srtp_t ctx,
1326 void *rtcp_hdr,
1327 int *pkt_octet_len);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001328
1329/**
1330 * @brief srtp_protect_rtcp_mki() is the Secure RTCP sender-side packet
1331 * processing function that can utilize mki.
Geir Istadb6109682017-07-10 19:01:17 +02001332 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001333 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
1334 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
1335 * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is
1336 * returned, then rtp_hdr points to the resulting SRTCP packet and
1337 * *len_ptr is the number of octets in that packet; otherwise, no
1338 * assumptions should be made about the value of either data elements.
Geir Istadb6109682017-07-10 19:01:17 +02001339 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001340 * @warning This function assumes that it can write the authentication
1341 * tag into the location in memory immediately following the RTCP
1342 * packet, and assumes that the RTCP packet is aligned on a 32-bit
1343 * boundary.
1344 *
Geir Istadb6109682017-07-10 19:01:17 +02001345 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4
1346 * into the location in memory immediately following the RTCP packet.
1347 * Callers MUST ensure that this much writable memory is available in
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001348 * the buffer that holds the RTCP packet.
Geir Istadb6109682017-07-10 19:01:17 +02001349 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001350 * @param ctx is the SRTP context to use in processing the packet.
1351 *
1352 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
1353 * the function returns, it points to the srtp packet.
1354 *
1355 * @param pkt_octet_len is a pointer to the length in octets of the
1356 * complete RTCP packet (header and body) before the function call,
1357 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
1358 * was returned. Otherwise, the value of the data to which it points
1359 * is undefined.
1360 *
Geir Istadb6109682017-07-10 19:01:17 +02001361 * @param use_mki is a boolean to tell the system if mki is being used. If
1362 * set to false then will use the first set of session keys. If set to true
1363 * will
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001364 * use the session keys identified by the mki_index
1365 *
1366 * @param mki_index integer value specifying which set of session kesy should be
1367 * used if use_mki is set to true.
1368 *
Geir Istadb6109682017-07-10 19:01:17 +02001369 * @return
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001370 * - srtp_err_status_ok if there were no problems.
Geir Istadb6109682017-07-10 19:01:17 +02001371 * - [other] if there was a failure in
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001372 * the cryptographic mechanisms.
1373 */
Geir Istadb6109682017-07-10 19:01:17 +02001374srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx,
1375 void *rtcp_hdr,
1376 int *pkt_octet_len,
1377 unsigned int use_mki,
1378 unsigned int mki_index);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001379
Cullen Jennings235513a2005-09-21 22:51:36 +00001380/**
1381 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
1382 * processing function.
1383 *
1384 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
1385 * verifies the Secure RTCP protection of the SRTCP packet pointed to
1386 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
jfigus857009c2014-11-05 11:17:43 -05001387 * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
Cullen Jennings235513a2005-09-21 22:51:36 +00001388 * to the resulting RTCP packet and *len_ptr is the number of octets
1389 * in that packet; otherwise, no assumptions should be made about the
1390 * value of either data elements.
Geir Istadb6109682017-07-10 19:01:17 +02001391 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001392 * @warning This function assumes that the SRTCP packet is aligned on a
1393 * 32-bit boundary.
1394 *
1395 * @param ctx is a pointer to the srtp_t which applies to the
1396 * particular packet.
1397 *
1398 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
1399 * (before the call). After the function returns, it points to the
jfigus857009c2014-11-05 11:17:43 -05001400 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
Cullen Jennings235513a2005-09-21 22:51:36 +00001401 * the data to which it points is undefined.
1402 *
1403 * @param pkt_octet_len is a pointer to the length in octets of the
1404 * complete SRTCP packet (header and body) before the function call,
jfigus857009c2014-11-05 11:17:43 -05001405 * and of the complete rtp packet after the call, if srtp_err_status_ok was
Cullen Jennings235513a2005-09-21 22:51:36 +00001406 * returned. Otherwise, the value of the data to which it points is
1407 * undefined.
1408 *
Geir Istadb6109682017-07-10 19:01:17 +02001409 * @return
jfigus857009c2014-11-05 11:17:43 -05001410 * - srtp_err_status_ok if the RTCP packet is valid.
Geir Istadb6109682017-07-10 19:01:17 +02001411 * - srtp_err_status_auth_fail if the SRTCP packet failed the message
Cullen Jennings235513a2005-09-21 22:51:36 +00001412 * authentication check.
jfigus857009c2014-11-05 11:17:43 -05001413 * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
Cullen Jennings235513a2005-09-21 22:51:36 +00001414 * already been processed and accepted).
1415 * - [other] if there has been an error in the cryptographic mechanisms.
1416 *
1417 */
Geir Istad013228a2017-09-29 07:06:22 +02001418srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx,
1419 void *srtcp_hdr,
1420 int *pkt_octet_len);
Cullen Jennings235513a2005-09-21 22:51:36 +00001421
1422/**
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001423 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
1424 * processing function.
1425 *
1426 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
1427 * verifies the Secure RTCP protection of the SRTCP packet pointed to
1428 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
1429 * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points
1430 * to the resulting RTCP packet and *len_ptr is the number of octets
1431 * in that packet; otherwise, no assumptions should be made about the
1432 * value of either data elements.
Geir Istadb6109682017-07-10 19:01:17 +02001433 *
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001434 * @warning This function assumes that the SRTCP packet is aligned on a
1435 * 32-bit boundary.
1436 *
1437 * @param ctx is a pointer to the srtp_t which applies to the
1438 * particular packet.
1439 *
1440 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
1441 * (before the call). After the function returns, it points to the
1442 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
1443 * the data to which it points is undefined.
1444 *
1445 * @param pkt_octet_len is a pointer to the length in octets of the
1446 * complete SRTCP packet (header and body) before the function call,
1447 * and of the complete rtp packet after the call, if srtp_err_status_ok was
1448 * returned. Otherwise, the value of the data to which it points is
1449 * undefined.
1450 *
Geir Istad659419e2017-03-29 06:53:40 +02001451 * @param use_mki is a boolean to tell the system if mki is being used. If
Geir Istadb6109682017-07-10 19:01:17 +02001452 * set to false then will use the first set of session keys. If set to true
1453 * will use the session keys identified by the mki_index
Geir Istad659419e2017-03-29 06:53:40 +02001454 *
Geir Istadb6109682017-07-10 19:01:17 +02001455 * @return
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001456 * - srtp_err_status_ok if the RTCP packet is valid.
Geir Istadb6109682017-07-10 19:01:17 +02001457 * - srtp_err_status_auth_fail if the SRTCP packet failed the message
1458 * authentication check.
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001459 * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
Geir Istadb6109682017-07-10 19:01:17 +02001460 * already been processed and accepted).
1461 * - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI
1462 * id
1463 * - [other] if there has been an error in the
1464 * cryptographic mechanisms.
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001465 *
1466 */
Geir Istadb6109682017-07-10 19:01:17 +02001467srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx,
1468 void *srtcp_hdr,
Geir Istad626e9e82017-02-20 18:15:05 +01001469 int *pkt_octet_len,
1470 unsigned int use_mki);
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001471
1472/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001473 * @}
1474 */
1475
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +02001476/**
1477 * @defgroup User data associated to a SRTP session.
1478 * @ingroup SRTP
1479 *
1480 * @brief Store custom user data within a SRTP session.
1481 *
1482 * @{
1483 */
1484
1485/**
1486 * @brief srtp_set_user_data() stores the given pointer into the SRTP
1487 * session for later retrieval.
1488 *
1489 * @param ctx is the srtp_t context in which the given data pointer is
1490 * stored.
1491 *
1492 * @param data is a pointer to the custom information (struct, function,
1493 * etc) associated with the SRTP session.
1494 *
1495 * @return void.
1496 *
1497 */
Geir Istadb6109682017-07-10 19:01:17 +02001498void srtp_set_user_data(srtp_t ctx, void *data);
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +02001499
1500/**
1501 * @brief srtp_get_user_data() retrieves the pointer to the custom data
1502 * previously stored with srtp_set_user_data().
1503 *
1504 * This function is mostly useful for retrieving data associated to a
1505 * SRTP session when an event fires. The user can then get such a custom
1506 * data by calling this function with the session field of the
1507 * srtp_event_data_t struct as argument.
1508 *
1509 * @param ctx is the srtp_t context in which the given data pointer was
1510 * stored.
1511 *
1512 * @return void* pointer to the user data.
1513 *
1514 */
Geir Istadb6109682017-07-10 19:01:17 +02001515void *srtp_get_user_data(srtp_t ctx);
Iñaki Baz Castillo241fec32014-08-21 00:51:00 +02001516
1517/**
1518 * @}
1519 */
1520
Cullen Jennings235513a2005-09-21 22:51:36 +00001521/**
1522 * @defgroup SRTPevents SRTP events and callbacks
1523 * @ingroup SRTP
1524 *
Geir Istadb6109682017-07-10 19:01:17 +02001525 * @brief libSRTP can use a user-provided callback function to
Cullen Jennings235513a2005-09-21 22:51:36 +00001526 * handle events.
1527 *
Geir Istadb6109682017-07-10 19:01:17 +02001528 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001529 * libSRTP allows a user to provide a callback function to handle
1530 * events that need to be dealt with outside of the data plane (see
1531 * the enum srtp_event_t for a description of these events). Dealing
1532 * with these events is not a strict necessity; they are not
1533 * security-critical, but the application may suffer if they are not
1534 * handled. The function srtp_set_event_handler() is used to provide
1535 * the callback function.
1536 *
1537 * A default event handler that merely reports on the events as they
1538 * happen is included. It is also possible to set the event handler
1539 * function to NULL, in which case all events will just be silently
1540 * ignored.
1541 *
1542 * @{
1543 */
1544
1545/**
1546 * @brief srtp_event_t defines events that need to be handled
1547 *
1548 * The enum srtp_event_t defines events that need to be handled
Geir Istadb6109682017-07-10 19:01:17 +02001549 * outside the `data plane', such as SSRC collisions and
1550 * key expirations.
Cullen Jennings235513a2005-09-21 22:51:36 +00001551 *
1552 * When a key expires or the maximum number of packets has been
1553 * reached, an SRTP stream will enter an `expired' state in which no
1554 * more packets can be protected or unprotected. When this happens,
1555 * it is likely that you will want to either deallocate the stream
jfigus92c3de32016-02-02 13:44:39 -05001556 * (using srtp_remove_stream()), and possibly allocate a new one.
Cullen Jennings235513a2005-09-21 22:51:36 +00001557 *
1558 * When an SRTP stream expires, the other streams in the same session
1559 * are unaffected, unless key sharing is used by that stream. In the
1560 * latter case, all of the streams in the session will expire.
1561 */
Geir Istadb6109682017-07-10 19:01:17 +02001562typedef enum {
1563 event_ssrc_collision, /**< An SSRC collision occured. */
1564 event_key_soft_limit, /**< An SRTP stream reached the soft key */
1565 /**< usage limit and will expire soon. */
1566 event_key_hard_limit, /**< An SRTP stream reached the hard */
1567 /**< key usage limit and has expired. */
1568 event_packet_index_limit /**< An SRTP stream reached the hard */
1569 /**< packet limit (2^48 packets). */
Cullen Jennings235513a2005-09-21 22:51:36 +00001570} srtp_event_t;
1571
1572/**
Geir Istadb6109682017-07-10 19:01:17 +02001573 * @brief srtp_event_data_t is the structure passed as a callback to
Cullen Jennings235513a2005-09-21 22:51:36 +00001574 * the event handler function
1575 *
1576 * The struct srtp_event_data_t holds the data passed to the event
Geir Istadb6109682017-07-10 19:01:17 +02001577 * handler function.
Cullen Jennings235513a2005-09-21 22:51:36 +00001578 */
Cullen Jennings235513a2005-09-21 22:51:36 +00001579typedef struct srtp_event_data_t {
Geir Istadb6109682017-07-10 19:01:17 +02001580 srtp_t session; /**< The session in which the event happend. */
1581 uint32_t ssrc; /**< The ssrc in host order of the stream in which */
1582 /**< the event happend */
1583 srtp_event_t event; /**< An enum indicating the type of event. */
Cullen Jennings235513a2005-09-21 22:51:36 +00001584} srtp_event_data_t;
1585
1586/**
1587 * @brief srtp_event_handler_func_t is the function prototype for
1588 * the event handler.
1589 *
1590 * The typedef srtp_event_handler_func_t is the prototype for the
1591 * event handler function. It has as its only argument an
1592 * srtp_event_data_t which describes the event that needs to be handled.
1593 * There can only be a single, global handler for all events in
1594 * libSRTP.
1595 */
Geir Istadb6109682017-07-10 19:01:17 +02001596typedef void(srtp_event_handler_func_t)(srtp_event_data_t *data);
Cullen Jennings235513a2005-09-21 22:51:36 +00001597
1598/**
1599 * @brief sets the event handler to the function supplied by the caller.
Geir Istadb6109682017-07-10 19:01:17 +02001600 *
Cullen Jennings235513a2005-09-21 22:51:36 +00001601 * The function call srtp_install_event_handler(func) sets the event
1602 * handler function to the value func. The value NULL is acceptable
1603 * as an argument; in this case, events will be ignored rather than
1604 * handled.
1605 *
1606 * @param func is a pointer to a fuction that takes an srtp_event_data_t
1607 * pointer as an argument and returns void. This function
1608 * will be used by libSRTP to handle events.
1609 */
jfigus857009c2014-11-05 11:17:43 -05001610srtp_err_status_t srtp_install_event_handler(srtp_event_handler_func_t func);
Cullen Jennings235513a2005-09-21 22:51:36 +00001611
1612/**
Geir Istadb6109682017-07-10 19:01:17 +02001613 * @brief Returns the version string of the library.
1614 *
jfigusf62b64d2014-10-08 13:53:57 -04001615 */
Christian Oiend4e3eec2014-10-24 10:14:08 +02001616const char *srtp_get_version_string(void);
jfigusf62b64d2014-10-08 13:53:57 -04001617
1618/**
Geir Istadb6109682017-07-10 19:01:17 +02001619 * @brief Returns the numeric representation of the library version.
1620 *
jfigusf62b64d2014-10-08 13:53:57 -04001621 */
1622unsigned int srtp_get_version(void);
1623
1624/**
jfigus46d6b472014-11-14 16:42:01 -05001625 * @brief srtp_set_debug_module(mod_name, v)
Geir Istadb6109682017-07-10 19:01:17 +02001626 *
jfigus46d6b472014-11-14 16:42:01 -05001627 * sets dynamic debugging to the value v (0 for off, 1 for on) for the
1628 * debug module with the name mod_name
1629 *
1630 * returns err_status_ok on success, err_status_fail otherwise
1631 */
Pascal Bühler57f18522017-04-12 17:28:03 +02001632srtp_err_status_t srtp_set_debug_module(const char *mod_name, int v);
jfigus46d6b472014-11-14 16:42:01 -05001633
1634/**
1635 * @brief srtp_list_debug_modules() outputs a list of debugging modules
1636 *
1637 */
1638srtp_err_status_t srtp_list_debug_modules(void);
1639
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001640/**
Pascal Bühleraf151782017-02-24 10:51:52 +01001641 * @brief srtp_log_level_t defines log levels.
1642 *
1643 * The enumeration srtp_log_level_t defines log levels reported
1644 * in the srtp_log_handler_func_t.
1645 *
1646 */
1647typedef enum {
1648 srtp_log_level_error, /**< log level is reporting an error message */
1649 srtp_log_level_warning, /**< log level is reporting a warning message */
1650 srtp_log_level_info, /**< log level is reporting an info message */
1651 srtp_log_level_debug /**< log level is reporting a debug message */
1652} srtp_log_level_t;
1653
1654/**
1655 * @brief srtp_log_handler_func_t is the function prototype for
1656 * the log handler.
1657 *
1658 * The typedef srtp_event_handler_func_t is the prototype for the
Pascal Bühler98762312017-03-01 11:24:35 +01001659 * event handler function. It has as srtp_log_level_t, log
1660 * message and data as arguments.
Pascal Bühleraf151782017-02-24 10:51:52 +01001661 * There can only be a single, global handler for all log messages in
1662 * libSRTP.
1663 */
Geir Istadb6109682017-07-10 19:01:17 +02001664typedef void(srtp_log_handler_func_t)(srtp_log_level_t level,
1665 const char *msg,
1666 void *data);
Pascal Bühleraf151782017-02-24 10:51:52 +01001667
1668/**
1669 * @brief sets the log handler to the function supplied by the caller.
1670 *
1671 * The function call srtp_install_log_handler(func) sets the log
1672 * handler function to the value func. The value NULL is acceptable
1673 * as an argument; in this case, log messages will be ignored.
1674 * This function can be called before srtp_init() inorder to capture
1675 * any logging during start up.
1676 *
1677 * @param func is a pointer to a fuction of type srtp_log_handler_func_t.
1678 * This function will be used by libSRTP to output log messages.
Geir Istadb6109682017-07-10 19:01:17 +02001679 * @param data is a user pointer that will be returned as the data argument in
1680 * func.
Pascal Bühleraf151782017-02-24 10:51:52 +01001681 */
Geir Istadb6109682017-07-10 19:01:17 +02001682srtp_err_status_t srtp_install_log_handler(srtp_log_handler_func_t func,
1683 void *data);
Pascal Bühleraf151782017-02-24 10:51:52 +01001684
1685/**
Ryan Hooperab0345b2017-02-07 16:07:59 -05001686 * @brief srtp_get_protect_trailer_length(session, use_mki, mki_index, length)
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001687 *
Geir Istadb6109682017-07-10 19:01:17 +02001688 * Determines the length of the amount of data Lib SRTP will add to the
1689 * packet during the protect process. The length is returned in the length
1690 * parameter
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001691 *
Geir Istadb6109682017-07-10 19:01:17 +02001692 * returns err_status_ok on success, err_status_bad_mki if the MKI index is
1693 * invalid
Ryan Hooperfe5d8b82016-12-15 14:53:58 -05001694 *
1695 */
Geir Istadb6109682017-07-10 19:01:17 +02001696srtp_err_status_t srtp_get_protect_trailer_length(srtp_t session,
1697 uint32_t use_mki,
1698 uint32_t mki_index,
1699 uint32_t *length);
Ryan Hooperab0345b2017-02-07 16:07:59 -05001700
1701/**
Geir Istadb6109682017-07-10 19:01:17 +02001702 * @brief srtp_get_protect_rtcp_trailer_length(session, use_mki, mki_index,
1703 * length)
Ryan Hooperab0345b2017-02-07 16:07:59 -05001704 *
Geir Istadb6109682017-07-10 19:01:17 +02001705 * Determines the length of the amount of data Lib SRTP will add to the
1706 * packet during the protect process. The length is returned in the length
1707 * parameter
Ryan Hooperab0345b2017-02-07 16:07:59 -05001708 *
Geir Istadb6109682017-07-10 19:01:17 +02001709 * returns err_status_ok on success, err_status_bad_mki if the MKI index is
1710 * invalid
Ryan Hooperab0345b2017-02-07 16:07:59 -05001711 *
1712 */
Geir Istadb6109682017-07-10 19:01:17 +02001713srtp_err_status_t srtp_get_protect_rtcp_trailer_length(srtp_t session,
1714 uint32_t use_mki,
1715 uint32_t mki_index,
1716 uint32_t *length);
jfigus46d6b472014-11-14 16:42:01 -05001717
1718/**
Ulf Olsson7af219a2017-04-03 16:06:55 +02001719 * @brief srtp_set_stream_roc(session, ssrc, roc)
1720 *
1721 * Set the roll-over-counter on a session for a given SSRC
1722 *
1723 * returns err_status_ok on success, srtp_err_status_bad_param if there is no
1724 * stream found
1725 *
1726 */
Geir Istad013228a2017-09-29 07:06:22 +02001727srtp_err_status_t srtp_set_stream_roc(srtp_t session,
1728 uint32_t ssrc,
1729 uint32_t roc);
Ulf Olsson7af219a2017-04-03 16:06:55 +02001730
1731/**
1732 * @brief srtp_get_stream_roc(session, ssrc, roc)
1733 *
1734 * Get the roll-over-counter on a session for a given SSRC
1735 *
1736 * returns err_status_ok on success, srtp_err_status_bad_param if there is no
1737 * stream found
1738 *
1739 */
Geir Istad013228a2017-09-29 07:06:22 +02001740srtp_err_status_t srtp_get_stream_roc(srtp_t session,
1741 uint32_t ssrc,
1742 uint32_t *roc);
Ulf Olsson7af219a2017-04-03 16:06:55 +02001743
1744/**
Cullen Jennings235513a2005-09-21 22:51:36 +00001745 * @}
1746 */
Geir Istadb6109682017-07-10 19:01:17 +02001747
Cullen Jennings235513a2005-09-21 22:51:36 +00001748/* in host order, so outside the #if */
Geir Istadb6109682017-07-10 19:01:17 +02001749#define SRTCP_E_BIT 0x80000000
1750
Cullen Jennings235513a2005-09-21 22:51:36 +00001751/* for byte-access */
1752#define SRTCP_E_BYTE_BIT 0x80
1753#define SRTCP_INDEX_MASK 0x7fffffff
1754
Marcus Sundbergcb60bf82005-10-17 17:23:05 +00001755#ifdef __cplusplus
1756}
1757#endif
1758
Pascal Bühlerc3655db2017-02-01 09:11:27 +01001759#endif /* SRTP_SRTP_H */