30 #include <ccrtp-config.h>
37 #include <commoncpp/config.h>
38 #include <commoncpp/export.h>
46 using_mki(false),mkiLength(0),mki(NULL), s_l(0),
48 master_key(NULL), master_key_length(0),
49 master_salt(NULL), master_salt_length(0),
50 n_e(0),k_e(NULL),n_a(0),k_a(NULL),n_s(0),k_s(NULL),
52 ekeyl(0), akeyl(0), skeyl(0),
53 macCtx(NULL), cipher(NULL), f8Cipher(NULL)
61 int32 master_key_length,
63 int32 master_salt_length,
69 ssrcCtx(ssrc),using_mki(false),mkiLength(0),mki(NULL),
70 replay_window(0), macCtx(NULL), cipher(NULL), f8Cipher(NULL)
80 memcpy(this->master_key, master_key, master_key_length);
84 memcpy(this->master_salt, master_salt, master_salt_length);
143 if (master_key_length > 0) {
144 memset(master_key, 0, master_key_length);
145 master_key_length = 0;
148 if (master_salt_length > 0) {
149 memset(master_salt, 0, master_salt_length);
150 master_salt_length = 0;
210 unsigned char iv[16];
218 iv[4] = ((ssrc >> 24) & 0xff) ^
k_s[4];
219 iv[5] = ((ssrc >> 16) & 0xff) ^
k_s[5];
220 iv[6] = ((ssrc >> 8) & 0xff) ^
k_s[6];
221 iv[7] = (ssrc & 0xff) ^
k_s[7];
226 iv[10] = ((index >> 24) & 0xff) ^
k_s[10];
227 iv[11] = ((index >> 16) & 0xff) ^
k_s[11];
228 iv[12] = ((index >> 8) & 0xff) ^
k_s[12];
229 iv[13] = (index & 0xff) ^
k_s[13];
233 cipher->ctr_encrypt(rtp, len, iv);
238 unsigned char iv[16];
248 index = index | 0x80000000;
257 memcpy(iv+8, rtp, 8);
273 unsigned char temp[20];
274 const unsigned char* chunks[3];
275 unsigned int chunkLength[3];
276 uint32_t beIndex = htonl(index);
279 chunkLength[0] = len;
281 chunks[1] = (
unsigned char *)&beIndex;
308 static void computeIv(
unsigned char* iv, uint8 label, uint8* master_salt)
319 memcpy(iv, master_salt, 14);
333 cipher->setNewKey(master_key, master_key_length);
334 memset(master_key, 0, master_key_length);
338 computeIv(iv, label, master_salt);
343 computeIv(iv, label, master_salt);
360 computeIv(iv, label, master_salt);
362 memset(master_salt, 0, master_salt_length);
380 int64 delta =
s_l - index;
409 int64 delta = index -
s_l;
432 this->master_key_length,
434 this->master_salt_length,
Implments the SRTP encryption modes as defined in RFC3711.
void deriveSrtcpKeys()
Perform key derivation according to SRTP specification.
The implementation for a SRTCP cryptographic context.
int32 getTagLength() const
Get the length of the SRTP authentication tag in bytes.
CryptoContextCtrl(uint32 ssrc)
Constructor for empty SRTP cryptographic context.
uint32 master_salt_length
#define REPLAY_WINDOW_SIZE
void hmacSha1Ctx(void *ctx, const uint8_t *data, uint32_t data_length, uint8_t *mac, int32_t *mac_length)
Compute SHA1 HMAC.
const int SrtpEncryptionAESF8
void srtcpEncrypt(uint8 *rtp, size_t len, uint64 index, uint32 ssrc)
Perform SRTP encryption.
void * createSha1HmacContext(uint8_t *key, int32_t key_length)
Create and initialize a SHA1 HMAC context.
void macSkeinCtx(void *ctx, const uint8_t *data, uint32_t data_length, uint8_t *mac)
Compute Skein MAC.
void freeSkeinMacContext(void *ctx)
Free Skein MAC context.
void freeSha1HmacContext(void *ctx)
Free SHA1 HMAC context.
void * createSkeinMacContext(uint8_t *key, int32_t key_length, int32_t mac_length, SkeinSize_t skeinSize)
Create and initialize a Skein MAC context.
const int SrtpEncryptionTWOF8
Functions to compute SHA1 HAMAC.
const int SrtpEncryptionTWOCM
Function that provide Skein MAC support.
const int SrtpAuthenticationSkeinHmac
bool checkReplay(uint32 newSeqNumber)
Check for packet replay.
void srtcpAuthenticate(uint8 *rtp, size_t len, uint32 roc, uint8 *tag)
Compute the authentication tag.
const int SrtpEncryptionNull
const int SrtpAuthenticationSha1Hmac
Base elements for RTP stacks: constants, types and global functions.
CryptoContextCtrl * newCryptoContextForSSRC(uint32 ssrc)
Derive a new Crypto Context for use with a new SSRC.
const int SrtpAuthenticationNull
void update(uint32 newSeqNumber)
Update the SRTP packet index.
const int SrtpEncryptionAESCM
~CryptoContextCtrl()
Destructor.