FFmpeg
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, in big-endian byte order. */
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  */
63  uint8_t *key_id;
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  */
71  uint8_t *iv;
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  */
94  uint8_t* system_id;
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  */
101  uint8_t** key_ids;
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  */
116  uint8_t* data;
117  uint32_t data_size;
118 
119  /**
120  * An optional pointer to the next initialization info in the list.
121  */
124 
125 /**
126  * Allocates an AVEncryptionInfo structure and sub-pointers to hold the given
127  * number of subsamples. This will allocate pointers for the key ID, IV,
128  * and subsample entries, set the size members, and zero-initialize the rest.
129  *
130  * @param subsample_count The number of subsamples.
131  * @param key_id_size The number of bytes in the key ID, should be 16.
132  * @param iv_size The number of bytes in the IV, should be 16.
133  *
134  * @return The new AVEncryptionInfo structure, or NULL on error.
135  */
136 AVEncryptionInfo *av_encryption_info_alloc(uint32_t subsample_count, uint32_t key_id_size, uint32_t iv_size);
137 
138 /**
139  * Allocates an AVEncryptionInfo structure with a copy of the given data.
140  * @return The new AVEncryptionInfo structure, or NULL on error.
141  */
143 
144 /**
145  * Frees the given encryption info object. This MUST NOT be used to free the
146  * side-data data pointer, that should use normal side-data methods.
147  */
149 
150 /**
151  * Creates a copy of the AVEncryptionInfo that is contained in the given side
152  * data. The resulting object should be passed to av_encryption_info_free()
153  * when done.
154  *
155  * @return The new AVEncryptionInfo structure, or NULL on error.
156  */
157 AVEncryptionInfo *av_encryption_info_get_side_data(const uint8_t *side_data, size_t side_data_size);
158 
159 /**
160  * Allocates and initializes side data that holds a copy of the given encryption
161  * info. The resulting pointer should be either freed using av_free or given
162  * to av_packet_add_side_data().
163  *
164  * @return The new side-data pointer, or NULL.
165  */
167  const AVEncryptionInfo *info, size_t *side_data_size);
168 
169 
170 /**
171  * Allocates an AVEncryptionInitInfo structure and sub-pointers to hold the
172  * given sizes. This will allocate pointers and set all the fields.
173  *
174  * @return The new AVEncryptionInitInfo structure, or NULL on error.
175  */
177  uint32_t system_id_size, uint32_t num_key_ids, uint32_t key_id_size, uint32_t data_size);
178 
179 /**
180  * Frees the given encryption init info object. This MUST NOT be used to free
181  * the side-data data pointer, that should use normal side-data methods.
182  */
184 
185 /**
186  * Creates a copy of the AVEncryptionInitInfo that is contained in the given
187  * side data. The resulting object should be passed to
188  * av_encryption_init_info_free() when done.
189  *
190  * @return The new AVEncryptionInitInfo structure, or NULL on error.
191  */
193  const uint8_t* side_data, size_t side_data_size);
194 
195 /**
196  * Allocates and initializes side data that holds a copy of the given encryption
197  * init info. The resulting pointer should be either freed using av_free or
198  * given to av_packet_add_side_data().
199  *
200  * @return The new side-data pointer, or NULL.
201  */
203  const AVEncryptionInitInfo *info, size_t *side_data_size);
204 
205 #endif /* AVUTIL_ENCRYPTION_INFO_H */
AVEncryptionInfo::key_id_size
uint32_t key_id_size
Definition: encryption_info.h:64
AVEncryptionInfo::crypt_byte_block
uint32_t crypt_byte_block
Only used for pattern encryption.
Definition: encryption_info.h:51
av_encryption_info_free
void av_encryption_info_free(AVEncryptionInfo *info)
Frees the given encryption info object.
Definition: encryption_info.c:82
av_encryption_info_add_side_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.
Definition: encryption_info.c:127
av_encryption_info_get_side_data
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.
Definition: encryption_info.c:92
AVEncryptionInfo::scheme
uint32_t scheme
The fourcc encryption scheme, in big-endian byte order.
Definition: encryption_info.h:45
AVEncryptionInitInfo::data_size
uint32_t data_size
Definition: encryption_info.h:117
AVEncryptionInfo::skip_byte_block
uint32_t skip_byte_block
Only used for pattern encryption.
Definition: encryption_info.h:57
AVEncryptionInitInfo::key_id_size
uint32_t key_id_size
The number of bytes in each key ID.
Definition: encryption_info.h:108
AVEncryptionInfo::iv
uint8_t * iv
The initialization vector.
Definition: encryption_info.h:71
av_encryption_init_info_add_side_data
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.
Definition: encryption_info.c:292
av_encryption_init_info_alloc
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.
Definition: encryption_info.c:178
info
MIPS optimizations info
Definition: mips.txt:2
AVSubsampleEncryptionInfo::bytes_of_clear_data
unsigned int bytes_of_clear_data
The number of bytes that are clear.
Definition: encryption_info.h:27
AVEncryptionInfo::subsamples
AVSubsampleEncryptionInfo * subsamples
An array of subsample encryption info specifying how parts of the sample are encrypted.
Definition: encryption_info.h:79
AVEncryptionInitInfo
This describes info used to initialize an encryption key system.
Definition: encryption_info.h:88
AVEncryptionInitInfo::system_id
uint8_t * system_id
A unique identifier for the key system this is for, can be NULL if it is not known.
Definition: encryption_info.h:94
AVEncryptionInitInfo::num_key_ids
uint32_t num_key_ids
The number of key IDs.
Definition: encryption_info.h:103
av_encryption_info_alloc
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.
Definition: encryption_info.c:41
av_encryption_init_info_free
void av_encryption_init_info_free(AVEncryptionInitInfo *info)
Frees the given encryption init info object.
Definition: encryption_info.c:216
av_encryption_info_clone
AVEncryptionInfo * av_encryption_info_clone(const AVEncryptionInfo *info)
Allocates an AVEncryptionInfo structure with a copy of the given data.
Definition: encryption_info.c:65
AVSubsampleEncryptionInfo
This file is part of FFmpeg.
Definition: encryption_info.h:25
AVEncryptionInitInfo::next
struct AVEncryptionInitInfo * next
An optional pointer to the next initialization info in the list.
Definition: encryption_info.h:122
AVEncryptionInitInfo::key_ids
uint8_t ** key_ids
An array of key IDs this initialization data is for.
Definition: encryption_info.h:101
av_encryption_init_info_get_side_data
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.
Definition: encryption_info.c:231
AVEncryptionInfo::key_id
uint8_t * key_id
The ID of the key used to encrypt the packet.
Definition: encryption_info.h:63
AVEncryptionInitInfo::data
uint8_t * data
Key-system specific initialization data.
Definition: encryption_info.h:116
AVEncryptionInfo
This describes encryption info for a packet.
Definition: encryption_info.h:43
AVEncryptionInfo::subsample_count
uint32_t subsample_count
Definition: encryption_info.h:80
AVEncryptionInfo::iv_size
uint32_t iv_size
Definition: encryption_info.h:72
AVEncryptionInitInfo::system_id_size
uint32_t system_id_size
Definition: encryption_info.h:95
AVSubsampleEncryptionInfo::bytes_of_protected_data
unsigned int bytes_of_protected_data
The number of bytes that are protected.
Definition: encryption_info.h:34