Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * srtp.h |
| 3 | * |
| 4 | * interface to libsrtp |
| 5 | * |
| 6 | * David A. McGrew |
| 7 | * Cisco Systems, Inc. |
| 8 | */ |
| 9 | /* |
| 10 | * |
David McGrew | 7629bf2 | 2006-06-08 17:00:25 +0000 | [diff] [blame] | 11 | * Copyright (c) 2001-2006, Cisco Systems, Inc. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 12 | * All rights reserved. |
| 13 | * |
| 14 | * Redistribution and use in source and binary forms, with or without |
| 15 | * modification, are permitted provided that the following conditions |
| 16 | * are met: |
| 17 | * |
| 18 | * Redistributions of source code must retain the above copyright |
| 19 | * notice, this list of conditions and the following disclaimer. |
| 20 | * |
| 21 | * Redistributions in binary form must reproduce the above |
| 22 | * copyright notice, this list of conditions and the following |
| 23 | * disclaimer in the documentation and/or other materials provided |
| 24 | * with the distribution. |
| 25 | * |
| 26 | * Neither the name of the Cisco Systems, Inc. nor the names of its |
| 27 | * contributors may be used to endorse or promote products derived |
| 28 | * from this software without specific prior written permission. |
| 29 | * |
| 30 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 31 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 32 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 33 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 34 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 35 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 36 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 37 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 40 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 41 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 42 | * |
| 43 | */ |
| 44 | |
| 45 | |
| 46 | #ifndef SRTP_H |
| 47 | #define SRTP_H |
| 48 | |
Marcus Sundberg | cb60bf8 | 2005-10-17 17:23:05 +0000 | [diff] [blame] | 49 | #ifdef __cplusplus |
| 50 | extern "C" { |
| 51 | #endif |
| 52 | |
jfigus | 45ab533 | 2014-10-01 19:47:46 -0400 | [diff] [blame] | 53 | #include <stdint.h> |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * @defgroup SRTP Secure RTP |
| 57 | * |
| 58 | * @brief libSRTP provides functions for protecting RTP and RTCP. See |
| 59 | * Section @ref Overview for an introduction to the use of the library. |
| 60 | * |
| 61 | * @{ |
| 62 | */ |
| 63 | |
| 64 | /* |
| 65 | * SRTP_MASTER_KEY_LEN is the nominal master key length supported by libSRTP |
| 66 | */ |
| 67 | |
| 68 | #define SRTP_MASTER_KEY_LEN 30 |
| 69 | |
| 70 | /* |
| 71 | * SRTP_MAX_KEY_LEN is the maximum key length supported by libSRTP |
| 72 | */ |
| 73 | #define SRTP_MAX_KEY_LEN 64 |
| 74 | |
| 75 | /* |
| 76 | * SRTP_MAX_TAG_LEN is the maximum tag length supported by libSRTP |
| 77 | */ |
| 78 | |
jfigus | ed22129 | 2015-05-15 13:39:08 -0400 | [diff] [blame] | 79 | #define SRTP_MAX_TAG_LEN 16 |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer |
| 83 | * (authentication tag and MKI) supported by libSRTP. This value is |
| 84 | * the maximum number of octets that will be added to an RTP packet by |
| 85 | * srtp_protect(). |
| 86 | * |
| 87 | * @brief the maximum number of octets added by srtp_protect(). |
| 88 | */ |
| 89 | #define SRTP_MAX_TRAILER_LEN SRTP_MAX_TAG_LEN |
| 90 | |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 91 | /* |
| 92 | * SRTP_AEAD_SALT_LEN is the length of the SALT values used with |
| 93 | * GCM mode. GCM mode requires an IV. The SALT value is used |
| 94 | * as part of the IV formation logic applied to each RTP packet. |
| 95 | */ |
| 96 | #define SRTP_AEAD_SALT_LEN 12 |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 97 | #define SRTP_AES_128_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 16 |
| 98 | #define SRTP_AES_192_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 24 |
| 99 | #define SRTP_AES_256_GCM_KEYSIZE_WSALT SRTP_AEAD_SALT_LEN + 32 |
jfigus | 8719f95 | 2014-04-08 09:15:49 -0400 | [diff] [blame] | 100 | |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 101 | /* |
| 102 | * an srtp_hdr_t represents the srtp header |
| 103 | * |
| 104 | * in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned |
| 105 | * |
| 106 | * (note that this definition follows that of RFC 1889 Appendix A, but |
| 107 | * is not identical) |
| 108 | */ |
| 109 | |
| 110 | #ifndef WORDS_BIGENDIAN |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 111 | |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 112 | /* |
| 113 | * srtp_hdr_t represents an RTP or SRTP header. The bit-fields in |
| 114 | * this structure should be declared "unsigned int" instead of |
| 115 | * "unsigned char", but doing so causes the MS compiler to not |
| 116 | * fully pack the bit fields. |
| 117 | */ |
| 118 | |
| 119 | typedef struct { |
| 120 | unsigned char cc:4; /* CSRC count */ |
| 121 | unsigned char x:1; /* header extension flag */ |
| 122 | unsigned char p:1; /* padding flag */ |
| 123 | unsigned char version:2; /* protocol version */ |
| 124 | unsigned char pt:7; /* payload type */ |
| 125 | unsigned char m:1; /* marker bit */ |
| 126 | uint16_t seq; /* sequence number */ |
| 127 | uint32_t ts; /* timestamp */ |
| 128 | uint32_t ssrc; /* synchronization source */ |
| 129 | } srtp_hdr_t; |
| 130 | |
| 131 | #else /* BIG_ENDIAN */ |
| 132 | |
| 133 | typedef struct { |
| 134 | unsigned char version:2; /* protocol version */ |
| 135 | unsigned char p:1; /* padding flag */ |
| 136 | unsigned char x:1; /* header extension flag */ |
| 137 | unsigned char cc:4; /* CSRC count */ |
| 138 | unsigned char m:1; /* marker bit */ |
| 139 | unsigned char pt:7; /* payload type */ |
| 140 | uint16_t seq; /* sequence number */ |
| 141 | uint32_t ts; /* timestamp */ |
| 142 | uint32_t ssrc; /* synchronization source */ |
| 143 | } srtp_hdr_t; |
| 144 | |
| 145 | #endif |
| 146 | |
| 147 | typedef struct { |
| 148 | uint16_t profile_specific; /* profile-specific info */ |
| 149 | uint16_t length; /* number of 32-bit words in extension */ |
| 150 | } srtp_hdr_xtnd_t; |
| 151 | |
| 152 | |
| 153 | /* |
| 154 | * srtcp_hdr_t represents a secure rtcp header |
| 155 | * |
| 156 | * in this implementation, an srtcp header is assumed to be 32-bit |
| 157 | * alinged |
| 158 | */ |
| 159 | |
| 160 | #ifndef WORDS_BIGENDIAN |
| 161 | |
| 162 | typedef struct { |
| 163 | unsigned char rc:5; /* reception report count */ |
| 164 | unsigned char p:1; /* padding flag */ |
| 165 | unsigned char version:2; /* protocol version */ |
| 166 | unsigned char pt:8; /* payload type */ |
| 167 | uint16_t len; /* length */ |
| 168 | uint32_t ssrc; /* synchronization source */ |
| 169 | } srtcp_hdr_t; |
| 170 | |
| 171 | typedef struct { |
| 172 | unsigned int index:31; /* srtcp packet index in network order! */ |
| 173 | unsigned int e:1; /* encrypted? 1=yes */ |
| 174 | /* optional mikey/etc go here */ |
| 175 | /* and then the variable-length auth tag */ |
| 176 | } srtcp_trailer_t; |
| 177 | |
| 178 | |
| 179 | #else /* BIG_ENDIAN */ |
| 180 | |
| 181 | typedef struct { |
| 182 | unsigned char version:2; /* protocol version */ |
| 183 | unsigned char p:1; /* padding flag */ |
| 184 | unsigned char rc:5; /* reception report count */ |
| 185 | unsigned char pt:8; /* payload type */ |
| 186 | uint16_t len; /* length */ |
| 187 | uint32_t ssrc; /* synchronization source */ |
| 188 | } srtcp_hdr_t; |
| 189 | |
| 190 | typedef struct { |
| 191 | unsigned int version:2; /* protocol version */ |
| 192 | unsigned int p:1; /* padding flag */ |
| 193 | unsigned int count:5; /* varies by packet type */ |
| 194 | unsigned int pt:8; /* payload type */ |
| 195 | uint16_t length; /* len of uint32s of packet less header */ |
| 196 | } rtcp_common_t; |
| 197 | |
| 198 | typedef struct { |
| 199 | unsigned int e:1; /* encrypted? 1=yes */ |
| 200 | unsigned int index:31; /* srtcp packet index */ |
| 201 | /* optional mikey/etc go here */ |
| 202 | /* and then the variable-length auth tag */ |
| 203 | } srtcp_trailer_t; |
| 204 | |
| 205 | #endif |
| 206 | |
| 207 | |
| 208 | |
| 209 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 210 | * @brief A srtp_cipher_type_id_t is an identifier for a particular cipher |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 211 | * type. |
| 212 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 213 | * A srtp_cipher_type_id_t is an integer that represents a particular |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 214 | * cipher type, e.g. the Advanced Encryption Standard (AES). A |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 215 | * SRTP_NULL_CIPHER is avaliable; this cipher leaves the data unchanged, |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 216 | * and can be selected to indicate that no encryption is to take |
| 217 | * place. |
| 218 | * |
| 219 | * @ingroup Ciphers |
| 220 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 221 | typedef uint32_t srtp_cipher_type_id_t; |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 222 | |
| 223 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 224 | * @brief An srtp_auth_type_id_t is an identifier for a particular authentication |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 225 | * function. |
| 226 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 227 | * An srtp_auth_type_id_t is an integer that represents a particular |
jfigus | 67b9c73 | 2014-11-20 10:17:21 -0500 | [diff] [blame] | 228 | * authentication function type, e.g. HMAC-SHA1. A SRTP_NULL_AUTH is |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 229 | * avaliable; this authentication function performs no computation, |
| 230 | * and can be selected to indicate that no authentication is to take |
| 231 | * place. |
| 232 | * |
| 233 | * @ingroup Authentication |
| 234 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 235 | typedef uint32_t srtp_auth_type_id_t; |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 236 | |
| 237 | /* |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 238 | * @brief srtp_err_status_t defines error codes. |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 239 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 240 | * The enumeration srtp_err_status_t defines error codes. Note that the |
| 241 | * value of srtp_err_status_ok is equal to zero, which can simplify error |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 242 | * checking somewhat. |
| 243 | * |
| 244 | */ |
| 245 | typedef enum { |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 246 | srtp_err_status_ok = 0, /**< nothing to report */ |
| 247 | srtp_err_status_fail = 1, /**< unspecified failure */ |
| 248 | srtp_err_status_bad_param = 2, /**< unsupported parameter */ |
| 249 | srtp_err_status_alloc_fail = 3, /**< couldn't allocate memory */ |
| 250 | srtp_err_status_dealloc_fail = 4, /**< couldn't deallocate properly */ |
| 251 | srtp_err_status_init_fail = 5, /**< couldn't initialize */ |
| 252 | srtp_err_status_terminus = 6, /**< can't process as much data as requested */ |
| 253 | srtp_err_status_auth_fail = 7, /**< authentication failure */ |
| 254 | srtp_err_status_cipher_fail = 8, /**< cipher failure */ |
| 255 | srtp_err_status_replay_fail = 9, /**< replay check failed (bad index) */ |
| 256 | srtp_err_status_replay_old = 10, /**< replay check failed (index too old) */ |
| 257 | srtp_err_status_algo_fail = 11, /**< algorithm failed test routine */ |
| 258 | srtp_err_status_no_such_op = 12, /**< unsupported operation */ |
| 259 | srtp_err_status_no_ctx = 13, /**< no appropriate context found */ |
| 260 | srtp_err_status_cant_check = 14, /**< unable to perform desired validation */ |
| 261 | srtp_err_status_key_expired = 15, /**< can't use key any more */ |
| 262 | srtp_err_status_socket_err = 16, /**< error in use of socket */ |
| 263 | srtp_err_status_signal_err = 17, /**< error in use POSIX signals */ |
| 264 | srtp_err_status_nonce_bad = 18, /**< nonce check failed */ |
| 265 | srtp_err_status_read_fail = 19, /**< couldn't read data */ |
| 266 | srtp_err_status_write_fail = 20, /**< couldn't write data */ |
| 267 | srtp_err_status_parse_err = 21, /**< error parsing data */ |
| 268 | srtp_err_status_encode_err = 22, /**< error encoding data */ |
| 269 | srtp_err_status_semaphore_err = 23,/**< error while using semaphores */ |
| 270 | srtp_err_status_pfkey_err = 24 /**< error while using pfkey */ |
| 271 | } srtp_err_status_t; |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 272 | |
| 273 | typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t; |
| 274 | typedef struct srtp_ctx_t_ srtp_ctx_t; |
jfigus | 4494760 | 2014-10-08 13:08:52 -0400 | [diff] [blame] | 275 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 276 | /* |
| 277 | * nota bene: since libSRTP doesn't support the use of the MKI, the |
| 278 | * SRTP_MAX_TRAILER_LEN value is just the maximum tag length |
| 279 | */ |
| 280 | |
| 281 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 282 | * @brief srtp_sec_serv_t describes a set of security services. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 283 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 284 | * A srtp_sec_serv_t enumeration is used to describe the particular |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 285 | * security services that will be applied by a particular crypto |
| 286 | * policy (or other mechanism). |
| 287 | */ |
| 288 | |
| 289 | typedef enum { |
| 290 | sec_serv_none = 0, /**< no services */ |
| 291 | sec_serv_conf = 1, /**< confidentiality */ |
| 292 | sec_serv_auth = 2, /**< authentication */ |
| 293 | sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 294 | } srtp_sec_serv_t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 295 | |
| 296 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 297 | * @brief srtp_crypto_policy_t describes a particular crypto policy that |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 298 | * can be applied to an SRTP stream. |
| 299 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 300 | * A srtp_crypto_policy_t describes a particular cryptographic policy that |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 301 | * can be applied to an SRTP or SRTCP stream. An SRTP session policy |
| 302 | * consists of a list of these policies, one for each SRTP stream |
| 303 | * in the session. |
| 304 | */ |
| 305 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 306 | typedef struct srtp_crypto_policy_t { |
| 307 | srtp_cipher_type_id_t cipher_type; /**< An integer representing |
| 308 | * the type of cipher. */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 309 | int cipher_key_len; /**< The length of the cipher key |
| 310 | * in octets. */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 311 | srtp_auth_type_id_t auth_type; /**< An integer representing the |
| 312 | * authentication function. */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 313 | int auth_key_len; /**< The length of the authentication |
| 314 | * function key in octets. */ |
| 315 | int auth_tag_len; /**< The length of the authentication |
| 316 | * tag in octets. */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 317 | srtp_sec_serv_t sec_serv; /**< The flag indicating the security |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 318 | * services to be applied. */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 319 | } srtp_crypto_policy_t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 320 | |
| 321 | |
| 322 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 323 | * @brief srtp_ssrc_type_t describes the type of an SSRC. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 324 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 325 | * An srtp_ssrc_type_t enumeration is used to indicate a type of SSRC. See |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 326 | * @ref srtp_policy_t for more informataion. |
| 327 | */ |
| 328 | |
| 329 | typedef enum { |
| 330 | ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */ |
| 331 | ssrc_specific = 1, /**< Indicates a specific SSRC value */ |
| 332 | ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value |
| 333 | (i.e. a value that is used in the |
| 334 | function srtp_unprotect()) */ |
| 335 | ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value |
| 336 | (i.e. a value that is used in the |
| 337 | function srtp_protect()) */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 338 | } srtp_ssrc_type_t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 339 | |
| 340 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 341 | * @brief An srtp_ssrc_t represents a particular SSRC value, or a `wildcard' SSRC. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 342 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 343 | * An srtp_ssrc_t represents a particular SSRC value (if its type is |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 344 | * ssrc_specific), or a wildcard SSRC value that will match all |
| 345 | * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound |
| 346 | * SSRCs (if its type is ssrc_any_inbound). |
| 347 | * |
| 348 | */ |
| 349 | |
| 350 | typedef struct { |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 351 | srtp_ssrc_type_t type; /**< The type of this particular SSRC */ |
| 352 | unsigned int value; /**< The value of this SSRC, if it is not a wildcard */ |
| 353 | } srtp_ssrc_t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 354 | |
| 355 | |
David McGrew | 79870d6 | 2007-06-15 18:17:39 +0000 | [diff] [blame] | 356 | /** |
| 357 | * @brief points to an EKT policy |
| 358 | */ |
jfigus | c5887e7 | 2014-11-06 09:46:18 -0500 | [diff] [blame] | 359 | typedef struct srtp_ekt_policy_ctx_t *srtp_ekt_policy_t; |
David McGrew | 79870d6 | 2007-06-15 18:17:39 +0000 | [diff] [blame] | 360 | |
| 361 | |
| 362 | /** |
| 363 | * @brief points to EKT stream data |
| 364 | */ |
jfigus | c5887e7 | 2014-11-06 09:46:18 -0500 | [diff] [blame] | 365 | typedef struct srtp_ekt_stream_ctx_t *srtp_ekt_stream_t; |
David McGrew | 79870d6 | 2007-06-15 18:17:39 +0000 | [diff] [blame] | 366 | |
| 367 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 368 | /** |
| 369 | * @brief represents the policy for an SRTP session. |
| 370 | * |
| 371 | * A single srtp_policy_t struct represents the policy for a single |
| 372 | * SRTP stream, and a linked list of these elements represents the |
| 373 | * policy for an entire SRTP session. Each element contains the SRTP |
| 374 | * and SRTCP crypto policies for that stream, a pointer to the SRTP |
| 375 | * master key for that stream, the SSRC describing that stream, or a |
| 376 | * flag indicating a `wildcard' SSRC value, and a `next' field that |
| 377 | * holds a pointer to the next element in the list of policy elements, |
| 378 | * or NULL if it is the last element. |
| 379 | * |
| 380 | * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an |
| 381 | * inbound stream that for which there is no explicit SSRC entry in |
| 382 | * another policy element. Similarly, the value SSRC_ANY_OUTBOUND |
| 383 | * will matches any SSRC from an outbound stream that does not appear |
| 384 | * in another policy element. Note that wildcard SSRCs &b cannot be |
| 385 | * used to match both inbound and outbound traffic. This restriction |
| 386 | * is intentional, and it allows libSRTP to ensure that no security |
| 387 | * lapses result from accidental re-use of SSRC values during key |
| 388 | * sharing. |
| 389 | * |
| 390 | * |
| 391 | * @warning The final element of the list @b must have its `next' pointer |
| 392 | * set to NULL. |
| 393 | */ |
| 394 | |
| 395 | typedef struct srtp_policy_t { |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 396 | srtp_ssrc_t ssrc; /**< The SSRC value of stream, or the |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 397 | * flags SSRC_ANY_INBOUND or |
| 398 | * SSRC_ANY_OUTBOUND if key sharing |
| 399 | * is used for this policy element. |
| 400 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 401 | srtp_crypto_policy_t rtp; /**< SRTP crypto policy. */ |
| 402 | srtp_crypto_policy_t rtcp; /**< SRTCP crypto policy. */ |
David McGrew | 3c45e0c | 2006-07-12 00:50:56 +0000 | [diff] [blame] | 403 | unsigned char *key; /**< Pointer to the SRTP master key for |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 404 | * this stream. */ |
jfigus | c5887e7 | 2014-11-06 09:46:18 -0500 | [diff] [blame] | 405 | srtp_ekt_policy_t ekt; /**< Pointer to the EKT policy structure |
David McGrew | 79870d6 | 2007-06-15 18:17:39 +0000 | [diff] [blame] | 406 | * for this stream (if any) */ |
Jonathan Lennox | a1242f8 | 2010-05-17 21:46:04 +0000 | [diff] [blame] | 407 | unsigned long window_size; /**< The window size to use for replay |
| 408 | * protection. */ |
Jonathan Lennox | dcee5c6 | 2010-05-17 22:08:40 +0000 | [diff] [blame] | 409 | int allow_repeat_tx; /**< Whether retransmissions of |
| 410 | * packets with the same sequence number |
| 411 | * are allowed. (Note that such repeated |
| 412 | * transmissions must have the same RTP |
| 413 | * payload, or a severe security weakness |
| 414 | * is introduced!) */ |
Joachim Bauch | 99a7482 | 2015-11-17 00:08:19 +0100 | [diff] [blame] | 415 | int *enc_xtn_hdr; /**< List of header ids to encrypt. */ |
| 416 | int enc_xtn_hdr_count; /**< Number of entries in list of header ids. */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 417 | struct srtp_policy_t *next; /**< Pointer to next stream policy. */ |
| 418 | } srtp_policy_t; |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | /** |
| 424 | * @brief An srtp_t points to an SRTP session structure. |
| 425 | * |
| 426 | * The typedef srtp_t is a pointer to a structure that represents |
| 427 | * an SRTP session. This datatype is intentially opaque in |
| 428 | * order to separate the interface from the implementation. |
| 429 | * |
| 430 | * An SRTP session consists of all of the traffic sent to the RTP and |
| 431 | * RTCP destination transport addresses, using the RTP/SAVP (Secure |
| 432 | * Audio/Video Profile). A session can be viewed as a set of SRTP |
| 433 | * streams, each of which originates with a different participant. |
| 434 | */ |
| 435 | |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 436 | typedef srtp_ctx_t *srtp_t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 437 | |
| 438 | |
| 439 | /** |
| 440 | * @brief An srtp_stream_t points to an SRTP stream structure. |
| 441 | * |
| 442 | * The typedef srtp_stream_t is a pointer to a structure that |
| 443 | * represents an SRTP stream. This datatype is intentionally |
| 444 | * opaque in order to separate the interface from the implementation. |
| 445 | * |
| 446 | * An SRTP stream consists of all of the traffic sent to an SRTP |
| 447 | * session by a single participant. A session can be viewed as |
| 448 | * a set of streams. |
| 449 | * |
| 450 | */ |
jfigus | a9ac898 | 2014-10-31 14:49:31 -0400 | [diff] [blame] | 451 | typedef srtp_stream_ctx_t *srtp_stream_t; |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 452 | |
| 453 | |
| 454 | |
| 455 | /** |
| 456 | * @brief srtp_init() initializes the srtp library. |
| 457 | * |
| 458 | * @warning This function @b must be called before any other srtp |
| 459 | * functions. |
| 460 | */ |
| 461 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 462 | srtp_err_status_t srtp_init(void); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 463 | |
| 464 | /** |
Jonathan Lennox | 5ae7633 | 2010-05-15 04:48:59 +0000 | [diff] [blame] | 465 | * @brief srtp_shutdown() de-initializes the srtp library. |
| 466 | * |
| 467 | * @warning No srtp functions may be called after calling this function. |
| 468 | */ |
| 469 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 470 | srtp_err_status_t srtp_shutdown(void); |
Jonathan Lennox | 5ae7633 | 2010-05-15 04:48:59 +0000 | [diff] [blame] | 471 | |
| 472 | /** |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 473 | * @brief srtp_protect() is the Secure RTP sender-side packet processing |
| 474 | * function. |
| 475 | * |
| 476 | * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP |
| 477 | * protection to the RTP packet rtp_hdr (which has length *len_ptr) using |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 478 | * the SRTP context ctx. If srtp_err_status_ok is returned, then rtp_hdr |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 479 | * points to the resulting SRTP packet and *len_ptr is the number of |
| 480 | * octets in that packet; otherwise, no assumptions should be made |
| 481 | * about the value of either data elements. |
| 482 | * |
| 483 | * The sequence numbers of the RTP packets presented to this function |
| 484 | * need not be consecutive, but they @b must be out of order by less |
| 485 | * than 2^15 = 32,768 packets. |
| 486 | * |
| 487 | * @warning This function assumes that it can write the authentication |
| 488 | * tag into the location in memory immediately following the RTP |
| 489 | * packet, and assumes that the RTP packet is aligned on a 32-bit |
| 490 | * boundary. |
| 491 | * |
jfigus | dfe68ea | 2013-05-28 09:00:14 -0400 | [diff] [blame] | 492 | * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN |
| 493 | * into the location in memory immediately following the RTP packet. |
| 494 | * Callers MUST ensure that this much writable memory is available in |
| 495 | * the buffer that holds the RTP packet. |
jfigus | 5e33729 | 2013-05-28 13:57:47 -0400 | [diff] [blame] | 496 | * |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 497 | * @param ctx is the SRTP context to use in processing the packet. |
| 498 | * |
| 499 | * @param rtp_hdr is a pointer to the RTP packet (before the call); after |
| 500 | * the function returns, it points to the srtp packet. |
| 501 | * |
| 502 | * @param len_ptr is a pointer to the length in octets of the complete |
| 503 | * RTP packet (header and body) before the function call, and of the |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 504 | * complete SRTP packet after the call, if srtp_err_status_ok was returned. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 505 | * Otherwise, the value of the data to which it points is undefined. |
| 506 | * |
| 507 | * @return |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 508 | * - srtp_err_status_ok no problems |
| 509 | * - srtp_err_status_replay_fail rtp sequence number was non-increasing |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 510 | * - @e other failure in cryptographic mechanisms |
| 511 | */ |
| 512 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 513 | srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 514 | |
| 515 | /** |
| 516 | * @brief srtp_unprotect() is the Secure RTP receiver-side packet |
| 517 | * processing function. |
| 518 | * |
| 519 | * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies |
| 520 | * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr |
| 521 | * (which has length *len_ptr), using the SRTP context ctx. If |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 522 | * srtp_err_status_ok is returned, then srtp_hdr points to the resulting |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 523 | * RTP packet and *len_ptr is the number of octets in that packet; |
| 524 | * otherwise, no assumptions should be made about the value of either |
| 525 | * data elements. |
| 526 | * |
| 527 | * The sequence numbers of the RTP packets presented to this function |
| 528 | * need not be consecutive, but they @b must be out of order by less |
| 529 | * than 2^15 = 32,768 packets. |
| 530 | * |
| 531 | * @warning This function assumes that the SRTP packet is aligned on a |
| 532 | * 32-bit boundary. |
| 533 | * |
IƱaki Baz Castillo | 241fec3 | 2014-08-21 00:51:00 +0200 | [diff] [blame] | 534 | * @param ctx is the SRTP session which applies to the particular packet. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 535 | * |
| 536 | * @param srtp_hdr is a pointer to the header of the SRTP packet |
| 537 | * (before the call). after the function returns, it points to the |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 538 | * rtp packet if srtp_err_status_ok was returned; otherwise, the value of |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 539 | * the data to which it points is undefined. |
| 540 | * |
| 541 | * @param len_ptr is a pointer to the length in octets of the complete |
| 542 | * srtp packet (header and body) before the function call, and of the |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 543 | * complete rtp packet after the call, if srtp_err_status_ok was returned. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 544 | * Otherwise, the value of the data to which it points is undefined. |
| 545 | * |
| 546 | * @return |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 547 | * - srtp_err_status_ok if the RTP packet is valid. |
| 548 | * - srtp_err_status_auth_fail if the SRTP packet failed the message |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 549 | * authentication check. |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 550 | * - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet has |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 551 | * already been processed and accepted). |
| 552 | * - [other] if there has been an error in the cryptographic mechanisms. |
| 553 | * |
| 554 | */ |
| 555 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 556 | srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 557 | |
| 558 | |
| 559 | /** |
| 560 | * @brief srtp_create() allocates and initializes an SRTP session. |
| 561 | |
jfigus | 92c3de3 | 2016-02-02 13:44:39 -0500 | [diff] [blame] | 562 | * The function call srtp_create(session, policy) allocates and |
| 563 | * initializes an SRTP session context, applying the given policy. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 564 | * |
IƱaki Baz Castillo | 241fec3 | 2014-08-21 00:51:00 +0200 | [diff] [blame] | 565 | * @param session is a pointer to the SRTP session to which the policy is |
| 566 | * to be added. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 567 | * |
| 568 | * @param policy is the srtp_policy_t struct that describes the policy |
| 569 | * for the session. The struct may be a single element, or it may be |
| 570 | * the head of a list, in which case each element of the list is |
Marcus Sundberg | 75d9212 | 2005-10-05 12:40:31 +0000 | [diff] [blame] | 571 | * processed. It may also be NULL, in which case streams should be added |
| 572 | * later using srtp_add_stream(). The final element of the list @b must |
| 573 | * have its `next' field set to NULL. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 574 | * |
| 575 | * @return |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 576 | * - srtp_err_status_ok if creation succeded. |
| 577 | * - srtp_err_status_alloc_fail if allocation failed. |
| 578 | * - srtp_err_status_init_fail if initialization failed. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 579 | */ |
| 580 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 581 | srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 582 | |
| 583 | |
| 584 | /** |
| 585 | * @brief srtp_add_stream() allocates and initializes an SRTP stream |
| 586 | * within a given SRTP session. |
| 587 | * |
| 588 | * The function call srtp_add_stream(session, policy) allocates and |
| 589 | * initializes a new SRTP stream within a given, previously created |
| 590 | * session, applying the policy given as the other argument to that |
| 591 | * stream. |
| 592 | * |
| 593 | * @return values: |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 594 | * - srtp_err_status_ok if stream creation succeded. |
| 595 | * - srtp_err_status_alloc_fail if stream allocation failed |
| 596 | * - srtp_err_status_init_fail if stream initialization failed. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 597 | */ |
| 598 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 599 | srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 600 | |
| 601 | |
| 602 | /** |
| 603 | * @brief srtp_remove_stream() deallocates an SRTP stream. |
| 604 | * |
| 605 | * The function call srtp_remove_stream(session, ssrc) removes |
| 606 | * the SRTP stream with the SSRC value ssrc from the SRTP session |
| 607 | * context given by the argument session. |
| 608 | * |
| 609 | * @param session is the SRTP session from which the stream |
| 610 | * will be removed. |
| 611 | * |
jfigus | 68f8a88 | 2016-02-03 12:48:23 -0500 | [diff] [blame] | 612 | * @param ssrc is the SSRC value of the stream to be removed |
| 613 | * in network byte order. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 614 | * |
| 615 | * @warning Wildcard SSRC values cannot be removed from a |
| 616 | * session. |
| 617 | * |
| 618 | * @return |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 619 | * - srtp_err_status_ok if the stream deallocation succeded. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 620 | * - [other] otherwise. |
| 621 | * |
| 622 | */ |
| 623 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 624 | srtp_err_status_t srtp_remove_stream(srtp_t session, unsigned int ssrc); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 625 | |
| 626 | /** |
Pascal BĆ¼hler | bd3112a | 2015-11-06 20:29:15 +0100 | [diff] [blame] | 627 | * @brief srtp_update() udpates all streams in the session. |
| 628 | * |
| 629 | * The function call srtp_update(session, policy) updates |
| 630 | * all the streams in the session applying the given policy |
| 631 | * and key. The exsisting ROC value of all streams will be |
| 632 | * preserved. |
| 633 | * |
| 634 | * @param session is the SRTP session that contains the streams |
| 635 | * to be updated. |
| 636 | * |
| 637 | * @param policy is the srtp_policy_t struct that describes the policy |
| 638 | * for the session. The struct may be a single element, or it may be |
| 639 | * the head of a list, in which case each element of the list is |
| 640 | * processed. The final element of the list @b must |
| 641 | * have its `next' field set to NULL. |
| 642 | * |
| 643 | * @return |
| 644 | * - srtp_err_status_ok if stream creation succeded. |
| 645 | * - srtp_err_status_alloc_fail if stream allocation failed |
| 646 | * - srtp_err_status_init_fail if stream initialization failed. |
| 647 | * - [other] otherwise. |
| 648 | * |
| 649 | */ |
| 650 | |
| 651 | srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy); |
| 652 | |
| 653 | /** |
| 654 | * @brief srtp_update_stream() udpates a SRTP stream. |
| 655 | * |
| 656 | * The function call srtp_update_stream(session, policy) updates |
| 657 | * the stream(s) in the session that match applying the given |
| 658 | * policy and key. The exsisting ROC value of all stream(s) will |
| 659 | * be preserved. |
| 660 | * |
| 661 | * @param session is the SRTP session that contains the streams |
| 662 | * to be updated. |
| 663 | * |
| 664 | * @param policy is the srtp_policy_t struct that describes the policy |
| 665 | * for the session. |
| 666 | * |
| 667 | * @return |
| 668 | * - srtp_err_status_ok if stream creation succeded. |
| 669 | * - srtp_err_status_alloc_fail if stream allocation failed |
| 670 | * - srtp_err_status_init_fail if stream initialization failed. |
| 671 | * - [other] otherwise. |
| 672 | * |
| 673 | */ |
| 674 | |
| 675 | srtp_err_status_t srtp_update_stream(srtp_t session, const srtp_policy_t *policy); |
| 676 | |
| 677 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 678 | * @brief srtp_crypto_policy_set_rtp_default() sets a crypto policy |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 679 | * structure to the SRTP default policy for RTP protection. |
| 680 | * |
David McGrew | c4fc00b | 2006-06-08 18:51:27 +0000 | [diff] [blame] | 681 | * @param p is a pointer to the policy structure to be set |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 682 | * |
| 683 | * The function call crypto_policy_set_rtp_default(&p) sets the |
| 684 | * crypto_policy_t at location p to the SRTP default policy for RTP |
| 685 | * protection, as defined in the specification. This function is a |
| 686 | * convenience that helps to avoid dealing directly with the policy |
| 687 | * data structure. You are encouraged to initialize policy elements |
| 688 | * with this function call. Doing so may allow your code to be |
| 689 | * forward compatible with later versions of libSRTP that include more |
| 690 | * elements in the crypto_policy_t datatype. |
| 691 | * |
| 692 | * @return void. |
| 693 | * |
| 694 | */ |
| 695 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 696 | void srtp_crypto_policy_set_rtp_default(srtp_crypto_policy_t *p); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 697 | |
| 698 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 699 | * @brief srtp_crypto_policy_set_rtcp_default() sets a crypto policy |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 700 | * structure to the SRTP default policy for RTCP protection. |
| 701 | * |
David McGrew | c4fc00b | 2006-06-08 18:51:27 +0000 | [diff] [blame] | 702 | * @param p is a pointer to the policy structure to be set |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 703 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 704 | * The function call srtp_crypto_policy_set_rtcp_default(&p) sets the |
| 705 | * srtp_crypto_policy_t at location p to the SRTP default policy for RTCP |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 706 | * protection, as defined in the specification. This function is a |
| 707 | * convenience that helps to avoid dealing directly with the policy |
| 708 | * data structure. You are encouraged to initialize policy elements |
| 709 | * with this function call. Doing so may allow your code to be |
| 710 | * forward compatible with later versions of libSRTP that include more |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 711 | * elements in the srtp_crypto_policy_t datatype. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 712 | * |
| 713 | * @return void. |
| 714 | * |
| 715 | */ |
| 716 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 717 | void srtp_crypto_policy_set_rtcp_default(srtp_crypto_policy_t *p); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 718 | |
| 719 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 720 | * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 721 | * policy structure to the SRTP default policy for RTP protection. |
| 722 | * |
David McGrew | c4fc00b | 2006-06-08 18:51:27 +0000 | [diff] [blame] | 723 | * @param p is a pointer to the policy structure to be set |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 724 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 725 | * 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 Lennox | d8d5cd0 | 2010-05-17 20:08:17 +0000 | [diff] [blame] | 727 | * naming convention used in RFC 4568 (SDP Security Descriptions for |
| 728 | * Media Streams). |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 729 | * |
| 730 | * @return void. |
| 731 | * |
| 732 | */ |
| 733 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 734 | #define srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(p) srtp_crypto_policy_set_rtp_default(p) |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 735 | |
| 736 | |
| 737 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 738 | * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 739 | * policy structure to a short-authentication tag policy |
| 740 | * |
David McGrew | c4fc00b | 2006-06-08 18:51:27 +0000 | [diff] [blame] | 741 | * @param p is a pointer to the policy structure to be set |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 742 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 743 | * The function call srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&p) |
| 744 | * sets the srtp_crypto_policy_t at location p to use policy |
Jonathan Lennox | d8d5cd0 | 2010-05-17 20:08:17 +0000 | [diff] [blame] | 745 | * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568. |
| 746 | * This policy uses AES-128 |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 747 | * Counter Mode encryption and HMAC-SHA1 authentication, with an |
| 748 | * authentication tag that is only 32 bits long. This length is |
| 749 | * considered adequate only for protecting audio and video media that |
| 750 | * use a stateless playback function. See Section 7.5 of RFC 3711 |
| 751 | * (http://www.ietf.org/rfc/rfc3711.txt). |
| 752 | * |
| 753 | * This function is a convenience that helps to avoid dealing directly |
| 754 | * with the policy data structure. You are encouraged to initialize |
| 755 | * policy elements with this function call. Doing so may allow your |
| 756 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 757 | * include more elements in the srtp_crypto_policy_t datatype. |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 758 | * |
| 759 | * @warning This crypto policy is intended for use in SRTP, but not in |
| 760 | * SRTCP. It is recommended that a policy that uses longer |
| 761 | * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711 |
| 762 | * (http://www.ietf.org/rfc/rfc3711.txt). |
| 763 | * |
| 764 | * @return void. |
| 765 | * |
| 766 | */ |
| 767 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 768 | void srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(srtp_crypto_policy_t *p); |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 769 | |
| 770 | |
| 771 | |
| 772 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 773 | * @brief srtp_crypto_policy_set_aes_cm_128_null_auth() sets a crypto |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 774 | * policy structure to an encryption-only policy |
| 775 | * |
David McGrew | c4fc00b | 2006-06-08 18:51:27 +0000 | [diff] [blame] | 776 | * @param p is a pointer to the policy structure to be set |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 777 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 778 | * The function call srtp_crypto_policy_set_aes_cm_128_null_auth(&p) sets |
| 779 | * the srtp_crypto_policy_t at location p to use the SRTP default cipher |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 780 | * (AES-128 Counter Mode), but to use no authentication method. This |
| 781 | * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5 |
| 782 | * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt). |
| 783 | * |
| 784 | * This function is a convenience that helps to avoid dealing directly |
| 785 | * with the policy data structure. You are encouraged to initialize |
| 786 | * policy elements with this function call. Doing so may allow your |
| 787 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 788 | * include more elements in the srtp_crypto_policy_t datatype. |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 789 | * |
| 790 | * @warning This policy is NOT RECOMMENDED for SRTP unless it is |
| 791 | * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see |
| 792 | * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt). |
| 793 | * |
| 794 | * @return void. |
| 795 | * |
| 796 | */ |
| 797 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 798 | void srtp_crypto_policy_set_aes_cm_128_null_auth(srtp_crypto_policy_t *p); |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 799 | |
| 800 | |
| 801 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 802 | * @brief srtp_crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 803 | * policy structure to an authentication-only policy |
| 804 | * |
David McGrew | c4fc00b | 2006-06-08 18:51:27 +0000 | [diff] [blame] | 805 | * @param p is a pointer to the policy structure to be set |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 806 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 807 | * The function call srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&p) |
| 808 | * sets the srtp_crypto_policy_t at location p to use HMAC-SHA1 with an 80 |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 809 | * bit authentication tag to provide message authentication, but to |
| 810 | * use no encryption. This policy is NOT RECOMMENDED for SRTP unless |
| 811 | * there is a requirement to forego encryption. |
| 812 | * |
| 813 | * This function is a convenience that helps to avoid dealing directly |
| 814 | * with the policy data structure. You are encouraged to initialize |
| 815 | * policy elements with this function call. Doing so may allow your |
| 816 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 817 | * include more elements in the srtp_crypto_policy_t datatype. |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 818 | * |
| 819 | * @warning This policy is NOT RECOMMENDED for SRTP unless there is a |
| 820 | * requirement to forego encryption. |
| 821 | * |
| 822 | * @return void. |
| 823 | * |
| 824 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 825 | void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p); |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 826 | |
jfigus | 267956d | 2014-11-06 10:49:21 -0500 | [diff] [blame] | 827 | /** |
| 828 | * @brief srtp_crypto_policy_set_null_cipher_hmac_null() sets a crypto |
| 829 | * policy structure to use no encryption or authentication. |
| 830 | * |
| 831 | * @param p is a pointer to the policy structure to be set |
| 832 | * |
| 833 | * The function call srtp_crypto_policy_set_null_cipher_hmac_null(&p) |
| 834 | * sets the srtp_crypto_policy_t at location p to use no encryption and |
| 835 | * no authentication. This policy should only be used for testing and |
| 836 | * troubleshootingl. |
| 837 | * |
| 838 | * This function is a convenience that helps to avoid dealing directly |
| 839 | * with the policy data structure. You are encouraged to initialize |
| 840 | * policy elements with this function call. Doing so may allow your |
| 841 | * code to be forward compatible with later versions of libSRTP that |
| 842 | * include more elements in the srtp_crypto_policy_t datatype. |
| 843 | * |
| 844 | * @warning This policy is NOT RECOMMENDED for SRTP unless there is a |
| 845 | * requirement to forego encryption and authentication. |
| 846 | * |
| 847 | * @return void. |
| 848 | * |
| 849 | */ |
| 850 | void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p); |
| 851 | |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 852 | |
| 853 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 854 | * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 855 | * policy structure to a encryption and authentication policy using AES-256 |
| 856 | * for RTP protection. |
| 857 | * |
| 858 | * @param p is a pointer to the policy structure to be set |
| 859 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 860 | * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(&p) |
| 861 | * sets the srtp_crypto_policy_t at location p to use policy |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 862 | * AES_CM_256_HMAC_SHA1_80 as defined in |
| 863 | * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256 |
| 864 | * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit |
| 865 | * authentication tag. |
| 866 | * |
| 867 | * This function is a convenience that helps to avoid dealing directly |
| 868 | * with the policy data structure. You are encouraged to initialize |
| 869 | * policy elements with this function call. Doing so may allow your |
| 870 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 871 | * include more elements in the srtp_crypto_policy_t datatype. |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 872 | * |
| 873 | * @return void. |
| 874 | * |
| 875 | */ |
| 876 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 877 | void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(srtp_crypto_policy_t *p); |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 878 | |
| 879 | |
| 880 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 881 | * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 882 | * policy structure to a short-authentication tag policy using AES-256 |
| 883 | * encryption. |
| 884 | * |
| 885 | * @param p is a pointer to the policy structure to be set |
| 886 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 887 | * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&p) |
| 888 | * sets the srtp_crypto_policy_t at location p to use policy |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 889 | * AES_CM_256_HMAC_SHA1_32 as defined in |
| 890 | * draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256 |
| 891 | * Counter Mode encryption and HMAC-SHA1 authentication, with an |
| 892 | * authentication tag that is only 32 bits long. This length is |
| 893 | * considered adequate only for protecting audio and video media that |
| 894 | * use a stateless playback function. See Section 7.5 of RFC 3711 |
| 895 | * (http://www.ietf.org/rfc/rfc3711.txt). |
| 896 | * |
| 897 | * This function is a convenience that helps to avoid dealing directly |
| 898 | * with the policy data structure. You are encouraged to initialize |
| 899 | * policy elements with this function call. Doing so may allow your |
| 900 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 901 | * include more elements in the srtp_crypto_policy_t datatype. |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 902 | * |
| 903 | * @warning This crypto policy is intended for use in SRTP, but not in |
| 904 | * SRTCP. It is recommended that a policy that uses longer |
| 905 | * authentication tags be used for SRTCP. See Section 7.5 of RFC 3711 |
| 906 | * (http://www.ietf.org/rfc/rfc3711.txt). |
| 907 | * |
| 908 | * @return void. |
| 909 | * |
| 910 | */ |
| 911 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 912 | void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(srtp_crypto_policy_t *p); |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 913 | |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 914 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 915 | * @brief srtp_crypto_policy_set_aes_cm_256_null_auth() sets a crypto |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 916 | * policy structure to an encryption-only policy |
| 917 | * |
| 918 | * @param p is a pointer to the policy structure to be set |
| 919 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 920 | * The function call srtp_crypto_policy_set_aes_cm_256_null_auth(&p) sets |
| 921 | * the srtp_crypto_policy_t at location p to use the SRTP default cipher |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 922 | * (AES-256 Counter Mode), but to use no authentication method. This |
| 923 | * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5 |
| 924 | * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt). |
| 925 | * |
| 926 | * This function is a convenience that helps to avoid dealing directly |
| 927 | * with the policy data structure. You are encouraged to initialize |
| 928 | * policy elements with this function call. Doing so may allow your |
| 929 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 930 | * include more elements in the srtp_crypto_policy_t datatype. |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 931 | * |
| 932 | * @warning This policy is NOT RECOMMENDED for SRTP unless it is |
| 933 | * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see |
| 934 | * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt). |
| 935 | * |
| 936 | * @return void. |
| 937 | * |
| 938 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 939 | void srtp_crypto_policy_set_aes_cm_256_null_auth(srtp_crypto_policy_t *p); |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 940 | |
| 941 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 942 | * @brief srtp_crypto_policy_set_aes_gcm_128_8_auth() sets a crypto |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 943 | * policy structure to an AEAD encryption policy. |
| 944 | * |
| 945 | * @param p is a pointer to the policy structure to be set |
| 946 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 947 | * The function call srtp_crypto_policy_set_aes_gcm_128_8_auth(&p) sets |
| 948 | * the srtp_crypto_policy_t at location p to use the SRTP default cipher |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 949 | * (AES-128 Galois Counter Mode) with 8 octet auth tag. This |
| 950 | * policy applies confidentiality and authentication to both the |
| 951 | * RTP and RTCP packets. |
| 952 | * |
| 953 | * This function is a convenience that helps to avoid dealing directly |
| 954 | * with the policy data structure. You are encouraged to initialize |
| 955 | * policy elements with this function call. Doing so may allow your |
| 956 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 957 | * include more elements in the srtp_crypto_policy_t datatype. |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 958 | * |
| 959 | * @return void. |
| 960 | * |
| 961 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 962 | void srtp_crypto_policy_set_aes_gcm_128_8_auth(srtp_crypto_policy_t *p); |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 963 | |
| 964 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 965 | * @brief srtp_crypto_policy_set_aes_gcm_256_8_auth() sets a crypto |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 966 | * policy structure to an AEAD encryption policy |
| 967 | * |
| 968 | * @param p is a pointer to the policy structure to be set |
| 969 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 970 | * The function call srtp_crypto_policy_set_aes_gcm_256_8_auth(&p) sets |
| 971 | * the srtp_crypto_policy_t at location p to use the SRTP default cipher |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 972 | * (AES-256 Galois Counter Mode) with 8 octet auth tag. This |
| 973 | * policy applies confidentiality and authentication to both the |
| 974 | * RTP and RTCP packets. |
| 975 | * |
| 976 | * This function is a convenience that helps to avoid dealing directly |
| 977 | * with the policy data structure. You are encouraged to initialize |
| 978 | * policy elements with this function call. Doing so may allow your |
| 979 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 980 | * include more elements in the srtp_crypto_policy_t datatype. |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 981 | * |
| 982 | * @return void. |
| 983 | * |
| 984 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 985 | void srtp_crypto_policy_set_aes_gcm_256_8_auth(srtp_crypto_policy_t *p); |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 986 | |
| 987 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 988 | * @brief srtp_crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 989 | * policy structure to an AEAD authentication-only policy |
| 990 | * |
| 991 | * @param p is a pointer to the policy structure to be set |
| 992 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 993 | * The function call srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets |
| 994 | * the srtp_crypto_policy_t at location p to use the SRTP default cipher |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 995 | * (AES-128 Galois Counter Mode) with 8 octet auth tag. This policy |
| 996 | * applies confidentiality and authentication to the RTP packets, |
| 997 | * but only authentication to the RTCP packets. |
| 998 | * |
| 999 | * This function is a convenience that helps to avoid dealing directly |
| 1000 | * with the policy data structure. You are encouraged to initialize |
| 1001 | * policy elements with this function call. Doing so may allow your |
| 1002 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1003 | * include more elements in the srtp_crypto_policy_t datatype. |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 1004 | * |
| 1005 | * @return void. |
| 1006 | * |
| 1007 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1008 | void srtp_crypto_policy_set_aes_gcm_128_8_only_auth(srtp_crypto_policy_t *p); |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 1009 | |
| 1010 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1011 | * @brief srtp_crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 1012 | * policy structure to an AEAD authentication-only policy |
| 1013 | * |
| 1014 | * @param p is a pointer to the policy structure to be set |
| 1015 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1016 | * The function call srtp_crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets |
| 1017 | * the srtp_crypto_policy_t at location p to use the SRTP default cipher |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 1018 | * (AES-256 Galois Counter Mode) with 8 octet auth tag. This policy |
| 1019 | * applies confidentiality and authentication to the RTP packets, |
| 1020 | * but only authentication to the RTCP packets. |
| 1021 | * |
| 1022 | * This function is a convenience that helps to avoid dealing directly |
| 1023 | * with the policy data structure. You are encouraged to initialize |
| 1024 | * policy elements with this function call. Doing so may allow your |
| 1025 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1026 | * include more elements in the srtp_crypto_policy_t datatype. |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 1027 | * |
| 1028 | * @return void. |
| 1029 | * |
| 1030 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1031 | void srtp_crypto_policy_set_aes_gcm_256_8_only_auth(srtp_crypto_policy_t *p); |
jfigus | 8c36da2 | 2013-10-01 16:41:19 -0400 | [diff] [blame] | 1032 | |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1033 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1034 | * @brief srtp_crypto_policy_set_aes_gcm_128_16_auth() sets a crypto |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1035 | * policy structure to an AEAD encryption policy. |
| 1036 | * |
| 1037 | * @param p is a pointer to the policy structure to be set |
| 1038 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1039 | * The function call srtp_crypto_policy_set_aes_gcm_128_16_auth(&p) sets |
| 1040 | * the srtp_crypto_policy_t at location p to use the SRTP default cipher |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1041 | * (AES-128 Galois Counter Mode) with 16 octet auth tag. This |
| 1042 | * policy applies confidentiality and authentication to both the |
| 1043 | * RTP and RTCP packets. |
| 1044 | * |
| 1045 | * This function is a convenience that helps to avoid dealing directly |
| 1046 | * with the policy data structure. You are encouraged to initialize |
| 1047 | * policy elements with this function call. Doing so may allow your |
| 1048 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1049 | * include more elements in the srtp_crypto_policy_t datatype. |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1050 | * |
| 1051 | * @return void. |
| 1052 | * |
| 1053 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1054 | void srtp_crypto_policy_set_aes_gcm_128_16_auth(srtp_crypto_policy_t *p); |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1055 | |
| 1056 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1057 | * @brief srtp_crypto_policy_set_aes_gcm_256_16_auth() sets a crypto |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1058 | * policy structure to an AEAD encryption policy |
| 1059 | * |
| 1060 | * @param p is a pointer to the policy structure to be set |
| 1061 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1062 | * The function call srtp_crypto_policy_set_aes_gcm_256_16_auth(&p) sets |
| 1063 | * the srtp_crypto_policy_t at location p to use the SRTP default cipher |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1064 | * (AES-256 Galois Counter Mode) with 16 octet auth tag. This |
| 1065 | * policy applies confidentiality and authentication to both the |
| 1066 | * RTP and RTCP packets. |
| 1067 | * |
| 1068 | * This function is a convenience that helps to avoid dealing directly |
| 1069 | * with the policy data structure. You are encouraged to initialize |
| 1070 | * policy elements with this function call. Doing so may allow your |
| 1071 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1072 | * include more elements in the srtp_crypto_policy_t datatype. |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1073 | * |
| 1074 | * @return void. |
| 1075 | * |
| 1076 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1077 | void srtp_crypto_policy_set_aes_gcm_256_16_auth(srtp_crypto_policy_t *p); |
jfigus | c13c100 | 2014-05-08 13:34:53 -0400 | [diff] [blame] | 1078 | |
Jonathan Lennox | 5df951a | 2010-05-20 20:55:54 +0000 | [diff] [blame] | 1079 | |
David McGrew | a854688 | 2006-01-12 17:56:02 +0000 | [diff] [blame] | 1080 | /** |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1081 | * @brief srtp_dealloc() deallocates storage for an SRTP session |
| 1082 | * context. |
| 1083 | * |
| 1084 | * The function call srtp_dealloc(s) deallocates storage for the |
| 1085 | * SRTP session context s. This function should be called no more |
| 1086 | * than one time for each of the contexts allocated by the function |
| 1087 | * srtp_create(). |
| 1088 | * |
| 1089 | * @param s is the srtp_t for the session to be deallocated. |
| 1090 | * |
| 1091 | * @return |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1092 | * - srtp_err_status_ok if there no problems. |
| 1093 | * - srtp_err_status_dealloc_fail a memory deallocation failure occured. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1094 | */ |
| 1095 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1096 | srtp_err_status_t srtp_dealloc(srtp_t s); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1097 | |
| 1098 | |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1099 | /* |
| 1100 | * @brief identifies a particular SRTP profile |
| 1101 | * |
| 1102 | * An srtp_profile_t enumeration is used to identify a particular SRTP |
| 1103 | * profile (that is, a set of algorithms and parameters). These |
| 1104 | * profiles are defined in the DTLS-SRTP draft. |
| 1105 | */ |
| 1106 | |
| 1107 | typedef enum { |
| 1108 | srtp_profile_reserved = 0, |
| 1109 | srtp_profile_aes128_cm_sha1_80 = 1, |
| 1110 | srtp_profile_aes128_cm_sha1_32 = 2, |
| 1111 | srtp_profile_aes256_cm_sha1_80 = 3, |
| 1112 | srtp_profile_aes256_cm_sha1_32 = 4, |
| 1113 | srtp_profile_null_sha1_80 = 5, |
| 1114 | srtp_profile_null_sha1_32 = 6, |
| 1115 | } srtp_profile_t; |
| 1116 | |
| 1117 | |
| 1118 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1119 | * @brief srtp_crypto_policy_set_from_profile_for_rtp() sets a crypto policy |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1120 | * structure to the appropriate value for RTP based on an srtp_profile_t |
| 1121 | * |
| 1122 | * @param p is a pointer to the policy structure to be set |
| 1123 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1124 | * The function call srtp_crypto_policy_set_rtp_default(&policy, profile) |
| 1125 | * sets the srtp_crypto_policy_t at location policy to the policy for RTP |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1126 | * protection, as defined by the srtp_profile_t profile. |
| 1127 | * |
| 1128 | * This function is a convenience that helps to avoid dealing directly |
| 1129 | * with the policy data structure. You are encouraged to initialize |
| 1130 | * policy elements with this function call. Doing so may allow your |
| 1131 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1132 | * include more elements in the srtp_crypto_policy_t datatype. |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1133 | * |
| 1134 | * @return values |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1135 | * - srtp_err_status_ok no problems were encountered |
| 1136 | * - srtp_err_status_bad_param the profile is not supported |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1137 | * |
| 1138 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1139 | srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtp(srtp_crypto_policy_t *policy, srtp_profile_t profile); |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1140 | |
| 1141 | |
| 1142 | |
| 1143 | |
| 1144 | /** |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1145 | * @brief srtp_crypto_policy_set_from_profile_for_rtcp() sets a crypto policy |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1146 | * structure to the appropriate value for RTCP based on an srtp_profile_t |
| 1147 | * |
| 1148 | * @param p is a pointer to the policy structure to be set |
| 1149 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1150 | * The function call srtp_crypto_policy_set_rtcp_default(&policy, profile) |
| 1151 | * sets the srtp_crypto_policy_t at location policy to the policy for RTCP |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1152 | * protection, as defined by the srtp_profile_t profile. |
| 1153 | * |
| 1154 | * This function is a convenience that helps to avoid dealing directly |
| 1155 | * with the policy data structure. You are encouraged to initialize |
| 1156 | * policy elements with this function call. Doing so may allow your |
| 1157 | * code to be forward compatible with later versions of libSRTP that |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1158 | * include more elements in the srtp_crypto_policy_t datatype. |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1159 | * |
| 1160 | * @return values |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1161 | * - srtp_err_status_ok no problems were encountered |
| 1162 | * - srtp_err_status_bad_param the profile is not supported |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1163 | * |
| 1164 | */ |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1165 | srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtcp(srtp_crypto_policy_t *policy, srtp_profile_t profile); |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1166 | |
| 1167 | /** |
| 1168 | * @brief returns the master key length for a given SRTP profile |
| 1169 | */ |
| 1170 | unsigned int |
| 1171 | srtp_profile_get_master_key_length(srtp_profile_t profile); |
| 1172 | |
| 1173 | |
| 1174 | /** |
| 1175 | * @brief returns the master salt length for a given SRTP profile |
| 1176 | */ |
| 1177 | unsigned int |
| 1178 | srtp_profile_get_master_salt_length(srtp_profile_t profile); |
| 1179 | |
| 1180 | /** |
| 1181 | * @brief appends the salt to the key |
| 1182 | * |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1183 | * The function call srtp_append_salt_to_key(k, klen, s, slen) |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1184 | * copies the string s to the location at klen bytes following |
| 1185 | * the location k. |
| 1186 | * |
| 1187 | * @warning There must be at least bytes_in_salt + bytes_in_key bytes |
| 1188 | * available at the location pointed to by key. |
| 1189 | * |
| 1190 | */ |
| 1191 | |
| 1192 | void |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1193 | srtp_append_salt_to_key(unsigned char *key, unsigned int bytes_in_key, |
| 1194 | unsigned char *salt, unsigned int bytes_in_salt); |
David McGrew | 0cb86ee | 2006-07-07 15:46:57 +0000 | [diff] [blame] | 1195 | |
| 1196 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1197 | |
| 1198 | /** |
| 1199 | * @} |
| 1200 | */ |
| 1201 | |
| 1202 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1203 | |
| 1204 | /** |
| 1205 | * @defgroup SRTCP Secure RTCP |
| 1206 | * @ingroup SRTP |
| 1207 | * |
| 1208 | * @brief Secure RTCP functions are used to protect RTCP traffic. |
| 1209 | * |
| 1210 | * RTCP is the control protocol for RTP. libSRTP protects RTCP |
| 1211 | * traffic in much the same way as it does RTP traffic. The function |
| 1212 | * srtp_protect_rtcp() applies cryptographic protections to outbound |
| 1213 | * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on |
| 1214 | * inbound RTCP packets. |
| 1215 | * |
| 1216 | * A note on the naming convention: srtp_protect_rtcp() has an srtp_t |
| 1217 | * as its first argument, and thus has `srtp_' as its prefix. The |
| 1218 | * trailing `_rtcp' indicates the protocol on which it acts. |
| 1219 | * |
| 1220 | * @{ |
| 1221 | */ |
| 1222 | |
| 1223 | /** |
| 1224 | * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet |
| 1225 | * processing function. |
| 1226 | * |
| 1227 | * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies |
| 1228 | * SRTCP protection to the RTCP packet rtcp_hdr (which has length |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1229 | * *len_ptr) using the SRTP session context ctx. If srtp_err_status_ok is |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1230 | * returned, then rtp_hdr points to the resulting SRTCP packet and |
| 1231 | * *len_ptr is the number of octets in that packet; otherwise, no |
| 1232 | * assumptions should be made about the value of either data elements. |
| 1233 | * |
| 1234 | * @warning This function assumes that it can write the authentication |
| 1235 | * tag into the location in memory immediately following the RTCP |
| 1236 | * packet, and assumes that the RTCP packet is aligned on a 32-bit |
| 1237 | * boundary. |
| 1238 | * |
jfigus | 5e33729 | 2013-05-28 13:57:47 -0400 | [diff] [blame] | 1239 | * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4 |
| 1240 | * into the location in memory immediately following the RTCP packet. |
| 1241 | * Callers MUST ensure that this much writable memory is available in |
| 1242 | * the buffer that holds the RTCP packet. |
| 1243 | * |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1244 | * @param ctx is the SRTP context to use in processing the packet. |
| 1245 | * |
| 1246 | * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after |
| 1247 | * the function returns, it points to the srtp packet. |
| 1248 | * |
| 1249 | * @param pkt_octet_len is a pointer to the length in octets of the |
| 1250 | * complete RTCP packet (header and body) before the function call, |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1251 | * and of the complete SRTCP packet after the call, if srtp_err_status_ok |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1252 | * was returned. Otherwise, the value of the data to which it points |
| 1253 | * is undefined. |
| 1254 | * |
| 1255 | * @return |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1256 | * - srtp_err_status_ok if there were no problems. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1257 | * - [other] if there was a failure in |
| 1258 | * the cryptographic mechanisms. |
| 1259 | */ |
| 1260 | |
| 1261 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1262 | srtp_err_status_t srtp_protect_rtcp(srtp_t ctx, void *rtcp_hdr, int *pkt_octet_len); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1263 | |
| 1264 | /** |
| 1265 | * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet |
| 1266 | * processing function. |
| 1267 | * |
| 1268 | * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr) |
| 1269 | * verifies the Secure RTCP protection of the SRTCP packet pointed to |
| 1270 | * by srtcp_hdr (which has length *len_ptr), using the SRTP session |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1271 | * context ctx. If srtp_err_status_ok is returned, then srtcp_hdr points |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1272 | * to the resulting RTCP packet and *len_ptr is the number of octets |
| 1273 | * in that packet; otherwise, no assumptions should be made about the |
| 1274 | * value of either data elements. |
| 1275 | * |
| 1276 | * @warning This function assumes that the SRTCP packet is aligned on a |
| 1277 | * 32-bit boundary. |
| 1278 | * |
| 1279 | * @param ctx is a pointer to the srtp_t which applies to the |
| 1280 | * particular packet. |
| 1281 | * |
| 1282 | * @param srtcp_hdr is a pointer to the header of the SRTCP packet |
| 1283 | * (before the call). After the function returns, it points to the |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1284 | * rtp packet if srtp_err_status_ok was returned; otherwise, the value of |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1285 | * the data to which it points is undefined. |
| 1286 | * |
| 1287 | * @param pkt_octet_len is a pointer to the length in octets of the |
| 1288 | * complete SRTCP packet (header and body) before the function call, |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1289 | * and of the complete rtp packet after the call, if srtp_err_status_ok was |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1290 | * returned. Otherwise, the value of the data to which it points is |
| 1291 | * undefined. |
| 1292 | * |
| 1293 | * @return |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1294 | * - srtp_err_status_ok if the RTCP packet is valid. |
| 1295 | * - srtp_err_status_auth_fail if the SRTCP packet failed the message |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1296 | * authentication check. |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1297 | * - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1298 | * already been processed and accepted). |
| 1299 | * - [other] if there has been an error in the cryptographic mechanisms. |
| 1300 | * |
| 1301 | */ |
| 1302 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1303 | srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx, void *srtcp_hdr, int *pkt_octet_len); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1304 | |
| 1305 | /** |
| 1306 | * @} |
| 1307 | */ |
| 1308 | |
IƱaki Baz Castillo | 241fec3 | 2014-08-21 00:51:00 +0200 | [diff] [blame] | 1309 | |
| 1310 | /** |
| 1311 | * @defgroup User data associated to a SRTP session. |
| 1312 | * @ingroup SRTP |
| 1313 | * |
| 1314 | * @brief Store custom user data within a SRTP session. |
| 1315 | * |
| 1316 | * @{ |
| 1317 | */ |
| 1318 | |
| 1319 | /** |
| 1320 | * @brief srtp_set_user_data() stores the given pointer into the SRTP |
| 1321 | * session for later retrieval. |
| 1322 | * |
| 1323 | * @param ctx is the srtp_t context in which the given data pointer is |
| 1324 | * stored. |
| 1325 | * |
| 1326 | * @param data is a pointer to the custom information (struct, function, |
| 1327 | * etc) associated with the SRTP session. |
| 1328 | * |
| 1329 | * @return void. |
| 1330 | * |
| 1331 | */ |
| 1332 | |
| 1333 | void |
| 1334 | srtp_set_user_data(srtp_t ctx, void *data); |
| 1335 | |
| 1336 | /** |
| 1337 | * @brief srtp_get_user_data() retrieves the pointer to the custom data |
| 1338 | * previously stored with srtp_set_user_data(). |
| 1339 | * |
| 1340 | * This function is mostly useful for retrieving data associated to a |
| 1341 | * SRTP session when an event fires. The user can then get such a custom |
| 1342 | * data by calling this function with the session field of the |
| 1343 | * srtp_event_data_t struct as argument. |
| 1344 | * |
| 1345 | * @param ctx is the srtp_t context in which the given data pointer was |
| 1346 | * stored. |
| 1347 | * |
| 1348 | * @return void* pointer to the user data. |
| 1349 | * |
| 1350 | */ |
| 1351 | |
| 1352 | void* |
| 1353 | srtp_get_user_data(srtp_t ctx); |
| 1354 | |
| 1355 | /** |
| 1356 | * @} |
| 1357 | */ |
| 1358 | |
| 1359 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1360 | /** |
| 1361 | * @defgroup SRTPevents SRTP events and callbacks |
| 1362 | * @ingroup SRTP |
| 1363 | * |
| 1364 | * @brief libSRTP can use a user-provided callback function to |
| 1365 | * handle events. |
| 1366 | * |
| 1367 | * |
| 1368 | * libSRTP allows a user to provide a callback function to handle |
| 1369 | * events that need to be dealt with outside of the data plane (see |
| 1370 | * the enum srtp_event_t for a description of these events). Dealing |
| 1371 | * with these events is not a strict necessity; they are not |
| 1372 | * security-critical, but the application may suffer if they are not |
| 1373 | * handled. The function srtp_set_event_handler() is used to provide |
| 1374 | * the callback function. |
| 1375 | * |
| 1376 | * A default event handler that merely reports on the events as they |
| 1377 | * happen is included. It is also possible to set the event handler |
| 1378 | * function to NULL, in which case all events will just be silently |
| 1379 | * ignored. |
| 1380 | * |
| 1381 | * @{ |
| 1382 | */ |
| 1383 | |
| 1384 | /** |
| 1385 | * @brief srtp_event_t defines events that need to be handled |
| 1386 | * |
| 1387 | * The enum srtp_event_t defines events that need to be handled |
| 1388 | * outside the `data plane', such as SSRC collisions and |
| 1389 | * key expirations. |
| 1390 | * |
| 1391 | * When a key expires or the maximum number of packets has been |
| 1392 | * reached, an SRTP stream will enter an `expired' state in which no |
| 1393 | * more packets can be protected or unprotected. When this happens, |
| 1394 | * it is likely that you will want to either deallocate the stream |
jfigus | 92c3de3 | 2016-02-02 13:44:39 -0500 | [diff] [blame] | 1395 | * (using srtp_remove_stream()), and possibly allocate a new one. |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1396 | * |
| 1397 | * When an SRTP stream expires, the other streams in the same session |
| 1398 | * are unaffected, unless key sharing is used by that stream. In the |
| 1399 | * latter case, all of the streams in the session will expire. |
| 1400 | */ |
| 1401 | |
| 1402 | typedef enum { |
| 1403 | event_ssrc_collision, /**< |
| 1404 | * An SSRC collision occured. |
| 1405 | */ |
| 1406 | event_key_soft_limit, /**< An SRTP stream reached the soft key |
| 1407 | * usage limit and will expire soon. |
| 1408 | */ |
| 1409 | event_key_hard_limit, /**< An SRTP stream reached the hard |
| 1410 | * key usage limit and has expired. |
| 1411 | */ |
| 1412 | event_packet_index_limit /**< An SRTP stream reached the hard |
| 1413 | * packet limit (2^48 packets). |
| 1414 | */ |
| 1415 | } srtp_event_t; |
| 1416 | |
| 1417 | /** |
| 1418 | * @brief srtp_event_data_t is the structure passed as a callback to |
| 1419 | * the event handler function |
| 1420 | * |
| 1421 | * The struct srtp_event_data_t holds the data passed to the event |
| 1422 | * handler function. |
| 1423 | */ |
| 1424 | |
| 1425 | typedef struct srtp_event_data_t { |
| 1426 | srtp_t session; /**< The session in which the event happend. */ |
| 1427 | srtp_stream_t stream; /**< The stream in which the event happend. */ |
| 1428 | srtp_event_t event; /**< An enum indicating the type of event. */ |
| 1429 | } srtp_event_data_t; |
| 1430 | |
| 1431 | /** |
| 1432 | * @brief srtp_event_handler_func_t is the function prototype for |
| 1433 | * the event handler. |
| 1434 | * |
| 1435 | * The typedef srtp_event_handler_func_t is the prototype for the |
| 1436 | * event handler function. It has as its only argument an |
| 1437 | * srtp_event_data_t which describes the event that needs to be handled. |
| 1438 | * There can only be a single, global handler for all events in |
| 1439 | * libSRTP. |
| 1440 | */ |
| 1441 | |
| 1442 | typedef void (srtp_event_handler_func_t)(srtp_event_data_t *data); |
| 1443 | |
| 1444 | /** |
| 1445 | * @brief sets the event handler to the function supplied by the caller. |
| 1446 | * |
| 1447 | * The function call srtp_install_event_handler(func) sets the event |
| 1448 | * handler function to the value func. The value NULL is acceptable |
| 1449 | * as an argument; in this case, events will be ignored rather than |
| 1450 | * handled. |
| 1451 | * |
| 1452 | * @param func is a pointer to a fuction that takes an srtp_event_data_t |
| 1453 | * pointer as an argument and returns void. This function |
| 1454 | * will be used by libSRTP to handle events. |
| 1455 | */ |
| 1456 | |
jfigus | 857009c | 2014-11-05 11:17:43 -0500 | [diff] [blame] | 1457 | srtp_err_status_t srtp_install_event_handler(srtp_event_handler_func_t func); |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1458 | |
| 1459 | /** |
jfigus | f62b64d | 2014-10-08 13:53:57 -0400 | [diff] [blame] | 1460 | * @brief Returns the version string of the library. |
| 1461 | * |
| 1462 | */ |
Christian Oien | d4e3eec | 2014-10-24 10:14:08 +0200 | [diff] [blame] | 1463 | const char *srtp_get_version_string(void); |
jfigus | f62b64d | 2014-10-08 13:53:57 -0400 | [diff] [blame] | 1464 | |
| 1465 | /** |
| 1466 | * @brief Returns the numeric representation of the library version. |
| 1467 | * |
| 1468 | */ |
| 1469 | unsigned int srtp_get_version(void); |
| 1470 | |
| 1471 | /** |
jfigus | 46d6b47 | 2014-11-14 16:42:01 -0500 | [diff] [blame] | 1472 | * @brief srtp_set_debug_module(mod_name, v) |
| 1473 | * |
| 1474 | * sets dynamic debugging to the value v (0 for off, 1 for on) for the |
| 1475 | * debug module with the name mod_name |
| 1476 | * |
| 1477 | * returns err_status_ok on success, err_status_fail otherwise |
| 1478 | */ |
| 1479 | srtp_err_status_t srtp_set_debug_module(char *mod_name, int v); |
| 1480 | |
| 1481 | /** |
| 1482 | * @brief srtp_list_debug_modules() outputs a list of debugging modules |
| 1483 | * |
| 1484 | */ |
| 1485 | srtp_err_status_t srtp_list_debug_modules(void); |
| 1486 | |
| 1487 | |
| 1488 | /** |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1489 | * @} |
| 1490 | */ |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1491 | /* in host order, so outside the #if */ |
| 1492 | #define SRTCP_E_BIT 0x80000000 |
| 1493 | /* for byte-access */ |
| 1494 | #define SRTCP_E_BYTE_BIT 0x80 |
| 1495 | #define SRTCP_INDEX_MASK 0x7fffffff |
| 1496 | |
Marcus Sundberg | cb60bf8 | 2005-10-17 17:23:05 +0000 | [diff] [blame] | 1497 | #ifdef __cplusplus |
| 1498 | } |
| 1499 | #endif |
| 1500 | |
Cullen Jennings | 235513a | 2005-09-21 22:51:36 +0000 | [diff] [blame] | 1501 | #endif /* SRTP_H */ |