CryptoContextCtrl.h
Go to the documentation of this file.
/*
Copyright (C) 2004-2006 the Minisip Team
Copyright (C) 2011 Werner Dittmann for the SRTCP support
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CRYPTOCONTEXTCTRL_H
#define CRYPTOCONTEXTCTRL_H
#include <commoncpp/config.h>
#define REPLAY_WINDOW_SIZE 64
#ifdef SRTP_SUPPORT
#include <ccrtp/crypto/SrtpSymCrypto.h>
#endif
NAMESPACE_COMMONCPP
class __EXPORT CryptoContextCtrl {
public:
CryptoContextCtrl( uint32 ssrc );
CryptoContextCtrl( uint32 ssrc,
const int32 ealg,
const int32 aalg,
uint8* masterKey,
int32 masterKeyLength,
uint8* masterSalt,
int32 masterSaltLength,
int32 ekeyl,
int32 akeyl,
int32 skeyl,
int32 tagLength );
~CryptoContextCtrl();
void srtcpEncrypt( uint8* rtp, size_t len, uint64 index, uint32 ssrc );
void srtcpAuthenticate(uint8* rtp, size_t len, uint32 roc, uint8* tag );
void deriveSrtcpKeys();
bool checkReplay(uint32 newSeqNumber);
void update( uint32 newSeqNumber );
inline int32
getTagLength() const
{return tagLength;}
inline int32
getMkiLength() const
{return mkiLength;}
inline uint32
getSsrc() const
{return ssrcCtx;}
CryptoContextCtrl* newCryptoContextForSSRC(uint32 ssrc);
private:
uint32 ssrcCtx;
bool using_mki;
uint32 mkiLength;
uint8* mki;
uint32 s_l;
/* bitmask for replay check */
uint64 replay_window;
uint8* master_key;
uint32 master_key_length;
uint8* master_salt;
uint32 master_salt_length;
/* Session Encryption, Authentication keys, Salt */
int32 n_e;
uint8* k_e;
int32 n_a;
uint8* k_a;
int32 n_s;
uint8* k_s;
int32 ealg;
int32 aalg;
int32 ekeyl;
int32 akeyl;
int32 skeyl;
int32 tagLength;
void* macCtx;
#ifdef SRTP_SUPPORT
SrtpSymCrypto* cipher;
SrtpSymCrypto* f8Cipher;
#else
void* cipher;
void* f8Cipher;
#endif
};
END_NAMESPACE
#endif
CryptoContextCtrl::CryptoContextCtrl
CryptoContextCtrl(uint32 ssrc)
Constructor for empty SRTP cryptographic context.
CryptoContextCtrl::checkReplay
bool checkReplay(uint32 newSeqNumber)
Check for packet replay.
CryptoContextCtrl::deriveSrtcpKeys
void deriveSrtcpKeys()
Perform key derivation according to SRTP specification.
CryptoContextCtrl::getTagLength
int32 getTagLength() const
Get the length of the SRTP authentication tag in bytes.
Definition CryptoContextCtrl.h:241
CryptoContextCtrl::getSsrc
uint32 getSsrc() const
Get the SSRC of this SRTP Cryptograhic context.
Definition CryptoContextCtrl.h:260
CryptoContextCtrl::getMkiLength
int32 getMkiLength() const
Get the length of the MKI in bytes.
Definition CryptoContextCtrl.h:251
CryptoContextCtrl::~CryptoContextCtrl
~CryptoContextCtrl()
Destructor.
CryptoContextCtrl::update
void update(uint32 newSeqNumber)
Update the SRTP packet index.
CryptoContextCtrl::CryptoContextCtrl
CryptoContextCtrl(uint32 ssrc, const int32 ealg, const int32 aalg, uint8 *masterKey, int32 masterKeyLength, uint8 *masterSalt, int32 masterSaltLength, int32 ekeyl, int32 akeyl, int32 skeyl, int32 tagLength)
Constructor for an active SRTP cryptographic context.
CryptoContextCtrl::srtcpAuthenticate
void srtcpAuthenticate(uint8 *rtp, size_t len, uint32 roc, uint8 *tag)
Compute the authentication tag.
CryptoContextCtrl::newCryptoContextForSSRC
CryptoContextCtrl * newCryptoContextForSSRC(uint32 ssrc)
Derive a new Crypto Context for use with a new SSRC.
CryptoContextCtrl::srtcpEncrypt
void srtcpEncrypt(uint8 *rtp, size_t len, uint64 index, uint32 ssrc)
Perform SRTP encryption.