blob: 1c7a11511a228b8b03105f0ee5be6798ebb7a0a9 [file] [log] [blame]
Benny Prijono8a0ab282008-01-23 20:17:42 +00001/*
2 * srtp_priv.h
3 *
4 * private internal data structures and functions for libSRTP
5 *
6 * David A. McGrew
7 * Cisco Systems, Inc.
8 */
9/*
10 *
11 * Copyright (c) 2001-2006 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_PRIV_H
46#define SRTP_PRIV_H
47
48#include "srtp.h"
49#include "rdbx.h"
50#include "rdb.h"
51#include "integers.h"
52
53/*
54 * an srtp_hdr_t represents the srtp header
55 *
56 * in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
57 *
58 * (note that this definition follows that of RFC 1889 Appendix A, but
59 * is not identical)
60 */
61
Nanang Izzuddin2e4f03f2009-04-27 19:18:38 +000062#ifdef _MSC_VER
63# pragma warning(push)
64# pragma warning(disable:4214) // bit field types other than int
65#endif
66
Benny Prijono8a0ab282008-01-23 20:17:42 +000067#ifndef WORDS_BIGENDIAN
68
69/*
70 * srtp_hdr_t represents an RTP or SRTP header. The bit-fields in
71 * this structure should be declared "unsigned int" instead of
72 * "unsigned char", but doing so causes the MS compiler to not
73 * fully pack the bit fields.
74 */
Benny Prijono8a0ab282008-01-23 20:17:42 +000075typedef struct {
76 unsigned char cc:4; /* CSRC count */
77 unsigned char x:1; /* header extension flag */
78 unsigned char p:1; /* padding flag */
79 unsigned char version:2; /* protocol version */
80 unsigned char pt:7; /* payload type */
81 unsigned char m:1; /* marker bit */
82 uint16_t seq; /* sequence number */
83 uint32_t ts; /* timestamp */
84 uint32_t ssrc; /* synchronization source */
85} srtp_hdr_t;
86
87#else /* BIG_ENDIAN */
88
89typedef struct {
90 unsigned char version:2; /* protocol version */
91 unsigned char p:1; /* padding flag */
92 unsigned char x:1; /* header extension flag */
93 unsigned char cc:4; /* CSRC count */
94 unsigned char m:1; /* marker bit */
95 unsigned pt:7; /* payload type */
96 uint16_t seq; /* sequence number */
97 uint32_t ts; /* timestamp */
98 uint32_t ssrc; /* synchronization source */
99} srtp_hdr_t;
100
101#endif
Nanang Izzuddin2e4f03f2009-04-27 19:18:38 +0000102
103#ifdef _MSC_VER
104# pragma warning( pop )
105#endif
106
Benny Prijono8a0ab282008-01-23 20:17:42 +0000107
108typedef struct {
109 uint16_t profile_specific; /* profile-specific info */
110 uint16_t length; /* number of 32-bit words in extension */
111} srtp_hdr_xtnd_t;
112
113
114/*
115 * srtcp_hdr_t represents a secure rtcp header
116 *
117 * in this implementation, an srtcp header is assumed to be 32-bit
118 * alinged
119 */
120
121#ifndef WORDS_BIGENDIAN
122
123typedef struct {
124 unsigned char rc:5; /* reception report count */
125 unsigned char p:1; /* padding flag */
126 unsigned char version:2; /* protocol version */
127 unsigned char pt:8; /* payload type */
128 uint16_t len; /* length */
129 uint32_t ssrc; /* synchronization source */
130} srtcp_hdr_t;
131
132typedef struct {
133 unsigned int index:31; /* srtcp packet index in network order! */
134 unsigned int e:1; /* encrypted? 1=yes */
135 /* optional mikey/etc go here */
136 /* and then the variable-length auth tag */
137} srtcp_trailer_t;
138
139
140#else /* BIG_ENDIAN */
141
142typedef struct {
143 unsigned char version:2; /* protocol version */
144 unsigned char p:1; /* padding flag */
145 unsigned char rc:5; /* reception report count */
146 unsigned char pt:8; /* payload type */
147 uint16_t len; /* length */
148 uint32_t ssrc; /* synchronization source */
149} srtcp_hdr_t;
150
151typedef struct {
152 unsigned int version:2; /* protocol version */
153 unsigned int p:1; /* padding flag */
154 unsigned int count:5; /* varies by packet type */
155 unsigned int pt:8; /* payload type */
156 uint16_t length; /* len of uint32s of packet less header */
157} rtcp_common_t;
158
159typedef struct {
160 unsigned int e:1; /* encrypted? 1=yes */
161 unsigned int index:31; /* srtcp packet index */
162 /* optional mikey/etc go here */
163 /* and then the variable-length auth tag */
164} srtcp_trailer_t;
165
166#endif
167
168
169/*
170 * the following declarations are libSRTP internal functions
171 */
172
173/*
174 * srtp_get_stream(ssrc) returns a pointer to the stream corresponding
175 * to ssrc, or NULL if no stream exists for that ssrc
176 */
177
178srtp_stream_t
179srtp_get_stream(srtp_t srtp, uint32_t ssrc);
180
181
182/*
183 * srtp_stream_init_keys(s, k) (re)initializes the srtp_stream_t s by
184 * deriving all of the needed keys using the KDF and the key k.
185 */
186
187
188err_status_t
189srtp_stream_init_keys(srtp_stream_t srtp, const void *key);
190
191/*
192 * libsrtp internal datatypes
193 */
194
195typedef enum direction_t {
196 dir_unknown = 0,
197 dir_srtp_sender = 1,
198 dir_srtp_receiver = 2
199} direction_t;
200
201/*
202 * an srtp_stream_t has its own SSRC, encryption key, authentication
203 * key, sequence number, and replay database
204 *
205 * note that the keys might not actually be unique, in which case the
206 * cipher_t and auth_t pointers will point to the same structures
207 */
208
209typedef struct srtp_stream_ctx_t {
210 uint32_t ssrc;
211 cipher_t *rtp_cipher;
212 auth_t *rtp_auth;
213 rdbx_t rtp_rdbx;
214 sec_serv_t rtp_services;
215 cipher_t *rtcp_cipher;
216 auth_t *rtcp_auth;
217 rdb_t rtcp_rdb;
218 sec_serv_t rtcp_services;
219 key_limit_ctx_t *limit;
220 direction_t direction;
221 struct srtp_stream_ctx_t *next; /* linked list of streams */
222} srtp_stream_ctx_t;
223
224
225/*
226 * an srtp_ctx_t holds a stream list and a service description
227 */
228
229typedef struct srtp_ctx_t {
230 srtp_stream_ctx_t *stream_list; /* linked list of streams */
231 srtp_stream_ctx_t *stream_template; /* act as template for other streams */
232} srtp_ctx_t;
233
234
235
236/*
237 * srtp_handle_event(srtp, srtm, evnt) calls the event handling
238 * function, if there is one.
239 *
240 * This macro is not included in the documentation as it is
241 * an internal-only function.
242 */
243
244#define srtp_handle_event(srtp, strm, evnt) \
245 if(srtp_event_handler) { \
246 srtp_event_data_t data; \
247 data.session = srtp; \
248 data.stream = strm; \
249 data.event = evnt; \
250 srtp_event_handler(&data); \
251}
252
253
254#endif /* SRTP_PRIV_H */