Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CryptoContextCtrl.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004-2006 the Minisip Team
3  Copyright (C) 2011 Werner Dittmann for the SRTCP support
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 
21 #ifndef CRYPTOCONTEXTCTRL_H
22 #define CRYPTOCONTEXTCTRL_H
23 
24 #include <commoncpp/config.h>
25 
26 #define REPLAY_WINDOW_SIZE 64
27 
28 #ifdef SRTP_SUPPORT
29 #include <ccrtp/crypto/SrtpSymCrypto.h>
30 #endif
31 
32 NAMESPACE_COMMONCPP
33 
62  public:
72  CryptoContextCtrl( uint32 ssrc );
73 
139  CryptoContextCtrl( uint32 ssrc,
140  const int32 ealg,
141  const int32 aalg,
142  uint8* masterKey,
143  int32 masterKeyLength,
144  uint8* masterSalt,
145  int32 masterSaltLength,
146  int32 ekeyl,
147  int32 akeyl,
148  int32 skeyl,
149  int32 tagLength );
156 
173  void srtcpEncrypt( uint8* rtp, size_t len, uint64 index, uint32 ssrc );
174 
191  void srtcpAuthenticate(uint8* rtp, size_t len, uint32 roc, uint8* tag );
192 
204  void deriveSrtcpKeys();
205 
221  bool checkReplay(uint32 newSeqNumber);
222 
232  void update( uint32 newSeqNumber );
233 
239  inline int32
240  getTagLength() const
241  {return tagLength;}
242 
243 
249  inline int32
250  getMkiLength() const
251  {return mkiLength;}
252 
258  inline uint32
259  getSsrc() const
260  {return ssrcCtx;}
261 
283  CryptoContextCtrl* newCryptoContextForSSRC(uint32 ssrc);
284 
285  private:
286 
287  uint32 ssrcCtx;
288  bool using_mki;
289  uint32 mkiLength;
290  uint8* mki;
291 
292  uint32 s_l;
293 
294  /* bitmask for replay check */
296 
297  uint8* master_key;
299  uint8* master_salt;
301 
302  /* Session Encryption, Authentication keys, Salt */
303  int32 n_e;
304  uint8* k_e;
305  int32 n_a;
306  uint8* k_a;
307  int32 n_s;
308  uint8* k_s;
309 
310  int32 ealg;
311  int32 aalg;
312  int32 ekeyl;
313  int32 akeyl;
314  int32 skeyl;
315  int32 tagLength;
316 
317  void* macCtx;
318 
319 #ifdef SRTP_SUPPORT
320  SrtpSymCrypto* cipher;
321  SrtpSymCrypto* f8Cipher;
322 #else
323  void* cipher;
324  void* f8Cipher;
325 #endif
326 
327  };
328 
329 END_NAMESPACE
330 
331 #endif
332 
The implementation for a SRTCP cryptographic context.
int32 getTagLength() const
Get the length of the SRTP authentication tag in bytes.
uint32 getSsrc() const
Get the SSRC of this SRTP Cryptograhic context.
#define __EXPORT
Definition: audio2.h:51
int32 getMkiLength() const
Get the length of the MKI in bytes.