Ignore:
Timestamp:
Jul 4, 2017 5:22:51 AM (7 years ago)
Author:
nanang
Message:

Close #1993: Updated bundled libSRTP version to 2.1.0.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/third_party/srtp/include/srtp_priv.h

    r5261 r5614  
    99/* 
    1010 *       
    11  * Copyright (c) 2001-2006 Cisco Systems, Inc. 
     11 * Copyright (c) 2001-2017 Cisco Systems, Inc. 
    1212 * All rights reserved. 
    1313 *  
     
    4646#define SRTP_PRIV_H 
    4747 
     48// Leave this as the top level import. Ensures the existence of defines 
    4849#include "config.h" 
     50 
    4951#include "srtp.h" 
    5052#include "rdbx.h" 
    5153#include "rdb.h" 
    5254#include "integers.h" 
    53 #include "crypto.h" 
    5455#include "cipher.h" 
    5556#include "auth.h" 
     
    5859#include "crypto_kernel.h" 
    5960 
     61#ifdef __cplusplus 
     62extern "C" { 
     63#endif 
     64 
    6065#define SRTP_VER_STRING     PACKAGE_STRING 
    6166#define SRTP_VERSION        PACKAGE_VERSION 
    6267 
    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  
     68typedef struct srtp_stream_ctx_t_ srtp_stream_ctx_t; 
     69typedef srtp_stream_ctx_t *srtp_stream_t; 
    16970 
    17071/* 
     
    17677 * to ssrc, or NULL if no stream exists for that ssrc 
    17778 */ 
    178  
    179 srtp_stream_t  
    180 srtp_get_stream(srtp_t srtp, uint32_t ssrc); 
     79srtp_stream_t srtp_get_stream(srtp_t srtp, uint32_t ssrc); 
    18180 
    18281 
     
    18584 * deriving all of the needed keys using the KDF and the key k. 
    18685 */ 
    187  
    188  
    189 err_status_t 
    190 srtp_stream_init_keys(srtp_stream_t srtp, const void *key); 
     86srtp_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 */ 
     94srtp_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); 
    19198 
    19299/* 
     
    194101 * use the policy at the location p 
    195102 */ 
    196 err_status_t 
    197 srtp_stream_init(srtp_stream_t srtp,  
    198                  const srtp_policy_t *p); 
     103srtp_err_status_t srtp_stream_init(srtp_stream_t srtp, const srtp_policy_t *p); 
    199104 
    200105 
     
    209114} direction_t; 
    210115 
     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 */ 
     121typedef 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 
    211135/*  
    212136 * an srtp_stream_t has its own SSRC, encryption key, authentication 
     
    214138 *  
    215139 * 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 { 
     140 * srtp_cipher_t and srtp_auth_t pointers will point to the same structures 
     141 */ 
     142 
     143typedef struct srtp_stream_ctx_t_ { 
    220144  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; 
    230151  direction_t direction; 
    231152  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_; 
    237159 
    238160 
     
    241163 */ 
    242164 
    243 typedef struct srtp_ctx_t { 
    244   srtp_stream_ctx_t *stream_list;     /* linked list of streams            */ 
    245   srtp_stream_ctx_t *stream_template; /* act as template for other streams */ 
     165typedef 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 */ 
    246168  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 
     186typedef 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 
     200typedef 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 
     215typedef 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 
     230typedef 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 
     239typedef 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 
     248typedef 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 
     257typedef 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 
    249265 
    250266 
     
    261277      srtp_event_data_t data;                       \ 
    262278      data.session = srtp;                          \ 
    263       data.stream  = strm;                          \ 
     279      data.ssrc    = ntohl(strm->ssrc);             \ 
    264280      data.event   = evnt;                          \ 
    265281      srtp_event_handler(&data);                    \ 
    266282}    
    267283 
     284#ifdef __cplusplus 
     285} 
     286#endif 
    268287 
    269288#endif /* SRTP_PRIV_H */ 
Note: See TracChangeset for help on using the changeset viewer.