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 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 
61  class __EXPORT CryptoContextCtrl {
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 
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 
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 */
295  uint64 replay_window;
296 
297  uint8* master_key;
298  uint32 master_key_length;
299  uint8* master_salt;
300  uint32 master_salt_length;
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 
CryptoContextCtrl::update
void update(uint32 newSeqNumber)
Update the SRTP packet index.
CryptoContextCtrl::~CryptoContextCtrl
~CryptoContextCtrl()
Destructor.
CryptoContextCtrl::getMkiLength
int32 getMkiLength() const
Get the length of the MKI in bytes.
Definition: CryptoContextCtrl.h:250
CryptoContextCtrl::CryptoContextCtrl
CryptoContextCtrl(uint32 ssrc)
Constructor for empty SRTP cryptographic context.
CryptoContextCtrl::getTagLength
int32 getTagLength() const
Get the length of the SRTP authentication tag in bytes.
Definition: CryptoContextCtrl.h:240
CryptoContextCtrl::newCryptoContextForSSRC
CryptoContextCtrl * newCryptoContextForSSRC(uint32 ssrc)
Derive a new Crypto Context for use with a new SSRC.
CryptoContextCtrl
The implementation for a SRTCP cryptographic context.
Definition: CryptoContextCtrl.h:61
CryptoContextCtrl::srtcpAuthenticate
void srtcpAuthenticate(uint8 *rtp, size_t len, uint32 roc, uint8 *tag)
Compute the authentication tag.
CryptoContextCtrl::getSsrc
uint32 getSsrc() const
Get the SSRC of this SRTP Cryptograhic context.
Definition: CryptoContextCtrl.h:259
CryptoContextCtrl::deriveSrtcpKeys
void deriveSrtcpKeys()
Perform key derivation according to SRTP specification.
CryptoContextCtrl::CryptoContextCtrl
CryptoContextCtrl(uint32 ssrc, const int32 ealg, const int32 aalg, uint8 *masterKey, int32 masterKeyLength, uint8 *masterSalt, int32 masterSaltLength, int32 ekeyl, int32 akeyl, int32 skeyl, int32 tagLength)
Constructor for an active SRTP cryptographic context.
CryptoContextCtrl::checkReplay
bool checkReplay(uint32 newSeqNumber)
Check for packet replay.
CryptoContextCtrl::srtcpEncrypt
void srtcpEncrypt(uint8 *rtp, size_t len, uint64 index, uint32 ssrc)
Perform SRTP encryption.