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