Bayonne2 / Common C++ 2 Framework
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CryptoContext.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004-2006 the Minisip Team
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
19 
20 
21 #ifndef CRYPTOCONTEXT_H
22 #define CRYPTOCONTEXT_H
23 
24 #include <cc++/config.h>
25 
26 #include <ccrtp/rtppkt.h>
27 
28 #ifdef SRTP_SUPPORT
29 #include <ccrtp/crypto/AesSrtp.h>
30 #endif
31 
32 #define REPLAY_WINDOW_SIZE 64
33 
34 
35 const int SrtpAuthenticationNull = 0;
37 
38 const int SrtpEncryptionNull = 0;
39 const int SrtpEncryptionAESCM = 1;
40 const int SrtpEncryptionAESF8 = 2;
41 
42 #ifdef CCXX_NAMESPACES
43 namespace ost {
44 #endif
45 
46  class RTPPacket;
47 
77  public:
87  CryptoContext( uint32 ssrc );
88 
163  CryptoContext( uint32 ssrc, int32 roc,
164  int64 keyDerivRate,
165  const int32 ealg,
166  const int32 aalg,
167  uint8* masterKey,
168  int32 masterKeyLength,
169  uint8* masterSalt,
170  int32 masterSaltLength,
171  int32 ekeyl,
172  int32 akeyl,
173  int32 skeyl,
174  int32 tagLength );
180  ~CryptoContext();
181 
191  inline void
192  setRoc(uint32 r)
193  {roc = r;}
194 
203  inline uint32
204  getRoc() const
205  {return roc;}
206 
223  void srtpEncrypt( RTPPacket* rtp, uint64 index, uint32 ssrc );
224 
241  void srtpAuthenticate(RTPPacket* rtp, uint32 roc, uint8* tag );
242 
254  void deriveSrtpKeys(uint64 index);
255 
268  uint64 guessIndex(uint16 newSeqNumber);
269 
285  bool checkReplay(uint16 newSeqNumber);
286 
296  void update( uint16 newSeqNumber );
297 
303  inline int32
304  getTagLength() const
305  {return tagLength;}
306 
307 
313  inline int32
314  getMkiLength() const
315  {return mkiLength;}
316 
322  inline uint32
323  getSsrc() const
324  {return ssrc;}
325 
348  CryptoContext* newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate);
349 
350  private:
351 
352  uint32 ssrc;
353  bool using_mki;
354  uint32 mkiLength;
355  uint8* mki;
356 
357  uint32 roc;
358  uint32 guessed_roc;
359  uint16 s_l;
361 
362  /* bitmask for replay check */
364 
365  uint8* master_key;
369  uint8* master_salt;
371 
372  /* Session Encryption, Authentication keys, Salt */
373  int32 n_e;
374  uint8* k_e;
375  int32 n_a;
376  uint8* k_a;
377  int32 n_s;
378  uint8* k_s;
379 
380  uint8 ealg;
381  uint8 aalg;
382  uint8 ekeyl;
383  uint8 akeyl;
384  uint8 skeyl;
385  uint8 tagLength;
386  bool seqNumSet;
387 
388 #ifdef SRTP_SUPPORT
389  AesSrtp* aesCipher;
390  AesSrtp* f8AesCipher;
391 #else
392  void* aesCipher;
393  void* f8AesCipher;
394 #endif
395 
396  };
397 #ifdef CCXX_NAMESPACES
398 }
399 #endif
400 
401 #endif
402 
uint64 replay_window
A base class for both IncomingRTPPkt and OutgoingRTPPkt.
Definition: rtppkt.h:75
int32 getMkiLength() const
Get the length of the MKI in bytes.
The implementation for a SRTP cryptographic context.
Definition: CryptoContext.h:76
void setRoc(uint32 r)
Set the Roll-Over-Counter.
uint32 master_key_srtcp_use_nb
const int SrtpEncryptionAESF8
Definition: CryptoContext.h:40
uint32 getRoc() const
Get the Roll-Over-Counter.
uint32 master_key_length
uint32 master_salt_length
uint32 guessed_roc
int64 key_deriv_rate
#define __EXPORT
Definition: audio2.h:51
uint8 * master_key
const int SrtpEncryptionNull
Definition: CryptoContext.h:38
int32 getTagLength() const
Get the length of the SRTP authentication tag in bytes.
const int SrtpAuthenticationSha1Hmac
Definition: CryptoContext.h:36
void * f8AesCipher
uint32 getSsrc() const
Get the SSRC of this SRTP Cryptograhic context.
uint8 * master_salt
const int SrtpAuthenticationNull
Definition: CryptoContext.h:35
uint32 master_key_srtp_use_nb
const int SrtpEncryptionAESCM
Definition: CryptoContext.h:39
RTP packets handling.