Ignore:
Timestamp:
Mar 15, 2016 3:57:39 AM (8 years ago)
Author:
nanang
Message:

Close #1847: Upgraded libsrtp version to 1.5.4 and added support for AES-CM-256 crypto.

File:
1 edited

Legend:

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

    r4537 r5261  
    5151#endif 
    5252 
    53 #ifdef _MSC_VER 
    54 #   ifdef WIN64 
    55 #       pragma pack(8) 
    56 #   else 
    57 #       pragma pack(4) 
    58 #   endif 
    59 #endif 
    60  
    61 #include "crypto_kernel.h" 
     53#include <stdint.h> 
     54#include "crypto.h"  
     55#include "crypto_types.h" 
     56#include "err.h" 
    6257 
    6358/** 
     
    8580 */ 
    8681 
    87 #define SRTP_MAX_TAG_LEN 12  
     82#define SRTP_MAX_TAG_LEN 16  
    8883 
    8984/** 
     
    9691 */ 
    9792#define SRTP_MAX_TRAILER_LEN SRTP_MAX_TAG_LEN  
     93 
     94/* 
     95 * SRTP_AEAD_SALT_LEN is the length of the SALT values used with  
     96 * GCM mode.  GCM mode requires an IV.  The SALT value is used 
     97 * as part of the IV formation logic applied to each RTP packet. 
     98 */ 
     99#define SRTP_AEAD_SALT_LEN      12 
     100#define AES_128_GCM_KEYSIZE_WSALT   SRTP_AEAD_SALT_LEN + 16 
     101#define AES_192_GCM_KEYSIZE_WSALT   SRTP_AEAD_SALT_LEN + 24 
     102#define AES_256_GCM_KEYSIZE_WSALT   SRTP_AEAD_SALT_LEN + 32 
     103 
     104 
    98105 
    99106/*  
     
    177184 
    178185 
     186/** 
     187 * @brief points to an EKT policy 
     188 */ 
     189typedef struct ekt_policy_ctx_t *ekt_policy_t; 
     190 
     191 
     192/** 
     193 * @brief points to EKT stream data 
     194 */ 
     195typedef struct ekt_stream_ctx_t *ekt_stream_t; 
     196 
     197 
    179198/**  
    180199 * @brief represents the policy for an SRTP session.   
     
    214233  unsigned char *key;          /**< Pointer to the SRTP master key for 
    215234                                *    this stream.                        */ 
     235  ekt_policy_t ekt;            /**< Pointer to the EKT policy structure 
     236                                *   for this stream (if any)             */  
     237  unsigned long window_size;   /**< The window size to use for replay 
     238                                *   protection. */ 
     239  int        allow_repeat_tx;  /**< Whether retransmissions of 
     240                                *   packets with the same sequence number 
     241                                *   are allowed.  (Note that such repeated 
     242                                *   transmissions must have the same RTP 
     243                                *   payload, or a severe security weakness 
     244                                *   is introduced!)                      */ 
    216245  struct srtp_policy_t *next;  /**< Pointer to next stream policy.       */ 
    217246} srtp_policy_t; 
     
    263292 
    264293/** 
    265  * @brief srtp_deinit() deinitializes the srtp library.   
    266  * 
    267  * @warning This function @b must be called on quitting application or 
    268  * after srtp is no longer used. 
     294 * @brief srtp_shutdown() de-initializes the srtp library. 
     295 * 
     296 * @warning No srtp functions may be called after calling this function. 
    269297 */ 
    270298 
    271299err_status_t 
    272 srtp_deinit(void); 
     300srtp_shutdown(void); 
    273301 
    274302/** 
     
    292320 * boundary. 
    293321 * 
     322 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN  
     323 * into the location in memory immediately following the RTP packet.    
     324 * Callers MUST ensure that this much writable memory is available in  
     325 * the buffer that holds the RTP packet. 
     326 *  
    294327 * @param ctx is the SRTP context to use in processing the packet. 
    295328 * 
     
    330363 * 32-bit boundary. 
    331364 * 
    332  * @param ctx is a pointer to the srtp_t which applies to the 
    333  * particular packet. 
     365 * @param ctx is the SRTP session which applies to the particular packet. 
    334366 * 
    335367 * @param srtp_hdr is a pointer to the header of the SRTP packet 
     
    364396 * key. 
    365397 * 
    366  * @param session is the SRTP session to which the policy is to be added. 
     398 * @param session is a pointer to the SRTP session to which the policy is 
     399 * to be added. 
    367400 *  
    368401 * @param policy is the srtp_policy_t struct that describes the policy 
     
    479512 * The function crypto_policy_set_aes_cm_128_hmac_sha1_80() is a 
    480513 * synonym for crypto_policy_set_rtp_default().  It conforms to the 
    481  * naming convention used in 
    482  * http://www.ietf.org/internet-drafts/draft-ietf-mmusic-sdescriptions-12.txt 
     514 * naming convention used in RFC 4568 (SDP Security Descriptions for 
     515 * Media Streams). 
    483516 *  
    484517 * @return void. 
     
    497530 * The function call crypto_policy_set_aes_cm_128_hmac_sha1_32(&p) 
    498531 * sets the crypto_policy_t at location p to use policy 
    499  * AES_CM_128_HMAC_SHA1_32 as defined in 
    500  * draft-ietf-mmusic-sdescriptions-12.txt.  This policy uses AES-128 
     532 * AES_CM_128_HMAC_SHA1_32 as defined in RFC 4568. 
     533 * This policy uses AES-128 
    501534 * Counter Mode encryption and HMAC-SHA1 authentication, with an 
    502535 * authentication tag that is only 32 bits long.  This length is 
     
    582615void 
    583616crypto_policy_set_null_cipher_hmac_sha1_80(crypto_policy_t *p); 
     617 
     618 
     619/** 
     620 * @brief crypto_policy_set_aes_cm_256_hmac_sha1_80() sets a crypto 
     621 * policy structure to a encryption and authentication policy using AES-256  
     622 * for RTP protection. 
     623 * 
     624 * @param p is a pointer to the policy structure to be set  
     625 *  
     626 * The function call crypto_policy_set_aes_cm_256_hmac_sha1_80(&p) 
     627 * sets the crypto_policy_t at location p to use policy 
     628 * AES_CM_256_HMAC_SHA1_80 as defined in 
     629 * draft-ietf-avt-srtp-big-aes-03.txt.  This policy uses AES-256 
     630 * Counter Mode encryption and HMAC-SHA1 authentication, with an 80 bit 
     631 * authentication tag. 
     632 *  
     633 * This function is a convenience that helps to avoid dealing directly 
     634 * with the policy data structure.  You are encouraged to initialize 
     635 * policy elements with this function call.  Doing so may allow your 
     636 * code to be forward compatible with later versions of libSRTP that 
     637 * include more elements in the crypto_policy_t datatype. 
     638 * 
     639 * @return void. 
     640 *  
     641 */ 
     642 
     643void crypto_policy_set_aes_cm_256_hmac_sha1_80(crypto_policy_t *p); 
     644 
     645 
     646/** 
     647 * @brief crypto_policy_set_aes_cm_256_hmac_sha1_32() sets a crypto 
     648 * policy structure to a short-authentication tag policy using AES-256 
     649 * encryption. 
     650 * 
     651 * @param p is a pointer to the policy structure to be set  
     652 *  
     653 * The function call crypto_policy_set_aes_cm_256_hmac_sha1_32(&p) 
     654 * sets the crypto_policy_t at location p to use policy 
     655 * AES_CM_256_HMAC_SHA1_32 as defined in 
     656 * draft-ietf-avt-srtp-big-aes-03.txt.  This policy uses AES-256 
     657 * Counter Mode encryption and HMAC-SHA1 authentication, with an 
     658 * authentication tag that is only 32 bits long.  This length is 
     659 * considered adequate only for protecting audio and video media that 
     660 * use a stateless playback function.  See Section 7.5 of RFC 3711 
     661 * (http://www.ietf.org/rfc/rfc3711.txt). 
     662 *  
     663 * This function is a convenience that helps to avoid dealing directly 
     664 * with the policy data structure.  You are encouraged to initialize 
     665 * policy elements with this function call.  Doing so may allow your 
     666 * code to be forward compatible with later versions of libSRTP that 
     667 * include more elements in the crypto_policy_t datatype. 
     668 * 
     669 * @warning This crypto policy is intended for use in SRTP, but not in 
     670 * SRTCP.  It is recommended that a policy that uses longer 
     671 * authentication tags be used for SRTCP.  See Section 7.5 of RFC 3711 
     672 * (http://www.ietf.org/rfc/rfc3711.txt). 
     673 * 
     674 * @return void. 
     675 *  
     676 */ 
     677 
     678void 
     679crypto_policy_set_aes_cm_256_hmac_sha1_32(crypto_policy_t *p); 
     680 
     681/** 
     682 * @brief crypto_policy_set_aes_cm_256_null_auth() sets a crypto 
     683 * policy structure to an encryption-only policy 
     684 * 
     685 * @param p is a pointer to the policy structure to be set 
     686 * 
     687 * The function call crypto_policy_set_aes_cm_256_null_auth(&p) sets 
     688 * the crypto_policy_t at location p to use the SRTP default cipher 
     689 * (AES-256 Counter Mode), but to use no authentication method.  This 
     690 * policy is NOT RECOMMENDED unless it is unavoidable; see Section 7.5 
     691 * of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt). 
     692 * 
     693 * This function is a convenience that helps to avoid dealing directly 
     694 * with the policy data structure.  You are encouraged to initialize 
     695 * policy elements with this function call.  Doing so may allow your 
     696 * code to be forward compatible with later versions of libSRTP that 
     697 * include more elements in the crypto_policy_t datatype. 
     698 * 
     699 * @warning This policy is NOT RECOMMENDED for SRTP unless it is 
     700 * unavoidable, and it is NOT RECOMMENDED at all for SRTCP; see 
     701 * Section 7.5 of RFC 3711 (http://www.ietf.org/rfc/rfc3711.txt). 
     702 * 
     703 * @return void. 
     704 * 
     705 */ 
     706void 
     707crypto_policy_set_aes_cm_256_null_auth(crypto_policy_t *p); 
     708 
     709/** 
     710 * @brief crypto_policy_set_aes_gcm_128_8_auth() sets a crypto 
     711 * policy structure to an AEAD encryption policy. 
     712 * 
     713 * @param p is a pointer to the policy structure to be set  
     714 *  
     715 * The function call crypto_policy_set_aes_gcm_128_8_auth(&p) sets 
     716 * the crypto_policy_t at location p to use the SRTP default cipher 
     717 * (AES-128 Galois Counter Mode) with 8 octet auth tag.  This 
     718 * policy applies confidentiality and authentication to both the 
     719 * RTP and RTCP packets. 
     720 *  
     721 * This function is a convenience that helps to avoid dealing directly 
     722 * with the policy data structure.  You are encouraged to initialize 
     723 * policy elements with this function call.  Doing so may allow your 
     724 * code to be forward compatible with later versions of libSRTP that 
     725 * include more elements in the crypto_policy_t datatype. 
     726 * 
     727 * @return void. 
     728 *  
     729 */ 
     730void 
     731crypto_policy_set_aes_gcm_128_8_auth(crypto_policy_t *p); 
     732 
     733/** 
     734 * @brief crypto_policy_set_aes_gcm_256_8_auth() sets a crypto 
     735 * policy structure to an AEAD encryption policy 
     736 * 
     737 * @param p is a pointer to the policy structure to be set  
     738 *  
     739 * The function call crypto_policy_set_aes_gcm_256_8_auth(&p) sets 
     740 * the crypto_policy_t at location p to use the SRTP default cipher 
     741 * (AES-256 Galois Counter Mode) with 8 octet auth tag.  This  
     742 * policy applies confidentiality and authentication to both the 
     743 * RTP and RTCP packets. 
     744 *  
     745 * This function is a convenience that helps to avoid dealing directly 
     746 * with the policy data structure.  You are encouraged to initialize 
     747 * policy elements with this function call.  Doing so may allow your 
     748 * code to be forward compatible with later versions of libSRTP that 
     749 * include more elements in the crypto_policy_t datatype. 
     750 * 
     751 * @return void. 
     752 *  
     753 */ 
     754void 
     755crypto_policy_set_aes_gcm_256_8_auth(crypto_policy_t *p); 
     756 
     757/** 
     758 * @brief crypto_policy_set_aes_gcm_128_8_only_auth() sets a crypto 
     759 * policy structure to an AEAD authentication-only policy 
     760 * 
     761 * @param p is a pointer to the policy structure to be set  
     762 *  
     763 * The function call crypto_policy_set_aes_gcm_128_8_only_auth(&p) sets 
     764 * the crypto_policy_t at location p to use the SRTP default cipher 
     765 * (AES-128 Galois Counter Mode) with 8 octet auth tag.  This policy  
     766 * applies confidentiality and authentication to the RTP packets,  
     767 * but only authentication to the RTCP packets. 
     768 *  
     769 * This function is a convenience that helps to avoid dealing directly 
     770 * with the policy data structure.  You are encouraged to initialize 
     771 * policy elements with this function call.  Doing so may allow your 
     772 * code to be forward compatible with later versions of libSRTP that 
     773 * include more elements in the crypto_policy_t datatype. 
     774 * 
     775 * @return void. 
     776 *  
     777 */ 
     778void 
     779crypto_policy_set_aes_gcm_128_8_only_auth(crypto_policy_t *p); 
     780 
     781/** 
     782 * @brief crypto_policy_set_aes_gcm_256_8_only_auth() sets a crypto 
     783 * policy structure to an AEAD authentication-only policy 
     784 * 
     785 * @param p is a pointer to the policy structure to be set  
     786 *  
     787 * The function call crypto_policy_set_aes_gcm_256_8_only_auth(&p) sets 
     788 * the crypto_policy_t at location p to use the SRTP default cipher 
     789 * (AES-256 Galois Counter Mode) with 8 octet auth tag.  This policy  
     790 * applies confidentiality and authentication to the RTP packets,  
     791 * but only authentication to the RTCP packets. 
     792 *  
     793 * This function is a convenience that helps to avoid dealing directly 
     794 * with the policy data structure.  You are encouraged to initialize 
     795 * policy elements with this function call.  Doing so may allow your 
     796 * code to be forward compatible with later versions of libSRTP that 
     797 * include more elements in the crypto_policy_t datatype. 
     798 * 
     799 * @return void. 
     800 *  
     801 */ 
     802void 
     803crypto_policy_set_aes_gcm_256_8_only_auth(crypto_policy_t *p); 
     804 
     805/** 
     806 * @brief crypto_policy_set_aes_gcm_128_16_auth() sets a crypto 
     807 * policy structure to an AEAD encryption policy. 
     808 * 
     809 * @param p is a pointer to the policy structure to be set  
     810 *  
     811 * The function call crypto_policy_set_aes_gcm_128_16_auth(&p) sets 
     812 * the crypto_policy_t at location p to use the SRTP default cipher 
     813 * (AES-128 Galois Counter Mode) with 16 octet auth tag.  This 
     814 * policy applies confidentiality and authentication to both the 
     815 * RTP and RTCP packets. 
     816 *  
     817 * This function is a convenience that helps to avoid dealing directly 
     818 * with the policy data structure.  You are encouraged to initialize 
     819 * policy elements with this function call.  Doing so may allow your 
     820 * code to be forward compatible with later versions of libSRTP that 
     821 * include more elements in the crypto_policy_t datatype. 
     822 * 
     823 * @return void. 
     824 *  
     825 */ 
     826void 
     827crypto_policy_set_aes_gcm_128_16_auth(crypto_policy_t *p); 
     828 
     829/** 
     830 * @brief crypto_policy_set_aes_gcm_256_16_auth() sets a crypto 
     831 * policy structure to an AEAD encryption policy 
     832 * 
     833 * @param p is a pointer to the policy structure to be set  
     834 *  
     835 * The function call crypto_policy_set_aes_gcm_256_16_auth(&p) sets 
     836 * the crypto_policy_t at location p to use the SRTP default cipher 
     837 * (AES-256 Galois Counter Mode) with 16 octet auth tag.  This  
     838 * policy applies confidentiality and authentication to both the 
     839 * RTP and RTCP packets. 
     840 *  
     841 * This function is a convenience that helps to avoid dealing directly 
     842 * with the policy data structure.  You are encouraged to initialize 
     843 * policy elements with this function call.  Doing so may allow your 
     844 * code to be forward compatible with later versions of libSRTP that 
     845 * include more elements in the crypto_policy_t datatype. 
     846 * 
     847 * @return void. 
     848 *  
     849 */ 
     850void 
     851crypto_policy_set_aes_gcm_256_16_auth(crypto_policy_t *p); 
     852 
    584853 
    585854/** 
     
    7471016 * boundary. 
    7481017 * 
     1018 * @warning This function assumes that it can write SRTP_MAX_TRAILER_LEN+4  
     1019 * into the location in memory immediately following the RTCP packet.    
     1020 * Callers MUST ensure that this much writable memory is available in  
     1021 * the buffer that holds the RTCP packet. 
     1022 *  
    7491023 * @param ctx is the SRTP context to use in processing the packet. 
    7501024 * 
     
    8131087 * @} 
    8141088 */ 
     1089 
     1090 
     1091/** 
     1092 * @defgroup User data associated to a SRTP session. 
     1093 * @ingroup  SRTP 
     1094 * 
     1095 * @brief Store custom user data within a SRTP session. 
     1096 * 
     1097 * @{ 
     1098 */ 
     1099 
     1100/** 
     1101 * @brief srtp_set_user_data() stores the given pointer into the SRTP 
     1102 * session for later retrieval. 
     1103 * 
     1104 * @param ctx is the srtp_t context in which the given data pointer is 
     1105 * stored. 
     1106 * 
     1107 * @param data is a pointer to the custom information (struct, function, 
     1108 * etc) associated with the SRTP session. 
     1109 * 
     1110 * @return void. 
     1111 * 
     1112 */ 
     1113 
     1114void 
     1115srtp_set_user_data(srtp_t ctx, void *data); 
     1116 
     1117/** 
     1118 * @brief srtp_get_user_data() retrieves the pointer to the custom data 
     1119 * previously stored with srtp_set_user_data(). 
     1120 * 
     1121 * This function is mostly useful for retrieving data associated to a 
     1122 * SRTP session when an event fires. The user can then get such a custom 
     1123 * data by calling this function with the session field of the 
     1124 * srtp_event_data_t struct as argument. 
     1125 * 
     1126 * @param ctx is the srtp_t context in which the given data pointer was 
     1127 * stored. 
     1128 * 
     1129 * @return void* pointer to the user data. 
     1130 * 
     1131 */ 
     1132 
     1133void* 
     1134srtp_get_user_data(srtp_t ctx); 
     1135 
     1136/** 
     1137 * @} 
     1138 */ 
     1139 
    8151140 
    8161141/** 
     
    9151240 
    9161241/** 
     1242 * @brief Returns the version string of the library.  
     1243 *  
     1244 */ 
     1245const char *srtp_get_version_string(void); 
     1246 
     1247/** 
     1248 * @brief Returns the numeric representation of the library version.  
     1249 *  
     1250 */ 
     1251unsigned int srtp_get_version(void); 
     1252 
     1253/** 
    9171254 * @} 
    9181255 */ 
     
    9231260#define SRTCP_INDEX_MASK 0x7fffffff 
    9241261 
    925 #ifdef _MSC_VER 
    926 #pragma pack() 
    927 #endif 
    928  
    9291262#ifdef __cplusplus 
    9301263} 
Note: See TracChangeset for help on using the changeset viewer.