00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CRYPTOCONTEXT_H
00022 #define CRYPTOCONTEXT_H
00023
00024 #include <cc++/config.h>
00025
00026 #include <ccrtp/rtppkt.h>
00027
00028 #ifdef SRTP_SUPPORT
00029 #include <ccrtp/crypto/AesSrtp.h>
00030 #endif
00031
00032 #define REPLAY_WINDOW_SIZE 64
00033
00034
00035 const int SrtpAuthenticationNull = 0;
00036 const int SrtpAuthenticationSha1Hmac = 1;
00037
00038 const int SrtpEncryptionNull = 0;
00039 const int SrtpEncryptionAESCM = 1;
00040 const int SrtpEncryptionAESF8 = 2;
00041
00042 #ifdef CCXX_NAMESPACES
00043 namespace ost {
00044 #endif
00045
00046 class RTPPacket;
00047
00076 class __EXPORT CryptoContext {
00077 public:
00087 CryptoContext( uint32 ssrc );
00088
00163 CryptoContext( uint32 ssrc, int32 roc,
00164 int64 keyDerivRate,
00165 const int32 ealg,
00166 const int32 aalg,
00167 uint8* masterKey,
00168 int32 masterKeyLength,
00169 uint8* masterSalt,
00170 int32 masterSaltLength,
00171 int32 ekeyl,
00172 int32 akeyl,
00173 int32 skeyl,
00174 int32 tagLength );
00180 ~CryptoContext();
00181
00191 inline void
00192 setRoc(uint32 r)
00193 {roc = r;}
00194
00203 inline uint32
00204 getRoc() const
00205 {return roc;}
00206
00223 void srtpEncrypt( RTPPacket* rtp, uint64 index, uint32 ssrc );
00224
00241 void srtpAuthenticate(RTPPacket* rtp, uint32 roc, uint8* tag );
00242
00254 void deriveSrtpKeys(uint64 index);
00255
00268 uint64 guessIndex(uint16 newSeqNumber);
00269
00285 bool checkReplay(uint16 newSeqNumber);
00286
00296 void update( uint16 newSeqNumber );
00297
00303 inline int32
00304 getTagLength() const
00305 {return tagLength;}
00306
00307
00313 inline int32
00314 getMkiLength() const
00315 {return mkiLength;}
00316
00322 inline uint32
00323 getSsrc() const
00324 {return ssrc;}
00325
00348 CryptoContext* newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate);
00349
00350 private:
00351
00352 uint32 ssrc;
00353 bool using_mki;
00354 uint32 mkiLength;
00355 uint8* mki;
00356
00357 uint32 roc;
00358 uint32 guessed_roc;
00359 uint16 s_l;
00360 int64 key_deriv_rate;
00361
00362
00363 uint64 replay_window;
00364
00365 uint8* master_key;
00366 uint32 master_key_length;
00367 uint32 master_key_srtp_use_nb;
00368 uint32 master_key_srtcp_use_nb;
00369 uint8* master_salt;
00370 uint32 master_salt_length;
00371
00372
00373 int32 n_e;
00374 uint8* k_e;
00375 int32 n_a;
00376 uint8* k_a;
00377 int32 n_s;
00378 uint8* k_s;
00379
00380 uint8 ealg;
00381 uint8 aalg;
00382 uint8 ekeyl;
00383 uint8 akeyl;
00384 uint8 skeyl;
00385 uint8 tagLength;
00386 bool seqNumSet;
00387
00388 #ifdef SRTP_SUPPORT
00389 AesSrtp* aesCipher;
00390 AesSrtp* f8AesCipher;
00391 #else
00392 void* aesCipher;
00393 void* f8AesCipher;
00394 #endif
00395
00396 };
00397 #ifdef CCXX_NAMESPACES
00398 }
00399 #endif
00400
00401 #endif
00402