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, int32 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 );
00176             ~CryptoContext();
00177 
00187             inline void
00188             setRoc(uint32 r)
00189             {roc = r;}
00190 
00199             inline uint32
00200             getRoc() const
00201             {return roc;}
00202 
00219             void srtpEncrypt( RTPPacket* rtp, uint64 index, uint32 ssrc );
00220 
00237             void srtpAuthenticate(RTPPacket* rtp, uint32 roc, uint8* tag );
00238 
00250             void deriveSrtpKeys(uint64 index);
00251 
00264             uint64 guessIndex(uint16 newSeqNumber);
00265 
00281             bool checkReplay(uint16 newSeqNumber);
00282 
00292             void update( uint16 newSeqNumber );
00293 
00299             inline int32
00300             getTagLength() const
00301             {return tagLength;}
00302 
00303 
00309             inline int32
00310             getMkiLength() const
00311             {return mkiLength;}
00312 
00318             inline uint32
00319             getSsrc() const
00320             {return ssrc;}
00321 
00344             CryptoContext* newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate);
00345 
00346         private:
00347 
00348             uint32 ssrc;
00349             bool   using_mki;
00350             uint32 mkiLength;
00351             uint8* mki;
00352 
00353             uint32 roc;
00354             uint32 guessed_roc;
00355             uint16 s_l;
00356             int64  key_deriv_rate;
00357 
00358             /* bitmask for replay check */
00359             uint64 replay_window;
00360 
00361             uint8* master_key;
00362             uint32 master_key_length;
00363             uint32 master_key_srtp_use_nb;
00364             uint32 master_key_srtcp_use_nb;
00365             uint8* master_salt;
00366             uint32 master_salt_length;
00367 
00368             /* Session Encryption, Authentication keys, Salt */
00369             int32  n_e;
00370             uint8* k_e;
00371             int32  n_a;
00372             uint8* k_a;
00373             int32  n_s;
00374             uint8* k_s;
00375 
00376             uint8 ealg;
00377             uint8 aalg;
00378             uint8 ekeyl;
00379             uint8 akeyl;
00380             uint8 skeyl;
00381             uint8 tagLength;
00382             bool  seqNumSet;
00383     };
00384 #ifdef  CCXX_NAMESPACES
00385 }
00386 #endif
00387 
00388 #endif
00389 

Generated on Wed Jan 9 22:54:39 2008 for ccRTP by  doxygen 1.5.4