Re: [libav-devel] [PATCH 1/2] Add a protocol handler for AES CBC decryption with PKCS7 padding

2011-04-22 Thread Martin Storsjö
On Wed, 20 Apr 2011, Anton Khirnov wrote:

> This could use more verbosity, especially if it'll be visible to users
> later on.
> 
> Otherwise looks fine to me.

Since both patches had gotten ok's now - pushed.

// Martin
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] Add a protocol handler for AES CBC decryption with PKCS7 padding

2011-04-20 Thread Anton Khirnov
On Wed, 20 Apr 2011 16:27:58 +0300, Martin Storsjö  wrote:
> This can later be extended to support other AES bit sizes,
> encryption, other crypto algorithms, reading the key from a URL, etc.
> 
> In order to use it, the key and initialization vector has to be
> passed via AVOptions. Since such options can't be passed to
> protocols from the command line, the protocol is currently
> only for libavformat internal use.
> ---
>  libavformat/Makefile |1 +
>  libavformat/allformats.c |1 +
>  libavformat/crypto.c |  170 
> ++
>  3 files changed, 172 insertions(+), 0 deletions(-)
>  create mode 100644 libavformat/crypto.c
> 
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 5e029ed..e2e3982 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -312,6 +312,7 @@ OBJS+= avio.o aviobuf.o
>  
>  OBJS-$(CONFIG_APPLEHTTP_PROTOCOL)+= applehttpproto.o
>  OBJS-$(CONFIG_CONCAT_PROTOCOL)   += concat.o
> +OBJS-$(CONFIG_CRYPTO_PROTOCOL)   += crypto.o
>  OBJS-$(CONFIG_FILE_PROTOCOL) += file.o
>  OBJS-$(CONFIG_GOPHER_PROTOCOL)   += gopher.o
>  OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o httpauth.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 931947d..f1c3d3b 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -235,6 +235,7 @@ void av_register_all(void)
>  /* protocols */
>  REGISTER_PROTOCOL (APPLEHTTP, applehttp);
>  REGISTER_PROTOCOL (CONCAT, concat);
> +REGISTER_PROTOCOL (CRYPTO, crypto);
>  REGISTER_PROTOCOL (FILE, file);
>  REGISTER_PROTOCOL (GOPHER, gopher);
>  REGISTER_PROTOCOL (HTTP, http);
> diff --git a/libavformat/crypto.c b/libavformat/crypto.c
> new file mode 100644
> index 000..4157c4d
> --- /dev/null
> +++ b/libavformat/crypto.c
> @@ -0,0 +1,170 @@
> +/*
> + * Decryption protocol handler
> + * Copyright (c) 2011 Martin Storsjo
> + *
> + * This file is part of Libav.
> + *
> + * Libav is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * Libav is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with Libav; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
> + */
> +
> +#include "avformat.h"
> +#include "libavutil/aes.h"
> +#include "libavutil/avstring.h"
> +#include "libavutil/opt.h"
> +#include "internal.h"
> +#include "url.h"
> +
> +#define MAX_BUFFER_BLOCKS 150
> +#define BLOCKSIZE 16
> +
> +typedef struct {
> +const AVClass *class;
> +URLContext *hd;
> +uint8_t inbuffer [BLOCKSIZE*MAX_BUFFER_BLOCKS],
> +outbuffer[BLOCKSIZE*MAX_BUFFER_BLOCKS];
> +uint8_t *outptr;
> +int indata, indata_used, outdata;
> +int eof;
> +uint8_t *key;
> +int keylen;
> +uint8_t *iv;
> +int ivlen;
> +struct AVAES *aes;
> +} CryptoContext;
> +
> +#define OFFSET(x) offsetof(CryptoContext, x)
> +static const AVOption options[] = {
> +{"key", "", OFFSET(key), FF_OPT_TYPE_BINARY },
> +{"iv",  "", OFFSET(iv),  FF_OPT_TYPE_BINARY },

This could use more verbosity, especially if it'll be visible to users
later on.

Otherwise looks fine to me.

-- 
Anton Khirnov
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] Add a protocol handler for AES CBC decryption with PKCS7 padding

2011-04-12 Thread Martin Storsjö
On Tue, 12 Apr 2011, Diego Biurrun wrote:

