CryptoContext.h
Go to the documentation of this file.
/*
Copyright (C) 2004-2006 the Minisip Team
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 CRYPTOCONTEXT_H
#define CRYPTOCONTEXT_H
#include <commoncpp/config.h>
#include <ccrtp/rtppkt.h>
#define REPLAY_WINDOW_SIZE 64
const int SrtpAuthenticationNull = 0;
const int SrtpAuthenticationSha1Hmac = 1;
const int SrtpAuthenticationSkeinHmac = 2;
const int SrtpEncryptionNull = 0;
const int SrtpEncryptionAESCM = 1;
const int SrtpEncryptionAESF8 = 2;
const int SrtpEncryptionTWOCM = 3;
const int SrtpEncryptionTWOF8 = 4;
#ifndef CRYPTOCONTEXTCTRL_H
#include <stdint.h>
#ifdef SRTP_SUPPORT
#include <ccrtp/crypto/SrtpSymCrypto.h>
#endif
class SrtpSymCrypto;
NAMESPACE_COMMONCPP
class RTPPacket;
class __EXPORT CryptoContext {
public:
CryptoContext( uint32 ssrc );
CryptoContext( uint32 ssrc, int32 roc,
int64 keyDerivRate,
const int32 ealg,
const int32 aalg,
uint8* masterKey,
int32 masterKeyLength,
uint8* masterSalt,
int32 masterSaltLength,
int32 ekeyl,
int32 akeyl,
int32 skeyl,
int32 tagLength );
~CryptoContext();
inline void
setRoc(uint32 r)
{roc = r;}
inline uint32
getRoc() const
{return roc;}
void srtpEncrypt( RTPPacket* rtp, uint64 index, uint32 ssrc );
void srtpAuthenticate(RTPPacket* rtp, uint32 roc, uint8* tag );
void deriveSrtpKeys(uint64 index);
uint64 guessIndex(uint16 newSeqNumber);
bool checkReplay(uint16 newSeqNumber);
void update( uint16 newSeqNumber );
inline int32
getTagLength() const
{return tagLength;}
inline int32
getMkiLength() const
{return mkiLength;}
inline uint32
getSsrc() const
{return ssrcCtx;}
CryptoContext* newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate);
private:
uint32 ssrcCtx;
bool using_mki;
uint32 mkiLength;
uint8* mki;
uint32 roc;
uint32 guessed_roc;
uint16 s_l;
int64 key_deriv_rate;
/* bitmask for replay check */
uint64 replay_window;
uint8* master_key;
uint32 master_key_length;
uint32 master_key_srtp_use_nb;
uint32 master_key_srtcp_use_nb;
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;
bool seqNumSet;
void* macCtx;
#ifdef SRTP_SUPPORT
SrtpSymCrypto* cipher;
SrtpSymCrypto* f8Cipher;
#else
void* cipher;
void* f8Cipher;
#endif
};
END_NAMESPACE
#endif
#endif
CryptoContext::getRoc
uint32 getRoc() const
Get the Roll-Over-Counter.
Definition: CryptoContext.h:211
SrtpAuthenticationSkeinHmac
const int SrtpAuthenticationSkeinHmac
Definition: CryptoContext.h:33
CryptoContext
The implementation for a SRTP cryptographic context.
Definition: CryptoContext.h:83
SrtpEncryptionAESCM
const int SrtpEncryptionAESCM
Definition: CryptoContext.h:36
rtppkt.h
RTP packets handling.
CryptoContext::setRoc
void setRoc(uint32 r)
Set the Roll-Over-Counter.
Definition: CryptoContext.h:199
SrtpEncryptionTWOCM
const int SrtpEncryptionTWOCM
Definition: CryptoContext.h:38
SrtpAuthenticationSha1Hmac
const int SrtpAuthenticationSha1Hmac
Definition: CryptoContext.h:32
CryptoContext::getTagLength
int32 getTagLength() const
Get the length of the SRTP authentication tag in bytes.
Definition: CryptoContext.h:311
CryptoContext::getSsrc
uint32 getSsrc() const
Get the SSRC of this SRTP Cryptograhic context.
Definition: CryptoContext.h:330
SrtpEncryptionTWOF8
const int SrtpEncryptionTWOF8
Definition: CryptoContext.h:39
SrtpEncryptionNull
const int SrtpEncryptionNull
Definition: CryptoContext.h:35
CryptoContext::getMkiLength
int32 getMkiLength() const
Get the length of the MKI in bytes.
Definition: CryptoContext.h:321
SrtpEncryptionAESF8
const int SrtpEncryptionAESF8
Definition: CryptoContext.h:37
RTPPacket
A base class for both IncomingRTPPkt and OutgoingRTPPkt.
Definition: rtppkt.h:73
SrtpAuthenticationNull
const int SrtpAuthenticationNull
Definition: CryptoContext.h:31