On Sun, Jul 01, 2012 at 04:03:00PM +0200, Samuel Pitoiset wrote:
> ---
>  libavutil/Makefile       |    3 +
>  libavutil/avutil.h       |    2 +-
>  libavutil/xtea.c         |  149 
> ++++++++++++++++++++++++++++++++++++++++++++++
>  libavutil/xtea.h         |   58 ++++++++++++++++++
>  tests/fate/libavutil.mak |    4 +
>  tests/ref/fate/xtea      |    1 +
>  6 files changed, 216 insertions(+), 1 deletions(-)
>  create mode 100644 libavutil/xtea.c
>  create mode 100644 libavutil/xtea.h
>  create mode 100644 tests/ref/fate/xtea
> 
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index 6fe174b..aac18ad 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -37,6 +37,7 @@ HEADERS = adler32.h                                         
>             \
>            samplefmt.h                                                   \
>            sha.h                                                         \
>            time.h                                                        \
> +          xtea.h                                                        \
>  
>  ARCH_HEADERS = bswap.h                                                  \
>                 intmath.h                                                \
> @@ -81,6 +82,7 @@ OBJS = adler32.o                                            
>             \
>         time.o                                                           \
>         tree.o                                                           \
>         utils.o                                                          \
> +       xtea.o                                                           \
>  
>  TESTPROGS = adler32                                                     \
>              aes                                                         \
> @@ -98,3 +100,4 @@ TESTPROGS = adler32                                        
>              \
>              parseutils                                                  \
>              sha                                                         \
>              tree                                                        \
> +            xtea                                                        \
> diff --git a/libavutil/avutil.h b/libavutil/avutil.h
> index 351e827..3181152 100644
> --- a/libavutil/avutil.h
> +++ b/libavutil/avutil.h
> @@ -152,7 +152,7 @@
>   */
>  
>  #define LIBAVUTIL_VERSION_MAJOR 51
> -#define LIBAVUTIL_VERSION_MINOR 34
> +#define LIBAVUTIL_VERSION_MINOR 35
>  #define LIBAVUTIL_VERSION_MICRO  0
>  
>  #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
> diff --git a/libavutil/xtea.c b/libavutil/xtea.c
> new file mode 100644
> index 0000000..3adaf2e
> --- /dev/null
> +++ b/libavutil/xtea.c
> @@ -0,0 +1,149 @@
> +/*
> + * An 32-bit implementation of the XTEA algorithm
> + * Copyright (c) 2012 Samuel Pitoiset
> + *
> + * loosely based on the implementation of David Wheeler and Roger Needham
> + *
> + * 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 "libavutil/intreadwrite.h"
> +
> +#include "avutil.h"
> +#include "common.h"
> +#include "xtea.h"
> +
> +void av_xtea_init(AVXTEA *x, const uint8_t key[16])
> +{
> +    int i;
> +
> +    for (i = 0; i < 4; i++)
> +        x->key[i] = AV_RB32(key + (i << 2));
> +}
> +
> +void av_xtea_encrypt(AVXTEA *x, uint8_t *dst, const uint8_t *src, int count)
> +{
> +    uint32_t v0, v1, sum = 0, delta = 0x9E3779B9;
> +    int i;
> +
> +    while (count-- > 0) {
> +        v0 = AV_RB32(src);
> +        v1 = AV_RB32(src + 4);
> +
> +        for (i = 0; i < 32; i++) {
> +            v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + x->key[sum & 3]);
> +            sum += delta;
> +            v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + x->key[(sum >> 11) 
> & 3]);
> +        }
> +
> +        AV_WB32(dst, v0);
> +        AV_WB32(dst + 4, v1);
> +
> +        src++;
> +        dst++;

it should be incremented by 8

Otherwise it looks more or less fine.
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to