mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 13:12:03 +00:00
update to cvs head srtp
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* ekt.h
|
||||
*
|
||||
* interface to Encrypted Key Transport for SRTP
|
||||
*
|
||||
* David McGrew
|
||||
* Cisco Systems, Inc.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2005 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.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* EKT implementation strategy
|
||||
*
|
||||
* use stream_template approach
|
||||
*
|
||||
* in srtp_unprotect, when a new stream appears, check if template has
|
||||
* EKT defined, and if it does, then apply EKT processing
|
||||
*
|
||||
* question: will we want to allow key-sharing templates in addition
|
||||
* to EKT templates? could define a new ssrc_type_t that's associated
|
||||
* with an EKT, e.g. ssrc_any_ekt.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef EKT_H
|
||||
#define EKT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "srtp_priv.h"
|
||||
|
||||
#define EKT_CIPHER_DEFAULT 1
|
||||
#define EKT_CIPHER_AES_128_ECB 1
|
||||
#define EKT_CIPHER_AES_192_KEY_WRAP 2
|
||||
#define EKT_CIPHER_AES_256_KEY_WRAP 3
|
||||
|
||||
typedef uint16_t ekt_spi_t;
|
||||
|
||||
|
||||
unsigned
|
||||
ekt_octets_after_base_tag(ekt_stream_t ekt);
|
||||
|
||||
/*
|
||||
* an srtp_policy_t structure can contain a pointer to an
|
||||
* ekt_policy_t structure
|
||||
*
|
||||
* this structure holds all of the high level EKT information, and it
|
||||
* is passed into libsrtp to indicate what policy should be in effect
|
||||
*/
|
||||
|
||||
typedef struct ekt_policy_ctx_t {
|
||||
ekt_spi_t spi; /* security parameter index */
|
||||
uint8_t ekt_cipher_type;
|
||||
uint8_t *ekt_key;
|
||||
struct ekt_policy_ctx_t *next_ekt_policy;
|
||||
} ekt_policy_ctx_t;
|
||||
|
||||
|
||||
/*
|
||||
* an ekt_data_t structure holds the data corresponding to an ekt key,
|
||||
* spi, and so on
|
||||
*/
|
||||
|
||||
typedef struct ekt_data_t {
|
||||
ekt_spi_t spi;
|
||||
uint8_t ekt_cipher_type;
|
||||
aes_expanded_key_t ekt_enc_key;
|
||||
aes_expanded_key_t ekt_dec_key;
|
||||
struct ekt_data_t *next_ekt_data;
|
||||
} ekt_data_t;
|
||||
|
||||
/*
|
||||
* an srtp_stream_ctx_t can contain an ekt_stream_ctx_t
|
||||
*
|
||||
* an ekt_stream_ctx_t structure holds all of the EKT information for
|
||||
* a specific SRTP stream
|
||||
*/
|
||||
|
||||
typedef struct ekt_stream_ctx_t {
|
||||
ekt_data_t *data;
|
||||
uint16_t isn; /* initial sequence number */
|
||||
uint8_t encrypted_master_key[SRTP_MAX_KEY_LEN];
|
||||
} ekt_stream_ctx_t;
|
||||
|
||||
|
||||
|
||||
err_status_t
|
||||
ekt_alloc(ekt_stream_t *stream_data, ekt_policy_t policy);
|
||||
|
||||
err_status_t
|
||||
ekt_stream_init(ekt_stream_t e,
|
||||
ekt_spi_t spi,
|
||||
void *ekt_key,
|
||||
unsigned ekt_cipher_type);
|
||||
|
||||
err_status_t
|
||||
ekt_stream_init_from_policy(ekt_stream_t e, ekt_policy_t p);
|
||||
|
||||
|
||||
|
||||
err_status_t
|
||||
srtp_stream_init_from_ekt(srtp_stream_t stream,
|
||||
const void *srtcp_hdr,
|
||||
unsigned pkt_octet_len);
|
||||
|
||||
|
||||
void
|
||||
ekt_write_data(ekt_stream_t ekt,
|
||||
uint8_t *base_tag,
|
||||
unsigned base_tag_len,
|
||||
int *packet_len,
|
||||
xtd_seq_num_t pkt_index);
|
||||
|
||||
/*
|
||||
* We handle EKT by performing some additional steps before
|
||||
* authentication (copying the auth tag into a temporary location,
|
||||
* zeroizing the "base tag" field in the packet)
|
||||
*
|
||||
* With EKT, the tag_len parameter is actually the base tag
|
||||
* length
|
||||
*/
|
||||
|
||||
err_status_t
|
||||
ekt_tag_verification_preproces(uint8_t *pkt_tag,
|
||||
uint8_t *pkt_tag_copy,
|
||||
unsigned tag_len);
|
||||
|
||||
err_status_t
|
||||
ekt_tag_verification_postproces(uint8_t *pkt_tag,
|
||||
uint8_t *pkt_tag_copy,
|
||||
unsigned tag_len);
|
||||
|
||||
|
||||
/*
|
||||
* @brief EKT pre-processing for srtcp tag generation
|
||||
*
|
||||
* This function does the pre-processing of the SRTCP authentication
|
||||
* tag format. When EKT is used, it consists of writing the Encrypted
|
||||
* Master Key, the SRTP ROC, the Initial Sequence Number, and SPI
|
||||
* fields. The Base Authentication Tag field is set to the all-zero
|
||||
* value
|
||||
*
|
||||
* When EKT is not used, this function is a no-op.
|
||||
*
|
||||
*/
|
||||
|
||||
err_status_t
|
||||
srtp_stream_srtcp_auth_tag_generation_preprocess(const srtp_stream_t *s,
|
||||
uint8_t *pkt_tag,
|
||||
unsigned pkt_octet_len);
|
||||
|
||||
/* it's not clear that a tag_generation_postprocess function is needed */
|
||||
|
||||
err_status_t
|
||||
srtcp_auth_tag_generation_postprocess(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* EKT_H */
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* getopt.h
|
||||
*
|
||||
* interface to a minimal implementation of the getopt() function,
|
||||
* written so that test applications that use that function can run on
|
||||
* non-POSIX platforms
|
||||
*
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* 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 GETOPT_S_H
|
||||
#define GETOPT_S_H
|
||||
|
||||
/*
|
||||
* getopt_s(), optarg_s, and optind_s are small, locally defined
|
||||
* versions of the POSIX standard getopt() interface.
|
||||
*/
|
||||
|
||||
int
|
||||
getopt_s(int argc, char * const argv[], const char *optstring);
|
||||
|
||||
extern char *optarg_s; /* defined in getopt.c */
|
||||
|
||||
extern int optind_s; /* defined in getopt.c */
|
||||
|
||||
#endif /* GETOPT_S_H */
|
||||
+53
-39
@@ -16,7 +16,7 @@
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2005, Cisco Systems, Inc.
|
||||
* Copyright (c) 2001-2006, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -54,72 +54,86 @@
|
||||
#ifndef RTP_H
|
||||
#define RTP_H
|
||||
|
||||
#include "srtp.h"
|
||||
|
||||
#ifdef HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
#elif defined HAVE_WINSOCK2_H
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#define rtp_header_len 12
|
||||
#include "srtp.h"
|
||||
|
||||
typedef srtp_hdr_t rtp_hdr_t;
|
||||
typedef struct rtp_sender_ctx_t *rtp_sender_t;
|
||||
|
||||
#define RTP_MAX_BUF_LEN 16384
|
||||
|
||||
typedef struct {
|
||||
srtp_hdr_t header;
|
||||
char body[RTP_MAX_BUF_LEN];
|
||||
} rtp_msg_t;
|
||||
|
||||
typedef struct {
|
||||
rtp_msg_t message;
|
||||
int socket;
|
||||
srtp_ctx_t *srtp_ctx;
|
||||
struct sockaddr_in addr; /* reciever's address */
|
||||
} rtp_sender_t;
|
||||
|
||||
typedef struct {
|
||||
rtp_msg_t message;
|
||||
int socket;
|
||||
srtp_ctx_t *srtp_ctx;
|
||||
struct sockaddr_in addr; /* receiver's address */
|
||||
} rtp_receiver_t;
|
||||
|
||||
|
||||
ssize_t
|
||||
rtp_sendto(rtp_sender_t *sender, const void* msg, int len);
|
||||
|
||||
ssize_t
|
||||
rtp_recvfrom(rtp_receiver_t *receiver, void *msg, int *len);
|
||||
typedef struct rtp_receiver_ctx_t *rtp_receiver_t;
|
||||
|
||||
int
|
||||
rtp_receiver_init(rtp_receiver_t *rcvr, int socket,
|
||||
struct sockaddr_in addr, uint32_t ssrc);
|
||||
rtp_sendto(rtp_sender_t sender, const void* msg, int len);
|
||||
|
||||
int
|
||||
rtp_sender_init(rtp_sender_t *sender, int socket,
|
||||
struct sockaddr_in addr, uint32_t ssrc);
|
||||
rtp_recvfrom(rtp_receiver_t receiver, void *msg, int *len);
|
||||
|
||||
int
|
||||
rtp_receiver_init(rtp_receiver_t rcvr, int sock,
|
||||
struct sockaddr_in addr, unsigned int ssrc);
|
||||
|
||||
int
|
||||
rtp_sender_init(rtp_sender_t sender, int sock,
|
||||
struct sockaddr_in addr, unsigned int ssrc);
|
||||
|
||||
/*
|
||||
* srtp_sender_init(...) initializes an rtp_sender_t
|
||||
*
|
||||
*/
|
||||
|
||||
int
|
||||
srtp_sender_init(rtp_sender_t *rtp_ctx, /* structure to be init'ed */
|
||||
srtp_sender_init(rtp_sender_t rtp_ctx, /* structure to be init'ed */
|
||||
struct sockaddr_in name, /* socket name */
|
||||
sec_serv_t security_services, /* sec. servs. to be used */
|
||||
unsigned char *input_key /* master key/salt in hex */
|
||||
);
|
||||
|
||||
int
|
||||
srtp_receiver_init(rtp_receiver_t *rtp_ctx, /* structure to be init'ed */
|
||||
srtp_receiver_init(rtp_receiver_t rtp_ctx, /* structure to be init'ed */
|
||||
struct sockaddr_in name, /* socket name */
|
||||
sec_serv_t security_services, /* sec. servs. to be used */
|
||||
unsigned char *input_key /* master key/salt in hex */
|
||||
);
|
||||
|
||||
|
||||
int
|
||||
rtp_sender_init_srtp(rtp_sender_t sender, const srtp_policy_t *policy);
|
||||
|
||||
int
|
||||
rtp_sender_deinit_srtp(rtp_sender_t sender);
|
||||
|
||||
int
|
||||
rtp_receiver_init_srtp(rtp_receiver_t sender, const srtp_policy_t *policy);
|
||||
|
||||
int
|
||||
rtp_receiver_deinit_srtp(rtp_receiver_t sender);
|
||||
|
||||
|
||||
rtp_sender_t
|
||||
rtp_sender_alloc(void);
|
||||
|
||||
void
|
||||
rtp_sender_dealloc(rtp_sender_t rtp_ctx);
|
||||
|
||||
rtp_receiver_t
|
||||
rtp_receiver_alloc(void);
|
||||
|
||||
void
|
||||
rtp_receiver_dealloc(rtp_receiver_t rtp_ctx);
|
||||
|
||||
|
||||
/*
|
||||
* RTP_HEADER_LEN indicates the size of an RTP header
|
||||
*/
|
||||
#define RTP_HEADER_LEN 12
|
||||
|
||||
/*
|
||||
* RTP_MAX_BUF_LEN defines the largest RTP packet in the rtp.c implementation
|
||||
*/
|
||||
#define RTP_MAX_BUF_LEN 16384
|
||||
|
||||
|
||||
#endif /* RTP_H */
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* rtp_priv.h
|
||||
*
|
||||
* private, internal header file for RTP
|
||||
*
|
||||
* 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 RTP_PRIV_H
|
||||
#define RTP_PRIV_H
|
||||
|
||||
#include "srtp_priv.h"
|
||||
#include "rtp.h"
|
||||
|
||||
typedef srtp_hdr_t rtp_hdr_t;
|
||||
|
||||
typedef struct {
|
||||
srtp_hdr_t header;
|
||||
char body[RTP_MAX_BUF_LEN];
|
||||
} rtp_msg_t;
|
||||
|
||||
typedef struct rtp_sender_ctx_t {
|
||||
rtp_msg_t message;
|
||||
int socket;
|
||||
srtp_ctx_t *srtp_ctx;
|
||||
struct sockaddr_in addr; /* reciever's address */
|
||||
} rtp_sender_ctx_t;
|
||||
|
||||
typedef struct rtp_receiver_ctx_t {
|
||||
rtp_msg_t message;
|
||||
int socket;
|
||||
srtp_ctx_t *srtp_ctx;
|
||||
struct sockaddr_in addr; /* receiver's address */
|
||||
} rtp_receiver_ctx_t;
|
||||
|
||||
|
||||
#endif /* RTP_PRIV_H */
|
||||
+212
-211
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2005, Cisco Systems, Inc.
|
||||
* Copyright (c) 2001-2006, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -50,14 +50,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable:4214)
|
||||
#endif
|
||||
|
||||
#include "crypto_kernel.h"
|
||||
#include "rdbx.h"
|
||||
#include "rdb.h"
|
||||
#include "integers.h"
|
||||
#include "crypto_kernel.h"
|
||||
|
||||
/**
|
||||
* @defgroup SRTP Secure RTP
|
||||
@@ -171,10 +164,22 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
ssrc_type_t type; /**< The type of this particular SSRC */
|
||||
uint32_t value; /**< The value of this SSRC, if it is not a wildcard */
|
||||
unsigned int value; /**< The value of this SSRC, if it is not a wildcard */
|
||||
} ssrc_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief points to an EKT policy
|
||||
*/
|
||||
typedef struct ekt_policy_ctx_t *ekt_policy_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief points to EKT stream data
|
||||
*/
|
||||
typedef struct ekt_stream_ctx_t *ekt_stream_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief represents the policy for an SRTP session.
|
||||
*
|
||||
@@ -210,8 +215,18 @@ typedef struct srtp_policy_t {
|
||||
*/
|
||||
crypto_policy_t rtp; /**< SRTP crypto policy. */
|
||||
crypto_policy_t rtcp; /**< SRTCP crypto policy. */
|
||||
uint8_t *key; /**< Pointer to the SRTP master key for
|
||||
unsigned char *key; /**< Pointer to the SRTP master key for
|
||||
* this stream. */
|
||||
ekt_policy_t ekt; /**< Pointer to the EKT policy structure
|
||||
* for this stream (if any) */
|
||||
unsigned long window_size; /**< The window size to use for replay
|
||||
* protection. */
|
||||
int allow_repeat_tx; /**< Whether retransmissions of
|
||||
* packets with the same sequence number
|
||||
* are allowed. (Note that such repeated
|
||||
* transmissions must have the same RTP
|
||||
* payload, or a severe security weakness
|
||||
* is introduced!) */
|
||||
struct srtp_policy_t *next; /**< Pointer to next stream policy. */
|
||||
} srtp_policy_t;
|
||||
|
||||
@@ -260,6 +275,15 @@ typedef struct srtp_stream_ctx_t *srtp_stream_t;
|
||||
err_status_t
|
||||
srtp_init(void);
|
||||
|
||||
/**
|
||||
* @brief srtp_shutdown() de-initializes the srtp library.
|
||||
*
|
||||
* @warning No srtp functions may be called after calling this function.
|
||||
*/
|
||||
|
||||
err_status_t
|
||||
srtp_shutdown(void);
|
||||
|
||||
/**
|
||||
* @brief srtp_protect() is the Secure RTP sender-side packet processing
|
||||
* function.
|
||||
@@ -413,14 +437,13 @@ srtp_add_stream(srtp_t session,
|
||||
*/
|
||||
|
||||
err_status_t
|
||||
srtp_remove_stream(srtp_t session, uint32_t ssrc);
|
||||
srtp_remove_stream(srtp_t session, unsigned int ssrc);
|
||||
|
||||
/**
|
||||
* @brief crypto_policy_set_rtp_default() sets a crypto policy
|
||||
* structure to the SRTP default policy for RTP protection.
|
||||
*
|
||||
* @param p is a pointer to the policy strucutre to be set to the
|
||||
* default policy.
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_rtp_default(&p) sets the
|
||||
* crypto_policy_t at location p to the SRTP default policy for RTP
|
||||
@@ -442,8 +465,7 @@ crypto_policy_set_rtp_default(crypto_policy_t *p);
|
||||
* @brief crypto_policy_set_rtcp_default() sets a crypto policy
|
||||
* structure to the SRTP default policy for RTCP protection.
|
||||
*
|
||||
* @param p is a pointer to the policy strucutre to be set to the
|
||||
* default policy.
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_rtcp_default(&p) sets the
|
||||
* crypto_policy_t at location p to the SRTP default policy for RTCP
|
||||
@@ -465,13 +487,12 @@ crypto_policy_set_rtcp_default(crypto_policy_t *p);
|
||||
* @brief crypto_policy_set_aes_cm_128_hmac_sha1_80() sets a crypto
|
||||
* policy structure to the SRTP default policy for RTP protection.
|
||||
*
|
||||
* @param p is a pointer to the policy strucutre to be set to the
|
||||
* default policy.
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function crypto_policy_set_aes_cm_128_hmac_sha1_80() is a
|
||||
* synonym for crypto_policy_set_rtp_default(). It conforms to the
|
||||
* naming convention used in
|
||||
* http://www.ietf.org/internet-drafts/draft-ietf-mmusic-sdescriptions-12.txt
|
||||
* naming convention used in RFC 4568 (SDP Security Descriptions for
|
||||
* Media Streams).
|
||||
*
|
||||
* @return void.
|
||||
*
|
||||
@@ -484,13 +505,12 @@ crypto_policy_set_rtcp_default(crypto_policy_t *p);
|
||||
* @brief crypto_policy_set_aes_cm_128_hmac_sha1_32() sets a crypto
|
||||
* policy structure to a short-authentication tag policy
|
||||
*
|
||||
* @param p is a pointer to the policy strucutre to be set to the
|
||||
* default policy.
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_aes_cm_128_hmac_sha1_32(&p)
|
||||
* sets the crypto_policy_t at location p to use policy
|
||||
* AES_CM_128_HMAC_SHA1_32 as defined in
|
||||
* draft-ietf-mmusic-sdescriptions-12.txt. This policy uses AES-128
|
||||
* AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568.
|
||||
* This policy uses AES-128
|
||||
* Counter Mode encryption and HMAC-SHA1 authentication, with an
|
||||
* authentication tag that is only 32 bits long. This length is
|
||||
* considered adequate only for protecting audio and video media that
|
||||
@@ -521,8 +541,7 @@ crypto_policy_set_aes_cm_128_hmac_sha1_32(crypto_policy_t *p);
|
||||
* @brief crypto_policy_set_aes_cm_128_null_auth() sets a crypto
|
||||
* policy structure to an encryption-only policy
|
||||
*
|
||||
* @param p is a pointer to the policy strucutre to be set to the
|
||||
* default policy.
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_aes_cm_128_null_auth(&p) sets
|
||||
* the crypto_policy_t at location p to use the SRTP default cipher
|
||||
@@ -552,8 +571,7 @@ crypto_policy_set_aes_cm_128_null_auth(crypto_policy_t *p);
|
||||
* @brief crypto_policy_set_null_cipher_hmac_sha1_80() sets a crypto
|
||||
* policy structure to an authentication-only policy
|
||||
*
|
||||
* @param p is a pointer to the policy strucutre to be set to the
|
||||
* default policy.
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_null_cipher_hmac_sha1_80(&p)
|
||||
* sets the crypto_policy_t at location p to use HMAC-SHA1 with an 80
|
||||
@@ -577,6 +595,70 @@ crypto_policy_set_aes_cm_128_null_auth(crypto_policy_t *p);
|
||||
void
|
||||
crypto_policy_set_null_cipher_hmac_sha1_80(crypto_policy_t *p);
|
||||
|
||||
|
||||
/**
|
||||
* @brief crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto
|
||||
* policy structure to a encryption and authentication policy using AES-256
|
||||
* for RTP protection.
|
||||
*
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_aes_cm_256_hmac_sha1_80(&p)
|
||||
* sets the crypto_policy_t at location p to use policy
|
||||
* AES_CM_256_HMAC_SHA1_80 as defined in
|
||||
* draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
|
||||
* Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit
|
||||
* authentication tag.
|
||||
*
|
||||
* This function is a convenience that helps to avoid dealing directly
|
||||
* with the policy data structure. You are encouraged to initialize
|
||||
* policy elements with this function call. Doing so may allow your
|
||||
* code to be forward compatible with later versions of libSRTP that
|
||||
* include more elements in the crypto_policy_t datatype.
|
||||
*
|
||||
* @return void.
|
||||
*
|
||||
*/
|
||||
|
||||
void crypto_policy_set_aes_cm_256_hmac_sha1_80(crypto_policy_t *p);
|
||||
|
||||
|
||||
/**
|
||||
* @brief crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto
|
||||
* policy structure to a short-authentication tag policy using AES-256
|
||||
* encryption.
|
||||
*
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_aes_cm_256_hmac_sha1_32(&p)
|
||||
* sets the crypto_policy_t at location p to use policy
|
||||
* AES_CM_256_HMAC_SHA1_32 as defined in
|
||||
* draft-ietf-avt-srtp-big-aes-03.txt. This policy uses AES-256
|
||||
* Counter Mode encryption and HMAC-SHA1 authentication, with an
|
||||
* authentication tag that is only 32 bits long. This length is
|
||||
* considered adequate only for protecting audio and video media that
|
||||
* use a stateless playback function. See Section 7.5 of RFC 3711
|
||||
* (http://www.ietf.org/rfc/rfc3711.txt).
|
||||
*
|
||||
* This function is a convenience that helps to avoid dealing directly
|
||||
* with the policy data structure. You are encouraged to initialize
|
||||
* policy elements with this function call. Doing so may allow your
|
||||
* code to be forward compatible with later versions of libSRTP that
|
||||
* include more elements in the crypto_policy_t datatype.
|
||||
*
|
||||
* @warning This crypto policy is intended for use in SRTP, but not in
|
||||
* SRTCP. It is recommended that a policy that uses longer
|
||||
* authentication tags be used for SRTCP. See Section 7.5 of RFC 3711
|
||||
* (http://www.ietf.org/rfc/rfc3711.txt).
|
||||
*
|
||||
* @return void.
|
||||
*
|
||||
*/
|
||||
|
||||
void
|
||||
crypto_policy_set_aes_cm_256_hmac_sha1_32(crypto_policy_t *p);
|
||||
|
||||
|
||||
/**
|
||||
* @brief srtp_dealloc() deallocates storage for an SRTP session
|
||||
* context.
|
||||
@@ -597,70 +679,114 @@ err_status_t
|
||||
srtp_dealloc(srtp_t s);
|
||||
|
||||
|
||||
/*
|
||||
* @brief identifies a particular SRTP profile
|
||||
*
|
||||
* An srtp_profile_t enumeration is used to identify a particular SRTP
|
||||
* profile (that is, a set of algorithms and parameters). These
|
||||
* profiles are defined in the DTLS-SRTP draft.
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
srtp_profile_reserved = 0,
|
||||
srtp_profile_aes128_cm_sha1_80 = 1,
|
||||
srtp_profile_aes128_cm_sha1_32 = 2,
|
||||
srtp_profile_aes256_cm_sha1_80 = 3,
|
||||
srtp_profile_aes256_cm_sha1_32 = 4,
|
||||
srtp_profile_null_sha1_80 = 5,
|
||||
srtp_profile_null_sha1_32 = 6,
|
||||
} srtp_profile_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief crypto_policy_set_from_profile_for_rtp() sets a crypto policy
|
||||
* structure to the appropriate value for RTP based on an srtp_profile_t
|
||||
*
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_rtp_default(&policy, profile)
|
||||
* sets the crypto_policy_t at location policy to the policy for RTP
|
||||
* protection, as defined by the srtp_profile_t profile.
|
||||
*
|
||||
* This function is a convenience that helps to avoid dealing directly
|
||||
* with the policy data structure. You are encouraged to initialize
|
||||
* policy elements with this function call. Doing so may allow your
|
||||
* code to be forward compatible with later versions of libSRTP that
|
||||
* include more elements in the crypto_policy_t datatype.
|
||||
*
|
||||
* @return values
|
||||
* - err_status_ok no problems were encountered
|
||||
* - err_status_bad_param the profile is not supported
|
||||
*
|
||||
*/
|
||||
err_status_t
|
||||
crypto_policy_set_from_profile_for_rtp(crypto_policy_t *policy,
|
||||
srtp_profile_t profile);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief crypto_policy_set_from_profile_for_rtcp() sets a crypto policy
|
||||
* structure to the appropriate value for RTCP based on an srtp_profile_t
|
||||
*
|
||||
* @param p is a pointer to the policy structure to be set
|
||||
*
|
||||
* The function call crypto_policy_set_rtcp_default(&policy, profile)
|
||||
* sets the crypto_policy_t at location policy to the policy for RTCP
|
||||
* protection, as defined by the srtp_profile_t profile.
|
||||
*
|
||||
* This function is a convenience that helps to avoid dealing directly
|
||||
* with the policy data structure. You are encouraged to initialize
|
||||
* policy elements with this function call. Doing so may allow your
|
||||
* code to be forward compatible with later versions of libSRTP that
|
||||
* include more elements in the crypto_policy_t datatype.
|
||||
*
|
||||
* @return values
|
||||
* - err_status_ok no problems were encountered
|
||||
* - err_status_bad_param the profile is not supported
|
||||
*
|
||||
*/
|
||||
err_status_t
|
||||
crypto_policy_set_from_profile_for_rtcp(crypto_policy_t *policy,
|
||||
srtp_profile_t profile);
|
||||
|
||||
/**
|
||||
* @brief returns the master key length for a given SRTP profile
|
||||
*/
|
||||
unsigned int
|
||||
srtp_profile_get_master_key_length(srtp_profile_t profile);
|
||||
|
||||
|
||||
/**
|
||||
* @brief returns the master salt length for a given SRTP profile
|
||||
*/
|
||||
unsigned int
|
||||
srtp_profile_get_master_salt_length(srtp_profile_t profile);
|
||||
|
||||
/**
|
||||
* @brief appends the salt to the key
|
||||
*
|
||||
* The function call append_salt_to_key(k, klen, s, slen)
|
||||
* copies the string s to the location at klen bytes following
|
||||
* the location k.
|
||||
*
|
||||
* @warning There must be at least bytes_in_salt + bytes_in_key bytes
|
||||
* available at the location pointed to by key.
|
||||
*
|
||||
*/
|
||||
|
||||
void
|
||||
append_salt_to_key(unsigned char *key, unsigned int bytes_in_key,
|
||||
unsigned char *salt, unsigned int bytes_in_salt);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* the following declarations are libSRTP internal functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_get_stream(ssrc) returns a pointer to the stream corresponding
|
||||
* to ssrc, or NULL if no stream exists for that ssrc
|
||||
*/
|
||||
|
||||
srtp_stream_t
|
||||
srtp_get_stream(srtp_t srtp, uint32_t ssrc);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* libsrtp internal datatypes
|
||||
*/
|
||||
|
||||
typedef enum direction_t {
|
||||
dir_unknown = 0,
|
||||
dir_srtp_sender = 1,
|
||||
dir_srtp_receiver = 2
|
||||
} direction_t;
|
||||
|
||||
/*
|
||||
* an srtp_stream_t has its own SSRC, encryption key, authentication
|
||||
* key, sequence number, and replay database
|
||||
*
|
||||
* note that the keys might not actually be unique, in which case the
|
||||
* cipher_t and auth_t pointers will point to the same structures
|
||||
*/
|
||||
|
||||
typedef struct srtp_stream_ctx_t {
|
||||
uint32_t ssrc;
|
||||
cipher_t *rtp_cipher;
|
||||
auth_t *rtp_auth;
|
||||
rdbx_t rtp_rdbx;
|
||||
sec_serv_t rtp_services;
|
||||
cipher_t *rtcp_cipher;
|
||||
auth_t *rtcp_auth;
|
||||
rdb_t rtcp_rdb;
|
||||
sec_serv_t rtcp_services;
|
||||
key_limit_ctx_t *limit;
|
||||
direction_t direction;
|
||||
struct srtp_stream_ctx_t *next; /* linked list of streams */
|
||||
} srtp_stream_ctx_t;
|
||||
|
||||
|
||||
/*
|
||||
* an srtp_ctx_t holds a stream list and a service description
|
||||
*/
|
||||
|
||||
typedef struct srtp_ctx_t {
|
||||
srtp_stream_ctx_t *stream_list; /* linked list of streams */
|
||||
srtp_stream_ctx_t *stream_template; /* act as template for other streams */
|
||||
} srtp_ctx_t;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @defgroup SRTCP Secure RTCP
|
||||
@@ -867,137 +993,12 @@ srtp_install_event_handler(srtp_event_handler_func_t func);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_handle_event(srtp, srtm, evnt) calls the event handling
|
||||
* function, if there is one.
|
||||
*
|
||||
* This macro is not included in the documentation as it is
|
||||
* an internal-only function.
|
||||
*/
|
||||
|
||||
#define srtp_handle_event(srtp, strm, evnt) \
|
||||
if(srtp_event_handler) { \
|
||||
srtp_event_data_t data; \
|
||||
data.session = srtp; \
|
||||
data.stream = strm; \
|
||||
data.event = evnt; \
|
||||
srtp_event_handler(&data); \
|
||||
}
|
||||
|
||||
/*
|
||||
* an srtp_hdr_t represents the srtp header
|
||||
*
|
||||
* in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
|
||||
*
|
||||
* (note that this definition follows that of RFC 1889 Appendix A, but
|
||||
* is not identical)
|
||||
*/
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(push, r1, 1)
|
||||
#endif
|
||||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
|
||||
typedef struct {
|
||||
unsigned cc:4; /* CSRC count */
|
||||
unsigned x:1; /* header extension flag */
|
||||
unsigned p:1; /* padding flag */
|
||||
unsigned version:2; /* protocol version */
|
||||
unsigned pt:7; /* payload type */
|
||||
unsigned m:1; /* marker bit */
|
||||
unsigned seq:16; /* sequence number */
|
||||
unsigned ts:32; /* timestamp */
|
||||
unsigned ssrc:32; /* synchronization source */
|
||||
} srtp_hdr_t;
|
||||
|
||||
#else /* BIG_ENDIAN */
|
||||
|
||||
typedef struct {
|
||||
unsigned version:2; /* protocol version */
|
||||
unsigned p:1; /* padding flag */
|
||||
unsigned x:1; /* header extension flag */
|
||||
unsigned cc:4; /* CSRC count */
|
||||
unsigned m:1; /* marker bit */
|
||||
unsigned pt:7; /* payload type */
|
||||
unsigned seq:16; /* sequence number */
|
||||
unsigned ts:32; /* timestamp */
|
||||
unsigned ssrc:32; /* synchronization source */
|
||||
} srtp_hdr_t;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint16_t profile_specific; /* profile-specific info */
|
||||
uint16_t length; /* number of 32-bit words in extension */
|
||||
} srtp_hdr_xtnd_t;
|
||||
|
||||
|
||||
/*
|
||||
* srtcp_hdr_t represents a secure rtcp header
|
||||
*
|
||||
* in this implementation, an srtcp header is assumed to be 32-bit
|
||||
* alinged
|
||||
*/
|
||||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
|
||||
typedef struct {
|
||||
unsigned rc:5; /* reception report count */
|
||||
unsigned p:1; /* padding flag */
|
||||
unsigned version:2; /* protocol version */
|
||||
unsigned pt:8; /* payload type */
|
||||
unsigned len:16; /* length */
|
||||
unsigned ssrc:32; /* synchronization source */
|
||||
} srtcp_hdr_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int index:31; /* srtcp packet index in network order! */
|
||||
unsigned int e:1; /* encrypted? 1=yes */
|
||||
/* optional mikey/etc go here */
|
||||
/* and then the variable-length auth tag */
|
||||
} srtcp_trailer_t;
|
||||
|
||||
|
||||
#else /* BIG_ENDIAN */
|
||||
|
||||
typedef struct {
|
||||
unsigned version:2; /* protocol version */
|
||||
unsigned p:1; /* padding flag */
|
||||
unsigned rc:5; /* reception report count */
|
||||
unsigned pt:8; /* payload type */
|
||||
unsigned len:16; /* length */
|
||||
unsigned ssrc:32; /* synchronization source */
|
||||
} srtcp_hdr_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int version:2; /* protocol version */
|
||||
unsigned int p:1; /* padding flag */
|
||||
unsigned int count:5; /* varies by packet type */
|
||||
unsigned int pt:8; /* payload type */
|
||||
unsigned length:16; /* len of uint32s of packet less header */
|
||||
} rtcp_common_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int e:1; /* encrypted? 1=yes */
|
||||
unsigned int index:31; /* srtcp packet index */
|
||||
/* optional mikey/etc go here */
|
||||
/* and then the variable-length auth tag */
|
||||
} srtcp_trailer_t;
|
||||
|
||||
#endif
|
||||
|
||||
/* in host order, so outside the #if */
|
||||
#define SRTCP_E_BIT 0x80000000
|
||||
/* for byte-access */
|
||||
#define SRTCP_E_BYTE_BIT 0x80
|
||||
#define SRTCP_INDEX_MASK 0x7fffffff
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma pack(pop, r1)
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* srtp_priv.h
|
||||
*
|
||||
* private internal data structures and functions for 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_PRIV_H
|
||||
#define SRTP_PRIV_H
|
||||
|
||||
#include "srtp.h"
|
||||
#include "rdbx.h"
|
||||
#include "rdb.h"
|
||||
#include "integers.h"
|
||||
|
||||
/*
|
||||
* an srtp_hdr_t represents the srtp header
|
||||
*
|
||||
* in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
|
||||
*
|
||||
* (note that this definition follows that of RFC 1889 Appendix A, but
|
||||
* is not identical)
|
||||
*/
|
||||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
|
||||
/*
|
||||
* srtp_hdr_t represents an RTP or SRTP header. The bit-fields in
|
||||
* this structure should be declared "unsigned int" instead of
|
||||
* "unsigned char", but doing so causes the MS compiler to not
|
||||
* fully pack the bit fields.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
unsigned cc:4; /* CSRC count */
|
||||
unsigned x:1; /* header extension flag */
|
||||
unsigned p:1; /* padding flag */
|
||||
unsigned version:2; /* protocol version */
|
||||
unsigned pt:7; /* payload type */
|
||||
unsigned m:1; /* marker bit */
|
||||
unsigned seq:16; /* sequence number */
|
||||
unsigned ts:32; /* timestamp */
|
||||
unsigned ssrc:32; /* synchronization source */
|
||||
} srtp_hdr_t;
|
||||
|
||||
#else /* BIG_ENDIAN */
|
||||
|
||||
typedef struct {
|
||||
unsigned char version:2; /* protocol version */
|
||||
unsigned char p:1; /* padding flag */
|
||||
unsigned char x:1; /* header extension flag */
|
||||
unsigned char cc:4; /* CSRC count */
|
||||
unsigned char m:1; /* marker bit */
|
||||
unsigned pt:7; /* payload type */
|
||||
unsigned seq:16; /* sequence number */
|
||||
unsigned ts:32; /* timestamp */
|
||||
unsigned ssrc:32; /* synchronization source */
|
||||
} srtp_hdr_t;
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint16_t profile_specific; /* profile-specific info */
|
||||
uint16_t length; /* number of 32-bit words in extension */
|
||||
} srtp_hdr_xtnd_t;
|
||||
|
||||
|
||||
/*
|
||||
* srtcp_hdr_t represents a secure rtcp header
|
||||
*
|
||||
* in this implementation, an srtcp header is assumed to be 32-bit
|
||||
* alinged
|
||||
*/
|
||||
|
||||
#ifndef WORDS_BIGENDIAN
|
||||
|
||||
typedef struct {
|
||||
unsigned rc:5; /* reception report count */
|
||||
unsigned p:1; /* padding flag */
|
||||
unsigned version:2; /* protocol version */
|
||||
unsigned pt:8; /* payload type */
|
||||
unsigned len:16; /* length */
|
||||
unsigned ssrc:32; /* synchronization source */
|
||||
} srtcp_hdr_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int index:31; /* srtcp packet index in network order! */
|
||||
unsigned int e:1; /* encrypted? 1=yes */
|
||||
/* optional mikey/etc go here */
|
||||
/* and then the variable-length auth tag */
|
||||
} srtcp_trailer_t;
|
||||
|
||||
|
||||
#else /* BIG_ENDIAN */
|
||||
|
||||
typedef struct {
|
||||
unsigned char version:2; /* protocol version */
|
||||
unsigned char p:1; /* padding flag */
|
||||
unsigned char rc:5; /* reception report count */
|
||||
unsigned char pt:8; /* payload type */
|
||||
uint16_t len; /* length */
|
||||
uint32_t ssrc; /* synchronization source */
|
||||
} srtcp_hdr_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int version:2; /* protocol version */
|
||||
unsigned int p:1; /* padding flag */
|
||||
unsigned int count:5; /* varies by packet type */
|
||||
unsigned int pt:8; /* payload type */
|
||||
uint16_t length; /* len of uint32s of packet less header */
|
||||
} rtcp_common_t;
|
||||
|
||||
typedef struct {
|
||||
unsigned int e:1; /* encrypted? 1=yes */
|
||||
unsigned int index:31; /* srtcp packet index */
|
||||
/* optional mikey/etc go here */
|
||||
/* and then the variable-length auth tag */
|
||||
} srtcp_trailer_t;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* the following declarations are libSRTP internal functions
|
||||
*/
|
||||
|
||||
/*
|
||||
* srtp_get_stream(ssrc) returns a pointer to the stream corresponding
|
||||
* to ssrc, or NULL if no stream exists for that ssrc
|
||||
*/
|
||||
|
||||
srtp_stream_t
|
||||
srtp_get_stream(srtp_t srtp, uint32_t ssrc);
|
||||
|
||||
|
||||
/*
|
||||
* srtp_stream_init_keys(s, k) (re)initializes the srtp_stream_t s by
|
||||
* deriving all of the needed keys using the KDF and the key k.
|
||||
*/
|
||||
|
||||
|
||||
err_status_t
|
||||
srtp_stream_init_keys(srtp_stream_t srtp, const void *key);
|
||||
|
||||
/*
|
||||
* srtp_stream_init(s, p) initializes the srtp_stream_t s to
|
||||
* use the policy at the location p
|
||||
*/
|
||||
err_status_t
|
||||
srtp_stream_init(srtp_stream_t srtp,
|
||||
const srtp_policy_t *p);
|
||||
|
||||
|
||||
/*
|
||||
* libsrtp internal datatypes
|
||||
*/
|
||||
|
||||
typedef enum direction_t {
|
||||
dir_unknown = 0,
|
||||
dir_srtp_sender = 1,
|
||||
dir_srtp_receiver = 2
|
||||
} direction_t;
|
||||
|
||||
/*
|
||||
* an srtp_stream_t has its own SSRC, encryption key, authentication
|
||||
* key, sequence number, and replay database
|
||||
*
|
||||
* note that the keys might not actually be unique, in which case the
|
||||
* cipher_t and auth_t pointers will point to the same structures
|
||||
*/
|
||||
|
||||
typedef struct srtp_stream_ctx_t {
|
||||
uint32_t ssrc;
|
||||
cipher_t *rtp_cipher;
|
||||
auth_t *rtp_auth;
|
||||
rdbx_t rtp_rdbx;
|
||||
sec_serv_t rtp_services;
|
||||
cipher_t *rtcp_cipher;
|
||||
auth_t *rtcp_auth;
|
||||
rdb_t rtcp_rdb;
|
||||
sec_serv_t rtcp_services;
|
||||
key_limit_ctx_t *limit;
|
||||
direction_t direction;
|
||||
int allow_repeat_tx;
|
||||
ekt_stream_t ekt;
|
||||
struct srtp_stream_ctx_t *next; /* linked list of streams */
|
||||
} srtp_stream_ctx_t;
|
||||
|
||||
|
||||
/*
|
||||
* an srtp_ctx_t holds a stream list and a service description
|
||||
*/
|
||||
|
||||
typedef struct srtp_ctx_t {
|
||||
srtp_stream_ctx_t *stream_list; /* linked list of streams */
|
||||
srtp_stream_ctx_t *stream_template; /* act as template for other streams */
|
||||
} srtp_ctx_t;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* srtp_handle_event(srtp, srtm, evnt) calls the event handling
|
||||
* function, if there is one.
|
||||
*
|
||||
* This macro is not included in the documentation as it is
|
||||
* an internal-only function.
|
||||
*/
|
||||
|
||||
#define srtp_handle_event(srtp, strm, evnt) \
|
||||
if(srtp_event_handler) { \
|
||||
srtp_event_data_t data; \
|
||||
data.session = srtp; \
|
||||
data.stream = strm; \
|
||||
data.event = evnt; \
|
||||
srtp_event_handler(&data); \
|
||||
}
|
||||
|
||||
|
||||
#endif /* SRTP_PRIV_H */
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 2001-2005, Cisco Systems, Inc.
|
||||
* Copyright (c) 2001-2006, Cisco Systems, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
Reference in New Issue
Block a user