tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

srtp.h (71879B)


      1 /*
      2 * srtp.h
      3 *
      4 * interface to libsrtp
      5 *
      6 * David A. McGrew
      7 * Cisco Systems, Inc.
      8 */
      9 /*
     10 *
     11 * Copyright (c) 2001-2017, Cisco Systems, Inc.
     12 * All rights reserved.
     13 *
     14 * Redistribution and use in source and binary forms, with or without
     15 * modification, are permitted provided that the following conditions
     16 * are met:
     17 *
     18 *   Redistributions of source code must retain the above copyright
     19 *   notice, this list of conditions and the following disclaimer.
     20 *
     21 *   Redistributions in binary form must reproduce the above
     22 *   copyright notice, this list of conditions and the following
     23 *   disclaimer in the documentation and/or other materials provided
     24 *   with the distribution.
     25 *
     26 *   Neither the name of the Cisco Systems, Inc. nor the names of its
     27 *   contributors may be used to endorse or promote products derived
     28 *   from this software without specific prior written permission.
     29 *
     30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     33 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     34 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     35 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     36 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     37 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     41 * OF THE POSSIBILITY OF SUCH DAMAGE.
     42 *
     43 */
     44 
     45 #ifndef SRTP_SRTP_H
     46 #define SRTP_SRTP_H
     47 
     48 #include <stdint.h>
     49 
     50 #ifdef __cplusplus
     51 extern "C" {
     52 #endif
     53 
     54 /**
     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 */
     72 #define SRTP_MAX_KEY_LEN 64
     73 
     74 /*
     75 * SRTP_MAX_TAG_LEN is the maximum tag length supported by libSRTP
     76 */
     77 
     78 #define SRTP_MAX_TAG_LEN 16
     79 
     80 /**
     81 * 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 
     86 /**
     87 * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer
     88 * (authentication tag and MKI) supported by libSRTP.  This value is
     89 * the maximum number of octets that will be added to an RTP packet by
     90 * srtp_protect().
     91 *
     92 * @brief the maximum number of octets added by srtp_protect().
     93 */
     94 #define SRTP_MAX_TRAILER_LEN (SRTP_MAX_TAG_LEN + SRTP_MAX_MKI_LEN)
     95 
     96 /**
     97 * SRTP_SRCTP_INDEX_LEN is the size the SRTCP index which is
     98 * 4 bytes
     99 */
    100 #define SRTP_SRCTP_INDEX_LEN 4
    101 
    102 /**
    103 * SRTP_MAX_SRTCP_TRAILER_LEN is the maximum length of the SRTCP trailer
    104 * (index, authentication tag and MKI) supported by libSRTP.  This value is
    105 * the maximum number of octets that will be added to an RTCP packet by
    106 * srtp_protect_rtcp().
    107 *
    108 * @brief the maximum number of octets added by srtp_protect().
    109 */
    110 #define SRTP_MAX_SRTCP_TRAILER_LEN                                             \
    111    (SRTP_SRCTP_INDEX_LEN + SRTP_MAX_TAG_LEN + SRTP_MAX_MKI_LEN)
    112 
    113 /**
    114 * SRTP_MAX_NUM_MASTER_KEYS is the maximum number of Master keys for
    115 * MKI supported by libSRTP.
    116 *
    117 */
    118 #define SRTP_MAX_NUM_MASTER_KEYS 16
    119 
    120 #define SRTP_SALT_LEN 14
    121 
    122 /*
    123 * SRTP_AEAD_SALT_LEN is the length of the SALT values used with
    124 * GCM mode.  GCM mode requires an IV.  The SALT value is used
    125 * as part of the IV formation logic applied to each RTP packet.
    126 */
    127 #define SRTP_AEAD_SALT_LEN 12
    128 
    129 #define SRTP_AES_128_KEY_LEN 16
    130 #define SRTP_AES_192_KEY_LEN 24
    131 #define SRTP_AES_256_KEY_LEN 32
    132 
    133 #define SRTP_AES_ICM_128_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_128_KEY_LEN)
    134 #define SRTP_AES_ICM_192_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_192_KEY_LEN)
    135 #define SRTP_AES_ICM_256_KEY_LEN_WSALT (SRTP_SALT_LEN + SRTP_AES_256_KEY_LEN)
    136 
    137 #define SRTP_AES_GCM_128_KEY_LEN_WSALT                                         \
    138    (SRTP_AEAD_SALT_LEN + SRTP_AES_128_KEY_LEN)
    139 #define SRTP_AES_GCM_192_KEY_LEN_WSALT                                         \
    140    (SRTP_AEAD_SALT_LEN + SRTP_AES_192_KEY_LEN)
    141 #define SRTP_AES_GCM_256_KEY_LEN_WSALT                                         \
    142    (SRTP_AEAD_SALT_LEN + SRTP_AES_256_KEY_LEN)
    143 
    144 /**
    145 *  @brief A srtp_cipher_type_id_t is an identifier for a particular cipher
    146 *  type.
    147 *
    148 *  A srtp_cipher_type_id_t is an integer that represents a particular
    149 *  cipher type, e.g. the Advanced Encryption Standard (AES).  A
    150 *  SRTP_NULL_CIPHER is available; this cipher leaves the data unchanged,
    151 *  and can be selected to indicate that no encryption is to take
    152 *  place.
    153 *
    154 *  @ingroup Ciphers
    155 */
    156 typedef uint32_t srtp_cipher_type_id_t;
    157 
    158 /**
    159 *  @brief An srtp_auth_type_id_t is an identifier for a particular
    160 * authentication
    161 *   function.
    162 *
    163 *  An srtp_auth_type_id_t is an integer that represents a particular
    164 *  authentication function type, e.g. HMAC-SHA1.  A SRTP_NULL_AUTH is
    165 *  available; this authentication function performs no computation,
    166 *  and can be selected to indicate that no authentication is to take
    167 *  place.
    168 *
    169 *  @ingroup Authentication
    170 */
    171 typedef uint32_t srtp_auth_type_id_t;
    172 
    173 /**
    174 * @brief srtp_err_status_t defines error codes.
    175 *
    176 * The enumeration srtp_err_status_t defines error codes.  Note that the
    177 * value of srtp_err_status_ok is equal to zero, which can simplify error
    178 * checking somewhat.
    179 *
    180 */
    181 typedef enum {
    182    srtp_err_status_ok = 0,             /**< nothing to report               */
    183    srtp_err_status_fail = 1,           /**< unspecified failure             */
    184    srtp_err_status_bad_param = 2,      /**< unsupported parameter           */
    185    srtp_err_status_alloc_fail = 3,     /**< couldn't allocate memory        */
    186    srtp_err_status_dealloc_fail = 4,   /**< couldn't deallocate properly    */
    187    srtp_err_status_init_fail = 5,      /**< couldn't initialize             */
    188    srtp_err_status_terminus = 6,       /**< can't process as much data as   */
    189                                        /**< requested                       */
    190    srtp_err_status_auth_fail = 7,      /**< authentication failure          */
    191    srtp_err_status_cipher_fail = 8,    /**< cipher failure                  */
    192    srtp_err_status_replay_fail = 9,    /**< replay check failed (bad index) */
    193    srtp_err_status_replay_old = 10,    /**< replay check failed (index too  */
    194                                        /**< old)                            */
    195    srtp_err_status_algo_fail = 11,     /**< algorithm failed test routine   */
    196    srtp_err_status_no_such_op = 12,    /**< unsupported operation           */
    197    srtp_err_status_no_ctx = 13,        /**< no appropriate context found    */
    198    srtp_err_status_cant_check = 14,    /**< unable to perform desired       */
    199                                        /**< validation                      */
    200    srtp_err_status_key_expired = 15,   /**< can't use key any more          */
    201    srtp_err_status_socket_err = 16,    /**< error in use of socket          */
    202    srtp_err_status_signal_err = 17,    /**< error in use POSIX signals      */
    203    srtp_err_status_nonce_bad = 18,     /**< nonce check failed              */
    204    srtp_err_status_read_fail = 19,     /**< couldn't read data              */
    205    srtp_err_status_write_fail = 20,    /**< couldn't write data             */
    206    srtp_err_status_parse_err = 21,     /**< error parsing data              */
    207    srtp_err_status_encode_err = 22,    /**< error encoding data             */
    208    srtp_err_status_semaphore_err = 23, /**< error while using semaphores    */
    209    srtp_err_status_pfkey_err = 24,     /**< error while using pfkey         */
    210    srtp_err_status_bad_mki = 25,       /**< error MKI present in packet is  */
    211                                        /**< invalid                         */
    212    srtp_err_status_pkt_idx_old = 26,   /**< packet index is too old to      */
    213                                        /**< consider                        */
    214    srtp_err_status_pkt_idx_adv = 27    /**< packet index advanced, reset    */
    215                                        /**< needed                          */
    216 } srtp_err_status_t;
    217 
    218 typedef struct srtp_ctx_t_ srtp_ctx_t;
    219 
    220 /**
    221 * @brief srtp_sec_serv_t describes a set of security services.
    222 *
    223 * A srtp_sec_serv_t enumeration is used to describe the particular
    224 * security services that will be applied by a particular crypto
    225 * policy (or other mechanism).
    226 */
    227 typedef enum {
    228    sec_serv_none = 0,         /**< no services                        */
    229    sec_serv_conf = 1,         /**< confidentiality                    */
    230    sec_serv_auth = 2,         /**< authentication                     */
    231    sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */
    232 } srtp_sec_serv_t;
    233 
    234 /**
    235 * @brief srtp_crypto_policy_t describes a particular crypto policy that
    236 * can be applied to an SRTP stream.
    237 *
    238 * A srtp_crypto_policy_t describes a particular cryptographic policy that
    239 * can be applied to an SRTP or SRTCP stream.  An SRTP session policy
    240 * consists of a list of these policies, one for each SRTP stream
    241 * in the session.
    242 */
    243 typedef struct srtp_crypto_policy_t {
    244    srtp_cipher_type_id_t cipher_type; /**< An integer representing          */
    245                                       /**< the type of cipher.              */
    246    int cipher_key_len;                /**< The length of the cipher key     */
    247                                       /**< in octets.                       */
    248    srtp_auth_type_id_t auth_type;     /**< An integer representing the      */
    249                                       /**< authentication function.         */
    250    int auth_key_len;                  /**< The length of the authentication */
    251                                       /**< function key in octets.          */
    252    int auth_tag_len;                  /**< The length of the authentication */
    253                                       /**< tag in octets.                   */
    254    srtp_sec_serv_t sec_serv;          /**< The flag indicating the security */
    255                                       /**< services to be applied.          */
    256 } srtp_crypto_policy_t;
    257 
    258 /**
    259 * @brief srtp_ssrc_type_t describes the type of an SSRC.
    260 *
    261 * An srtp_ssrc_type_t enumeration is used to indicate a type of SSRC.  See
    262 * @ref srtp_policy_t for more information.
    263 */
    264 typedef enum {
    265    ssrc_undefined = 0,   /**< Indicates an undefined SSRC type.    */
    266    ssrc_specific = 1,    /**< Indicates a specific SSRC value      */
    267    ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value     */
    268                          /**< (i.e. a value that is used in the    */
    269                          /**< function srtp_unprotect())           */
    270    ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value    */
    271                          /**< (i.e. a value that is used in the    */
    272                          /**< function srtp_protect())             */
    273 } srtp_ssrc_type_t;
    274 
    275 /**
    276 * @brief An srtp_ssrc_t represents a particular SSRC value, or a `wildcard'
    277 * SSRC.
    278 *
    279 * An srtp_ssrc_t represents a particular SSRC value (if its type is
    280 * ssrc_specific), or a wildcard SSRC value that will match all
    281 * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound
    282 * SSRCs (if its type is ssrc_any_inbound).
    283 */
    284 typedef struct {
    285    srtp_ssrc_type_t type; /**< The type of this particular SSRC */
    286    unsigned int value;    /**< The value of this SSRC, if it is not a */
    287                           /**< wildcard */
    288 } srtp_ssrc_t;
    289 
    290 /**
    291 * @brief srtp_master_key_t represents a master key.  There will
    292 * be a Master Key Index and the Master Key associated with the
    293 * Master Key Index.  Need to also keep track of the Master Key
    294 * Index Size to correctly read it from a packet.
    295 */
    296 typedef struct srtp_master_key_t {
    297    unsigned char *key;
    298    unsigned char *mki_id;
    299    unsigned int mki_size;
    300 } srtp_master_key_t;
    301 
    302 /**
    303 * @brief represents the policy for an SRTP session.
    304 *
    305 * A single srtp_policy_t struct represents the policy for a single
    306 * SRTP stream, and a linked list of these elements represents the
    307 * policy for an entire SRTP session.  Each element contains the SRTP
    308 * and SRTCP crypto policies for that stream, a pointer to the SRTP
    309 * master key for that stream, the SSRC describing that stream, or a
    310 * flag indicating a `wildcard' SSRC value, and a `next' field that
    311 * holds a pointer to the next element in the list of policy elements,
    312 * or NULL if it is the last element.
    313 *
    314 * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an
    315 * inbound stream that for which there is no explicit SSRC entry in
    316 * another policy element.  Similarly, the value SSRC_ANY_OUTBOUND
    317 * will matches any SSRC from an outbound stream that does not appear
    318 * in another policy element.  Note that wildcard SSRCs &b cannot be
    319 * used to match both inbound and outbound traffic.  This restriction
    320 * is intentional, and it allows libSRTP to ensure that no security
    321 * lapses result from accidental re-use of SSRC values during key
    322 * sharing.
    323 *
    324 * @warning The final element of the list @b must have its `next' pointer
    325 *          set to NULL.
    326 */
    327 
    328 typedef struct srtp_policy_t {
    329    srtp_ssrc_t ssrc;              /**< The SSRC value of stream, or the    */
    330                                   /**< flags SSRC_ANY_INBOUND or           */
    331                                   /**< SSRC_ANY_OUTBOUND if key sharing    */
    332                                   /**< is used for this policy element.    */
    333    srtp_crypto_policy_t rtp;      /**< SRTP crypto policy.                 */
    334    srtp_crypto_policy_t rtcp;     /**< SRTCP crypto policy.                */
    335    unsigned char *key;            /**< Pointer to the SRTP master key for  */
    336                                   /**< this stream.                        */
    337    srtp_master_key_t **keys;      /** Array of Master Key structures       */
    338    unsigned long num_master_keys; /** Number of master keys                */
    339    void *deprecated_ekt;          /**< DEPRECATED: pointer to the EKT      */
    340                                   /**< policy structure for this stream    */
    341    unsigned long window_size;     /**< The window size to use for replay   */
    342                                   /**< protection.                         */
    343    int allow_repeat_tx;           /**< Whether retransmissions of          */
    344                                   /**< packets with the same sequence      */
    345                                   /**< number are allowed.                 */
    346                                   /**< (Note that such repeated            */
    347                                   /**< transmissions must have the same    */
    348                                   /**< RTP payload, or a severe security   */
    349                                   /**< weakness is introduced!)            */
    350    int *enc_xtn_hdr;              /**< List of header ids to encrypt.      */
    351    int enc_xtn_hdr_count;         /**< Number of entries in list of header */
    352                                   /**<  ids.                               */
    353    struct srtp_policy_t *next;    /**< Pointer to next stream policy.      */
    354 } srtp_policy_t;
    355 
    356 /**
    357 * @brief An srtp_t points to an SRTP session structure.
    358 *
    359 * The typedef srtp_t is a pointer to a structure that represents
    360 * an SRTP session.  This datatype is intentionally opaque in
    361 * order to separate the interface from the implementation.
    362 *
    363 * An SRTP session consists of all of the traffic sent to the RTP and
    364 * RTCP destination transport addresses, using the RTP/SAVP (Secure
    365 * Audio/Video Profile).  A session can be viewed as a set of SRTP
    366 * streams, each of which originates with a different participant.
    367 */
    368 typedef srtp_ctx_t *srtp_t;
    369 
    370 /**
    371 * @brief srtp_init() initializes the srtp library.
    372 *
    373 * @warning This function @b must be called before any other srtp
    374 * functions.
    375 */
    376 srtp_err_status_t srtp_init(void);
    377 
    378 /**
    379 * @brief srtp_shutdown() de-initializes the srtp library.
    380 *
    381 * @warning No srtp functions may be called after calling this function.
    382 */
    383 srtp_err_status_t srtp_shutdown(void);
    384 
    385 /**
    386 * @brief srtp_protect() is the Secure RTP sender-side packet processing
    387 * function.
    388 *
    389 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
    390 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
    391 * the SRTP context ctx.  If srtp_err_status_ok is returned, then rtp_hdr
    392 * points to the resulting SRTP packet and *len_ptr is the number of
    393 * octets in that packet; otherwise, no assumptions should be made
    394 * about the value of either data elements.
    395 *
    396 * The sequence numbers of the RTP packets presented to this function
    397 * need not be consecutive, but they @b must be out of order by less
    398 * than 2^15 = 32,768 packets.
    399 *
    400 * @warning This function assumes that it can write the authentication
    401 * tag into the location in memory immediately following the RTP
    402 * packet, and assumes that the RTP packet is aligned on a 32-bit
    403 * boundary.
    404 *
    405 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
    406 * into the location in memory immediately following the RTP packet.
    407 * Callers MUST ensure that this much writable memory is available in
    408 * the buffer that holds the RTP packet.
    409 *
    410 * @param ctx is the SRTP context to use in processing the packet.
    411 *
    412 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
    413 * the function returns, it points to the srtp packet.
    414 *
    415 * @param len_ptr is a pointer to the length in octets of the complete
    416 * RTP packet (header and body) before the function call, and of the
    417 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
    418 * Otherwise, the value of the data to which it points is undefined.
    419 *
    420 * @return
    421 *    - srtp_err_status_ok            no problems
    422 *    - srtp_err_status_replay_fail   rtp sequence number was non-increasing
    423 *    - @e other                 failure in cryptographic mechanisms
    424 */
    425 srtp_err_status_t srtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr);
    426 
    427 /**
    428 * @brief srtp_protect_mki() is the Secure RTP sender-side packet processing
    429 * function that can utilize MKI.
    430 *
    431 * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP
    432 * protection to the RTP packet rtp_hdr (which has length *len_ptr) using
    433 * the SRTP context ctx.  If srtp_err_status_ok is returned, then rtp_hdr
    434 * points to the resulting SRTP packet and *len_ptr is the number of
    435 * octets in that packet; otherwise, no assumptions should be made
    436 * about the value of either data elements.
    437 *
    438 * The sequence numbers of the RTP packets presented to this function
    439 * need not be consecutive, but they @b must be out of order by less
    440 * than 2^15 = 32,768 packets.
    441 *
    442 * @warning This function assumes that it can write the authentication
    443 * tag into the location in memory immediately following the RTP
    444 * packet, and assumes that the RTP packet is aligned on a 32-bit
    445 * boundary.
    446 *
    447 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN
    448 * into the location in memory immediately following the RTP packet.
    449 * Callers MUST ensure that this much writable memory is available in
    450 * the buffer that holds the RTP packet.
    451 *
    452 * @param ctx is the SRTP context to use in processing the packet.
    453 *
    454 * @param rtp_hdr is a pointer to the RTP packet (before the call); after
    455 * the function returns, it points to the srtp packet.
    456 *
    457 * @param pkt_octet_len is a pointer to the length in octets of the complete
    458 * RTP packet (header and body) before the function call, and of the
    459 * complete SRTP packet after the call, if srtp_err_status_ok was returned.
    460 * Otherwise, the value of the data to which it points is undefined.
    461 *
    462 * @param use_mki is a boolean to tell the system if mki is being used.  If
    463 * set to false then will use the first set of session keys.  If set to true
    464 * will
    465 * use the session keys identified by the mki_index
    466 *
    467 * @param mki_index integer value specifying which set of session keys should be
    468 * used if use_mki is set to true.
    469 *
    470 * @return
    471 *    - srtp_err_status_ok            no problems
    472 *    - srtp_err_status_replay_fail   rtp sequence number was non-increasing
    473 *    - @e other                 failure in cryptographic mechanisms
    474 */
    475 srtp_err_status_t srtp_protect_mki(srtp_ctx_t *ctx,
    476                                   void *rtp_hdr,
    477                                   int *pkt_octet_len,
    478                                   unsigned int use_mki,
    479                                   unsigned int mki_index);
    480 
    481 /**
    482 * @brief srtp_unprotect() is the Secure RTP receiver-side packet
    483 * processing function.
    484 *
    485 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
    486 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
    487 * (which has length *len_ptr), using the SRTP context ctx.  If
    488 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
    489 * RTP packet and *len_ptr is the number of octets in that packet;
    490 * otherwise, no assumptions should be made about the value of either
    491 * data elements.
    492 *
    493 * The sequence numbers of the RTP packets presented to this function
    494 * need not be consecutive, but they @b must be out of order by less
    495 * than 2^15 = 32,768 packets.
    496 *
    497 * @warning This function assumes that the SRTP packet is aligned on a
    498 * 32-bit boundary.
    499 *
    500 * @param ctx is the SRTP session which applies to the particular packet.
    501 *
    502 * @param srtp_hdr is a pointer to the header of the SRTP packet
    503 * (before the call).  after the function returns, it points to the
    504 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
    505 * the data to which it points is undefined.
    506 *
    507 * @param len_ptr is a pointer to the length in octets of the complete
    508 * srtp packet (header and body) before the function call, and of the
    509 * complete rtp packet after the call, if srtp_err_status_ok was returned.
    510 * Otherwise, the value of the data to which it points is undefined.
    511 *
    512 * @return
    513 *    - srtp_err_status_ok          if the RTP packet is valid.
    514 *    - srtp_err_status_auth_fail   if the SRTP packet failed the message
    515 *                                  authentication check.
    516 *    - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet
    517 *                                  has already been processed and accepted).
    518 *    - [other]  if there has been an error in the cryptographic mechanisms.
    519 *
    520 */
    521 srtp_err_status_t srtp_unprotect(srtp_t ctx, void *srtp_hdr, int *len_ptr);
    522 
    523 /**
    524 * @brief srtp_unprotect_mki() is the Secure RTP receiver-side packet
    525 * processing function that checks for MKI.
    526 *
    527 * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies
    528 * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr
    529 * (which has length *len_ptr), using the SRTP context ctx.  If
    530 * srtp_err_status_ok is returned, then srtp_hdr points to the resulting
    531 * RTP packet and *len_ptr is the number of octets in that packet;
    532 * otherwise, no assumptions should be made about the value of either
    533 * data elements.
    534 *
    535 * The sequence numbers of the RTP packets presented to this function
    536 * need not be consecutive, but they @b must be out of order by less
    537 * than 2^15 = 32,768 packets.
    538 *
    539 * @warning This function assumes that the SRTP packet is aligned on a
    540 * 32-bit boundary.
    541 *
    542 * @param ctx is the SRTP session which applies to the particular packet.
    543 *
    544 * @param srtp_hdr is a pointer to the header of the SRTP packet
    545 * (before the call).  after the function returns, it points to the
    546 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
    547 * the data to which it points is undefined.
    548 *
    549 * @param len_ptr is a pointer to the length in octets of the complete
    550 * srtp packet (header and body) before the function call, and of the
    551 * complete rtp packet after the call, if srtp_err_status_ok was returned.
    552 * Otherwise, the value of the data to which it points is undefined.
    553 *
    554 * @param use_mki is a boolean to tell the system if mki is being used.  If
    555 * set to false then will use the first set of session keys.  If set to true
    556 * will
    557 * use the session keys identified by the mki_index
    558 *
    559 * @return
    560 *    - srtp_err_status_ok          if the RTP packet is valid.
    561 *    - srtp_err_status_auth_fail   if the SRTP packet failed the message
    562 *                                  authentication check.
    563 *    - srtp_err_status_replay_fail if the SRTP packet is a replay (e.g. packet
    564 *                                  has already been processed and accepted).
    565 *    - srtp_err_status_bad_mki if the MKI in the packet is not a known MKI id
    566 *    - [other]  if there has been an error in the cryptographic mechanisms.
    567 *
    568 */
    569 srtp_err_status_t srtp_unprotect_mki(srtp_t ctx,
    570                                     void *srtp_hdr,
    571                                     int *len_ptr,
    572                                     unsigned int use_mki);
    573 
    574 /**
    575 * @brief srtp_create() allocates and initializes an SRTP session.
    576 
    577 * The function call srtp_create(session, policy) allocates and
    578 * initializes an SRTP session context, applying the given policy.
    579 *
    580 * @param session is a pointer to the SRTP session to which the policy is
    581 * to be added.
    582 *
    583 * @param policy is the srtp_policy_t struct that describes the policy
    584 * for the session.  The struct may be a single element, or it may be
    585 * the head of a list, in which case each element of the list is
    586 * processed.  It may also be NULL, in which case streams should be added
    587 * later using srtp_add_stream().  The final element of the list @b must
    588 * have its `next' field set to NULL.
    589 *
    590 * @return
    591 *    - srtp_err_status_ok           if creation succeeded.
    592 *    - srtp_err_status_alloc_fail   if allocation failed.
    593 *    - srtp_err_status_init_fail    if initialization failed.
    594 */
    595 srtp_err_status_t srtp_create(srtp_t *session, const srtp_policy_t *policy);
    596 
    597 /**
    598 * @brief srtp_add_stream() allocates and initializes an SRTP stream
    599 * within a given SRTP session.
    600 *
    601 * The function call srtp_add_stream(session, policy) allocates and
    602 * initializes a new SRTP stream within a given, previously created
    603 * session, applying the policy given as the other argument to that
    604 * stream.
    605 *
    606 * @return values:
    607 *    - srtp_err_status_ok           if stream creation succeeded.
    608 *    - srtp_err_status_alloc_fail   if stream allocation failed
    609 *    - srtp_err_status_init_fail    if stream initialization failed.
    610 */
    611 srtp_err_status_t srtp_add_stream(srtp_t session, const srtp_policy_t *policy);
    612 
    613 /**
    614 * @brief srtp_remove_stream() deallocates an SRTP stream.
    615 *
    616 * The function call srtp_remove_stream(session, ssrc) removes
    617 * the SRTP stream with the SSRC value ssrc from the SRTP session
    618 * context given by the argument session.
    619 *
    620 * @param session is the SRTP session from which the stream
    621 *        will be removed.
    622 *
    623 * @param ssrc is the SSRC value of the stream to be removed
    624 *             in network byte order.
    625 *
    626 * @warning Wildcard SSRC values cannot be removed from a
    627 *          session.
    628 *
    629 * @return
    630 *    - srtp_err_status_ok     if the stream deallocation succeeded.
    631 *    - [other]           otherwise.
    632 *
    633 */
    634 srtp_err_status_t srtp_remove_stream(srtp_t session, uint32_t ssrc);
    635 
    636 /**
    637 * @brief srtp_update() updates all streams in the session.
    638 *
    639 * The function call srtp_update(session, policy) updates
    640 * all the streams in the session applying the given policy
    641 * and key. The existing ROC value of all streams will be
    642 * preserved.
    643 *
    644 * @param session is the SRTP session that contains the streams
    645 *        to be updated.
    646 *
    647 * @param policy is the srtp_policy_t struct that describes the policy
    648 * for the session.  The struct may be a single element, or it may be
    649 * the head of a list, in which case each element of the list is
    650 * processed. The final element of the list @b must
    651 * have its `next' field set to NULL.
    652 *
    653 * @return
    654 *    - srtp_err_status_ok           if stream creation succeed.
    655 *    - srtp_err_status_alloc_fail   if stream allocation failed
    656 *    - srtp_err_status_init_fail    if stream initialization failed.
    657 *    - [other]                 otherwise.
    658 *
    659 */
    660 srtp_err_status_t srtp_update(srtp_t session, const srtp_policy_t *policy);
    661 
    662 /**
    663 * @brief srtp_update_stream() updates a SRTP stream.
    664 *
    665 * The function call srtp_update_stream(session, policy) updates
    666 * the stream(s) in the session that match applying the given
    667 * policy and key. The existing ROC value of all stream(s) will
    668 * be preserved.
    669 *
    670 * @param session is the SRTP session that contains the streams
    671 *        to be updated.
    672 *
    673 * @param policy is the srtp_policy_t struct that describes the policy
    674 * for the session.
    675 *
    676 * @return
    677 *    - srtp_err_status_ok           if stream creation succeeded.
    678 *    - srtp_err_status_alloc_fail   if stream allocation failed
    679 *    - srtp_err_status_init_fail    if stream initialization failed.
    680 *    - [other]                      otherwise.
    681 *
    682 */
    683 srtp_err_status_t srtp_update_stream(srtp_t session,
    684                                     const srtp_policy_t *policy);
    685 
    686 /**
    687 * @brief srtp_crypto_policy_set_rtp_default() sets a crypto policy
    688 * structure to the SRTP default policy for RTP protection.
    689 *
    690 * @param p is a pointer to the policy structure to be set
    691 *
    692 * The function call srtp_crypto_policy_set_rtp_default(&p) sets the
    693 * srtp_crypto_policy_t at location p to the SRTP default policy for RTP
    694 * protection, as defined in the specification.  This function is a
    695 * convenience that helps to avoid dealing directly with the policy
    696 * data structure.  You are encouraged to initialize policy elements
    697 * with this function call.  Doing so may allow your code to be
    698 * forward compatible with later versions of libSRTP that include more
    699 * elements in the srtp_crypto_policy_t datatype.
    700 *
    701 * @return void.
    702 *
    703 */
    704 void srtp_crypto_policy_set_rtp_default(srtp_crypto_policy_t *p);
    705 
    706 /**
    707 * @brief srtp_crypto_policy_set_rtcp_default() sets a crypto policy
    708 * structure to the SRTP default policy for RTCP protection.
    709 *
    710 * @param p is a pointer to the policy structure to be set
    711 *
    712 * The function call srtp_crypto_policy_set_rtcp_default(&p) sets the
    713 * srtp_crypto_policy_t at location p to the SRTP default policy for RTCP
    714 * protection, as defined in the specification.  This function is a
    715 * convenience that helps to avoid dealing directly with the policy
    716 * data structure.  You are encouraged to initialize policy elements
    717 * with this function call.  Doing so may allow your code to be
    718 * forward compatible with later versions of libSRTP that include more
    719 * elements in the srtp_crypto_policy_t datatype.
    720 *
    721 * @return void.
    722 *
    723 */
    724 void srtp_crypto_policy_set_rtcp_default(srtp_crypto_policy_t *p);
    725 
    726 /**
    727 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
    728 * policy structure to the SRTP default policy for RTP protection.
    729 *
    730 * @param p is a pointer to the policy structure to be set
    731 *
    732 * The function srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
    733 * synonym for srtp_crypto_policy_set_rtp_default().  It conforms to the
    734 * naming convention used in RFC 4568 (SDP Security Descriptions for
    735 * Media Streams).
    736 *
    737 * @return void.
    738 *
    739 */
    740 #define srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(p)                      \
    741    srtp_crypto_policy_set_rtp_default(p)
    742 
    743 /**
    744 * @brief srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
    745 * policy structure to a short-authentication tag policy
    746 *
    747 * @param p is a pointer to the policy structure to be set
    748 *
    749 * The function call srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
    750 * sets the srtp_crypto_policy_t at location p to use policy
    751 * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568.
    752 * This policy uses AES-128
    753 * Counter Mode encryption and HMAC-SHA1 authentication, with an
    754 * authentication tag that is only 32 bits long.  This length is
    755 * considered adequate only for protecting audio and video media that
    756 * use a stateless playback function.  See Section 7.5 of RFC 3711
    757 * (http://www.ietf.org/rfc/rfc3711.txt).
    758 *
    759 * This function is a convenience that helps to avoid dealing directly
    760 * with the policy data structure.  You are encouraged to initialize
    761 * policy elements with this function call.  Doing so may allow your
    762 * code to be forward compatible with later versions of libSRTP that
    763 * include more elements in the srtp_crypto_policy_t datatype.
    764 *
    765 * @warning This crypto policy is intended for use in SRTP, but not in
    766 * SRTCP.  It is recommended that a policy that uses longer
    767 * authentication tags be used for SRTCP.  See Section 7.5 of RFC 3711
    768 * (http://www.ietf.org/rfc/rfc3711.txt).
    769 *
    770 * @return void.
    771 *
    772 */
    773 void srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(srtp_crypto_policy_t *p);
    774 
    775 /**
    776 * @brief srtp_crypto_policy_set_aes_cm_128_null_auth() sets a crypto
    777 * policy structure to an encryption-only policy
    778 *
    779 * @param p is a pointer to the policy structure to be set
    780 *
    781 * The function call srtp_crypto_policy_set_aes_cm_128_null_auth(&p) sets
    782 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
    783 * (AES-128 Counter Mode), but to use no authentication method.  This
    784 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
    785 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
    786 *
    787 * This function is a convenience that helps to avoid dealing directly
    788 * with the policy data structure.  You are encouraged to initialize
    789 * policy elements with this function call.  Doing so may allow your
    790 * code to be forward compatible with later versions of libSRTP that
    791 * include more elements in the srtp_crypto_policy_t datatype.
    792 *
    793 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
    794 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
    795 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
    796 *
    797 * @return void.
    798 *
    799 */
    800 void srtp_crypto_policy_set_aes_cm_128_null_auth(srtp_crypto_policy_t *p);
    801 
    802 /**
    803 * @brief srtp_crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
    804 * policy structure to an authentication-only policy
    805 *
    806 * @param p is a pointer to the policy structure to be set
    807 *
    808 * The function call srtp_crypto_policy_set_null_cipher_hmac_sha1_80(&p)
    809 * sets the srtp_crypto_policy_t at location p to use HMAC-SHA1 with an 80
    810 * bit authentication tag to provide message authentication, but to
    811 * use no encryption.  This policy is NOT RECOMMENDED for SRTP unless
    812 * there is a requirement to forgo encryption.
    813 *
    814 * This function is a convenience that helps to avoid dealing directly
    815 * with the policy data structure.  You are encouraged to initialize
    816 * policy elements with this function call.  Doing so may allow your
    817 * code to be forward compatible with later versions of libSRTP that
    818 * include more elements in the srtp_crypto_policy_t datatype.
    819 *
    820 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
    821 * requirement to forgo encryption.
    822 *
    823 * @return void.
    824 *
    825 */
    826 void srtp_crypto_policy_set_null_cipher_hmac_sha1_80(srtp_crypto_policy_t *p);
    827 
    828 /**
    829 * @brief srtp_crypto_policy_set_null_cipher_hmac_null() sets a crypto
    830 * policy structure to use no encryption or authentication.
    831 *
    832 * @param p is a pointer to the policy structure to be set
    833 *
    834 * The function call srtp_crypto_policy_set_null_cipher_hmac_null(&p)
    835 * sets the srtp_crypto_policy_t at location p to use no encryption and
    836 * no authentication.  This policy should only be used for testing and
    837 * troubleshooting.
    838 *
    839 * This function is a convenience that helps to avoid dealing directly
    840 * with the policy data structure.  You are encouraged to initialize
    841 * policy elements with this function call.  Doing so may allow your
    842 * code to be forward compatible with later versions of libSRTP that
    843 * include more elements in the srtp_crypto_policy_t datatype.
    844 *
    845 * @warning This policy is NOT RECOMMENDED for SRTP unless there is a
    846 * requirement to forgo encryption and authentication.
    847 *
    848 * @return void.
    849 *
    850 */
    851 void srtp_crypto_policy_set_null_cipher_hmac_null(srtp_crypto_policy_t *p);
    852 
    853 /**
    854 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto
    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 *
    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
    862 * AES_CM_256_HMAC_SHA1_80 as defined in RFC 6188.  This policy uses AES-256
    863 * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
    864 * authentication tag.
    865 *
    866 * This function is a convenience that helps to avoid dealing directly
    867 * with the policy data structure.  You are encouraged to initialize
    868 * policy elements with this function call.  Doing so may allow your
    869 * code to be forward compatible with later versions of libSRTP that
    870 * include more elements in the srtp_crypto_policy_t datatype.
    871 *
    872 * @return void.
    873 *
    874 */
    875 void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_80(srtp_crypto_policy_t *p);
    876 
    877 /**
    878 * @brief srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto
    879 * policy structure to a short-authentication tag policy using AES-256
    880 * encryption.
    881 *
    882 * @param p is a pointer to the policy structure to be set
    883 *
    884 * The function call srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(&p)
    885 * sets the srtp_crypto_policy_t at location p to use policy
    886 * AES_CM_256_HMAC_SHA1_32 as defined in RFC 6188.  This policy uses AES-256
    887 * Counter Mode encryption and HMAC-SHA1 authentication, with an
    888 * authentication tag that is only 32 bits long.  This length is
    889 * considered adequate only for protecting audio and video media that
    890 * use a stateless playback function.  See Section 7.5 of RFC 3711
    891 * (http://www.ietf.org/rfc/rfc3711.txt).
    892 *
    893 * This function is a convenience that helps to avoid dealing directly
    894 * with the policy data structure.  You are encouraged to initialize
    895 * policy elements with this function call.  Doing so may allow your
    896 * code to be forward compatible with later versions of libSRTP that
    897 * include more elements in the srtp_crypto_policy_t datatype.
    898 *
    899 * @warning This crypto policy is intended for use in SRTP, but not in
    900 * SRTCP.  It is recommended that a policy that uses longer
    901 * authentication tags be used for SRTCP.  See Section 7.5 of RFC 3711
    902 * (http://www.ietf.org/rfc/rfc3711.txt).
    903 *
    904 * @return void.
    905 *
    906 */
    907 void srtp_crypto_policy_set_aes_cm_256_hmac_sha1_32(srtp_crypto_policy_t *p);
    908 
    909 /**
    910 * @brief srtp_crypto_policy_set_aes_cm_256_null_auth() sets a crypto
    911 * policy structure to an encryption-only policy
    912 *
    913 * @param p is a pointer to the policy structure to be set
    914 *
    915 * The function call srtp_crypto_policy_set_aes_cm_256_null_auth(&p) sets
    916 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
    917 * (AES-256 Counter Mode), but to use no authentication method.  This
    918 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
    919 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
    920 *
    921 * This function is a convenience that helps to avoid dealing directly
    922 * with the policy data structure.  You are encouraged to initialize
    923 * policy elements with this function call.  Doing so may allow your
    924 * code to be forward compatible with later versions of libSRTP that
    925 * include more elements in the srtp_crypto_policy_t datatype.
    926 *
    927 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
    928 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
    929 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
    930 *
    931 * @return void.
    932 *
    933 */
    934 void srtp_crypto_policy_set_aes_cm_256_null_auth(srtp_crypto_policy_t *p);
    935 
    936 /**
    937 * @brief srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80() sets a crypto
    938 * policy structure to a encryption and authentication policy using AES-192
    939 * for RTP protection.
    940 *
    941 * @param p is a pointer to the policy structure to be set
    942 *
    943 * The function call srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(&p)
    944 * sets the srtp_crypto_policy_t at location p to use policy
    945 * AES_CM_192_HMAC_SHA1_80 as defined in RFC 6188.  This policy uses AES-192
    946 * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
    947 * authentication tag.
    948 *
    949 * This function is a convenience that helps to avoid dealing directly
    950 * with the policy data structure.  You are encouraged to initialize
    951 * policy elements with this function call.  Doing so may allow your
    952 * code to be forward compatible with later versions of libSRTP that
    953 * include more elements in the srtp_crypto_policy_t datatype.
    954 *
    955 * @return void.
    956 *
    957 */
    958 void srtp_crypto_policy_set_aes_cm_192_hmac_sha1_80(srtp_crypto_policy_t *p);
    959 
    960 /**
    961 * @brief srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32() sets a crypto
    962 * policy structure to a short-authentication tag policy using AES-192
    963 * encryption.
    964 *
    965 * @param p is a pointer to the policy structure to be set
    966 *
    967 * The function call srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(&p)
    968 * sets the srtp_crypto_policy_t at location p to use policy
    969 * AES_CM_192_HMAC_SHA1_32 as defined in RFC 6188.  This policy uses AES-192
    970 * Counter Mode encryption and HMAC-SHA1 authentication, with an
    971 * authentication tag that is only 32 bits long.  This length is
    972 * considered adequate only for protecting audio and video media that
    973 * use a stateless playback function.  See Section 7.5 of RFC 3711
    974 * (http://www.ietf.org/rfc/rfc3711.txt).
    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
    980 * include more elements in the srtp_crypto_policy_t datatype.
    981 *
    982 * @warning This crypto policy is intended for use in SRTP, but not in
    983 * SRTCP.  It is recommended that a policy that uses longer
    984 * authentication tags be used for SRTCP.  See Section 7.5 of RFC 3711
    985 * (http://www.ietf.org/rfc/rfc3711.txt).
    986 *
    987 * @return void.
    988 *
    989 */
    990 void srtp_crypto_policy_set_aes_cm_192_hmac_sha1_32(srtp_crypto_policy_t *p);
    991 
    992 /**
    993 * @brief srtp_crypto_policy_set_aes_cm_192_null_auth() sets a crypto
    994 * policy structure to an encryption-only policy
    995 *
    996 * @param p is a pointer to the policy structure to be set
    997 *
    998 * The function call srtp_crypto_policy_set_aes_cm_192_null_auth(&p) sets
    999 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
   1000 * (AES-192 Counter Mode), but to use no authentication method.  This
   1001 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5
   1002 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
   1003 *
   1004 * This function is a convenience that helps to avoid dealing directly
   1005 * with the policy data structure.  You are encouraged to initialize
   1006 * policy elements with this function call.  Doing so may allow your
   1007 * code to be forward compatible with later versions of libSRTP that
   1008 * include more elements in the srtp_crypto_policy_t datatype.
   1009 *
   1010 * @warning This policy is NOT RECOMMENDED for SRTP unless it is
   1011 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see
   1012 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt).
   1013 *
   1014 * @return void.
   1015 *
   1016 */
   1017 void srtp_crypto_policy_set_aes_cm_192_null_auth(srtp_crypto_policy_t *p);
   1018 
   1019 /**
   1020 * @brief srtp_crypto_policy_set_aes_gcm_128_8_auth() sets a crypto
   1021 * policy structure to an AEAD encryption policy.
   1022 *
   1023 * @param p is a pointer to the policy structure to be set
   1024 *
   1025 * The function call srtp_crypto_policy_set_aes_gcm_128_8_auth(&p) sets
   1026 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
   1027 * (AES-128 Galois Counter Mode) with 8 octet auth tag.  This
   1028 * policy applies confidentiality and authentication to both the
   1029 * RTP and RTCP packets.
   1030 *
   1031 * This function is a convenience that helps to avoid dealing directly
   1032 * with the policy data structure.  You are encouraged to initialize
   1033 * policy elements with this function call.  Doing so may allow your
   1034 * code to be forward compatible with later versions of libSRTP that
   1035 * include more elements in the srtp_crypto_policy_t datatype.
   1036 *
   1037 * @return void.
   1038 *
   1039 */
   1040 void srtp_crypto_policy_set_aes_gcm_128_8_auth(srtp_crypto_policy_t *p);
   1041 
   1042 /**
   1043 * @brief srtp_crypto_policy_set_aes_gcm_256_8_auth() sets a crypto
   1044 * policy structure to an AEAD encryption policy
   1045 *
   1046 * @param p is a pointer to the policy structure to be set
   1047 *
   1048 * The function call srtp_crypto_policy_set_aes_gcm_256_8_auth(&p) sets
   1049 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
   1050 * (AES-256 Galois Counter Mode) with 8 octet auth tag.  This
   1051 * policy applies confidentiality and authentication to both the
   1052 * RTP and RTCP packets.
   1053 *
   1054 * This function is a convenience that helps to avoid dealing directly
   1055 * with the policy data structure.  You are encouraged to initialize
   1056 * policy elements with this function call.  Doing so may allow your
   1057 * code to be forward compatible with later versions of libSRTP that
   1058 * include more elements in the srtp_crypto_policy_t datatype.
   1059 *
   1060 * @return void.
   1061 *
   1062 */
   1063 void srtp_crypto_policy_set_aes_gcm_256_8_auth(srtp_crypto_policy_t *p);
   1064 
   1065 /**
   1066 * @brief srtp_crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto
   1067 * policy structure to an AEAD authentication-only policy
   1068 *
   1069 * @param p is a pointer to the policy structure to be set
   1070 *
   1071 * The function call srtp_crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets
   1072 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
   1073 * (AES-128 Galois Counter Mode) with 8 octet auth tag.  This policy
   1074 * applies confidentiality and authentication to the RTP packets,
   1075 * but only authentication to the RTCP packets.
   1076 *
   1077 * This function is a convenience that helps to avoid dealing directly
   1078 * with the policy data structure.  You are encouraged to initialize
   1079 * policy elements with this function call.  Doing so may allow your
   1080 * code to be forward compatible with later versions of libSRTP that
   1081 * include more elements in the srtp_crypto_policy_t datatype.
   1082 *
   1083 * @return void.
   1084 *
   1085 */
   1086 void srtp_crypto_policy_set_aes_gcm_128_8_only_auth(srtp_crypto_policy_t *p);
   1087 
   1088 /**
   1089 * @brief srtp_crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto
   1090 * policy structure to an AEAD authentication-only policy
   1091 *
   1092 * @param p is a pointer to the policy structure to be set
   1093 *
   1094 * The function call srtp_crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets
   1095 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
   1096 * (AES-256 Galois Counter Mode) with 8 octet auth tag.  This policy
   1097 * applies confidentiality and authentication to the RTP packets,
   1098 * but only authentication to the RTCP packets.
   1099 *
   1100 * This function is a convenience that helps to avoid dealing directly
   1101 * with the policy data structure.  You are encouraged to initialize
   1102 * policy elements with this function call.  Doing so may allow your
   1103 * code to be forward compatible with later versions of libSRTP that
   1104 * include more elements in the srtp_crypto_policy_t datatype.
   1105 *
   1106 * @return void.
   1107 *
   1108 */
   1109 void srtp_crypto_policy_set_aes_gcm_256_8_only_auth(srtp_crypto_policy_t *p);
   1110 
   1111 /**
   1112 * @brief srtp_crypto_policy_set_aes_gcm_128_16_auth() sets a crypto
   1113 * policy structure to an AEAD encryption policy.
   1114 *
   1115 * @param p is a pointer to the policy structure to be set
   1116 *
   1117 * The function call srtp_crypto_policy_set_aes_gcm_128_16_auth(&p) sets
   1118 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
   1119 * (AES-128 Galois Counter Mode) with 16 octet auth tag.  This
   1120 * policy applies confidentiality and authentication to both the
   1121 * RTP and RTCP packets.
   1122 *
   1123 * This function is a convenience that helps to avoid dealing directly
   1124 * with the policy data structure.  You are encouraged to initialize
   1125 * policy elements with this function call.  Doing so may allow your
   1126 * code to be forward compatible with later versions of libSRTP that
   1127 * include more elements in the srtp_crypto_policy_t datatype.
   1128 *
   1129 * @return void.
   1130 *
   1131 */
   1132 void srtp_crypto_policy_set_aes_gcm_128_16_auth(srtp_crypto_policy_t *p);
   1133 
   1134 /**
   1135 * @brief srtp_crypto_policy_set_aes_gcm_256_16_auth() sets a crypto
   1136 * policy structure to an AEAD encryption policy
   1137 *
   1138 * @param p is a pointer to the policy structure to be set
   1139 *
   1140 * The function call srtp_crypto_policy_set_aes_gcm_256_16_auth(&p) sets
   1141 * the srtp_crypto_policy_t at location p to use the SRTP default cipher
   1142 * (AES-256 Galois Counter Mode) with 16 octet auth tag.  This
   1143 * policy applies confidentiality and authentication to both the
   1144 * RTP and RTCP packets.
   1145 *
   1146 * This function is a convenience that helps to avoid dealing directly
   1147 * with the policy data structure.  You are encouraged to initialize
   1148 * policy elements with this function call.  Doing so may allow your
   1149 * code to be forward compatible with later versions of libSRTP that
   1150 * include more elements in the srtp_crypto_policy_t datatype.
   1151 *
   1152 * @return void.
   1153 *
   1154 */
   1155 void srtp_crypto_policy_set_aes_gcm_256_16_auth(srtp_crypto_policy_t *p);
   1156 
   1157 /**
   1158 * @brief srtp_dealloc() deallocates storage for an SRTP session
   1159 * context.
   1160 *
   1161 * The function call srtp_dealloc(s) deallocates storage for the
   1162 * SRTP session context s.  This function should be called no more
   1163 * than one time for each of the contexts allocated by the function
   1164 * srtp_create().
   1165 *
   1166 * @param s is the srtp_t for the session to be deallocated.
   1167 *
   1168 * @return
   1169 *    - srtp_err_status_ok             if there no problems.
   1170 *    - srtp_err_status_dealloc_fail   a memory deallocation failure occurred.
   1171 */
   1172 srtp_err_status_t srtp_dealloc(srtp_t s);
   1173 
   1174 /*
   1175 * @brief identifies a particular SRTP profile
   1176 *
   1177 * An srtp_profile_t enumeration is used to identify a particular SRTP
   1178 * profile (that is, a set of algorithms and parameters).
   1179 */
   1180 typedef enum {
   1181    srtp_profile_reserved = 0,
   1182    srtp_profile_aes128_cm_sha1_80 = 1,
   1183    srtp_profile_aes128_cm_sha1_32 = 2,
   1184    srtp_profile_null_sha1_80 = 5,
   1185    srtp_profile_null_sha1_32 = 6,
   1186    srtp_profile_aead_aes_128_gcm = 7,
   1187    srtp_profile_aead_aes_256_gcm = 8
   1188 } srtp_profile_t;
   1189 
   1190 /**
   1191 * @brief srtp_crypto_policy_set_from_profile_for_rtp() sets a crypto policy
   1192 * structure to the appropriate value for RTP based on an srtp_profile_t
   1193 *
   1194 * @param policy is a pointer to the policy structure to be set
   1195 *
   1196 * @param profile is an enumeration for the policy to be set
   1197 *
   1198 * The function call srtp_crypto_policy_set_rtp_default(&policy, profile)
   1199 * sets the srtp_crypto_policy_t at location policy to the policy for RTP
   1200 * protection, as defined by the srtp_profile_t profile.
   1201 *
   1202 * This function is a convenience that helps to avoid dealing directly
   1203 * with the policy data structure.  You are encouraged to initialize
   1204 * policy elements with this function call.  Doing so may allow your
   1205 * code to be forward compatible with later versions of libSRTP that
   1206 * include more elements in the srtp_crypto_policy_t datatype.
   1207 *
   1208 * @return values
   1209 *     - srtp_err_status_ok         no problems were encountered
   1210 *     - srtp_err_status_bad_param  the profile is not supported
   1211 *
   1212 */
   1213 srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtp(
   1214    srtp_crypto_policy_t *policy,
   1215    srtp_profile_t profile);
   1216 
   1217 /**
   1218 * @brief srtp_crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
   1219 * structure to the appropriate value for RTCP based on an srtp_profile_t
   1220 *
   1221 * @param policy is a pointer to the policy structure to be set
   1222 *
   1223 * @param profile is an enumeration for the policy to be set
   1224 *
   1225 * The function call srtp_crypto_policy_set_rtcp_default(&policy, profile)
   1226 * sets the srtp_crypto_policy_t at location policy to the policy for RTCP
   1227 * protection, as defined by the srtp_profile_t profile.
   1228 *
   1229 * This function is a convenience that helps to avoid dealing directly
   1230 * with the policy data structure.  You are encouraged to initialize
   1231 * policy elements with this function call.  Doing so may allow your
   1232 * code to be forward compatible with later versions of libSRTP that
   1233 * include more elements in the srtp_crypto_policy_t datatype.
   1234 *
   1235 * @return values
   1236 *     - srtp_err_status_ok         no problems were encountered
   1237 *     - srtp_err_status_bad_param  the profile is not supported
   1238 *
   1239 */
   1240 srtp_err_status_t srtp_crypto_policy_set_from_profile_for_rtcp(
   1241    srtp_crypto_policy_t *policy,
   1242    srtp_profile_t profile);
   1243 
   1244 /**
   1245 * @brief returns the master key length for a given SRTP profile
   1246 */
   1247 unsigned int srtp_profile_get_master_key_length(srtp_profile_t profile);
   1248 
   1249 /**
   1250 * @brief returns the master salt length for a given SRTP profile
   1251 */
   1252 unsigned int srtp_profile_get_master_salt_length(srtp_profile_t profile);
   1253 
   1254 /**
   1255 * @brief appends the salt to the key
   1256 *
   1257 * The function call srtp_append_salt_to_key(k, klen, s, slen)
   1258 * copies the string s to the location at klen bytes following
   1259 * the location k.
   1260 *
   1261 * @warning There must be at least bytes_in_salt + bytes_in_key bytes
   1262 *          available at the location pointed to by key.
   1263 *
   1264 */
   1265 void srtp_append_salt_to_key(unsigned char *key,
   1266                             unsigned int bytes_in_key,
   1267                             unsigned char *salt,
   1268                             unsigned int bytes_in_salt);
   1269 
   1270 /**
   1271 * @}
   1272 */
   1273 
   1274 /**
   1275 * @defgroup SRTCP Secure RTCP
   1276 * @ingroup  SRTP
   1277 *
   1278 * @brief Secure RTCP functions are used to protect RTCP traffic.
   1279 *
   1280 * RTCP is the control protocol for RTP.  libSRTP protects RTCP
   1281 * traffic in much the same way as it does RTP traffic.  The function
   1282 * srtp_protect_rtcp() applies cryptographic protections to outbound
   1283 * RTCP packets, and srtp_unprotect_rtcp() verifies the protections on
   1284 * inbound RTCP packets.
   1285 *
   1286 * A note on the naming convention: srtp_protect_rtcp() has an srtp_t
   1287 * as its first argument, and thus has `srtp_' as its prefix.  The
   1288 * trailing `_rtcp' indicates the protocol on which it acts.
   1289 *
   1290 * @{
   1291 */
   1292 
   1293 /**
   1294 * @brief srtp_protect_rtcp() is the Secure RTCP sender-side packet
   1295 * processing function.
   1296 *
   1297 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
   1298 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
   1299 * *len_ptr) using the SRTP session context ctx.  If srtp_err_status_ok is
   1300 * returned, then rtp_hdr points to the resulting SRTCP packet and
   1301 * *len_ptr is the number of octets in that packet; otherwise, no
   1302 * assumptions should be made about the value of either data elements.
   1303 *
   1304 * @warning This function assumes that it can write the authentication
   1305 * tag into the location in memory immediately following the RTCP
   1306 * packet, and assumes that the RTCP packet is aligned on a 32-bit
   1307 * boundary.
   1308 *
   1309 * @warning This function assumes that it can write SRTP_MAX_SRTCP_TRAILER_LEN
   1310 * into the location in memory immediately following the RTCP packet.
   1311 * Callers MUST ensure that this much writable memory is available in
   1312 * the buffer that holds the RTCP packet.
   1313 *
   1314 * @param ctx is the SRTP context to use in processing the packet.
   1315 *
   1316 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
   1317 * the function returns, it points to the srtp packet.
   1318 *
   1319 * @param pkt_octet_len is a pointer to the length in octets of the
   1320 * complete RTCP packet (header and body) before the function call,
   1321 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
   1322 * was returned.  Otherwise, the value of the data to which it points
   1323 * is undefined.
   1324 *
   1325 * @return
   1326 *    - srtp_err_status_ok            if there were no problems.
   1327 *    - [other]                  if there was a failure in
   1328 *                               the cryptographic mechanisms.
   1329 */
   1330 srtp_err_status_t srtp_protect_rtcp(srtp_t ctx,
   1331                                    void *rtcp_hdr,
   1332                                    int *pkt_octet_len);
   1333 
   1334 /**
   1335 * @brief srtp_protect_rtcp_mki() is the Secure RTCP sender-side packet
   1336 * processing function that can utilize mki.
   1337 *
   1338 * The function call srtp_protect_rtcp(ctx, rtp_hdr, len_ptr) applies
   1339 * SRTCP protection to the RTCP packet rtcp_hdr (which has length
   1340 * *len_ptr) using the SRTP session context ctx.  If srtp_err_status_ok is
   1341 * returned, then rtp_hdr points to the resulting SRTCP packet and
   1342 * *len_ptr is the number of octets in that packet; otherwise, no
   1343 * assumptions should be made about the value of either data elements.
   1344 *
   1345 * @warning This function assumes that it can write the authentication
   1346 * tag into the location in memory immediately following the RTCP
   1347 * packet, and assumes that the RTCP packet is aligned on a 32-bit
   1348 * boundary.
   1349 *
   1350 * @warning This function assumes that it can write SRTP_MAX_SRTCP_TRAILER_LEN
   1351 * into the location in memory immediately following the RTCP packet.
   1352 * Callers MUST ensure that this much writable memory is available in
   1353 * the buffer that holds the RTCP packet.
   1354 *
   1355 * @param ctx is the SRTP context to use in processing the packet.
   1356 *
   1357 * @param rtcp_hdr is a pointer to the RTCP packet (before the call); after
   1358 * the function returns, it points to the srtp packet.
   1359 *
   1360 * @param pkt_octet_len is a pointer to the length in octets of the
   1361 * complete RTCP packet (header and body) before the function call,
   1362 * and of the complete SRTCP packet after the call, if srtp_err_status_ok
   1363 * was returned.  Otherwise, the value of the data to which it points
   1364 * is undefined.
   1365 *
   1366 * @param use_mki is a boolean to tell the system if mki is being used.  If
   1367 * set to false then will use the first set of session keys.  If set to true
   1368 * will
   1369 * use the session keys identified by the mki_index
   1370 *
   1371 * @param mki_index integer value specifying which set of session keys should be
   1372 * used if use_mki is set to true.
   1373 *
   1374 * @return
   1375 *    - srtp_err_status_ok            if there were no problems.
   1376 *    - [other]                  if there was a failure in
   1377 *                               the cryptographic mechanisms.
   1378 */
   1379 srtp_err_status_t srtp_protect_rtcp_mki(srtp_t ctx,
   1380                                        void *rtcp_hdr,
   1381                                        int *pkt_octet_len,
   1382                                        unsigned int use_mki,
   1383                                        unsigned int mki_index);
   1384 
   1385 /**
   1386 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
   1387 * processing function.
   1388 *
   1389 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
   1390 * verifies the Secure RTCP protection of the SRTCP packet pointed to
   1391 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
   1392 * context ctx.  If srtp_err_status_ok is returned, then srtcp_hdr points
   1393 * to the resulting RTCP packet and *len_ptr is the number of octets
   1394 * in that packet; otherwise, no assumptions should be made about the
   1395 * value of either data elements.
   1396 *
   1397 * @warning This function assumes that the SRTCP packet is aligned on a
   1398 * 32-bit boundary.
   1399 *
   1400 * @param ctx is a pointer to the srtp_t which applies to the
   1401 * particular packet.
   1402 *
   1403 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
   1404 * (before the call).  After the function returns, it points to the
   1405 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
   1406 * the data to which it points is undefined.
   1407 *
   1408 * @param pkt_octet_len is a pointer to the length in octets of the
   1409 * complete SRTCP packet (header and body) before the function call,
   1410 * and of the complete rtp packet after the call, if srtp_err_status_ok was
   1411 * returned.  Otherwise, the value of the data to which it points is
   1412 * undefined.
   1413 *
   1414 * @return
   1415 *    - srtp_err_status_ok          if the RTCP packet is valid.
   1416 *    - srtp_err_status_auth_fail   if the SRTCP packet failed the message
   1417 *                             authentication check.
   1418 *    - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
   1419 *                             already been processed and accepted).
   1420 *    - [other]  if there has been an error in the cryptographic mechanisms.
   1421 *
   1422 */
   1423 srtp_err_status_t srtp_unprotect_rtcp(srtp_t ctx,
   1424                                      void *srtcp_hdr,
   1425                                      int *pkt_octet_len);
   1426 
   1427 /**
   1428 * @brief srtp_unprotect_rtcp() is the Secure RTCP receiver-side packet
   1429 * processing function.
   1430 *
   1431 * The function call srtp_unprotect_rtcp(ctx, srtp_hdr, len_ptr)
   1432 * verifies the Secure RTCP protection of the SRTCP packet pointed to
   1433 * by srtcp_hdr (which has length *len_ptr), using the SRTP session
   1434 * context ctx.  If srtp_err_status_ok is returned, then srtcp_hdr points
   1435 * to the resulting RTCP packet and *len_ptr is the number of octets
   1436 * in that packet; otherwise, no assumptions should be made about the
   1437 * value of either data elements.
   1438 *
   1439 * @warning This function assumes that the SRTCP packet is aligned on a
   1440 * 32-bit boundary.
   1441 *
   1442 * @param ctx is a pointer to the srtp_t which applies to the
   1443 * particular packet.
   1444 *
   1445 * @param srtcp_hdr is a pointer to the header of the SRTCP packet
   1446 * (before the call).  After the function returns, it points to the
   1447 * rtp packet if srtp_err_status_ok was returned; otherwise, the value of
   1448 * the data to which it points is undefined.
   1449 *
   1450 * @param pkt_octet_len is a pointer to the length in octets of the
   1451 * complete SRTCP packet (header and body) before the function call,
   1452 * and of the complete rtp packet after the call, if srtp_err_status_ok was
   1453 * returned.  Otherwise, the value of the data to which it points is
   1454 * undefined.
   1455 *
   1456 * @param use_mki is a boolean to tell the system if mki is being used.  If
   1457 * set to false then will use the first set of session keys.  If set to true
   1458 * will use the session keys identified by the mki_index
   1459 *
   1460 * @return
   1461 *    - srtp_err_status_ok          if the RTCP packet is valid.
   1462 *    - srtp_err_status_auth_fail   if the SRTCP packet failed the message
   1463 *                                  authentication check.
   1464 *    - srtp_err_status_replay_fail if the SRTCP packet is a replay (e.g. has
   1465 *                                  already been processed and accepted).
   1466 *    - srtp_err_status_bad_mki     if the MKI in the packet is not a known MKI
   1467 *                                  id
   1468 *    - [other]                     if there has been an error in the
   1469 *                                  cryptographic mechanisms.
   1470 *
   1471 */
   1472 srtp_err_status_t srtp_unprotect_rtcp_mki(srtp_t ctx,
   1473                                          void *srtcp_hdr,
   1474                                          int *pkt_octet_len,
   1475                                          unsigned int use_mki);
   1476 
   1477 /**
   1478 * @}
   1479 */
   1480 
   1481 /**
   1482 * @defgroup User data associated to a SRTP session.
   1483 * @ingroup  SRTP
   1484 *
   1485 * @brief Store custom user data within a SRTP session.
   1486 *
   1487 * @{
   1488 */
   1489 
   1490 /**
   1491 * @brief srtp_set_user_data() stores the given pointer into the SRTP
   1492 * session for later retrieval.
   1493 *
   1494 * @param ctx is the srtp_t context in which the given data pointer is
   1495 * stored.
   1496 *
   1497 * @param data is a pointer to the custom information (struct, function,
   1498 * etc) associated with the SRTP session.
   1499 *
   1500 * @return void.
   1501 *
   1502 */
   1503 void srtp_set_user_data(srtp_t ctx, void *data);
   1504 
   1505 /**
   1506 * @brief srtp_get_user_data() retrieves the pointer to the custom data
   1507 * previously stored with srtp_set_user_data().
   1508 *
   1509 * This function is mostly useful for retrieving data associated to a
   1510 * SRTP session when an event fires. The user can then get such a custom
   1511 * data by calling this function with the session field of the
   1512 * srtp_event_data_t struct as argument.
   1513 *
   1514 * @param ctx is the srtp_t context in which the given data pointer was
   1515 * stored.
   1516 *
   1517 * @return void* pointer to the user data.
   1518 *
   1519 */
   1520 void *srtp_get_user_data(srtp_t ctx);
   1521 
   1522 /**
   1523 * @}
   1524 */
   1525 
   1526 /**
   1527 * @defgroup SRTPevents SRTP events and callbacks
   1528 * @ingroup  SRTP
   1529 *
   1530 * @brief libSRTP can use a user-provided callback function to
   1531 * handle events.
   1532 *
   1533 *
   1534 * libSRTP allows a user to provide a callback function to handle
   1535 * events that need to be dealt with outside of the data plane (see
   1536 * the enum srtp_event_t for a description of these events).  Dealing
   1537 * with these events is not a strict necessity; they are not
   1538 * security-critical, but the application may suffer if they are not
   1539 * handled.  The function srtp_set_event_handler() is used to provide
   1540 * the callback function.
   1541 *
   1542 * A default event handler that merely reports on the events as they
   1543 * happen is included.  It is also possible to set the event handler
   1544 * function to NULL, in which case all events will just be silently
   1545 * ignored.
   1546 *
   1547 * @{
   1548 */
   1549 
   1550 /**
   1551 * @brief srtp_event_t defines events that need to be handled
   1552 *
   1553 * The enum srtp_event_t defines events that need to be handled
   1554 * outside the `data plane', such as SSRC collisions and
   1555 * key expirations.
   1556 *
   1557 * When a key expires or the maximum number of packets has been
   1558 * reached, an SRTP stream will enter an `expired' state in which no
   1559 * more packets can be protected or unprotected.  When this happens,
   1560 * it is likely that you will want to either deallocate the stream
   1561 * (using srtp_remove_stream()), and possibly allocate a new one.
   1562 *
   1563 * When an SRTP stream expires, the other streams in the same session
   1564 * are unaffected, unless key sharing is used by that stream.  In the
   1565 * latter case, all of the streams in the session will expire.
   1566 */
   1567 typedef enum {
   1568    event_ssrc_collision,    /**< An SSRC collision occurred.           */
   1569    event_key_soft_limit,    /**< An SRTP stream reached the soft key   */
   1570                             /**< usage limit and will expire soon.     */
   1571    event_key_hard_limit,    /**< An SRTP stream reached the hard       */
   1572                             /**< key usage limit and has expired.      */
   1573    event_packet_index_limit /**< An SRTP stream reached the hard       */
   1574                             /**< packet limit (2^48 packets).          */
   1575 } srtp_event_t;
   1576 
   1577 /**
   1578 * @brief srtp_event_data_t is the structure passed as a callback to
   1579 * the event handler function
   1580 *
   1581 * The struct srtp_event_data_t holds the data passed to the event
   1582 * handler function.
   1583 */
   1584 typedef struct srtp_event_data_t {
   1585    srtp_t session;     /**< The session in which the event happened.       */
   1586    uint32_t ssrc;      /**< The ssrc in host order of the stream in which  */
   1587                        /**< the event happened                             */
   1588    srtp_event_t event; /**< An enum indicating the type of event.          */
   1589 } srtp_event_data_t;
   1590 
   1591 /**
   1592 * @brief srtp_event_handler_func_t is the function prototype for
   1593 * the event handler.
   1594 *
   1595 * The typedef srtp_event_handler_func_t is the prototype for the
   1596 * event handler function.  It has as its only argument an
   1597 * srtp_event_data_t which describes the event that needs to be handled.
   1598 * There can only be a single, global handler for all events in
   1599 * libSRTP.
   1600 */
   1601 typedef void(srtp_event_handler_func_t)(srtp_event_data_t *data);
   1602 
   1603 /**
   1604 * @brief sets the event handler to the function supplied by the caller.
   1605 *
   1606 * The function call srtp_install_event_handler(func) sets the event
   1607 * handler function to the value func.  The value NULL is acceptable
   1608 * as an argument; in this case, events will be ignored rather than
   1609 * handled.
   1610 *
   1611 * @param func is a pointer to a function that takes an srtp_event_data_t
   1612 *             pointer as an argument and returns void.  This function
   1613 *             will be used by libSRTP to handle events.
   1614 */
   1615 srtp_err_status_t srtp_install_event_handler(srtp_event_handler_func_t func);
   1616 
   1617 /**
   1618 * @brief Returns the version string of the library.
   1619 *
   1620 */
   1621 const char *srtp_get_version_string(void);
   1622 
   1623 /**
   1624 * @brief Returns the numeric representation of the library version.
   1625 *
   1626 */
   1627 unsigned int srtp_get_version(void);
   1628 
   1629 /**
   1630 * @brief srtp_set_debug_module(mod_name, v)
   1631 *
   1632 * sets dynamic debugging to the value v (0 for off, 1 for on) for the
   1633 * debug module with the name mod_name
   1634 *
   1635 * returns err_status_ok on success, err_status_fail otherwise
   1636 */
   1637 srtp_err_status_t srtp_set_debug_module(const char *mod_name, int v);
   1638 
   1639 /**
   1640 * @brief srtp_list_debug_modules() outputs a list of debugging modules
   1641 *
   1642 */
   1643 srtp_err_status_t srtp_list_debug_modules(void);
   1644 
   1645 /**
   1646 * @brief srtp_log_level_t defines log levels.
   1647 *
   1648 * The enumeration srtp_log_level_t defines log levels reported
   1649 * in the srtp_log_handler_func_t.
   1650 *
   1651 */
   1652 typedef enum {
   1653    srtp_log_level_error,   /**< log level is reporting an error message  */
   1654    srtp_log_level_warning, /**< log level is reporting a warning message */
   1655    srtp_log_level_info,    /**< log level is reporting an info message   */
   1656    srtp_log_level_debug    /**< log level is reporting a debug message   */
   1657 } srtp_log_level_t;
   1658 
   1659 /**
   1660 * @brief srtp_log_handler_func_t is the function prototype for
   1661 * the log handler.
   1662 *
   1663 * The typedef srtp_event_handler_func_t is the prototype for the
   1664 * event handler function.  It has as srtp_log_level_t, log
   1665 * message and data as arguments.
   1666 * There can only be a single, global handler for all log messages in
   1667 * libSRTP.
   1668 */
   1669 typedef void(srtp_log_handler_func_t)(srtp_log_level_t level,
   1670                                      const char *msg,
   1671                                      void *data);
   1672 
   1673 /**
   1674 * @brief sets the log handler to the function supplied by the caller.
   1675 *
   1676 * The function call srtp_install_log_handler(func) sets the log
   1677 * handler function to the value func.  The value NULL is acceptable
   1678 * as an argument; in this case, log messages will be ignored.
   1679 * This function can be called before srtp_init() in order to capture
   1680 * any logging during start up.
   1681 *
   1682 * @param func is a pointer to a function of type srtp_log_handler_func_t.
   1683 *             This function will be used by libSRTP to output log messages.
   1684 * @param data is a user pointer that will be returned as the data argument in
   1685 * func.
   1686 */
   1687 srtp_err_status_t srtp_install_log_handler(srtp_log_handler_func_t func,
   1688                                           void *data);
   1689 
   1690 /**
   1691 * @brief srtp_get_protect_trailer_length(session, use_mki, mki_index, length)
   1692 *
   1693 * Determines the length of the amount of data Lib SRTP will add to the
   1694 * packet during the protect process. The length is returned in the length
   1695 * parameter
   1696 *
   1697 * returns err_status_ok on success, err_status_bad_mki if the MKI index is
   1698 * invalid
   1699 *
   1700 */
   1701 srtp_err_status_t srtp_get_protect_trailer_length(srtp_t session,
   1702                                                  uint32_t use_mki,
   1703                                                  uint32_t mki_index,
   1704                                                  uint32_t *length);
   1705 
   1706 /**
   1707 * @brief srtp_get_protect_rtcp_trailer_length(session, use_mki, mki_index,
   1708 * length)
   1709 *
   1710 * Determines the length of the amount of data Lib SRTP will add to the
   1711 * packet during the protect process. The length is returned in the length
   1712 * parameter
   1713 *
   1714 * returns err_status_ok on success, err_status_bad_mki if the MKI index is
   1715 * invalid
   1716 *
   1717 */
   1718 srtp_err_status_t srtp_get_protect_rtcp_trailer_length(srtp_t session,
   1719                                                       uint32_t use_mki,
   1720                                                       uint32_t mki_index,
   1721                                                       uint32_t *length);
   1722 
   1723 /**
   1724 * @brief srtp_set_stream_roc(session, ssrc, roc)
   1725 *
   1726 * Set the roll-over-counter on a session for a given SSRC
   1727 *
   1728 * returns err_status_ok on success, srtp_err_status_bad_param if there is no
   1729 * stream found
   1730 *
   1731 */
   1732 srtp_err_status_t srtp_set_stream_roc(srtp_t session,
   1733                                      uint32_t ssrc,
   1734                                      uint32_t roc);
   1735 
   1736 /**
   1737 * @brief srtp_get_stream_roc(session, ssrc, roc)
   1738 *
   1739 * Get the roll-over-counter on a session for a given SSRC
   1740 *
   1741 * returns err_status_ok on success, srtp_err_status_bad_param if there is no
   1742 * stream found
   1743 *
   1744 */
   1745 srtp_err_status_t srtp_get_stream_roc(srtp_t session,
   1746                                      uint32_t ssrc,
   1747                                      uint32_t *roc);
   1748 
   1749 /**
   1750 * @}
   1751 */
   1752 
   1753 /* in host order, so outside the #if */
   1754 #define SRTCP_E_BIT 0x80000000
   1755 
   1756 /* for byte-access */
   1757 #define SRTCP_E_BYTE_BIT 0x80
   1758 #define SRTCP_INDEX_MASK 0x7fffffff
   1759 
   1760 #ifdef __cplusplus
   1761 }
   1762 #endif
   1763 
   1764 #endif /* SRTP_SRTP_H */