2
0

zrtp_srtp_builtin.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
  3. * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  4. * Contact: http://philzimmermann.com
  5. * For licensing and other legal details, see the file zrtp_legal.c.
  6. *
  7. * Viktor Krykun <v.krikun at zfoneproject.com>
  8. * Vitaly Rozhkov <v.rozhkov at soft-industry.com>
  9. */
  10. #ifndef __ZRTP_SRTP_BUILTIN_H__
  11. #define __ZRTP_SRTP_BUILTIN_H__
  12. #include "zrtp_config.h"
  13. #include "zrtp_error.h"
  14. #include "zrtp_types.h"
  15. #include "zrtp_crypto.h"
  16. /*!
  17. * \defgroup dev_srtp Built in SRTP realization
  18. * \ingroup zrtp_dev
  19. * \{
  20. */
  21. /*!
  22. * \brief Sliding window width in bits.
  23. * This window is used by the replay protection mechanism. As stated in the
  24. * RFC3711, '3.3.2., the replay protection sliding window width MUST be at least
  25. * 64, but MAY be set to a higher value.
  26. */
  27. #if (ZRTP_PLATFORM == ZP_SYMBIAN)
  28. # define ZRTP_SRTP_WINDOW_WIDTH 16
  29. #else
  30. # define ZRTP_SRTP_WINDOW_WIDTH 128
  31. #endif
  32. #if ZRTP_SRTP_WINDOW_WIDTH % 8
  33. /*!
  34. * \brief Sliding window width in bytes if padding is needed.
  35. * This is used for allocating a window as a uint8_t array.
  36. */
  37. #define ZRTP_SRTP_WINDOW_WIDTH_BYTES ZRTP_SRTP_WINDOW_WIDTH/8+1
  38. #else
  39. /*!
  40. * \brief Sliding window width in bytes if padding isn't needed.
  41. * This is used for allocating a window as a uint8_t array.
  42. */
  43. #define ZRTP_SRTP_WINDOW_WIDTH_BYTES ZRTP_SRTP_WINDOW_WIDTH/8
  44. #endif
  45. #define RP_INCOMING_DIRECTION 1
  46. #define RP_OUTGOING_DIRECTION 2
  47. /*! \brief Structure describing replay protection engine data */
  48. typedef struct
  49. {
  50. uint32_t seq; /*!< sequence number of packet on the top of sliding window */
  51. uint8_t window[ZRTP_SRTP_WINDOW_WIDTH_BYTES]; /*!< sliding window buffer */
  52. } zrtp_srtp_rp_t;
  53. /*! \brief Structure describing cipher wrapper */
  54. typedef struct
  55. {
  56. /*!< cipher that will be used for packet encryption */
  57. zrtp_cipher_t *cipher;
  58. /*!< pointer to cipher's context */
  59. void *ctx;
  60. } zrtp_srtp_cipher_t;
  61. /*! \brief Structure describing authentication wrapper */
  62. typedef struct
  63. {
  64. zrtp_hash_t *hash; /*!< hash component for authentication tag generation */
  65. uint8_t *key; /*!< key buffer for HMAC generation */
  66. uint32_t key_len; /*!< key length in bytes. Used for zeroes filling of buffer with key */
  67. zrtp_auth_tag_length_t *tag_len; /*!< SRTP authentication scheme component */
  68. } zrtp_srtp_auth_t;
  69. /*! \brief Structure for SRTP stream context description. */
  70. typedef struct
  71. {
  72. /*!< wrapper for cipher component and holding its auxiliary data. Used for RTP encryption */
  73. zrtp_srtp_cipher_t rtp_cipher;
  74. /*!< wrapper for hash component and holding its auxiliary data. Used for RTP authentication */
  75. zrtp_srtp_auth_t rtp_auth;
  76. /*!< wrapper for cipher component and holding its auxiliary data. Used for RTCP encryption */
  77. zrtp_srtp_cipher_t rtcp_cipher;
  78. /*!< wrapper for hash component and holding its auxiliary data. Used for RTCP authentication */
  79. zrtp_srtp_auth_t rtcp_auth;
  80. } zrtp_srtp_stream_ctx_t;
  81. /*!
  82. * \brief Enumeration of labels used in key derivation for various purposes.
  83. * See RFC3711, "4.3. Key Derivation" for more details
  84. */
  85. typedef enum
  86. {
  87. label_rtp_encryption = 0x00, /*!< for RTP cipher's key derivation */
  88. label_rtp_msg_auth = 0x01, /*!< for RTP packets authentication mechanism's key derivation */
  89. label_rtp_salt = 0x02, /*!< for RTP cipher's salt derivation */
  90. label_rtcp_encryption = 0x03, /*!< used for RTCP cipher's key derivation */
  91. label_rtcp_msg_auth = 0x04, /*!< for RTCP packets authentication mechanism key derivation */
  92. label_rtcp_salt = 0x05 /*!< for RTCP cipher's salt derivation */
  93. } zrtp_srtp_prf_label;
  94. typedef zrtp_srtp_cipher_t zrtp_dk_ctx;
  95. /*!
  96. * \brief Structure describing a protection node.
  97. * Each node keeps data for protecting RTP and RTCP packets against replays
  98. * within streams with a given SSRC. There are two replay protection nodes for
  99. * each SSRC value in the two lists. One is used for incoming packets and
  100. * the other for outgoing packets.
  101. */
  102. typedef struct
  103. {
  104. zrtp_srtp_rp_t rtp_rp; /*!< RTP replay protection data */
  105. zrtp_srtp_rp_t rtcp_rp; /*!< RTCP replay protection data */
  106. uint32_t ssrc; /*!< RTP media SSRC for nodes searching in the linked list */
  107. zrtp_srtp_ctx_t *srtp_ctx; /*!< SRTP context related with current node*/
  108. mlist_t mlist;
  109. } zrtp_rp_node_t;
  110. /*!
  111. * \brief Structure describing replay protection context.
  112. * This structure holds two linked list's heads and two mutexes for
  113. * synchronization access to appropriate lists.
  114. */
  115. typedef struct
  116. {
  117. zrtp_rp_node_t inc_head; /*!< head of replay protection nodes list for incoming packets */
  118. zrtp_mutex_t* inc_sync; /*!< mutex for incoming list access synchronization */
  119. zrtp_rp_node_t out_head; /*!< head of replay protection nodes list for outgoing packets */
  120. zrtp_mutex_t* out_sync; /*!< mutex for outgoing list access synchronization */
  121. } zrtp_rp_ctx_t;
  122. /* \} */
  123. #endif /* __ZRTP_SRTP_BUILTIN_H__ */