ccRTP
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 License
00016   along with GNU ccRTP.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 
00021 #ifndef CRYPTOCONTEXTCTRL_H
00022 #define CRYPTOCONTEXTCTRL_H
00023 
00024 #include <commoncpp/config.h>
00025 
00026 #define REPLAY_WINDOW_SIZE 64
00027 
00028 #ifdef SRTP_SUPPORT
00029 #include <ccrtp/crypto/SrtpSymCrypto.h>
00030 #endif
00031 
00032 NAMESPACE_COMMONCPP
00033 
00061     class __EXPORT CryptoContextCtrl {
00062     public:
00072     CryptoContextCtrl( uint32 ssrc );
00073 
00139     CryptoContextCtrl( uint32 ssrc,
00140                const  int32 ealg,
00141                const  int32 aalg,
00142                uint8* masterKey,
00143                int32  masterKeyLength,
00144                uint8* masterSalt,
00145                int32  masterSaltLength,
00146                int32  ekeyl,
00147                int32  akeyl,
00148                int32  skeyl,
00149                int32  tagLength );
00155     ~CryptoContextCtrl();
00156 
00173     void srtcpEncrypt( uint8* rtp, size_t len, uint64 index, uint32 ssrc );
00174 
00191     void srtcpAuthenticate(uint8* rtp, size_t len, uint32 roc, uint8* tag );
00192 
00204      void deriveSrtcpKeys();
00205 
00221      bool checkReplay(uint32 newSeqNumber);
00222 
00232     void update( uint32 newSeqNumber );
00233 
00239     inline int32
00240     getTagLength() const
00241         {return tagLength;}
00242 
00243 
00249     inline int32
00250     getMkiLength() const
00251         {return mkiLength;}
00252 
00258     inline uint32
00259     getSsrc() const
00260         {return ssrcCtx;}
00261 
00283     CryptoContextCtrl* newCryptoContextForSSRC(uint32 ssrc);
00284 
00285     private:
00286 
00287         uint32 ssrcCtx;
00288         bool   using_mki;
00289         uint32 mkiLength;
00290         uint8* mki;
00291 
00292         uint32 s_l;
00293 
00294         /* bitmask for replay check */
00295         uint64 replay_window;
00296 
00297         uint8* master_key;
00298         uint32 master_key_length;
00299         uint8* master_salt;
00300         uint32 master_salt_length;
00301 
00302         /* Session Encryption, Authentication keys, Salt */
00303         int32  n_e;
00304         uint8* k_e;
00305         int32  n_a;
00306         uint8* k_a;
00307         int32  n_s;
00308         uint8* k_s;
00309 
00310         int32 ealg;
00311         int32 aalg;
00312         int32 ekeyl;
00313         int32 akeyl;
00314         int32 skeyl;
00315         int32 tagLength;
00316 
00317         void*   macCtx;
00318 
00319 #ifdef SRTP_SUPPORT
00320         SrtpSymCrypto* cipher;
00321         SrtpSymCrypto* f8Cipher;
00322 #else
00323         void* cipher;
00324         void* f8Cipher;
00325 #endif
00326 
00327     };
00328 
00329 END_NAMESPACE
00330 
00331 #endif
00332