📄 srtp.h
字号:
/* * srtp.h * * interface to libsrtp * * David A. McGrew * Cisco Systems, Inc. *//* * * Copyright (c) 2001-2006, Cisco Systems, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of the Cisco Systems, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * */#ifndef SRTP_H#define SRTP_H#ifdef __cplusplusextern "C" {#endif#ifdef _MSC_VER#pragma pack(4)#endif#include "crypto_kernel.h"/** * @defgroup SRTP Secure RTP * * @brief libSRTP provides functions for protecting RTP and RTCP. See * Section @ref Overview for an introduction to the use of the library. * * @{ *//* * SRTP_MASTER_KEY_LEN is the nominal master key length supported by libSRTP */#define SRTP_MASTER_KEY_LEN 30/* * SRTP_MAX_KEY_LEN is the maximum key length supported by libSRTP */#define SRTP_MAX_KEY_LEN 64/* * SRTP_MAX_TAG_LEN is the maximum tag length supported by libSRTP */#define SRTP_MAX_TAG_LEN 12 /** * SRTP_MAX_TRAILER_LEN is the maximum length of the SRTP trailer * (authentication tag and MKI) supported by libSRTP. This value is * the maximum number of octets that will be added to an RTP packet by * srtp_protect(). * * @brief the maximum number of octets added by srtp_protect(). */#define SRTP_MAX_TRAILER_LEN SRTP_MAX_TAG_LEN /* * nota bene: since libSRTP doesn't support the use of the MKI, the * SRTP_MAX_TRAILER_LEN value is just the maximum tag length *//** * @brief sec_serv_t describes a set of security services. * * A sec_serv_t enumeration is used to describe the particular * security services that will be applied by a particular crypto * policy (or other mechanism). */typedef enum { sec_serv_none = 0, /**< no services */ sec_serv_conf = 1, /**< confidentiality */ sec_serv_auth = 2, /**< authentication */ sec_serv_conf_and_auth = 3 /**< confidentiality and authentication */} sec_serv_t;/** * @brief crypto_policy_t describes a particular crypto policy that * can be applied to an SRTP stream. * * A crypto_policy_t describes a particular cryptographic policy that * can be applied to an SRTP or SRTCP stream. An SRTP session policy * consists of a list of these policies, one for each SRTP stream * in the session. */typedef struct crypto_policy_t { cipher_type_id_t cipher_type; /**< An integer representing * the type of cipher. */ int cipher_key_len; /**< The length of the cipher key * in octets. */ auth_type_id_t auth_type; /**< An integer representing the * authentication function. */ int auth_key_len; /**< The length of the authentication * function key in octets. */ int auth_tag_len; /**< The length of the authentication * tag in octets. */ sec_serv_t sec_serv; /**< The flag indicating the security * services to be applied. */} crypto_policy_t;/** * @brief ssrc_type_t describes the type of an SSRC. * * An ssrc_type_t enumeration is used to indicate a type of SSRC. See * @ref srtp_policy_t for more informataion. */typedef enum { ssrc_undefined = 0, /**< Indicates an undefined SSRC type. */ ssrc_specific = 1, /**< Indicates a specific SSRC value */ ssrc_any_inbound = 2, /**< Indicates any inbound SSRC value (i.e. a value that is used in the function srtp_unprotect()) */ ssrc_any_outbound = 3 /**< Indicates any outbound SSRC value (i.e. a value that is used in the function srtp_protect()) */} ssrc_type_t;/** * @brief An ssrc_t represents a particular SSRC value, or a `wildcard' SSRC. * * An ssrc_t represents a particular SSRC value (if its type is * ssrc_specific), or a wildcard SSRC value that will match all * outbound SSRCs (if its type is ssrc_any_outbound) or all inbound * SSRCs (if its type is ssrc_any_inbound). * */typedef struct { ssrc_type_t type; /**< The type of this particular SSRC */ unsigned int value; /**< The value of this SSRC, if it is not a wildcard */} ssrc_t;/** * @brief represents the policy for an SRTP session. * * A single srtp_policy_t struct represents the policy for a single * SRTP stream, and a linked list of these elements represents the * policy for an entire SRTP session. Each element contains the SRTP * and SRTCP crypto policies for that stream, a pointer to the SRTP * master key for that stream, the SSRC describing that stream, or a * flag indicating a `wildcard' SSRC value, and a `next' field that * holds a pointer to the next element in the list of policy elements, * or NULL if it is the last element. * * The wildcard value SSRC_ANY_INBOUND matches any SSRC from an * inbound stream that for which there is no explicit SSRC entry in * another policy element. Similarly, the value SSRC_ANY_OUTBOUND * will matches any SSRC from an outbound stream that does not appear * in another policy element. Note that wildcard SSRCs &b cannot be * used to match both inbound and outbound traffic. This restriction * is intentional, and it allows libSRTP to ensure that no security * lapses result from accidental re-use of SSRC values during key * sharing. * * * @warning The final element of the list @b must have its `next' pointer * set to NULL. */typedef struct srtp_policy_t { ssrc_t ssrc; /**< The SSRC value of stream, or the * flags SSRC_ANY_INBOUND or * SSRC_ANY_OUTBOUND if key sharing * is used for this policy element. */ crypto_policy_t rtp; /**< SRTP crypto policy. */ crypto_policy_t rtcp; /**< SRTCP crypto policy. */ unsigned char *key; /**< Pointer to the SRTP master key for * this stream. */ struct srtp_policy_t *next; /**< Pointer to next stream policy. */} srtp_policy_t;/** * @brief An srtp_t points to an SRTP session structure. * * The typedef srtp_t is a pointer to a structure that represents * an SRTP session. This datatype is intentially opaque in * order to separate the interface from the implementation. * * An SRTP session consists of all of the traffic sent to the RTP and * RTCP destination transport addresses, using the RTP/SAVP (Secure * Audio/Video Profile). A session can be viewed as a set of SRTP * streams, each of which originates with a different participant. */typedef struct srtp_ctx_t *srtp_t;/** * @brief An srtp_stream_t points to an SRTP stream structure. * * The typedef srtp_stream_t is a pointer to a structure that * represents an SRTP stream. This datatype is intentionally * opaque in order to separate the interface from the implementation. * * An SRTP stream consists of all of the traffic sent to an SRTP * session by a single participant. A session can be viewed as * a set of streams. * */typedef struct srtp_stream_ctx_t *srtp_stream_t;/** * @brief srtp_init() initializes the srtp library. * * @warning This function @b must be called before any other srtp * functions. */err_status_tsrtp_init(void);/** * @brief srtp_protect() is the Secure RTP sender-side packet processing * function. * * The function call srtp_protect(ctx, rtp_hdr, len_ptr) applies SRTP * protection to the RTP packet rtp_hdr (which has length *len_ptr) using * the SRTP context ctx. If err_status_ok is returned, then rtp_hdr * points to the resulting SRTP packet and *len_ptr is the number of * octets in that packet; otherwise, no assumptions should be made * about the value of either data elements. * * The sequence numbers of the RTP packets presented to this function * need not be consecutive, but they @b must be out of order by less * than 2^15 = 32,768 packets. * * @warning This function assumes that it can write the authentication * tag into the location in memory immediately following the RTP * packet, and assumes that the RTP packet is aligned on a 32-bit * boundary. * * @param ctx is the SRTP context to use in processing the packet. * * @param rtp_hdr is a pointer to the RTP packet (before the call); after * the function returns, it points to the srtp packet. * * @param len_ptr is a pointer to the length in octets of the complete * RTP packet (header and body) before the function call, and of the * complete SRTP packet after the call, if err_status_ok was returned. * Otherwise, the value of the data to which it points is undefined. * * @return * - err_status_ok no problems * - err_status_replay_fail rtp sequence number was non-increasing * - @e other failure in cryptographic mechanisms */err_status_tsrtp_protect(srtp_t ctx, void *rtp_hdr, int *len_ptr); /** * @brief srtp_unprotect() is the Secure RTP receiver-side packet * processing function. * * The function call srtp_unprotect(ctx, srtp_hdr, len_ptr) verifies * the Secure RTP protection of the SRTP packet pointed to by srtp_hdr * (which has length *len_ptr), using the SRTP context ctx. If * err_status_ok is returned, then srtp_hdr points to the resulting * RTP packet and *len_ptr is the number of octets in that packet;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -