res_srtp.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2010 FIXME
  5. *
  6. * See http://www.asterisk.org for more information about
  7. * the Asterisk project. Please do not directly contact
  8. * any of the maintainers of this project for assistance;
  9. * the project provides a web site, mailing lists and IRC
  10. * channels for your use.
  11. *
  12. * This program is free software, distributed under the terms of
  13. * the GNU General Public License Version 2. See the LICENSE file
  14. * at the top of the source tree.
  15. */
  16. /*! \file
  17. * \brief SRTP resource
  18. */
  19. #ifndef _ASTERISK_RES_SRTP_H
  20. #define _ASTERISK_RES_SRTP_H
  21. struct ast_srtp;
  22. struct ast_srtp_policy;
  23. struct ast_rtp_instance;
  24. struct ast_srtp_cb {
  25. int (*no_ctx)(struct ast_rtp_instance *rtp, unsigned long ssrc, void *data);
  26. };
  27. struct ast_srtp_res {
  28. /*! Create a new SRTP session for an RTP instance with a default policy */
  29. int (*create)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy);
  30. /* Replace an existing SRTP session with a new session, along with a new default policy */
  31. int (*replace)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy);
  32. /*! Destroy an SRTP session, along with all associated policies */
  33. void (*destroy)(struct ast_srtp *srtp);
  34. /* Add a new stream to an existing SRTP session. Note that the policy cannot be for a wildcard SSRC */
  35. int (*add_stream)(struct ast_srtp *srtp, struct ast_srtp_policy *policy);
  36. /* Change the source on an existing SRTP session. */
  37. int (*change_source)(struct ast_srtp *srtp, unsigned int from_ssrc, unsigned int to_ssrc);
  38. /* Set a callback function */
  39. void (*set_cb)(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data);
  40. /* Unprotect SRTP data */
  41. int (*unprotect)(struct ast_srtp *srtp, void *buf, int *size, int rtcp);
  42. /* Protect RTP data */
  43. int (*protect)(struct ast_srtp *srtp, void **buf, int *size, int rtcp);
  44. /* Obtain a random cryptographic key */
  45. int (*get_random)(unsigned char *key, size_t len);
  46. };
  47. /* Crypto suites */
  48. enum ast_srtp_suite {
  49. AST_AES_CM_128_HMAC_SHA1_80 = 1,
  50. AST_AES_CM_128_HMAC_SHA1_32 = 2,
  51. AST_F8_128_HMAC_SHA1_80 = 3
  52. };
  53. struct ast_srtp_policy_res {
  54. struct ast_srtp_policy *(*alloc)(void);
  55. void (*destroy)(struct ast_srtp_policy *policy);
  56. int (*set_suite)(struct ast_srtp_policy *policy, enum ast_srtp_suite suite);
  57. int (*set_master_key)(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len);
  58. void (*set_ssrc)(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
  59. };
  60. #endif /* _ASTERISK_RES_SRTP_H */