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