33#define MAX_BUFFER_BLOCKS 257
66#define OFFSET(x) offsetof(CryptoContext, x)
67#define D AV_OPT_FLAG_DECODING_PARAM
68#define E AV_OPT_FLAG_ENCODING_PARAM
80 .class_name =
"crypto",
87 uint8_t *default_buf,
int default_buf_len,
91 if (!default_buf_len) {
94 }
else if (default_buf_len !=
BLOCKSIZE) {
96 "invalid %s size (%d bytes, block size is %d)\n",
100 *buf =
av_memdup(default_buf, default_buf_len);
103 *buf_len = default_buf_len;
106 "invalid %s size (%d bytes, block size is %d)\n",
115 const char *nested_url;
129 c->key,
c->keylen,
"decryption key")) < 0)
132 c->iv,
c->ivlen,
"decryption IV")) < 0)
138 c->key,
c->keylen,
"encryption key")) < 0)
142 c->iv,
c->ivlen,
"encryption IV")) < 0)
148 h->protocol_whitelist,
h->protocol_blacklist,
h)) < 0) {
155 if (!
c->aes_decrypt) {
164 if (
c->hd->is_streamed)
165 h->is_streamed =
c->hd->is_streamed;
170 if (!
c->aes_encrypt) {
191 if (
c->outdata > 0) {
193 memcpy(buf,
c->outptr,
size);
196 c->position =
c->position +
size;
205 sizeof(
c->inbuffer) -
c->indata);
218 blocks,
c->decrypt_iv, 1);
220 c->outptr =
c->outbuffer;
222 if (
c->indata_used >=
sizeof(
c->inbuffer)/2) {
223 memmove(
c->inbuffer,
c->inbuffer +
c->indata_used,
224 c->indata -
c->indata_used);
225 c->indata -=
c->indata_used;
230 int padding =
c->outbuffer[
c->outdata - 1];
231 c->outdata -= padding;
244 "Crypto: seek not supported for write\r\n");
262 "Crypto: seek_end - can't get file size (pos=%"PRId64
")\r\n",
pos);
271 "Crypto: no support for seek where 'whence' is %d\r\n", whence);
278 c->outptr =
c->outbuffer;
285 memcpy(
c->decrypt_iv,
c->iv,
c->ivlen );
299 "Crypto: nested protocol no support for seek or seek failed\n");
305 if (
pos -
c->position) {
321 "Crypto: discard read did not get all the bytes (%d remain) - read returned (%d)-%s\n",
333 int total_size, blocks, pad_len,
out_size;
336 total_size =
size +
c->pad_len;
348 memcpy(&
c->pad[
c->pad_len], buf,
BLOCKSIZE -
c->pad_len);
356 blocks,
c->encrypt_iv, 0);
362 memcpy(
c->pad, &buf[
size - pad_len], pad_len);
364 memcpy(&
c->pad[
c->pad_len], buf,
size);
366 c->pad_len = pad_len;
376 if (
c->aes_encrypt) {
380 memset(&
c->pad[
c->pad_len], pad, pad);
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.
int ffurl_closep(URLContext **hh)
Close the resource accessed by the URLContext h, and free the memory used by it.
#define AVIO_FLAG_READ
read-only
#define AVSEEK_SIZE
Passing this as the "whence" parameter to a seek function causes it to return the filesize without se...
#define AVIO_FLAG_WRITE
write-only
#define flags(name, subs,...)
static int64_t crypto_seek(URLContext *h, int64_t pos, int whence)
static int set_aes_arg(URLContext *h, uint8_t **buf, int *buf_len, uint8_t *default_buf, int default_buf_len, const char *desc)
static int crypto_write(URLContext *h, const unsigned char *buf, int size)
static int crypto_open2(URLContext *h, const char *uri, int flags, AVDictionary **options)
#define MAX_BUFFER_BLOCKS
static const AVOption crypto_options[]
const URLProtocol ff_crypto_protocol
static int crypto_close(URLContext *h)
static const AVClass crypto_class
static int crypto_read(URLContext *h, uint8_t *buf, int size)
@ 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...
struct AVAES * av_aes_alloc(void)
Allocate an AVAES context.
int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt)
Initialize an AVAES context.
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.
#define AVERROR_EOF
End of file.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
#define LIBAVUTIL_VERSION_INT
Memory handling functions.
#define BLOCKSIZE
subblock size in 16-bit words
Describe the class of an AVClass context structure.
struct AVAES * aes_encrypt
struct AVAES * aes_decrypt
uint8_t inbuffer[BLOCKSIZE *MAX_BUFFER_BLOCKS]
unsigned int write_buf_size
uint8_t outbuffer[BLOCKSIZE *MAX_BUFFER_BLOCKS]
unbuffered private I/O API
#define URL_PROTOCOL_FLAG_NESTED_SCHEME
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.
static int ffurl_write(URLContext *h, const uint8_t *buf, int size)
Write size bytes from buf to the resource accessed by h.
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.