CryptoContextCtrl.h

Go to the documentation of this file.
00001 /*
00002   Copyright (C) 2004-2006 the Minisip Team
00003   Copyright (C) 2011 Werner Dittmann for the SRTCP support
00004   
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009 
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 */
00019 
00020 
00021 
00022 #ifndef CRYPTOCONTEXTCTRL_H
00023 #define CRYPTOCONTEXTCTRL_H
00024 
00025 #include <commoncpp/config.h>
00026 
00027 #define REPLAY_WINDOW_SIZE 64
00028 
00029 #ifdef SRTP_SUPPORT
00030 #include <ccrtp/crypto/SrtpSymCrypto.h>
00031 #endif
00032 
00033 NAMESPACE_COMMONCPP
00034 
00062     class __EXPORT CryptoContextCtrl {
00063     public:
00073     CryptoContextCtrl( uint32 ssrc );
00074 
00140     CryptoContextCtrl( uint32 ssrc,
00141                const  int32 ealg,
00142                const  int32 aalg,
00143                uint8* masterKey,
00144                int32  masterKeyLength,
00145                uint8* masterSalt,
00146                int32  masterSaltLength,
00147                int32  ekeyl,
00148                int32  akeyl,
00149                int32  skeyl,
00150                int32  tagLength );
00156     ~CryptoContextCtrl();
00157 
00174     void srtcpEncrypt( uint8* rtp, size_t len, uint64 index, uint32 ssrc );
00175 
00192     void srtcpAuthenticate(uint8* rtp, size_t len, uint32 roc, uint8* tag );
00193 
00205      void deriveSrtcpKeys();
00206 
00222      bool checkReplay(uint32 newSeqNumber);
00223 
00233     void update( uint32 newSeqNumber );
00234 
00240     inline int32
00241     getTagLength() const
00242         {return tagLength;}
00243 
00244 
00250     inline int32
00251     getMkiLength() const
00252         {return mkiLength;}
00253 
00259     inline uint32
00260     getSsrc() const
00261         {return ssrcCtx;}
00262 
00284     CryptoContextCtrl* newCryptoContextForSSRC(uint32 ssrc);
00285 
00286     private:
00287 
00288         uint32 ssrcCtx;
00289         bool   using_mki;
00290         uint32 mkiLength;
00291         uint8* mki;
00292 
00293         uint32 s_l;
00294 
00295         /* bitmask for replay check */
00296         uint64 replay_window;
00297 
00298         uint8* master_key;
00299         uint32 master_key_length;
00300         uint8* master_salt;
00301         uint32 master_salt_length;
00302 
00303         /* Session Encryption, Authentication keys, Salt */
00304         int32  n_e;
00305         uint8* k_e;
00306         int32  n_a;
00307         uint8* k_a;
00308         int32  n_s;
00309         uint8* k_s;
00310 
00311         int32 ealg;
00312         int32 aalg;
00313         int32 ekeyl;
00314         int32 akeyl;
00315         int32 skeyl;
00316         int32 tagLength;
00317 
00318         void*   macCtx;
00319 
00320 #ifdef SRTP_SUPPORT
00321         SrtpSymCrypto* cipher;
00322         SrtpSymCrypto* f8Cipher;
00323 #else
00324         void* cipher;
00325         void* f8Cipher;
00326 #endif
00327 
00328     };
00329 
00330 END_NAMESPACE
00331 
00332 #endif
00333 

Generated on 14 Aug 2013 for ccRTP by  doxygen 1.4.7