Go to the documentation of this file.
29 #define MAX_BUFFER_BLOCKS 257
62 #define OFFSET(x) offsetof(CryptoContext, x)
63 #define D AV_OPT_FLAG_DECODING_PARAM
64 #define E AV_OPT_FLAG_ENCODING_PARAM
83 uint8_t *default_buf,
int default_buf_len,
87 if (!default_buf_len) {
90 }
else if (default_buf_len !=
BLOCKSIZE) {
92 "invalid %s size (%d bytes, block size is %d)\n",
96 *buf =
av_memdup(default_buf, default_buf_len);
99 *buf_len = default_buf_len;
102 "invalid %s size (%d bytes, block size is %d)\n",
111 const char *nested_url;
125 c->key,
c->keylen,
"decryption key")) < 0)
128 c->iv,
c->ivlen,
"decryption IV")) < 0)
134 c->key,
c->keylen,
"encryption key")) < 0)
138 c->iv,
c->ivlen,
"encryption IV")) < 0)
144 h->protocol_whitelist,
h->protocol_blacklist,
h)) < 0) {
151 if (!
c->aes_decrypt) {
160 if (
c->hd->is_streamed)
161 h->is_streamed =
c->hd->is_streamed;
166 if (!
c->aes_encrypt) {
187 if (
c->outdata > 0) {
189 memcpy(buf,
c->outptr,
size);
192 c->position =
c->position +
size;
201 sizeof(
c->inbuffer) -
c->indata);
214 blocks,
c->decrypt_iv, 1);
216 c->outptr =
c->outbuffer;
218 if (
c->indata_used >=
sizeof(
c->inbuffer)/2) {
219 memmove(
c->inbuffer,
c->inbuffer +
c->indata_used,
220 c->indata -
c->indata_used);
221 c->indata -=
c->indata_used;
226 int padding =
c->outbuffer[
c->outdata - 1];
227 c->outdata -= padding;
240 "Crypto: seek not supported for write\r\n");
258 "Crypto: seek_end - can't get file size (pos=%"PRId64
")\r\n",
pos);
267 "Crypto: no support for seek where 'whence' is %d\r\n", whence);
274 c->outptr =
c->outbuffer;
281 memcpy(
c->decrypt_iv,
c->iv,
c->ivlen );
295 "Crypto: nested protocol no support for seek or seek failed\n");
301 if (
pos -
c->position) {
316 char errbuf[100] =
"unknown error";
319 "Crypto: discard read did not get all the bytes (%d remain) - read returned (%d)-%s\n",
331 int total_size, blocks, pad_len,
out_size;
334 total_size =
size +
c->pad_len;
346 memcpy(&
c->pad[
c->pad_len], buf,
BLOCKSIZE -
c->pad_len);
354 blocks,
c->encrypt_iv, 0);
360 memcpy(
c->pad, &buf[
size - pad_len], pad_len);
362 memcpy(&
c->pad[
c->pad_len], buf,
size);
364 c->pad_len = pad_len;
374 if (
c->aes_encrypt) {
378 memset(&
c->pad[
c->pad_len], pad, pad);
static int64_t ffurl_seek(URLContext *h, int64_t pos, int whence)
Change the position that will be used by the next read/write operation on the resource accessed by h.
int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
Initialize an AVAES context.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int crypto_write(URLContext *h, const unsigned char *buf, int size)
#define AVERROR_EOF
End of file.
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
#define AVSEEK_SIZE
ORing this as the "whence" parameter to a seek function causes it to return the filesize without seek...
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
@ AV_OPT_TYPE_BINARY
Underlying C type is a uint8_t* that is either NULL or points to an array allocated with the av_mallo...
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
static const AVClass crypto_class
struct AVAES * aes_decrypt
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ffurl_open_whitelist(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options, const char *whitelist, const char *blacklist, URLContext *parent)
Create an URLContext for accessing to the resource indicated by url, and open it.
#define AVIO_FLAG_WRITE
write-only
static int set_aes_arg(URLContext *h, uint8_t **buf, int *buf_len, uint8_t *default_buf, int default_buf_len, const char *desc)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
const char * av_default_item_name(void *ptr)
Return the context name.
struct AVAES * aes_encrypt
void av_aes_crypt(AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt)
Encrypt or decrypt a buffer using a previously initialized context.
struct AVAES * av_aes_alloc(void)
Allocate an AVAES context.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
const OptionDef options[]
#define URL_PROTOCOL_FLAG_NESTED_SCHEME
static int crypto_open2(URLContext *h, const char *uri, int flags, AVDictionary **options)
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
uint8_t inbuffer[BLOCKSIZE *MAX_BUFFER_BLOCKS]
static int crypto_close(URLContext *h)
static const AVOption crypto_options[]
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
unsigned int write_buf_size
uint8_t outbuffer[BLOCKSIZE *MAX_BUFFER_BLOCKS]
static int crypto_read(URLContext *h, uint8_t *buf, int size)
#define AVIO_FLAG_READ
read-only
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
const URLProtocol ff_crypto_protocol
#define flags(name, subs,...)
The exact code depends on how similar the blocks are and how related they are to the block
static int64_t crypto_seek(URLContext *h, int64_t pos, int whence)
#define MAX_BUFFER_BLOCKS
static int ffurl_read(URLContext *h, uint8_t *buf, int size)
Read up to size bytes from the resource accessed by h, and store the read bytes in buf.