Changeset 5614 for pjproject/trunk/third_party/srtp/include/srtp_priv.h
- Timestamp:
- Jul 4, 2017 5:22:51 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/third_party/srtp/include/srtp_priv.h
r5261 r5614 9 9 /* 10 10 * 11 * Copyright (c) 2001-20 06Cisco Systems, Inc.11 * Copyright (c) 2001-2017 Cisco Systems, Inc. 12 12 * All rights reserved. 13 13 * … … 46 46 #define SRTP_PRIV_H 47 47 48 // Leave this as the top level import. Ensures the existence of defines 48 49 #include "config.h" 50 49 51 #include "srtp.h" 50 52 #include "rdbx.h" 51 53 #include "rdb.h" 52 54 #include "integers.h" 53 #include "crypto.h"54 55 #include "cipher.h" 55 56 #include "auth.h" … … 58 59 #include "crypto_kernel.h" 59 60 61 #ifdef __cplusplus 62 extern "C" { 63 #endif 64 60 65 #define SRTP_VER_STRING PACKAGE_STRING 61 66 #define SRTP_VERSION PACKAGE_VERSION 62 67 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 68 typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t; 69 typedef srtp_stream_ctx_t *srtp_stream_t; 169 70 170 71 /* … … 176 77 * to ssrc, or NULL if no stream exists for that ssrc 177 78 */ 178 179 srtp_stream_t 180 srtp_get_stream(srtp_t srtp, uint32_t ssrc); 79 srtp_stream_t srtp_get_stream(srtp_t srtp, uint32_t ssrc); 181 80 182 81 … … 185 84 * deriving all of the needed keys using the KDF and the key k. 186 85 */ 187 188 189 err_status_t 190 srtp_stream_init_keys(srtp_stream_t srtp, const void *key); 86 srtp_err_status_t srtp_stream_init_keys(srtp_stream_ctx_t *srtp, 87 srtp_master_key_t *master_key, 88 const unsigned int current_mki_index); 89 90 /* 91 * srtp_stream_init_all_master_keys(s, k, m) (re)initializes the srtp_stream_t s by 92 * deriving all of the needed keys for all the master keys using the KDF and the keys from k. 93 */ 94 srtp_err_status_t srtp_steam_init_all_master_keys(srtp_stream_ctx_t *srtp, 95 unsigned char *key, 96 srtp_master_key_t **keys, 97 const unsigned int max_master_keys); 191 98 192 99 /* … … 194 101 * use the policy at the location p 195 102 */ 196 err_status_t 197 srtp_stream_init(srtp_stream_t srtp, 198 const srtp_policy_t *p); 103 srtp_err_status_t srtp_stream_init(srtp_stream_t srtp, const srtp_policy_t *p); 199 104 200 105 … … 209 114 } direction_t; 210 115 116 /* 117 * srtp_session_keys_t will contain the encryption, hmac, salt keys 118 * for both SRTP and SRTCP. The session keys will also contain the 119 * MKI ID which is used to identify the session keys. 120 */ 121 typedef struct srtp_session_keys_t { 122 srtp_cipher_t *rtp_cipher; 123 srtp_cipher_t *rtp_xtn_hdr_cipher; 124 srtp_auth_t *rtp_auth; 125 srtp_cipher_t *rtcp_cipher; 126 srtp_auth_t *rtcp_auth; 127 uint8_t salt[SRTP_AEAD_SALT_LEN]; 128 uint8_t c_salt[SRTP_AEAD_SALT_LEN]; 129 uint8_t *mki_id; 130 unsigned int mki_size; 131 srtp_key_limit_ctx_t *limit; 132 } srtp_session_keys_t; 133 134 211 135 /* 212 136 * an srtp_stream_t has its own SSRC, encryption key, authentication … … 214 138 * 215 139 * note that the keys might not actually be unique, in which case the 216 * cipher_t andauth_t pointers will point to the same structures217 */ 218 219 typedef struct srtp_stream_ctx_t {140 * srtp_cipher_t and srtp_auth_t pointers will point to the same structures 141 */ 142 143 typedef struct srtp_stream_ctx_t_ { 220 144 uint32_t ssrc; 221 cipher_t *rtp_cipher; 222 auth_t *rtp_auth; 223 rdbx_t rtp_rdbx; 224 sec_serv_t rtp_services; 225 cipher_t *rtcp_cipher; 226 auth_t *rtcp_auth; 227 rdb_t rtcp_rdb; 228 sec_serv_t rtcp_services; 229 key_limit_ctx_t *limit; 145 srtp_session_keys_t *session_keys; 146 unsigned int num_master_keys; 147 srtp_rdbx_t rtp_rdbx; 148 srtp_sec_serv_t rtp_services; 149 srtp_rdb_t rtcp_rdb; 150 srtp_sec_serv_t rtcp_services; 230 151 direction_t direction; 231 152 int allow_repeat_tx; 232 ekt_stream_t ekt; 233 uint8_t salt[SRTP_AEAD_SALT_LEN]; /* used with GCM mode for SRTP */ 234 uint8_t c_salt[SRTP_AEAD_SALT_LEN]; /* used with GCM mode for SRTCP */ 235 struct srtp_stream_ctx_t *next; /* linked list of streams */ 236 } srtp_stream_ctx_t; 153 srtp_ekt_stream_t ekt; 154 int *enc_xtn_hdr; 155 int enc_xtn_hdr_count; 156 uint32_t pending_roc; 157 struct srtp_stream_ctx_t_ *next; /* linked list of streams */ 158 } strp_stream_ctx_t_; 237 159 238 160 … … 241 163 */ 242 164 243 typedef struct srtp_ctx_t {244 s rtp_stream_ctx_t*stream_list; /* linked list of streams */245 s rtp_stream_ctx_t*stream_template; /* act as template for other streams */165 typedef struct srtp_ctx_t_ { 166 struct srtp_stream_ctx_t_ *stream_list; /* linked list of streams */ 167 struct srtp_stream_ctx_t_ *stream_template; /* act as template for other streams */ 246 168 void *user_data; /* user custom data */ 247 } srtp_ctx_t; 248 169 } srtp_ctx_t_; 170 171 172 /* 173 * srtp_hdr_t represents an RTP or SRTP header. The bit-fields in 174 * this structure should be declared "unsigned int" instead of 175 * "unsigned char", but doing so causes the MS compiler to not 176 * fully pack the bit fields. 177 * 178 * In this implementation, an srtp_hdr_t is assumed to be 32-bit aligned 179 * 180 * (note that this definition follows that of RFC 1889 Appendix A, but 181 * is not identical) 182 */ 183 184 #ifndef WORDS_BIGENDIAN 185 186 typedef struct { 187 unsigned char cc : 4; /* CSRC count */ 188 unsigned char x : 1; /* header extension flag */ 189 unsigned char p : 1; /* padding flag */ 190 unsigned char version : 2; /* protocol version */ 191 unsigned char pt : 7; /* payload type */ 192 unsigned char m : 1; /* marker bit */ 193 uint16_t seq; /* sequence number */ 194 uint32_t ts; /* timestamp */ 195 uint32_t ssrc; /* synchronization source */ 196 } srtp_hdr_t; 197 198 #else /* BIG_ENDIAN */ 199 200 typedef struct { 201 unsigned char version : 2; /* protocol version */ 202 unsigned char p : 1; /* padding flag */ 203 unsigned char x : 1; /* header extension flag */ 204 unsigned char cc : 4; /* CSRC count */ 205 unsigned char m : 1; /* marker bit */ 206 unsigned char pt : 7; /* payload type */ 207 uint16_t seq; /* sequence number */ 208 uint32_t ts; /* timestamp */ 209 uint32_t ssrc; /* synchronization source */ 210 } srtp_hdr_t; 211 212 #endif 213 214 215 typedef struct { 216 uint16_t profile_specific; /* profile-specific info */ 217 uint16_t length; /* number of 32-bit words in extension */ 218 } srtp_hdr_xtnd_t; 219 220 221 /* 222 * srtcp_hdr_t represents a secure rtcp header 223 * 224 * in this implementation, an srtcp header is assumed to be 32-bit 225 * alinged 226 */ 227 228 #ifndef WORDS_BIGENDIAN 229 230 typedef struct { 231 unsigned char rc : 5; /* reception report count */ 232 unsigned char p : 1; /* padding flag */ 233 unsigned char version : 2; /* protocol version */ 234 unsigned char pt : 8; /* payload type */ 235 uint16_t len; /* length */ 236 uint32_t ssrc; /* synchronization source */ 237 } srtcp_hdr_t; 238 239 typedef struct { 240 unsigned int index : 31; /* srtcp packet index in network order! */ 241 unsigned int e : 1; /* encrypted? 1=yes */ 242 /* optional mikey/etc go here */ 243 /* and then the variable-length auth tag */ 244 } srtcp_trailer_t; 245 246 #else /* BIG_ENDIAN */ 247 248 typedef struct { 249 unsigned char version : 2; /* protocol version */ 250 unsigned char p : 1; /* padding flag */ 251 unsigned char rc : 5; /* reception report count */ 252 unsigned char pt : 8; /* payload type */ 253 uint16_t len; /* length */ 254 uint32_t ssrc; /* synchronization source */ 255 } srtcp_hdr_t; 256 257 typedef struct { 258 unsigned int e : 1; /* encrypted? 1=yes */ 259 unsigned int index : 31; /* srtcp packet index */ 260 /* optional mikey/etc go here */ 261 /* and then the variable-length auth tag */ 262 } srtcp_trailer_t; 263 264 #endif 249 265 250 266 … … 261 277 srtp_event_data_t data; \ 262 278 data.session = srtp; \ 263 data.s tream = strm;\279 data.ssrc = ntohl(strm->ssrc); \ 264 280 data.event = evnt; \ 265 281 srtp_event_handler(&data); \ 266 282 } 267 283 284 #ifdef __cplusplus 285 } 286 #endif 268 287 269 288 #endif /* SRTP_PRIV_H */
Note: See TracChangeset
for help on using the changeset viewer.