[FFmpeg-devel] [PATCH] Add SHA-2
Michael Niedermayer
michaelni
Wed Jul 8 17:25:24 CEST 2009
On Wed, Jul 08, 2009 at 07:44:31AM +0300, Kostya wrote:
> I intend to at least try pushing RTMP client before continuing work on
> it, and SHA-2 is used there. That's why this patch is appearing again.
>
> Note: files are renamed to sha.h and sha.c since they will contain code
> for both SHA-1 and SHA-2. Same for functions inside.
> Makefile | 4 -
> avutil.h | 2
> sha.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------
> sha.h | 38 +++++++--
> 4 files changed, 239 insertions(+), 48 deletions(-)
> 06d8a6ee4ef167c41e9c6c5dfb1cc21b5ac4f3a6 sha2.patch
> Index: libavutil/Makefile
> ===================================================================
> --- libavutil/Makefile (revision 19141)
> +++ libavutil/Makefile (working copy)
> @@ -17,7 +17,7 @@
> mem.h \
> pixfmt.h \
> rational.h \
> - sha1.h \
> + sha.h \
>
> OBJS = adler32.o \
> aes.o \
> @@ -41,7 +41,7 @@
> tree.o \
> utils.o \
>
> -TESTPROGS = adler32 aes base64 crc des lls md5 pca sha1 softfloat tree
> +TESTPROGS = adler32 aes base64 crc des lls md5 pca sha softfloat tree
> TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo
>
> DIRS = arm bfin sh4 x86
> Index: libavutil/avutil.h
> ===================================================================
> --- libavutil/avutil.h (revision 19141)
> +++ libavutil/avutil.h (working copy)
> @@ -35,7 +35,7 @@
> #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
>
> #define LIBAVUTIL_VERSION_MAJOR 50
> -#define LIBAVUTIL_VERSION_MINOR 3
> +#define LIBAVUTIL_VERSION_MINOR 4
> #define LIBAVUTIL_VERSION_MICRO 0
>
> #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
you cannot rename public headers (without a major version bump)
but iam not in favor of bumping now ...
> Index: libavutil/sha.c
> ===================================================================
> --- libavutil/sha.c (revision 19141)
> +++ libavutil/sha.c (working copy)
> @@ -1,6 +1,8 @@
> /*
> * Copyright (C) 2007 Michael Niedermayer <michaelni at gmx.at>
> + * Copyright (C) 2009 Konstantin Shishkov
> * based on public domain SHA-1 code by Steve Reid <steve at edmweb.com>
> + * and on BSD-licensed SHA-2 code by Aaron D. Gifford
> *
> * This file is part of FFmpeg.
> *
> @@ -21,15 +23,19 @@
>
> #include "common.h"
> #include "bswap.h"
> -#include "sha1.h"
> +#include "sha.h"
>
> -typedef struct AVSHA1 {
> - uint64_t count;
> - uint8_t buffer[64];
> - uint32_t state[5];
> -} AVSHA1;
> +/** hash context */
> +typedef struct AVSHA {
> + uint8_t digest_len; ///< digest length in 32-bit words
> + uint32_t state[8]; ///< current hash value
> + uint8_t buffer[64]; ///< 512-bit buffer of input values used in hash updating
> + uint64_t count; ///< number of bytes in buffer
> + /** function used to update hash for 512-bit input block */
> + void (*transform)(uint32_t *state, const uint8_t buffer[64]);
> +} AVSHA;
renaming non public things to sha without the 1 is ok and can be commited
adding doxy is ok as well in a seperate patch
adding the transform field is also ok as a serate patch
>
> -const int av_sha1_size = sizeof(AVSHA1);
> +const int av_sha_size = sizeof(AVSHA);
>
> #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
>
breaks ABI id guess
> @@ -43,9 +49,8 @@
> #define R3(v,w,x,y,z,i) z += (((w|x)&y)|(w&x)) + blk (i) + 0x8F1BBCDC + rol(v, 5); w = rol(w, 30);
> #define R4(v,w,x,y,z,i) z += ( w^x ^y) + blk (i) + 0xCA62C1D6 + rol(v, 5); w = rol(w, 30);
>
> -/* Hash a single 512-bit block. This is the core of the algorithm. */
>
> -static void transform(uint32_t state[5], const uint8_t buffer[64])
> +static void sha1_transform(uint32_t *state, const uint8_t buffer[64])
> {
> uint32_t block[80];
> unsigned int i, a, b, c, d, e;
probably belongs to the sha/sha1 rename
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090708/3eda0e3d/attachment.pgp>
More information about the ffmpeg-devel
mailing list