michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Original author: ekr@rtfm.com michael@0: michael@0: #ifndef srtpflow_h__ michael@0: #define srtpflow_h__ michael@0: michael@0: #include "ssl.h" michael@0: #include "sslproto.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "nsISupportsImpl.h" michael@0: michael@0: typedef struct srtp_policy_t srtp_policy_t; michael@0: typedef struct srtp_ctx_t *srtp_t; michael@0: typedef struct srtp_event_data_t srtp_event_data_t; michael@0: michael@0: namespace mozilla { michael@0: michael@0: #define SRTP_MASTER_KEY_LENGTH 16 michael@0: #define SRTP_MASTER_SALT_LENGTH 14 michael@0: #define SRTP_TOTAL_KEY_LENGTH (SRTP_MASTER_KEY_LENGTH + SRTP_MASTER_SALT_LENGTH) michael@0: michael@0: // For some reason libsrtp increases packet size by > 12 for RTCP even though michael@0: // the doc claims otherwise. michael@0: #define SRTP_MAX_EXPANSION 20 michael@0: michael@0: michael@0: class SrtpFlow { michael@0: public: michael@0: ~SrtpFlow(); michael@0: michael@0: michael@0: static mozilla::RefPtr Create(int cipher_suite, michael@0: bool inbound, michael@0: const void *key, michael@0: size_t key_len); michael@0: michael@0: nsresult ProtectRtp(void *in, int in_len, michael@0: int max_len, int *out_len); michael@0: nsresult UnprotectRtp(void *in, int in_len, michael@0: int max_len, int *out_len); michael@0: nsresult ProtectRtcp(void *in, int in_len, michael@0: int max_len, int *out_len); michael@0: nsresult UnprotectRtcp(void *in, int in_len, michael@0: int max_len, int *out_len); michael@0: michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SrtpFlow) michael@0: michael@0: static void srtp_event_handler(srtp_event_data_t *data); michael@0: michael@0: michael@0: private: michael@0: SrtpFlow() : session_(nullptr) {} michael@0: michael@0: nsresult CheckInputs(bool protect, void *in, int in_len, michael@0: int max_len, int *out_len); michael@0: michael@0: static nsresult Init(); michael@0: static bool initialized; // Was libsrtp initialized? Only happens once. michael@0: michael@0: srtp_t session_; michael@0: }; michael@0: michael@0: } // End of namespace michael@0: #endif michael@0: