mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 3/7] add sha1 support
Date: Thu, 16 Sep 2010 17:59:36 +0200	[thread overview]
Message-ID: <20100916155936.GD5762@game.jcrosoft.org> (raw)
In-Reply-To: <20100916155357.GB1473@pengutronix.de>

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@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@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.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2010-09-16 16:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-09 13:55 [PATCH 0/7] Digest and login/password Frameworks Jean-Christophe PLAGNIOL-VILLARD
2010-09-09 13:59 ` [PATCH 1/7] add digest framework Jean-Christophe PLAGNIOL-VILLARD
2010-09-09 13:59 ` [PATCH 2/7] add md5 support Jean-Christophe PLAGNIOL-VILLARD
2010-09-16 15:43   ` Sascha Hauer
2010-09-17  4:42     ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-09 13:59 ` [PATCH 3/7] add sha1 support Jean-Christophe PLAGNIOL-VILLARD
2010-09-16 15:53   ` Sascha Hauer
2010-09-16 15:59     ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2010-09-09 13:59 ` [PATCH 4/7] add sha256 support Jean-Christophe PLAGNIOL-VILLARD
2010-09-09 13:59 ` [PATCH 5/7] add password framework Jean-Christophe PLAGNIOL-VILLARD
2010-09-09 13:59 ` [PATCH 6/7] add passwd command Jean-Christophe PLAGNIOL-VILLARD
2010-09-09 13:59 ` [PATCH 7/7] add login support Jean-Christophe PLAGNIOL-VILLARD
2010-09-09 14:01 ` [PATCH 0/7] Digest and login/password Frameworks Jean-Christophe PLAGNIOL-VILLARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100916155936.GD5762@game.jcrosoft.org \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox