ekt.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * ekt.h
  3. *
  4. * interface to Encrypted Key Transport for SRTP
  5. *
  6. * David McGrew
  7. * Cisco Systems, Inc.
  8. */
  9. /*
  10. *
  11. * Copyright (c) 2001-2005 Cisco Systems, Inc.
  12. * All rights reserved.
  13. *
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification, are permitted provided that the following conditions
  16. * are met:
  17. *
  18. * Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. *
  21. * Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials provided
  24. * with the distribution.
  25. *
  26. * Neither the name of the Cisco Systems, Inc. nor the names of its
  27. * contributors may be used to endorse or promote products derived
  28. * from this software without specific prior written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34. * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  35. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  36. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  37. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  41. * OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. */
  44. /*
  45. * EKT implementation strategy
  46. *
  47. * use stream_template approach
  48. *
  49. * in srtp_unprotect, when a new stream appears, check if template has
  50. * EKT defined, and if it does, then apply EKT processing
  51. *
  52. * question: will we want to allow key-sharing templates in addition
  53. * to EKT templates? could define a new ssrc_type_t that's associated
  54. * with an EKT, e.g. ssrc_any_ekt.
  55. *
  56. *
  57. */
  58. #ifndef EKT_H
  59. #define EKT_H
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. #include "srtp_priv.h"
  64. #define EKT_CIPHER_DEFAULT 1
  65. #define EKT_CIPHER_AES_128_ECB 1
  66. #define EKT_CIPHER_AES_192_KEY_WRAP 2
  67. #define EKT_CIPHER_AES_256_KEY_WRAP 3
  68. typedef uint16_t ekt_spi_t;
  69. unsigned
  70. ekt_octets_after_base_tag(ekt_stream_t ekt);
  71. /*
  72. * an srtp_policy_t structure can contain a pointer to an
  73. * ekt_policy_t structure
  74. *
  75. * this structure holds all of the high level EKT information, and it
  76. * is passed into libsrtp to indicate what policy should be in effect
  77. */
  78. typedef struct ekt_policy_ctx_t {
  79. ekt_spi_t spi; /* security parameter index */
  80. uint8_t ekt_cipher_type;
  81. uint8_t *ekt_key;
  82. struct ekt_policy_ctx_t *next_ekt_policy;
  83. } ekt_policy_ctx_t;
  84. /*
  85. * an ekt_data_t structure holds the data corresponding to an ekt key,
  86. * spi, and so on
  87. */
  88. typedef struct ekt_data_t {
  89. ekt_spi_t spi;
  90. uint8_t ekt_cipher_type;
  91. aes_expanded_key_t ekt_enc_key;
  92. aes_expanded_key_t ekt_dec_key;
  93. struct ekt_data_t *next_ekt_data;
  94. } ekt_data_t;
  95. /*
  96. * an srtp_stream_ctx_t can contain an ekt_stream_ctx_t
  97. *
  98. * an ekt_stream_ctx_t structure holds all of the EKT information for
  99. * a specific SRTP stream
  100. */
  101. typedef struct ekt_stream_ctx_t {
  102. ekt_data_t *data;
  103. uint16_t isn; /* initial sequence number */
  104. uint8_t encrypted_master_key[SRTP_MAX_KEY_LEN];
  105. } ekt_stream_ctx_t;
  106. err_status_t
  107. ekt_alloc(ekt_stream_t *stream_data, ekt_policy_t policy);
  108. err_status_t
  109. ekt_stream_init(ekt_stream_t e,
  110. ekt_spi_t spi,
  111. void *ekt_key,
  112. unsigned ekt_cipher_type);
  113. err_status_t
  114. ekt_stream_init_from_policy(ekt_stream_t e, ekt_policy_t p);
  115. err_status_t
  116. srtp_stream_init_from_ekt(srtp_stream_t stream,
  117. const void *srtcp_hdr,
  118. unsigned pkt_octet_len);
  119. void
  120. ekt_write_data(ekt_stream_t ekt,
  121. uint8_t *base_tag,
  122. unsigned base_tag_len,
  123. int *packet_len,
  124. xtd_seq_num_t pkt_index);
  125. /*
  126. * We handle EKT by performing some additional steps before
  127. * authentication (copying the auth tag into a temporary location,
  128. * zeroizing the "base tag" field in the packet)
  129. *
  130. * With EKT, the tag_len parameter is actually the base tag
  131. * length
  132. */
  133. err_status_t
  134. ekt_tag_verification_preproces(uint8_t *pkt_tag,
  135. uint8_t *pkt_tag_copy,
  136. unsigned tag_len);
  137. err_status_t
  138. ekt_tag_verification_postproces(uint8_t *pkt_tag,
  139. uint8_t *pkt_tag_copy,
  140. unsigned tag_len);
  141. /*
  142. * @brief EKT pre-processing for srtcp tag generation
  143. *
  144. * This function does the pre-processing of the SRTCP authentication
  145. * tag format. When EKT is used, it consists of writing the Encrypted
  146. * Master Key, the SRTP ROC, the Initial Sequence Number, and SPI
  147. * fields. The Base Authentication Tag field is set to the all-zero
  148. * value
  149. *
  150. * When EKT is not used, this function is a no-op.
  151. *
  152. */
  153. err_status_t
  154. srtp_stream_srtcp_auth_tag_generation_preprocess(const srtp_stream_t *s,
  155. uint8_t *pkt_tag,
  156. unsigned pkt_octet_len);
  157. /* it's not clear that a tag_generation_postprocess function is needed */
  158. err_status_t
  159. srtcp_auth_tag_generation_postprocess(void);
  160. #ifdef __cplusplus
  161. }
  162. #endif
  163. #endif /* EKT_H */