encryption_info.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. */
  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. } AVEncryptionInitInfo;
  106. /**
  107. * Allocates an AVEncryptionInfo structure and sub-pointers to hold the given
  108. * number of subsamples. This will allocate pointers for the key ID, IV,
  109. * and subsample entries, set the size members, and zero-initialize the rest.
  110. *
  111. * @param subsample_count The number of subsamples.
  112. * @param key_id_size The number of bytes in the key ID, should be 16.
  113. * @param key_id_size The number of bytes in the IV, should be 16.
  114. *
  115. * @return The new AVEncryptionInfo structure, or NULL on error.
  116. */
  117. AVEncryptionInfo *av_encryption_info_alloc(uint32_t subsample_count, uint32_t key_id_size, uint32_t iv_size);
  118. /**
  119. * Allocates an AVEncryptionInfo structure with a copy of the given data.
  120. * @return The new AVEncryptionInfo structure, or NULL on error.
  121. */
  122. AVEncryptionInfo *av_encryption_info_clone(const AVEncryptionInfo *info);
  123. /**
  124. * Frees the given encryption info object. This MUST NOT be used to free the
  125. * side-data data pointer, that should use normal side-data methods.
  126. */
  127. void av_encryption_info_free(AVEncryptionInfo *info);
  128. /**
  129. * Creates a copy of the AVEncryptionInfo that is contained in the given side
  130. * data. The resulting object should be passed to av_encryption_info_free()
  131. * when done.
  132. *
  133. * @return The new AVEncryptionInfo structure, or NULL on error.
  134. */
  135. AVEncryptionInfo *av_encryption_info_get_side_data(const uint8_t *side_data, size_t side_data_size);
  136. /**
  137. * Allocates and initializes side data that holds a copy of the given encryption
  138. * info. The resulting pointer should be either freed using av_free or given
  139. * to av_packet_add_side_data().
  140. *
  141. * @return The new side-data pointer, or NULL.
  142. */
  143. uint8_t *av_encryption_info_add_side_data(
  144. const AVEncryptionInfo *info, size_t *side_data_size);
  145. /**
  146. * Allocates an AVEncryptionInitInfo structure and sub-pointers to hold the
  147. * given sizes. This will allocate pointers and set all the fields.
  148. *
  149. * @return The new AVEncryptionInitInfo structure, or NULL on error.
  150. */
  151. AVEncryptionInitInfo *av_encryption_init_info_alloc(
  152. uint32_t system_id_size, uint32_t num_key_ids, uint32_t key_id_size, uint32_t data_size);
  153. /**
  154. * Frees the given encryption init info object. This MUST NOT be used to free
  155. * the side-data data pointer, that should use normal side-data methods.
  156. */
  157. void av_encryption_init_info_free(AVEncryptionInitInfo* info);
  158. /**
  159. * Creates a copy of the AVEncryptionInitInfo that is contained in the given
  160. * side data. The resulting object should be passed to
  161. * av_encryption_init_info_free() when done.
  162. *
  163. * @return The new AVEncryptionInitInfo structure, or NULL on error.
  164. */
  165. AVEncryptionInitInfo *av_encryption_init_info_get_side_data(
  166. const uint8_t* side_data, size_t side_data_size);
  167. /**
  168. * Allocates and initializes side data that holds a copy of the given encryption
  169. * init info. The resulting pointer should be either freed using av_free or
  170. * given to av_packet_add_side_data().
  171. *
  172. * @return The new side-data pointer, or NULL.
  173. */
  174. uint8_t *av_encryption_init_info_add_side_data(
  175. const AVEncryptionInitInfo *info, size_t *side_data_size);
  176. #endif /* AVUTIL_ENCRYPTION_INFO_H */