4
* private internal data structures and functions for libSRTP
11
* Copyright (c) 2001-2006 Cisco Systems, Inc.
12
* All rights reserved.
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions
18
* Redistributions of source code must retain the above copyright
19
* notice, this list of conditions and the following disclaimer.
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.
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.
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.
54
* an srtp_hdr_t represents the srtp header
56
* in this implementation, an srtp_hdr_t is assumed to be 32-bit aligned
58
* (note that this definition follows that of RFC 1889 Appendix A, but
63
# pragma warning(push)
64
# pragma warning(disable:4214) // bit field types other than int
67
#ifndef WORDS_BIGENDIAN
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.
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 */
87
#else /* BIG_ENDIAN */
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 */
105
uint16_t profile_specific; /* profile-specific info */
106
uint16_t length; /* number of 32-bit words in extension */
111
* srtcp_hdr_t represents a secure rtcp header
113
* in this implementation, an srtcp header is assumed to be 32-bit
117
#ifndef WORDS_BIGENDIAN
120
unsigned char rc:5; /* reception report count */
121
unsigned char p:1; /* padding flag */
122
unsigned char version:2; /* protocol version */
123
unsigned char pt:8; /* payload type */
124
uint16_t len; /* length */
125
uint32_t ssrc; /* synchronization source */
129
unsigned int index:31; /* srtcp packet index in network order! */
130
unsigned int e:1; /* encrypted? 1=yes */
131
/* optional mikey/etc go here */
132
/* and then the variable-length auth tag */
136
#else /* BIG_ENDIAN */
139
unsigned char version:2; /* protocol version */
140
unsigned char p:1; /* padding flag */
141
unsigned char rc:5; /* reception report count */
142
unsigned char pt:8; /* payload type */
143
uint16_t len; /* length */
144
uint32_t ssrc; /* synchronization source */
148
unsigned int version:2; /* protocol version */
149
unsigned int p:1; /* padding flag */
150
unsigned int count:5; /* varies by packet type */
151
unsigned int pt:8; /* payload type */
152
uint16_t length; /* len of uint32s of packet less header */
156
unsigned int e:1; /* encrypted? 1=yes */
157
unsigned int index:31; /* srtcp packet index */
158
/* optional mikey/etc go here */
159
/* and then the variable-length auth tag */
166
# pragma warning( pop )
171
* the following declarations are libSRTP internal functions
175
* srtp_get_stream(ssrc) returns a pointer to the stream corresponding
176
* to ssrc, or NULL if no stream exists for that ssrc
180
srtp_get_stream(srtp_t srtp, uint32_t ssrc);
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.
190
srtp_stream_init_keys(srtp_stream_t srtp, const void *key);
193
* libsrtp internal datatypes
196
typedef enum direction_t {
199
dir_srtp_receiver = 2
203
* an srtp_stream_t has its own SSRC, encryption key, authentication
204
* key, sequence number, and replay database
206
* note that the keys might not actually be unique, in which case the
207
* cipher_t and auth_t pointers will point to the same structures
210
typedef struct srtp_stream_ctx_t {
212
cipher_t *rtp_cipher;
215
sec_serv_t rtp_services;
216
cipher_t *rtcp_cipher;
219
sec_serv_t rtcp_services;
220
key_limit_ctx_t *limit;
221
direction_t direction;
222
struct srtp_stream_ctx_t *next; /* linked list of streams */
227
* an srtp_ctx_t holds a stream list and a service description
230
typedef struct srtp_ctx_t {
231
srtp_stream_ctx_t *stream_list; /* linked list of streams */
232
srtp_stream_ctx_t *stream_template; /* act as template for other streams */
238
* srtp_handle_event(srtp, srtm, evnt) calls the event handling
239
* function, if there is one.
241
* This macro is not included in the documentation as it is
242
* an internal-only function.
245
#define srtp_handle_event(srtp, strm, evnt) \
246
if(srtp_event_handler) { \
247
srtp_event_data_t data; \
248
data.session = srtp; \
249
data.stream = strm; \
251
srtp_event_handler(&data); \
255
#endif /* SRTP_PRIV_H */