[PATCH 3/7] add sha1 support
Jean-Christophe PLAGNIOL-VILLARD
plagnioj at jcrosoft.com
Thu Sep 16 11:59:36 EDT 2010
On 17:53 Thu 16 Sep , Sascha Hauer wrote:
> On Thu, Sep 09, 2010 at 03:59:49PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
> > ---
> > lib/Kconfig | 3 +
> > lib/Makefile | 1 +
> > lib/sha1.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 400 insertions(+), 0 deletions(-)
> > create mode 100644 lib/sha1.c
> >
> > diff --git a/lib/Kconfig b/lib/Kconfig
> > index e8776a7..650e86c 100644
> > --- a/lib/Kconfig
> > +++ b/lib/Kconfig
> > @@ -19,6 +19,9 @@ config MD5
> > bool "MD5"
> > default y
> >
> > +config SHA1
> > + bool "SHA1"
> > +
> > endif
> >
> > config GENERIC_FIND_NEXT_BIT
> > diff --git a/lib/Makefile b/lib/Makefile
> > index 6a1fb5d..6f79d03 100644
> > --- a/lib/Makefile
> > +++ b/lib/Makefile
> > @@ -35,3 +35,4 @@ obj-y += show_progress.o
> > obj-$(CONFIG_LZO_DECOMPRESS) += decompress_unlzo.o
> > obj-$(CONFIG_PROCESS_ESCAPE_SEQUENCE) += process_escape_sequence.o
> > obj-$(CONFIG_MD5) += md5.o
> > +obj-$(CONFIG_SHA1) += sha1.o
> > diff --git a/lib/sha1.c b/lib/sha1.c
> > new file mode 100644
> > index 0000000..00dcc78
> > --- /dev/null
> > +++ b/lib/sha1.c
> > @@ -0,0 +1,396 @@
> > +/*
> > + * Heiko Schocher, DENX Software Engineering, hs at denx.de.
> > + * based on:
> > + * FIPS-180-1 compliant SHA-1 implementation
> > + *
> > + * Copyright (C) 2003-2006 Christophe Devine
> > + *
> > + * This library is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU Lesser General Public
> > + * License, version 2.1 as published by the Free Software Foundation.
> > + *
> > + * This library 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 this library; if not, write to the Free Software
> > + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
> > + * MA 02110-1301 USA
> > + */
> > +/*
> > + * The SHA-1 standard was published by NIST in 1993.
> > + *
> > + * http://www.itl.nist.gov/fipspubs/fip180-1.htm
> > + */
> > +
> > +#include <common.h>
> > +#include <digest.h>
> > +#include <init.h>
> > +#include <linux/string.h>
> > +
> > +#define SHA1_SUM_POS -0x20
> > +#define SHA1_SUM_LEN 20
> > +
> > +typedef struct
> > +{
> > + unsigned long total[2]; /*!< number of bytes processed */
> > + unsigned long state[5]; /*!< intermediate digest state */
> > + unsigned char buffer[64]; /*!< data block being processed */
> > +}
> > +sha1_context;
> > +
> > +/*
> > + * 32-bit integer manipulation macros (big endian)
> > + */
> > +#ifndef GET_UINT32_BE
> > +#define GET_UINT32_BE(n,b,i) { \
> > + (n) = ( (unsigned long) (b)[(i) ] << 24 ) \
> > + | ( (unsigned long) (b)[(i) + 1] << 16 ) \
> > + | ( (unsigned long) (b)[(i) + 2] << 8 ) \
> > + | ( (unsigned long) (b)[(i) + 3] ); \
> > +}
> > +#endif
> > +#ifndef PUT_UINT32_BE
> > +#define PUT_UINT32_BE(n,b,i) { \
> > + (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \
> > + (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \
> > + (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \
> > + (b)[(i) + 3] = (unsigned char) ( (n) ); \
> > +}
> > +#endif
>
> Isn't cpu_to_be32 a better weapon here?
>
> The corresponding kernel code looks cleaner to me. Have you considered
> using it?
no I did not take a look on it as I choose to keep the original code but I can
put new patch to do it as a second step to keep the history of modification
IIRC it's the same for sha256
Best Regards,
J.
More information about the barebox
mailing list