~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.1.0/third_party/srtp/include/srtp_priv.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-01-07 14:51:16 UTC
  • mfrom: (4.3.5 sid)
  • Revision ID: package-import@ubuntu.com-20150107145116-yxnafinf4lrdvrmx
Tags: 1.4.1-0.1ubuntu1
* Merge with Debian, remaining changes:
 - Drop soprano, nepomuk build-dep
* Drop ubuntu patches, now upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "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
 
#ifdef _MSC_VER
63
 
#   pragma warning(push)
64
 
#   pragma warning(disable:4214) // bit field types other than int
65
 
#endif
66
 
 
67
 
#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
 
 */
75
 
typedef 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
 
 
89
 
typedef 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
102
 
 
103
 
 
104
 
typedef struct {
105
 
  uint16_t profile_specific;    /* profile-specific info               */
106
 
  uint16_t length;              /* number of 32-bit words in extension */
107
 
} srtp_hdr_xtnd_t;
108
 
 
109
 
 
110
 
/*
111
 
 * srtcp_hdr_t represents a secure rtcp header 
112
 
 *
113
 
 * in this implementation, an srtcp header is assumed to be 32-bit
114
 
 * alinged
115
 
 */
116
 
 
117
 
#ifndef WORDS_BIGENDIAN
118
 
 
119
 
typedef struct {
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 */
126
 
} srtcp_hdr_t;
127
 
 
128
 
typedef struct {
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 */
133
 
} srtcp_trailer_t;
134
 
 
135
 
 
136
 
#else /*  BIG_ENDIAN */
137
 
 
138
 
typedef struct {
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 */
145
 
} srtcp_hdr_t;
146
 
 
147
 
typedef struct {
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 */
153
 
} rtcp_common_t;
154
 
 
155
 
typedef struct {
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 */
160
 
} srtcp_trailer_t;
161
 
 
162
 
#endif
163
 
 
164
 
 
165
 
#ifdef _MSC_VER
166
 
#   pragma warning( pop ) 
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
 
 * libsrtp internal datatypes 
194
 
 */
195
 
 
196
 
typedef enum direction_t { 
197
 
  dir_unknown       = 0,
198
 
  dir_srtp_sender   = 1, 
199
 
  dir_srtp_receiver = 2
200
 
} direction_t;
201
 
 
202
 
/* 
203
 
 * an srtp_stream_t has its own SSRC, encryption key, authentication
204
 
 * key, sequence number, and replay database
205
 
 * 
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
208
 
 */
209
 
 
210
 
typedef struct srtp_stream_ctx_t {
211
 
  uint32_t   ssrc;
212
 
  cipher_t  *rtp_cipher;
213
 
  auth_t    *rtp_auth;
214
 
  rdbx_t     rtp_rdbx;
215
 
  sec_serv_t rtp_services;
216
 
  cipher_t  *rtcp_cipher;
217
 
  auth_t    *rtcp_auth;
218
 
  rdb_t      rtcp_rdb;
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 */
223
 
} srtp_stream_ctx_t;
224
 
 
225
 
 
226
 
/*
227
 
 * an srtp_ctx_t holds a stream list and a service description
228
 
 */
229
 
 
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 */
233
 
} srtp_ctx_t;
234
 
 
235
 
 
236
 
 
237
 
/*
238
 
 * srtp_handle_event(srtp, srtm, evnt) calls the event handling
239
 
 * function, if there is one.
240
 
 *
241
 
 * This macro is not included in the documentation as it is 
242
 
 * an internal-only function.
243
 
 */
244
 
 
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;                          \
250
 
      data.event   = evnt;                          \
251
 
      srtp_event_handler(&data);                    \
252
 
}   
253
 
 
254
 
 
255
 
#endif /* SRTP_PRIV_H */