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