SrtpSession.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. ISC License
  3. Copyright © 2015, Iñaki Baz Castillo <ibc@aliax.net>
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted, provided that the above
  6. copyright notice and this permission notice appear in all copies.
  7. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  10. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  12. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  13. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #ifndef MS_RTC_SRTP_SESSION_HPP
  16. #define MS_RTC_SRTP_SESSION_HPP
  17. #include "Utils.hpp"
  18. #include <memory>
  19. typedef struct srtp_ctx_t_ *srtp_t;
  20. namespace RTC {
  21. class DepLibSRTP;
  22. class SrtpSession {
  23. public:
  24. enum class CryptoSuite {
  25. NONE = 0,
  26. AES_CM_128_HMAC_SHA1_80 = 1,
  27. AES_CM_128_HMAC_SHA1_32,
  28. AEAD_AES_256_GCM,
  29. AEAD_AES_128_GCM
  30. };
  31. public:
  32. enum class Type { INBOUND = 1, OUTBOUND };
  33. public:
  34. SrtpSession(Type type, CryptoSuite cryptoSuite, uint8_t *key, size_t keyLen);
  35. ~SrtpSession();
  36. public:
  37. bool EncryptRtp(uint8_t *data, int *len);
  38. bool DecryptSrtp(uint8_t *data, int *len);
  39. bool EncryptRtcp(uint8_t *data, int *len);
  40. bool DecryptSrtcp(uint8_t *data, int *len);
  41. void RemoveStream(uint32_t ssrc);
  42. private:
  43. // Allocated by this.
  44. srtp_t session { nullptr };
  45. std::shared_ptr<DepLibSRTP> _env;
  46. };
  47. } // namespace RTC
  48. #endif