> On Tue, Apr 12, 2011 at 11:08:13AM +0300, Martin Storsjö wrote:
> > This can later be extended to support other AES bit sizes,
> > encryption, other crypto algorithms, reading the key from a URL, etc.
> > 
> > --- /dev/null
> > +++ b/libavformat/crypto.c
> > @@ -0,0 +1,170 @@
> > +/*
> > + * Decryption protocol handler
> > + * Copyright (c) 2011 Martin Storsjo
> 
> You skip the umlaut in your own name?

I normally do that within files, yes. Since Janne used the full umlaut 
version in the git author names during the git conversion, I've kept on 
using it there, though, for consistency.

> > +#define OFFSET(x) offsetof(CryptoContext, x)
> > +static const AVOption options[] = {
> > +{"key", "", OFFSET(key), FF_OPT_TYPE_BINARY },
> > +{"iv", "", OFFSET(iv), FF_OPT_TYPE_BINARY },
> > +{NULL}
> > +};
> > +static const AVClass crypto_class = {
> > +"crypto", av_default_item_name, options, LIBAVUTIL_VERSION_INT
> > +};
> 
> That looks quite unreadable unindented and without separating empty
> lines.

Cleaned up locally. Normally, these AVOption lines get very very long, and 
skipping the indentation is a good compromise, but here it sure can be 
cleaned up.

> > +if (av_strstart(uri, "crypto+", &nested_url)) {
> > +} else if (av_strstart(uri, "crypto:", &nested_url)) {
> > +} else {
> > +av_log(NULL, AV_LOG_ERROR, "Unsupported url %s\n", uri);
> > +ret = AVERROR(EINVAL);
> > +goto err;
> > +}
> 
> Two empty if blocks?

They indicate the two cases where the url was successfully parsed. 
Simplified into if (!av_strstart() && !av_strstart()) { error; }.

> > +c->outptr += size;
> > +c->outdata -= size;
> 
> extra good alignment karma awaits here

Wooh, extra karma for me \o/

> > +c->outdata = BLOCKSIZE * blocks;
> > +c->outptr = c->outbuffer;
> > +c->indata_used += BLOCKSIZE * blocks;
> 
> ditto

Done

> > +c->indata -= c->indata_used;
> > +c->indata_used = 0;
> 
> ditto

Done

// Martin___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel


Re: [libav-devel] [PATCH 1/2] Add a protocol handler for AES CBC decryption with PKCS7 padding

2011-04-12 Thread Diego Biurrun
On Tue, Apr 12, 2011 at 11:08:13AM +0300, Martin Storsjö wrote:
> This can later be extended to support other AES bit sizes,
> encryption, other crypto algorithms, reading the key from a URL, etc.
> 
> --- /dev/null
> +++ b/libavformat/crypto.c
> @@ -0,0 +1,170 @@
> +/*
> + * Decryption protocol handler
> + * Copyright (c) 2011 Martin Storsjo

You skip the umlaut in your own name?

> +#define OFFSET(x) offsetof(CryptoContext, x)
> +static const AVOption options[] = {
> +{"key", "", OFFSET(key), FF_OPT_TYPE_BINARY },
> +{"iv", "", OFFSET(iv), FF_OPT_TYPE_BINARY },
> +{NULL}
> +};
> +static const AVClass crypto_class = {
> +"crypto", av_default_item_name, options, LIBAVUTIL_VERSION_INT
> +};

That looks quite unreadable unindented and without separating empty
lines.

> +if (av_strstart(uri, "crypto+", &nested_url)) {
> +} else if (av_strstart(uri, "crypto:", &nested_url)) {
> +} else {
> +av_log(NULL, AV_LOG_ERROR, "Unsupported url %s\n", uri);
> +ret = AVERROR(EINVAL);
> +goto err;
> +}

Two empty if blocks?

> +c->outptr += size;
> +c->outdata -= size;

extra good alignment karma awaits here

> +c->outdata = BLOCKSIZE * blocks;
> +c->outptr = c->outbuffer;
> +c->indata_used += BLOCKSIZE * blocks;

ditto

> +c->indata -= c->indata_used;
> +c->indata_used = 0;

ditto

> +static int crypto_close(URLContext *h)
> +{
> +CryptoContext *c = h->priv_data;
> +if (c->hd)
> +ffurl_close(c->hd);

unrelated: Maybe ffurl_close should be made NULL-tolerant.

Diego
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel