ccRTP
CryptoContext.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2004-2006 the Minisip Team
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19
20
21#ifndef CRYPTOCONTEXT_H
22#define CRYPTOCONTEXT_H
23
24#include <commoncpp/config.h>
25
26#include <ccrtp/rtppkt.h>
27
28
29#define REPLAY_WINDOW_SIZE 64
30
34
35const int SrtpEncryptionNull = 0;
36const int SrtpEncryptionAESCM = 1;
37const int SrtpEncryptionAESF8 = 2;
38const int SrtpEncryptionTWOCM = 3;
39const int SrtpEncryptionTWOF8 = 4;
40
41#ifndef CRYPTOCONTEXTCTRL_H
42
43#include <stdint.h>
44
45#ifdef SRTP_SUPPORT
46#include <ccrtp/crypto/SrtpSymCrypto.h>
47#endif
48
49class SrtpSymCrypto;
50
51NAMESPACE_COMMONCPP
52
53 class RTPPacket;
54
83 class __EXPORT CryptoContext {
84 public:
94 CryptoContext( uint32 ssrc );
95
170 CryptoContext( uint32 ssrc, int32 roc,
171 int64 keyDerivRate,
172 const int32 ealg,
173 const int32 aalg,
174 uint8* masterKey,
175 int32 masterKeyLength,
176 uint8* masterSalt,
177 int32 masterSaltLength,
178 int32 ekeyl,
179 int32 akeyl,
180 int32 skeyl,
181 int32 tagLength );
188
198 inline void
199 setRoc(uint32 r)
200 {roc = r;}
201
210 inline uint32
211 getRoc() const
212 {return roc;}
213
230 void srtpEncrypt( RTPPacket* rtp, uint64 index, uint32 ssrc );
231
248 void srtpAuthenticate(RTPPacket* rtp, uint32 roc, uint8* tag );
249
261 void deriveSrtpKeys(uint64 index);
262
275 uint64 guessIndex(uint16 newSeqNumber);
276
292 bool checkReplay(uint16 newSeqNumber);
293
303 void update( uint16 newSeqNumber );
304
310 inline int32
312 {return tagLength;}
313
314
320 inline int32
322 {return mkiLength;}
323
329 inline uint32
330 getSsrc() const
331 {return ssrcCtx;}
332
354 CryptoContext* newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate);
355
356 private:
357
358 uint32 ssrcCtx;
359 bool using_mki;
360 uint32 mkiLength;
361 uint8* mki;
362
363 uint32 roc;
364 uint32 guessed_roc;
365 uint16 s_l;
366 int64 key_deriv_rate;
367
368 /* bitmask for replay check */
369 uint64 replay_window;
370
371 uint8* master_key;
372 uint32 master_key_length;
373 uint32 master_key_srtp_use_nb;
374 uint32 master_key_srtcp_use_nb;
375 uint8* master_salt;
376 uint32 master_salt_length;
377
378 /* Session Encryption, Authentication keys, Salt */
379 int32 n_e;
380 uint8* k_e;
381 int32 n_a;
382 uint8* k_a;
383 int32 n_s;
384 uint8* k_s;
385
386 int32 ealg;
387 int32 aalg;
388 int32 ekeyl;
389 int32 akeyl;
390 int32 skeyl;
391 int32 tagLength;
392 bool seqNumSet;
393
394 void* macCtx;
395
396#ifdef SRTP_SUPPORT
397 SrtpSymCrypto* cipher;
398 SrtpSymCrypto* f8Cipher;
399#else
400 void* cipher;
401 void* f8Cipher;
402#endif
403
404 };
405
406END_NAMESPACE
407
408#endif
409
410#endif
411
const int SrtpEncryptionTWOF8
Definition CryptoContext.h:39
const int SrtpEncryptionAESF8
Definition CryptoContext.h:37
const int SrtpEncryptionAESCM
Definition CryptoContext.h:36
const int SrtpAuthenticationSkeinHmac
Definition CryptoContext.h:33
const int SrtpEncryptionNull
Definition CryptoContext.h:35
const int SrtpEncryptionTWOCM
Definition CryptoContext.h:38
const int SrtpAuthenticationSha1Hmac
Definition CryptoContext.h:32
const int SrtpAuthenticationNull
Definition CryptoContext.h:31
The implementation for a SRTP cryptographic context.
Definition CryptoContext.h:83
uint64 guessIndex(uint16 newSeqNumber)
Compute (guess) the new SRTP index based on the sequence number of a received RTP packet.
uint32 getRoc() const
Get the Roll-Over-Counter.
Definition CryptoContext.h:211
int32 getMkiLength() const
Get the length of the MKI in bytes.
Definition CryptoContext.h:321
void srtpEncrypt(RTPPacket *rtp, uint64 index, uint32 ssrc)
Perform SRTP encryption.
void srtpAuthenticate(RTPPacket *rtp, uint32 roc, uint8 *tag)
Compute the authentication tag.
CryptoContext(uint32 ssrc)
Constructor for empty SRTP cryptographic context.
void setRoc(uint32 r)
Set the Roll-Over-Counter.
Definition CryptoContext.h:199
CryptoContext * newCryptoContextForSSRC(uint32 ssrc, int roc, int64 keyDerivRate)
Derive a new Crypto Context for use with a new SSRC.
uint32 getSsrc() const
Get the SSRC of this SRTP Cryptograhic context.
Definition CryptoContext.h:330
~CryptoContext()
Destructor.
void update(uint16 newSeqNumber)
Update the SRTP packet index.
int32 getTagLength() const
Get the length of the SRTP authentication tag in bytes.
Definition CryptoContext.h:311
bool checkReplay(uint16 newSeqNumber)
Check for packet replay.
void deriveSrtpKeys(uint64 index)
Perform key derivation according to SRTP specification.
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)
Constructor for an active SRTP cryptographic context.
A base class for both IncomingRTPPkt and OutgoingRTPPkt.
Definition rtppkt.h:74
RTP packets handling.