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 #define REPLAY_WINDOW_SIZE 64
00029 
00030 
00031 const int SrtpAuthenticationNull     = 0;
00032 const int SrtpAuthenticationSha1Hmac = 1;
00033 
00034 const int SrtpEncryptionNull  = 0;
00035 const int SrtpEncryptionAESCM = 1;
00036 const int SrtpEncryptionAESF8 = 2;
00037 
00038 #ifdef CCXX_NAMESPACES
00039 namespace ost {
00040 #endif
00041 
00042     class RTPPacket;
00043 
00072     class __EXPORT CryptoContext {
00073         public:
00083             CryptoContext( uint32 ssrc );
00084 
00159             CryptoContext( uint32 ssrc, int roc,
00160                            int64  keyDerivRate,
00161                            const  int32 ealg,
00162                            const  int32 aalg,
00163                            uint8* masterKey,
00164                            int32  masterKeyLength,
00165                            uint8* masterSalt,
00166                            int32  masterSaltLength,
00167                            int32  ekeyl,
00168                            int32  akeyl,
00169                            int32  skeyl,
00170                            int32  tagLength );
00171 
00177             ~CryptoContext();
00178 
00188             inline void
00189             setRoc(uint32 r)
00190             {roc = r;}
00191 
00200             inline uint32
00201             getRoc() const
00202             {return roc;}
00203 
00220             void srtpEncrypt( RTPPacket* rtp, uint64 index, uint32 ssrc );
00221 
00238             void srtpAuthenticate(RTPPacket* rtp, uint32 roc, uint8* tag );
00239 
00251             void deriveSrtpKeys(uint64 index);
00252 
00265             uint64 guessIndex(uint16 newSeqNumber);
00266 
00282             bool checkReplay(uint16 newSeqNumber);
00283 
00293             void update( uint16 newSeqNumber );
00294 
00300             inline int32
00301             getTagLength() const
00302             {return tagLength;}
00303 
00304 
00310             inline int32
00311             getMkiLength() const
00312             {return mkiLength;}
00313 
00319             inline uint32
00320             getSsrc() const
00321             {return ssrc;}
00322 
00345             CryptoContext* newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate);
00346 
00347         private:
00348 
00349             uint32 ssrc;
00350             bool   using_mki;
00351             uint32 mkiLength;
00352             uint8* mki;
00353 
00354             uint32 roc;
00355             uint32 guessed_roc;
00356             uint16 s_l;
00357             int64  key_deriv_rate;
00358 
00359             /* bitmask for replay check */
00360             uint64 replay_window;
00361 
00362             uint8* master_key;
00363             uint32 master_key_length;
00364             uint32 master_key_srtp_use_nb;
00365             uint32 master_key_srtcp_use_nb;
00366             uint8* master_salt;
00367             uint32 master_salt_length;
00368 
00369             /* Session Encryption, Authentication keys, Salt */
00370             int32  n_e;
00371             uint8* k_e;
00372             int32  n_a;
00373             uint8* k_a;
00374             int32  n_s;
00375             uint8* k_s;
00376 
00377             uint8 ealg;
00378             uint8 aalg;
00379             uint8 ekeyl;
00380             uint8 akeyl;
00381             uint8 skeyl;
00382             uint8 tagLength;
00383             bool  seqNumSet;
00384     };
00385 #ifdef  CCXX_NAMESPACES
00386 }
00387 #endif
00388 
00389 #endif
00390 

Generated on Thu Oct 12 23:08:22 2006 for ccRTP by  doxygen 1.4.7