ccRTP
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
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 
21 
22 #ifndef CRYPTOCONTEXTCTRL_H
23 #define CRYPTOCONTEXTCTRL_H
24 
25 #include <commoncpp/config.h>
26 
27 #define REPLAY_WINDOW_SIZE 64
28 
29 #ifdef SRTP_SUPPORT
30 #include <ccrtp/crypto/SrtpSymCrypto.h>
31 #endif
32 
33 NAMESPACE_COMMONCPP
34 
62  class __EXPORT CryptoContextCtrl {
63  public:
73  CryptoContextCtrl( uint32 ssrc );
74 
140  CryptoContextCtrl( uint32 ssrc,
141  const int32 ealg,
142  const int32 aalg,
143  uint8* masterKey,
144  int32 masterKeyLength,
145  uint8* masterSalt,
146  int32 masterSaltLength,
147  int32 ekeyl,
148  int32 akeyl,
149  int32 skeyl,
150  int32 tagLength );
157 
174  void srtcpEncrypt( uint8* rtp, size_t len, uint64 index, uint32 ssrc );
175 
192  void srtcpAuthenticate(uint8* rtp, size_t len, uint32 roc, uint8* tag );
193 
205  void deriveSrtcpKeys();
206 
222  bool checkReplay(uint32 newSeqNumber);
223 
233  void update( uint32 newSeqNumber );
234 
240  inline int32
241  getTagLength() const
242  {return tagLength;}
243 
244 
250  inline int32
251  getMkiLength() const
252  {return mkiLength;}
253 
259  inline uint32
260  getSsrc() const
261  {return ssrcCtx;}
262 
284  CryptoContextCtrl* newCryptoContextForSSRC(uint32 ssrc);
285 
286  private:
287 
288  uint32 ssrcCtx;
289  bool using_mki;
290  uint32 mkiLength;
291  uint8* mki;
292 
293  uint32 s_l;
294 
295  /* bitmask for replay check */
296  uint64 replay_window;
297 
298  uint8* master_key;
299  uint32 master_key_length;
300  uint8* master_salt;
301  uint32 master_salt_length;
302 
303  /* Session Encryption, Authentication keys, Salt */
304  int32 n_e;
305  uint8* k_e;
306  int32 n_a;
307  uint8* k_a;
308  int32 n_s;
309  uint8* k_s;
310 
311  int32 ealg;
312  int32 aalg;
313  int32 ekeyl;
314  int32 akeyl;
315  int32 skeyl;
316  int32 tagLength;
317 
318  void* macCtx;
319 
320 #ifdef SRTP_SUPPORT
321  SrtpSymCrypto* cipher;
322  SrtpSymCrypto* f8Cipher;
323 #else
324  void* cipher;
325  void* f8Cipher;
326 #endif
327 
328  };
329 
330 END_NAMESPACE
331 
332 #endif
333 
uint32 getSsrc() const
Get the SSRC of this SRTP Cryptograhic context.
Definition: CryptoContextCtrl.h:260
The implementation for a SRTCP cryptographic context.
Definition: CryptoContextCtrl.h:62
int32 getTagLength() const
Get the length of the SRTP authentication tag in bytes.
Definition: CryptoContextCtrl.h:241
int32 getMkiLength() const
Get the length of the MKI in bytes.
Definition: CryptoContextCtrl.h:251