/src/mozilla-central/media/mtransport/SrtpFlow.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
3 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | // Original author: ekr@rtfm.com |
6 | | |
7 | | #ifndef srtpflow_h__ |
8 | | #define srtpflow_h__ |
9 | | |
10 | | #include "mozilla/RefPtr.h" |
11 | | #include "nsISupportsImpl.h" |
12 | | #include "srtp.h" |
13 | | |
14 | | namespace mozilla { |
15 | | |
16 | 0 | #define SRTP_ICM_MASTER_KEY_LENGTH 16 |
17 | 0 | #define SRTP_ICM_MASTER_SALT_LENGTH 14 |
18 | 0 | #define SRTP_ICM_MAX_MASTER_LEGNTH (SRTP_ICM_MASTER_KEY_LENGTH + SRTP_ICM_MASTER_SALT_LENGTH) |
19 | 0 | #define SRTP_GCM_MASTER_KEY_LENGTH 32 |
20 | 0 | #define SRTP_GCM_MASTER_SALT_LENGTH 12 |
21 | 0 | #define SRTP_GCM_MAX_MASTER_LEGNTH (SRTP_GCM_MASTER_KEY_LENGTH + SRTP_GCM_MASTER_SALT_LENGTH) |
22 | | |
23 | 0 | #define SRTP_MIN_KEY_LENGTH SRTP_ICM_MAX_MASTER_LEGNTH |
24 | 0 | #define SRTP_MAX_KEY_LENGTH SRTP_GCM_MAX_MASTER_LEGNTH |
25 | | |
26 | | // SRTCP requires an auth tag *plus* a 4-byte index-plus-'E'-bit value (see |
27 | | // RFC 3711) |
28 | 0 | #define SRTP_MAX_EXPANSION (SRTP_MAX_TRAILER_LEN+4) |
29 | | |
30 | | |
31 | | class SrtpFlow { |
32 | | ~SrtpFlow(); |
33 | | public: |
34 | | |
35 | | static unsigned int KeySize(int cipher_suite); |
36 | | static unsigned int SaltSize(int cipher_suite); |
37 | | |
38 | | static RefPtr<SrtpFlow> Create(int cipher_suite, |
39 | | bool inbound, |
40 | | const void *key, |
41 | | size_t key_len); |
42 | | |
43 | | nsresult ProtectRtp(void *in, int in_len, |
44 | | int max_len, int *out_len); |
45 | | nsresult UnprotectRtp(void *in, int in_len, |
46 | | int max_len, int *out_len); |
47 | | nsresult ProtectRtcp(void *in, int in_len, |
48 | | int max_len, int *out_len); |
49 | | nsresult UnprotectRtcp(void *in, int in_len, |
50 | | int max_len, int *out_len); |
51 | | |
52 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SrtpFlow) |
53 | | |
54 | | static void srtp_event_handler(srtp_event_data_t *data); |
55 | | |
56 | | |
57 | | private: |
58 | 0 | SrtpFlow() : session_(nullptr) {} |
59 | | |
60 | | nsresult CheckInputs(bool protect, void *in, int in_len, |
61 | | int max_len, int *out_len); |
62 | | |
63 | | static nsresult Init(); |
64 | | static bool initialized; // Was libsrtp initialized? Only happens once. |
65 | | |
66 | | srtp_t session_; |
67 | | }; |
68 | | |
69 | | } // End of namespace |
70 | | #endif |
71 | | |