00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef CRYPTOCONTEXT_H
00021 #define CRYPTOCONTEXT_H
00022
00023 #include <commoncpp/config.h>
00024
00025 #include <ccrtp/rtppkt.h>
00026
00027
00028 #define REPLAY_WINDOW_SIZE 64
00029
00030 const int SrtpAuthenticationNull = 0;
00031 const int SrtpAuthenticationSha1Hmac = 1;
00032 const int SrtpAuthenticationSkeinHmac = 2;
00033
00034 const int SrtpEncryptionNull = 0;
00035 const int SrtpEncryptionAESCM = 1;
00036 const int SrtpEncryptionAESF8 = 2;
00037 const int SrtpEncryptionTWOCM = 3;
00038 const int SrtpEncryptionTWOF8 = 4;
00039
00040 #ifndef CRYPTOCONTEXTCTRL_H
00041
00042 #include <stdint.h>
00043
00044 #ifdef SRTP_SUPPORT
00045 #include <ccrtp/crypto/SrtpSymCrypto.h>
00046 #endif
00047
00048 class SrtpSymCrypto;
00049
00050 NAMESPACE_COMMONCPP
00051
00052 class RTPPacket;
00053
00082 class __EXPORT CryptoContext {
00083 public:
00093 CryptoContext( uint32 ssrc );
00094
00169 CryptoContext( uint32 ssrc, int32 roc,
00170 int64 keyDerivRate,
00171 const int32 ealg,
00172 const int32 aalg,
00173 uint8* masterKey,
00174 int32 masterKeyLength,
00175 uint8* masterSalt,
00176 int32 masterSaltLength,
00177 int32 ekeyl,
00178 int32 akeyl,
00179 int32 skeyl,
00180 int32 tagLength );
00186 ~CryptoContext();
00187
00197 inline void
00198 setRoc(uint32 r)
00199 {roc = r;}
00200
00209 inline uint32
00210 getRoc() const
00211 {return roc;}
00212
00229 void srtpEncrypt( RTPPacket* rtp, uint64 index, uint32 ssrc );
00230
00247 void srtpAuthenticate(RTPPacket* rtp, uint32 roc, uint8* tag );
00248
00260 void deriveSrtpKeys(uint64 index);
00261
00274 uint64 guessIndex(uint16 newSeqNumber);
00275
00291 bool checkReplay(uint16 newSeqNumber);
00292
00302 void update( uint16 newSeqNumber );
00303
00309 inline int32
00310 getTagLength() const
00311 {return tagLength;}
00312
00313
00319 inline int32
00320 getMkiLength() const
00321 {return mkiLength;}
00322
00328 inline uint32
00329 getSsrc() const
00330 {return ssrcCtx;}
00331
00353 CryptoContext* newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate);
00354
00355 private:
00356
00357 uint32 ssrcCtx;
00358 bool using_mki;
00359 uint32 mkiLength;
00360 uint8* mki;
00361
00362 uint32 roc;
00363 uint32 guessed_roc;
00364 uint16 s_l;
00365 int64 key_deriv_rate;
00366
00367
00368 uint64 replay_window;
00369
00370 uint8* master_key;
00371 uint32 master_key_length;
00372 uint32 master_key_srtp_use_nb;
00373 uint32 master_key_srtcp_use_nb;
00374 uint8* master_salt;
00375 uint32 master_salt_length;
00376
00377
00378 int32 n_e;
00379 uint8* k_e;
00380 int32 n_a;
00381 uint8* k_a;
00382 int32 n_s;
00383 uint8* k_s;
00384
00385 int32 ealg;
00386 int32 aalg;
00387 int32 ekeyl;
00388 int32 akeyl;
00389 int32 skeyl;
00390 int32 tagLength;
00391 bool seqNumSet;
00392
00393 void* macCtx;
00394
00395 #ifdef SRTP_SUPPORT
00396 SrtpSymCrypto* cipher;
00397 SrtpSymCrypto* f8Cipher;
00398 #else
00399 void* cipher;
00400 void* f8Cipher;
00401 #endif
00402
00403 };
00404
00405 END_NAMESPACE
00406
00407 #endif
00408
00409 #endif
00410