- Main Page
- Modules
- Classes
- Files
- Examples

- File List
- File Members

# CryptoContext.h

Go to the documentation of this file.

    00001 /*
    00002   Copyright (C) 2004-2006 the Minisip Team
    00003
    00004   This library is free software; you can redistribute it and/or
    00005   modify it under the terms of the GNU Lesser General Public
    00006   License as published by the Free Software Foundation; either
    00007   version 2.1 of the License, or (at your option) any later version.
    00008
    00009   This library is distributed in the hope that it will be useful,
    00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012   Lesser General Public License for more details.
    00013
    00014   You should have received a copy of the GNU Lesser General Public
    00015   License along with this library; if not, write to the Free Software
    00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
    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 const int SrtpAuthenticationSkeinHmac = 2;
    00038
    00039 const int SrtpEncryptionNull  = 0;
    00040 const int SrtpEncryptionAESCM = 1;
    00041 const int SrtpEncryptionAESF8 = 2;
    00042 const int SrtpEncryptionTWOCM = 3;
    00043 const int SrtpEncryptionTWOF8 = 4;
    00044
    00045 #ifdef CCXX_NAMESPACES
    00046 namespace ost {
    00047 #endif
    00048
    00049     class RTPPacket;
    00050
    00079     class __EXPORT CryptoContext {
    00080         public:
    00090             CryptoContext( uint32 ssrc );
    00091
    00166             CryptoContext( uint32 ssrc, int32 roc,
    00167                            int64  keyDerivRate,
    00168                            const  int32 ealg,
    00169                            const  int32 aalg,
    00170                            uint8* masterKey,
    00171                            int32  masterKeyLength,
    00172                            uint8* masterSalt,
    00173                            int32  masterSaltLength,
    00174                            int32  ekeyl,
    00175                            int32  akeyl,
    00176                            int32  skeyl,
    00177                            int32  tagLength );
    00183             ~CryptoContext();
    00184
    00194             inline void
    00195             setRoc(uint32 r)
    00196             {roc = r;}
    00197
    00206             inline uint32
    00207             getRoc() const
    00208             {return roc;}
    00209
    00226             void srtpEncrypt( RTPPacket* rtp, uint64 index, uint32 ssrc );
    00227
    00244             void srtpAuthenticate(RTPPacket* rtp, uint32 roc, uint8* tag );
    00245
    00257             void deriveSrtpKeys(uint64 index);
    00258
    00271             uint64 guessIndex(uint16 newSeqNumber);
    00272
    00288             bool checkReplay(uint16 newSeqNumber);
    00289
    00299             void update( uint16 newSeqNumber );
    00300
    00306             inline int32
    00307             getTagLength() const
    00308             {return tagLength;}
    00309
    00310
    00316             inline int32
    00317             getMkiLength() const
    00318             {return mkiLength;}
    00319
    00325             inline uint32
    00326             getSsrc() const
    00327             {return ssrc;}
    00328
    00351             CryptoContext* newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate);
    00352
    00353         private:
    00354
    00355             uint32 ssrc;
    00356             bool   using_mki;
    00357             uint32 mkiLength;
    00358             uint8* mki;
    00359
    00360             uint32 roc;
    00361             uint32 guessed_roc;
    00362             uint16 s_l;
    00363             int64  key_deriv_rate;
    00364
    00365             /* bitmask for replay check */
    00366             uint64 replay_window;
    00367
    00368             uint8* master_key;
    00369             uint32 master_key_length;
    00370             uint32 master_key_srtp_use_nb;
    00371             uint32 master_key_srtcp_use_nb;
    00372             uint8* master_salt;
    00373             uint32 master_salt_length;
    00374
    00375             /* Session Encryption, Authentication keys, Salt */
    00376             int32  n_e;
    00377             uint8* k_e;
    00378             int32  n_a;
    00379             uint8* k_a;
    00380             int32  n_s;
    00381             uint8* k_s;
    00382
    00383             int32 ealg;
    00384             int32 aalg;
    00385             int32 ekeyl;
    00386             int32 akeyl;
    00387             int32 skeyl;
    00388             int32 tagLength;
    00389             bool  seqNumSet;
    00390
    00391         void*   macCtx;
    00392
    00393 #ifdef SRTP_SUPPORT
    00394             AesSrtp* aesCipher;
    00395             AesSrtp* f8AesCipher;
    00396 #else
    00397             void* aesCipher;
    00398             void* f8AesCipher;
    00399 #endif
    00400
    00401     };
    00402 #ifdef  CCXX_NAMESPACES
    00403 }
    00404 #endif
    00405
    00406 #endif
    00407