Samuel Pitoiset <[email protected]> writes:

> ---
>  libavutil/Makefile |    1 +
>  libavutil/bf.c     |  410 
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  libavutil/bf.h     |   59 ++++++++
>  3 files changed, 470 insertions(+), 0 deletions(-)
>  create mode 100644 libavutil/bf.c
>  create mode 100644 libavutil/bf.h
>
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index 6fe174b..b1f7183 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -51,6 +51,7 @@ OBJS = adler32.o                                            
>             \
>         audioconvert.o                                                   \
>         avstring.o                                                       \
>         base64.o                                                         \
> +       bf.o                                                             \

A slightly more descriptive filename would be nice.

> +static const uint32_t orig_p[BF_ROUNDS + 2] = {
> +    0x243F6A88L, 0x85A308D3L, 0x13198A2EL, 0x03707344L,

Drop the L suffix.  It serves no purpose.

> +static uint32_t F(AVBF *bf, uint32_t x)
> +{
> +    uint16_t a, b, c, d;

Why uint16_t?  The exact size of these variables does not appear to
matter, so please use plain 'unsigned'.

> +    uint32_t y;
> +
> +    d = (uint16_t)(x & 0xFF);
> +    x >>= 8;
> +    c = (uint16_t)(x & 0xFF);
> +    x >>= 8;
> +    b = (uint16_t)(x & 0xFF);
> +    x >>= 8;
> +    a = (uint16_t)(x & 0xFF);
> +    y = bf->s[0][a] + bf->s[1][b];
> +    y = y ^ bf->s[2][c];
> +    y = y + bf->s[3][d];
> +
> +    return y;
> +}
> +
> +void av_bf_init(AVBF *bf, const uint8_t *key, int key_len)
> +{
> +    uint32_t data, datal, datar;
> +    int i, j, k;
> +
> +    for (i = 0; i < 4; i++) {
> +        for (j = 0; j < 256; j++)
> +            bf->s[i][j] = orig_s[i][j];
> +    }
> +
> +    j = 0;
> +    for (i = 0; i < BF_ROUNDS + 2; ++i) {
> +        data = 0x00000000;

A plain 0 is fine.  This is just hard to read for no reason.  Also,
'data' is possibly the worst name ever used for a variable.
*Everything* is data.

> +        for (k = 0; k < 4; ++k) {
> +            data = (data << 8) | key[j];
> +            j = j + 1;
> +            if (j >= key_len)

if (++j >= key_len)

> diff --git a/libavutil/bf.h b/libavutil/bf.h
> new file mode 100644
> index 0000000..a4cba13
> --- /dev/null
> +++ b/libavutil/bf.h

This file could also use a more descriptive name.

> @@ -0,0 +1,59 @@
> +/*
> + * Blowfish algorithm
> + *
> + * 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
> + */
> +
> +#ifndef AVUTIL_BF_H
> +#define AVUTIL_BF_H
> +
> +#include <stdint.h>
> +
> +#define BF_ROUNDS 16

This should have an AV_ prefix.

> +struct AVBF {
> +    uint32_t p[BF_ROUNDS + 2];
> +    uint32_t s[4][256];
> +};

Short name again.  AVBlowfish would be better.

> +/**
> + * @brief Initializes an AVBF context.
> + *
> + * @param key a key
> + * @param key_len length of the key
> + */
> +void av_bf_init(struct AVBF *bf, const uint8_t *key, int key_len);

Please spell out 'blowfish' in all these functions instead of 'bf'.

-- 
Måns Rullgård
[email protected]
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to