1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/srtp/src/include/srtp_priv.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,256 @@ 1.4 +/* 1.5 + * srtp_priv.h 1.6 + * 1.7 + * private internal data structures and functions for libSRTP 1.8 + * 1.9 + * David A. McGrew 1.10 + * Cisco Systems, Inc. 1.11 + */ 1.12 +/* 1.13 + * 1.14 + * Copyright (c) 2001-2006 Cisco Systems, Inc. 1.15 + * All rights reserved. 1.16 + * 1.17 + * Redistribution and use in source and binary forms, with or without 1.18 + * modification, are permitted provided that the following conditions 1.19 + * are met: 1.20 + * 1.21 + * Redistributions of source code must retain the above copyright 1.22 + * notice, this list of conditions and the following disclaimer. 1.23 + * 1.24 + * Redistributions in binary form must reproduce the above 1.25 + * copyright notice, this list of conditions and the following 1.26 + * disclaimer in the documentation and/or other materials provided 1.27 + * with the distribution. 1.28 + * 1.29 + * Neither the name of the Cisco Systems, Inc. nor the names of its 1.30 + * contributors may be used to endorse or promote products derived 1.31 + * from this software without specific prior written permission. 1.32 + * 1.33 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.34 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.35 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 1.36 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 1.37 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 1.38 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 1.39 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 1.40 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.41 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.42 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.43 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 1.44 + * OF THE POSSIBILITY OF SUCH DAMAGE. 1.45 + * 1.46 + */ 1.47 + 1.48 +#ifndef SRTP_PRIV_H 1.49 +#define SRTP_PRIV_H 1.50 + 1.51 +#include "srtp.h" 1.52 +#include "rdbx.h" 1.53 +#include "rdb.h" 1.54 +#include "integers.h" 1.55 + 1.56 +/* 1.57 + * an srtp_hdr_t represents the srtp header 1.58 + * 1.59 + * in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned 1.60 + * 1.61 + * (note that this definition follows that of RFC 1889 Appendix A, but 1.62 + * is not identical) 1.63 + */ 1.64 + 1.65 +#ifndef WORDS_BIGENDIAN 1.66 + 1.67 +/* 1.68 + * srtp_hdr_t represents an RTP or SRTP header. The bit-fields in 1.69 + * this structure should be declared "unsigned int" instead of 1.70 + * "unsigned char", but doing so causes the MS compiler to not 1.71 + * fully pack the bit fields. 1.72 + */ 1.73 + 1.74 +typedef struct { 1.75 + unsigned char cc:4; /* CSRC count */ 1.76 + unsigned char x:1; /* header extension flag */ 1.77 + unsigned char p:1; /* padding flag */ 1.78 + unsigned char version:2; /* protocol version */ 1.79 + unsigned char pt:7; /* payload type */ 1.80 + unsigned char m:1; /* marker bit */ 1.81 + uint16_t seq; /* sequence number */ 1.82 + uint32_t ts; /* timestamp */ 1.83 + uint32_t ssrc; /* synchronization source */ 1.84 +} srtp_hdr_t; 1.85 + 1.86 +#else /* BIG_ENDIAN */ 1.87 + 1.88 +typedef struct { 1.89 + unsigned char version:2; /* protocol version */ 1.90 + unsigned char p:1; /* padding flag */ 1.91 + unsigned char x:1; /* header extension flag */ 1.92 + unsigned char cc:4; /* CSRC count */ 1.93 + unsigned char m:1; /* marker bit */ 1.94 + unsigned pt:7; /* payload type */ 1.95 + uint16_t seq; /* sequence number */ 1.96 + uint32_t ts; /* timestamp */ 1.97 + uint32_t ssrc; /* synchronization source */ 1.98 +} srtp_hdr_t; 1.99 + 1.100 +#endif 1.101 + 1.102 +typedef struct { 1.103 + uint16_t profile_specific; /* profile-specific info */ 1.104 + uint16_t length; /* number of 32-bit words in extension */ 1.105 +} srtp_hdr_xtnd_t; 1.106 + 1.107 + 1.108 +/* 1.109 + * srtcp_hdr_t represents a secure rtcp header 1.110 + * 1.111 + * in this implementation, an srtcp header is assumed to be 32-bit 1.112 + * alinged 1.113 + */ 1.114 + 1.115 +#ifndef WORDS_BIGENDIAN 1.116 + 1.117 +typedef struct { 1.118 + unsigned char rc:5; /* reception report count */ 1.119 + unsigned char p:1; /* padding flag */ 1.120 + unsigned char version:2; /* protocol version */ 1.121 + unsigned char pt:8; /* payload type */ 1.122 + uint16_t len; /* length */ 1.123 + uint32_t ssrc; /* synchronization source */ 1.124 +} srtcp_hdr_t; 1.125 + 1.126 +typedef struct { 1.127 + unsigned int index:31; /* srtcp packet index in network order! */ 1.128 + unsigned int e:1; /* encrypted? 1=yes */ 1.129 + /* optional mikey/etc go here */ 1.130 + /* and then the variable-length auth tag */ 1.131 +} srtcp_trailer_t; 1.132 + 1.133 + 1.134 +#else /* BIG_ENDIAN */ 1.135 + 1.136 +typedef struct { 1.137 + unsigned char version:2; /* protocol version */ 1.138 + unsigned char p:1; /* padding flag */ 1.139 + unsigned char rc:5; /* reception report count */ 1.140 + unsigned char pt:8; /* payload type */ 1.141 + uint16_t len; /* length */ 1.142 + uint32_t ssrc; /* synchronization source */ 1.143 +} srtcp_hdr_t; 1.144 + 1.145 +typedef struct { 1.146 + unsigned int version:2; /* protocol version */ 1.147 + unsigned int p:1; /* padding flag */ 1.148 + unsigned int count:5; /* varies by packet type */ 1.149 + unsigned int pt:8; /* payload type */ 1.150 + uint16_t length; /* len of uint32s of packet less header */ 1.151 +} rtcp_common_t; 1.152 + 1.153 +typedef struct { 1.154 + unsigned int e:1; /* encrypted? 1=yes */ 1.155 + unsigned int index:31; /* srtcp packet index */ 1.156 + /* optional mikey/etc go here */ 1.157 + /* and then the variable-length auth tag */ 1.158 +} srtcp_trailer_t; 1.159 + 1.160 +#endif 1.161 + 1.162 + 1.163 +/* 1.164 + * the following declarations are libSRTP internal functions 1.165 + */ 1.166 + 1.167 +/* 1.168 + * srtp_get_stream(ssrc) returns a pointer to the stream corresponding 1.169 + * to ssrc, or NULL if no stream exists for that ssrc 1.170 + */ 1.171 + 1.172 +srtp_stream_t 1.173 +srtp_get_stream(srtp_t srtp, uint32_t ssrc); 1.174 + 1.175 + 1.176 +/* 1.177 + * srtp_stream_init_keys(s, k) (re)initializes the srtp_stream_t s by 1.178 + * deriving all of the needed keys using the KDF and the key k. 1.179 + */ 1.180 + 1.181 + 1.182 +err_status_t 1.183 +srtp_stream_init_keys(srtp_stream_t srtp, const void *key); 1.184 + 1.185 +/* 1.186 + * srtp_stream_init(s, p) initializes the srtp_stream_t s to 1.187 + * use the policy at the location p 1.188 + */ 1.189 +err_status_t 1.190 +srtp_stream_init(srtp_stream_t srtp, 1.191 + const srtp_policy_t *p); 1.192 + 1.193 + 1.194 +/* 1.195 + * libsrtp internal datatypes 1.196 + */ 1.197 + 1.198 +typedef enum direction_t { 1.199 + dir_unknown = 0, 1.200 + dir_srtp_sender = 1, 1.201 + dir_srtp_receiver = 2 1.202 +} direction_t; 1.203 + 1.204 +/* 1.205 + * an srtp_stream_t has its own SSRC, encryption key, authentication 1.206 + * key, sequence number, and replay database 1.207 + * 1.208 + * note that the keys might not actually be unique, in which case the 1.209 + * cipher_t and auth_t pointers will point to the same structures 1.210 + */ 1.211 + 1.212 +typedef struct srtp_stream_ctx_t { 1.213 + uint32_t ssrc; 1.214 + cipher_t *rtp_cipher; 1.215 + auth_t *rtp_auth; 1.216 + rdbx_t rtp_rdbx; 1.217 + sec_serv_t rtp_services; 1.218 + cipher_t *rtcp_cipher; 1.219 + auth_t *rtcp_auth; 1.220 + rdb_t rtcp_rdb; 1.221 + sec_serv_t rtcp_services; 1.222 + key_limit_ctx_t *limit; 1.223 + direction_t direction; 1.224 + int allow_repeat_tx; 1.225 + ekt_stream_t ekt; 1.226 + struct srtp_stream_ctx_t *next; /* linked list of streams */ 1.227 +} srtp_stream_ctx_t; 1.228 + 1.229 + 1.230 +/* 1.231 + * an srtp_ctx_t holds a stream list and a service description 1.232 + */ 1.233 + 1.234 +typedef struct srtp_ctx_t { 1.235 + srtp_stream_ctx_t *stream_list; /* linked list of streams */ 1.236 + srtp_stream_ctx_t *stream_template; /* act as template for other streams */ 1.237 +} srtp_ctx_t; 1.238 + 1.239 + 1.240 + 1.241 +/* 1.242 + * srtp_handle_event(srtp, srtm, evnt) calls the event handling 1.243 + * function, if there is one. 1.244 + * 1.245 + * This macro is not included in the documentation as it is 1.246 + * an internal-only function. 1.247 + */ 1.248 + 1.249 +#define srtp_handle_event(srtp, strm, evnt) \ 1.250 + if(srtp_event_handler) { \ 1.251 + srtp_event_data_t data; \ 1.252 + data.session = srtp; \ 1.253 + data.stream = strm; \ 1.254 + data.event = evnt; \ 1.255 + srtp_event_handler(&data); \ 1.256 +} 1.257 + 1.258 + 1.259 +#endif /* SRTP_PRIV_H */