encryption_info.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg 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. * FFmpeg 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 FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #ifndef AVUTIL_ENCRYPTION_INFO_H
  19. #define AVUTIL_ENCRYPTION_INFO_H
  20. #include <stddef.h>
  21. #include <stdint.h>
  22. typedef struct AVSubsampleEncryptionInfo {
  23. /** The number of bytes that are clear. */
  24. unsigned int bytes_of_clear_data;
  25. /**
  26. * The number of bytes that are protected. If using pattern encryption,
  27. * the pattern applies to only the protected bytes; if not using pattern
  28. * encryption, all these bytes are encrypted.
  29. */
  30. unsigned int bytes_of_protected_data;
  31. } AVSubsampleEncryptionInfo;
  32. /**
  33. * This describes encryption info for a packet. This contains frame-specific
  34. * info for how to decrypt the packet before passing it to the decoder.
  35. *
  36. * The size of this struct is not part of the public ABI.
  37. */
  38. typedef struct AVEncryptionInfo {
  39. /** The fourcc encryption scheme, in big-endian byte order. */
  40. uint32_t scheme;
  41. /**
  42. * Only used for pattern encryption. This is the number of 16-byte blocks
  43. * that are encrypted.
  44. */
  45. uint32_t crypt_byte_block;
  46. /**
  47. * Only used for pattern encryption. This is the number of 16-byte blocks
  48. * that are clear.
  49. */
  50. uint32_t skip_byte_block;
  51. /**
  52. * The ID of the key used to encrypt the packet. This should always be
  53. * 16 bytes long, but may be changed in the future.
  54. */
  55. uint8_t *key_id;
  56. uint32_t key_id_size;
  57. /**
  58. * The initialization vector. This may have been zero-filled to be the
  59. * correct block size. This should always be 16 bytes long, but may be
  60. * changed in the future.
  61. */
  62. uint8_t *iv;
  63. uint32_t iv_size;
  64. /**
  65. * An array of subsample encryption info specifying how parts of the sample
  66. * are encrypted. If there are no subsamples, then the whole sample is
  67. * encrypted.
  68. */
  69. AVSubsampleEncryptionInfo *subsamples;
  70. uint32_t subsample_count;
  71. } AVEncryptionInfo;
  72. /**
  73. * This describes info used to initialize an encryption key system.
  74. *
  75. * The size of this struct is not part of the public ABI.
  76. */
  77. typedef struct AVEncryptionInitInfo {
  78. /**
  79. * A unique identifier for the key system this is for, can be NULL if it
  80. * is not known. This should always be 16 bytes, but may change in the
  81. * future.
  82. */
  83. uint8_t* system_id;
  84. uint32_t system_id_size;
  85. /**
  86. * An array of key IDs this initialization data is for. All IDs are the
  87. * same length. Can be NULL if there are no known key IDs.
  88. */
  89. uint8_t** key_ids;
  90. /** The number of key IDs. */
  91. uint32_t num_key_ids;
  92. /**
  93. * The number of bytes in each key ID. This should always be 16, but may
  94. * change in the future.
  95. */
  96. uint32_t key_id_size;
  97. /**
  98. * Key-system specific initialization data. This data is copied directly
  99. * from the file and the format depends on the specific key system. This
  100. * can be NULL if there is no initialization data; in that case, there
  101. * will be at least one key ID.
  102. */
  103. uint8_t* data;
  104. uint32_t data_size;
  105. /**
  106. * An optional pointer to the next initialization info in the list.
  107. */
  108. struct AVEncryptionInitInfo *next;
  109. } AVEncryptionInitInfo;
  110. /**
  111. * Allocates an AVEncryptionInfo structure and sub-pointers to hold the given
  112. * number of subsamples. This will allocate pointers for the key ID, IV,
  113. * and subsample entries, set the size members, and zero-initialize the rest.
  114. *
  115. * @param subsample_count The number of subsamples.
  116. * @param key_id_size The number of bytes in the key ID, should be 16.
  117. * @param iv_size The number of bytes in the IV, should be 16.
  118. *
  119. * @return The new AVEncryptionInfo structure, or NULL on error.
  120. */
  121. AVEncryptionInfo *av_encryption_info_alloc(uint32_t subsample_count, uint32_t key_id_size, uint32_t iv_size);
  122. /**
  123. * Allocates an AVEncryptionInfo structure with a copy of the given data.
  124. * @return The new AVEncryptionInfo structure, or NULL on error.
  125. */
  126. AVEncryptionInfo *av_encryption_info_clone(const AVEncryptionInfo *info);
  127. /**
  128. * Frees the given encryption info object. This MUST NOT be used to free the
  129. * side-data data pointer, that should use normal side-data methods.
  130. */
  131. void av_encryption_info_free(AVEncryptionInfo *info);
  132. /**
  133. * Creates a copy of the AVEncryptionInfo that is contained in the given side
  134. * data. The resulting object should be passed to av_encryption_info_free()
  135. * when done.
  136. *
  137. * @return The new AVEncryptionInfo structure, or NULL on error.
  138. */
  139. AVEncryptionInfo *av_encryption_info_get_side_data(const uint8_t *side_data, size_t side_data_size);
  140. /**
  141. * Allocates and initializes side data that holds a copy of the given encryption
  142. * info. The resulting pointer should be either freed using av_free or given
  143. * to av_packet_add_side_data().
  144. *
  145. * @return The new side-data pointer, or NULL.
  146. */
  147. uint8_t *av_encryption_info_add_side_data(
  148. const AVEncryptionInfo *info, size_t *side_data_size);
  149. /**
  150. * Allocates an AVEncryptionInitInfo structure and sub-pointers to hold the
  151. * given sizes. This will allocate pointers and set all the fields.
  152. *
  153. * @return The new AVEncryptionInitInfo structure, or NULL on error.
  154. */
  155. AVEncryptionInitInfo *av_encryption_init_info_alloc(
  156. uint32_t system_id_size, uint32_t num_key_ids, uint32_t key_id_size, uint32_t data_size);
  157. /**
  158. * Frees the given encryption init info object. This MUST NOT be used to free
  159. * the side-data data pointer, that should use normal side-data methods.
  160. */
  161. void av_encryption_init_info_free(AVEncryptionInitInfo* info);
  162. /**
  163. * Creates a copy of the AVEncryptionInitInfo that is contained in the given
  164. * side data. The resulting object should be passed to
  165. * av_encryption_init_info_free() when done.
  166. *
  167. * @return The new AVEncryptionInitInfo structure, or NULL on error.
  168. */
  169. AVEncryptionInitInfo *av_encryption_init_info_get_side_data(
  170. const uint8_t* side_data, size_t side_data_size);
  171. /**
  172. * Allocates and initializes side data that holds a copy of the given encryption
  173. * init info. The resulting pointer should be either freed using av_free or
  174. * given to av_packet_add_side_data().
  175. *
  176. * @return The new side-data pointer, or NULL.
  177. */
  178. uint8_t *av_encryption_init_info_add_side_data(
  179. const AVEncryptionInitInfo *info, size_t *side_data_size);
  180. #endif /* AVUTIL_ENCRYPTION_INFO_H */