Digest and login/password Frameworks
cover Digest and login/password Frameworks
Hi,
this patch serie will introduce the support of 2 frameworks
Digest Framework
Which allow you to add easely digest algo
with md5, sha1, sha256
Login/Passwd Framework
It will allow you to protect your barebox with a password and require it via login command or manange it via passwd This framework use the Digest framework to calculate the checksum to store the password
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/7 add digest framework
--- common/Makefile | 1 + common/digest.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/digest.h | 49 ++++++++++++++++++++++++++++++++++ lib/Kconfig | 7 +++++ 4 files changed, 134 insertions(+), 0 deletions(-) create mode 100644 common/digest.c create mode 100644 include/digest.h
common/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-y += clock.o obj-y += command.o obj-$(CONFIG_CONSOLE_FULL) += console.o obj-$(CONFIG_CONSOLE_SIMPLE) += console_simple.o +obj-$(CONFIG_DIGEST) += digest.o obj-y += env.o obj-y += startup.o obj-y += misc.o
common/digest.c new file +77 -0
77 lines not on this page · raw message
include/digest.h new file +49 -0
49 lines not on this page · raw message
lib/Kconfig +7 -0
@@ -10,6 +10,13 @@ config CRC32 config CRC16 bool +menuconfig DIGEST + bool "Digest" + +if DIGEST + +endif + config GENERIC_FIND_NEXT_BIT def_bool n
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/7 add md5 support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- lib/Kconfig | 4 + lib/Makefile | 1 + lib/md5.c | 317 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 322 insertions(+), 0 deletions(-) create mode 100644 lib/md5.c
lib/Kconfig +4 -0
@@ -15,6 +15,10 @@ menuconfig DIGEST if DIGEST +config MD5 + bool "MD5" + default y + endif config GENERIC_FIND_NEXT_BIT
lib/Makefile +1 -0
@@ -34,3 +34,4 @@ obj-y += lzo/ 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
lib/md5.c new file +317 -0
317 lines not on this page · raw message
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/7] add md5 support
Quoted 13 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- lib/Kconfig | 4 + lib/Makefile | 1 + lib/md5.c | 317 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 322 insertions(+), 0 deletions(-) create mode 100644 lib/md5.clib/Kconfig +0
-0
lib/Kconfig menuconfig DIGEST · line 20
Quoted 6 lines
lib/Kconfig +3
-0@@ -15,6 +15,10 @@ menuconfig DIGEST if DIGEST +config MD5 + bool "MD5" + default y
Please no default y here.
Sascha
Quoted 345 lines
lib/Kconfig +1
-0+ endif config GENERIC_FIND_NEXT_BITlib/Makefile +1
-0@@ -34,3 +34,4 @@ obj-y += lzo/ 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.olib/md5.c new file +317
-0@@ -0,0 +1,317 @@ +/* +* This file was transplanted with slight modifications from Linux sources +* (fs/cifs/md5.c) into U-Boot by Bartlomiej Sieka <[email protected]>. +*/ + +/* +* This code implements the MD5 message-digest algorithm. +* The algorithm is due to Ron Rivest. This code was +* written by Colin Plumb in 1993, no copyright is claimed. +* This code is in the public domain; do with it what you wish. +* +* Equivalent code is available from RSA Data Security, Inc. +* This code has been tested against that, and is equivalent, +* except that you don't need to include two pages of legalese +* with every copy. +* +* To compute the message digest of a chunk of bytes, declare an +* MD5Context structure, pass it to MD5Init, call MD5Update as +* needed on buffers full of bytes, and then call MD5Final, which +* will fill a supplied 16-byte array with the digest. +*/ + +/* This code slightly modified to fit into Samba by +[email protected] Jun 2001 +and to fit the cifs vfs by +Steve French [email protected] */ + +#include <common.h> +#include <digest.h> +#include <init.h> + +struct MD5Context { +__u32 buf[4 ]; +__u32 bits[2 ]; +unsigned char in[64 ]; +}; + +static void +MD5Transform (__u32 buf[4 ],__u32 const in[16 ]); + +/* +* Note: this code is harmless on little-endian machines. +*/ +static void +byteReverse (unsigned char *buf,unsigned longs) +{ +__u32 t; +do { + t = (__u32) ((unsigned ) buf[3 ] <<8 | buf[2 ]) <<16 | + ((unsigned ) buf[1 ] <<8 | buf[0 ]); + *(__u32 *) buf = t; + buf +=4 ; + }while (--longs); +} + +/* +* Start MD5 accumulation. Set bit count to 0 and buffer to mysterious +* initialization constants. +*/ +static void +MD5Init (struct MD5Context *ctx) +{ + ctx->buf[0 ] =0x67452301 ; + ctx->buf[1 ] =0xefcdab89 ; + ctx->buf[2 ] =0x98badcfe ; + ctx->buf[3 ] =0x10325476 ; + + ctx->bits[0 ] =0 ; + ctx->bits[1 ] =0 ; +} + +/* +* Update context to reflect the concatenation of another buffer full +* of bytes. +*/ +static void +MD5Update (struct MD5Context *ctx,unsigned char const *buf,unsigned len) +{ + register__u32 t; + +/* Update bitcount */ + + t = ctx->bits[0 ]; +if ((ctx->bits[0 ] = t + ((__u32 ) len <<3 )) < t) + ctx->bits[1 ]++;/* Carry from low to high */ + ctx->bits[1 ] += len >>29 ; + + t = (t >>3 ) &0x3f ;/* Bytes already in shsInfo->data */ + +/* Handle any leading odd-sized chunks */ + +if (t) { +unsigned char *p = (unsigned char *) ctx->in + t; + + t =64 - t; +if (len < t) { +memmove (p, buf, len); +return ; + } +memmove (p, buf, t); +byteReverse (ctx->in,16 ); +MD5Transform (ctx->buf, (__u32 *) ctx->in); + buf += t; + len -= t; + } +/* Process data in 64-byte chunks */ + +while (len >=64 ) { +memmove (ctx->in, buf,64 ); +byteReverse (ctx->in,16 ); +MD5Transform (ctx->buf, (__u32 *) ctx->in); + buf +=64 ; + len -=64 ; + } + +/* Handle any remaining bytes of data. */ + +memmove (ctx->in, buf, len); +} + +/* +* Final wrapup - pad to 64-byte boundary with the bit pattern +* 1 0* (64-bit count of bits processed, MSB-first) +*/ +static void +MD5Final (unsigned char digest[16 ],struct MD5Context *ctx) +{ +unsigned int count; +unsigned char *p; + +/* Compute number of bytes mod 64 */ + count = (ctx->bits[0 ] >>3 ) &0x3F ; + +/* Set the first char of padding to 0x80. This is safe since there is +always at least one byte free */ + p = ctx->in + count; + *p++ =0x80 ; + +/* Bytes of padding needed to make 64 bytes */ + count =64 -1 - count; + +/* Pad out to 56 mod 64 */ +if (count <8 ) { +/* Two lots of padding: Pad the first block to 64 bytes */ +memset (p,0 , count); +byteReverse (ctx->in,16 ); +MD5Transform (ctx->buf, (__u32 *) ctx->in); + +/* Now fill the next block with 56 bytes */ +memset (ctx->in,0 ,56 ); + }else { +/* Pad block to 56 bytes */ +memset (p,0 , count -8 ); + } +byteReverse (ctx->in,14 ); + +/* Append length in bits and transform */ + ((__u32 *) ctx->in)[14 ] = ctx->bits[0 ]; + ((__u32 *) ctx->in)[15 ] = ctx->bits[1 ]; + +MD5Transform (ctx->buf, (__u32 *) ctx->in); +byteReverse ((unsigned char *) ctx->buf,4 ); +memmove (digest, ctx->buf,16 ); +memset (ctx,0 ,sizeof (*ctx));/* In case it's sensitive */ +} + +/* The four core functions - F1 is optimized somewhat */ + +/* #define F1(x, y, z) (x & y | ~x & z) */ +#define F1 (x, y, z) (z ^ (x & (y ^ z))) +#define F2 (x, y, z) F1(z, x, y) +#define F3 (x, y, z) (x ^ y ^ z) +#define F4 (x, y, z) (y ^ (x | ~z)) + +/* This is the central step in the MD5 algorithm. */ +#define MD5STEP (f, w, x, y, z, data, s) \ + ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) + +/* +* The core of the MD5 algorithm, this alters an existing MD5 hash to +* reflect the addition of 16 longwords of new data. MD5Update blocks +* the data and converts bytes into longwords for this routine. +*/ +static void +MD5Transform (__u32 buf[4 ],__u32 const in[16 ]) +{ + register__u32 a, b, c, d; + + a = buf[0 ]; + b = buf[1 ]; + c = buf[2 ]; + d = buf[3 ]; + +MD5STEP (F1 , a, b, c, d, in[0 ] +0xd76aa478 ,7 ); +MD5STEP (F1 , d, a, b, c, in[1 ] +0xe8c7b756 ,12 ); +MD5STEP (F1 , c, d, a, b, in[2 ] +0x242070db ,17 ); +MD5STEP (F1 , b, c, d, a, in[3 ] +0xc1bdceee ,22 ); +MD5STEP (F1 , a, b, c, d, in[4 ] +0xf57c0faf ,7 ); +MD5STEP (F1 , d, a, b, c, in[5 ] +0x4787c62a ,12 ); +MD5STEP (F1 , c, d, a, b, in[6 ] +0xa8304613 ,17 ); +MD5STEP (F1 , b, c, d, a, in[7 ] +0xfd469501 ,22 ); +MD5STEP (F1 , a, b, c, d, in[8 ] +0x698098d8 ,7 ); +MD5STEP (F1 , d, a, b, c, in[9 ] +0x8b44f7af ,12 ); +MD5STEP (F1 , c, d, a, b, in[10 ] +0xffff5bb1 ,17 ); +MD5STEP (F1 , b, c, d, a, in[11 ] +0x895cd7be ,22 ); +MD5STEP (F1 , a, b, c, d, in[12 ] +0x6b901122 ,7 ); +MD5STEP (F1 , d, a, b, c, in[13 ] +0xfd987193 ,12 ); +MD5STEP (F1 , c, d, a, b, in[14 ] +0xa679438e ,17 ); +MD5STEP (F1 , b, c, d, a, in[15 ] +0x49b40821 ,22 ); + +MD5STEP (F2 , a, b, c, d, in[1 ] +0xf61e2562 ,5 ); +MD5STEP (F2 , d, a, b, c, in[6 ] +0xc040b340 ,9 ); +MD5STEP (F2 , c, d, a, b, in[11 ] +0x265e5a51 ,14 ); +MD5STEP (F2 , b, c, d, a, in[0 ] +0xe9b6c7aa ,20 ); +MD5STEP (F2 , a, b, c, d, in[5 ] +0xd62f105d ,5 ); +MD5STEP (F2 , d, a, b, c, in[10 ] +0x02441453 ,9 ); +MD5STEP (F2 , c, d, a, b, in[15 ] +0xd8a1e681 ,14 ); +MD5STEP (F2 , b, c, d, a, in[4 ] +0xe7d3fbc8 ,20 ); +MD5STEP (F2 , a, b, c, d, in[9 ] +0x21e1cde6 ,5 ); +MD5STEP (F2 , d, a, b, c, in[14 ] +0xc33707d6 ,9 ); +MD5STEP (F2 , c, d, a, b, in[3 ] +0xf4d50d87 ,14 ); +MD5STEP (F2 , b, c, d, a, in[8 ] +0x455a14ed ,20 ); +MD5STEP (F2 , a, b, c, d, in[13 ] +0xa9e3e905 ,5 ); +MD5STEP (F2 , d, a, b, c, in[2 ] +0xfcefa3f8 ,9 ); +MD5STEP (F2 , c, d, a, b, in[7 ] +0x676f02d9 ,14 ); +MD5STEP (F2 , b, c, d, a, in[12 ] +0x8d2a4c8a ,20 ); + +MD5STEP (F3 , a, b, c, d, in[5 ] +0xfffa3942 ,4 ); +MD5STEP (F3 , d, a, b, c, in[8 ] +0x8771f681 ,11 ); +MD5STEP (F3 , c, d, a, b, in[11 ] +0x6d9d6122 ,16 ); +MD5STEP (F3 , b, c, d, a, in[14 ] +0xfde5380c ,23 ); +MD5STEP (F3 , a, b, c, d, in[1 ] +0xa4beea44 ,4 ); +MD5STEP (F3 , d, a, b, c, in[4 ] +0x4bdecfa9 ,11 ); +MD5STEP (F3 , c, d, a, b, in[7 ] +0xf6bb4b60 ,16 ); +MD5STEP (F3 , b, c, d, a, in[10 ] +0xbebfbc70 ,23 ); +MD5STEP (F3 , a, b, c, d, in[13 ] +0x289b7ec6 ,4 ); +MD5STEP (F3 , d, a, b, c, in[0 ] +0xeaa127fa ,11 ); +MD5STEP (F3 , c, d, a, b, in[3 ] +0xd4ef3085 ,16 ); +MD5STEP (F3 , b, c, d, a, in[6 ] +0x04881d05 ,23 ); +MD5STEP (F3 , a, b, c, d, in[9 ] +0xd9d4d039 ,4 ); +MD5STEP (F3 , d, a, b, c, in[12 ] +0xe6db99e5 ,11 ); +MD5STEP (F3 , c, d, a, b, in[15 ] +0x1fa27cf8 ,16 ); +MD5STEP (F3 , b, c, d, a, in[2 ] +0xc4ac5665 ,23 ); + +MD5STEP (F4 , a, b, c, d, in[0 ] +0xf4292244 ,6 ); +MD5STEP (F4 , d, a, b, c, in[7 ] +0x432aff97 ,10 ); +MD5STEP (F4 , c, d, a, b, in[14 ] +0xab9423a7 ,15 ); +MD5STEP (F4 , b, c, d, a, in[5 ] +0xfc93a039 ,21 ); +MD5STEP (F4 , a, b, c, d, in[12 ] +0x655b59c3 ,6 ); +MD5STEP (F4 , d, a, b, c, in[3 ] +0x8f0ccc92 ,10 ); +MD5STEP (F4 , c, d, a, b, in[10 ] +0xffeff47d ,15 ); +MD5STEP (F4 , b, c, d, a, in[1 ] +0x85845dd1 ,21 ); +MD5STEP (F4 , a, b, c, d, in[8 ] +0x6fa87e4f ,6 ); +MD5STEP (F4 , d, a, b, c, in[15 ] +0xfe2ce6e0 ,10 ); +MD5STEP (F4 , c, d, a, b, in[6 ] +0xa3014314 ,15 ); +MD5STEP (F4 , b, c, d, a, in[13 ] +0x4e0811a1 ,21 ); +MD5STEP (F4 , a, b, c, d, in[4 ] +0xf7537e82 ,6 ); +MD5STEP (F4 , d, a, b, c, in[11 ] +0xbd3af235 ,10 ); +MD5STEP (F4 , c, d, a, b, in[2 ] +0x2ad7d2bb ,15 ); +MD5STEP (F4 , b, c, d, a, in[9 ] +0xeb86d391 ,21 ); + + buf[0 ] += a; + buf[1 ] += b; + buf[2 ] += c; + buf[3 ] += d; +} + +struct md5 { +struct MD5Context context; +struct digest d; +}; + +static int digest_md5_init (struct digest *d) +{ + struct md5 *m = container_of(d, struct md5, d); + +MD5Init (&m->context); + +return 0 ; +} + +static int digest_md5_update (struct digest *d,const void *data, +unsigned long len) +{ + struct md5 *m = container_of(d, struct md5, d); + +MD5Update (&m->context, data, len); + +return 0 ; +} + +static int digest_md5_final (struct digest *d,unsigned char *md) +{ + struct md5 *m = container_of(d, struct md5, d); + +MD5Final (md, &m->context); + +return 0 ; +} + +static struct md5 m = { + .d = { + .name ="md5" , + .init = digest_md5_init, + .update = digest_md5_update, + .final = digest_md5_final, + .length =16 , + } +}; + +static int md5_digest_register (void ) +{ +digest_register (&m.d); + +return 0 ; +} +device_initcall (md5_digest_register);Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 2/7] add md5 support
Quoted 15 lines · Sascha Hauer
Quoted 14 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- lib/Kconfig | 4 + lib/Makefile | 1 + lib/md5.c | 317 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 322 insertions(+), 0 deletions(-) create mode 100644 lib/md5.clib/Kconfig +0
-0@@ -15,6 +15,10 @@ menuconfig DIGEST
Quoted 7 lines
lib/Kconfig menuconfig DIGEST · line 20
Quoted 5 lines
lib/Kconfig +3
-0if DIGEST +config MD5 + bool "MD5" + default yPlease no default y here.
fix in the next pull request
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/7 add sha1 support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- lib/Kconfig | 3 + lib/Makefile | 1 + lib/sha1.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 400 insertions(+), 0 deletions(-) create mode 100644 lib/sha1.c
lib/Kconfig +3 -0
@@ -19,6 +19,9 @@ config MD5 bool "MD5" default y +config SHA1 + bool "SHA1" + endif config GENERIC_FIND_NEXT_BIT
lib/Makefile +1 -0
@@ -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
lib/sha1.c new file +396 -0
396 lines not on this page · raw message
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 3/7] add sha1 support
Quoted 89 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- lib/Kconfig | 3 + lib/Makefile | 1 + lib/sha1.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 400 insertions(+), 0 deletions(-) create mode 100644 lib/sha1.clib/Kconfig +3
-0@@ -19,6 +19,9 @@ config MD5 bool "MD5" default y +config SHA1 + bool "SHA1" + endif config GENERIC_FIND_NEXT_BITlib/Makefile +1
-0@@ -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.olib/sha1.c new file +52
-0@@ -0,0 +1,396 @@ +/* +* Heiko Schocher, DENX Software Engineering, [email protected]. +* 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] ); \
lib/sha1.c line 62
Quoted 10 lines
lib/sha1.c new file +10
-0+} +#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?
Sascha
Signature · 9 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Re: [PATCH 3/7] add sha1 support
Quoted 103 lines · Sascha Hauer
Quoted 89 lines · Jean-Christophe PLAGNIOL-VILLARD
Signed-off-by Jean-Christophe PLAGNIOL-VILLARD <[email protected]>--- lib/Kconfig | 3 + lib/Makefile | 1 + lib/sha1.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 400 insertions(+), 0 deletions(-) create mode 100644 lib/sha1.clib/Kconfig +3
-0@@ -19,6 +19,9 @@ config MD5 bool "MD5" default y +config SHA1 + bool "SHA1" + endif config GENERIC_FIND_NEXT_BITlib/Makefile +1
-0@@ -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.olib/sha1.c new file +52
-0@@ -0,0 +1,396 @@ +/* +* Heiko Schocher, DENX Software Engineering, [email protected]. +* 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] ); \lib/sha1.c line 62
Quoted 10 lines
lib/sha1.c new file +10
-0+} +#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_be32a better weapon here?
Quoted 2 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/7 add sha256 support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- lib/Kconfig | 3 + lib/Makefile | 1 + lib/sha256.c | 319 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 323 insertions(+), 0 deletions(-) create mode 100644 lib/sha256.c
lib/Kconfig +3 -0
@@ -22,6 +22,9 @@ config MD5 config SHA1 bool "SHA1" +config SHA256 + bool "SHA256" + endif config GENERIC_FIND_NEXT_BIT
lib/Makefile +1 -0
@@ -36,3 +36,4 @@ 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 +obj-$(CONFIG_SHA256) += sha256.o
lib/sha256.c new file +319 -0
319 lines not on this page · raw message
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/7 add password framework
In reply to Jean-Christophe PLAGNIOL-VILLARD--- common/Kconfig | 28 +++++ common/Makefile | 1 + common/password.c | 286 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/password.h | 41 ++++++++ 4 files changed, 356 insertions(+), 0 deletions(-) create mode 100644 common/password.c create mode 100644 include/password.h
common/Kconfig +28 -0
@@ -264,6 +264,34 @@ config MENU a menu framework that allow us to create list menu to simplify barebox and make it more user-frendly +config PASSWORD + bool + prompt "Password Framework" + select DIGEST + help + allow you to have password protection framework + +if PASSWORD + +choice + prompt "passwd checksum" + +config PASSWD_SUM_MD5 + bool "MD5" + select MD5 + +config PASSWD_SUM_SHA1 + bool "SHA1" + select SHA1 + +config PASSWD_SUM_SHA256 + bool "SHA256" + select SHA256 + +endchoice + +endif + config DYNAMIC_CRC_TABLE bool depends on CRC32
common/Makefile +1 -0
@@ -17,6 +17,7 @@ obj-y += startup.o obj-y += misc.o obj-y += memsize.o obj-$(CONFIG_MENU) += menu.o +obj-$(CONFIG_PASSWORD) += password.o obj-$(CONFIG_MODULES) += module.o extra-$(CONFIG_MODULES) += module.lds
common/password.c new file +286 -0
286 lines not on this page · raw message
include/password.h new file +41 -0
41 lines not on this page · raw message
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 6/7 add passwd command
In reply to Jean-Christophe PLAGNIOL-VILLARD--- commands/Kconfig | 23 ++++++++++++ commands/Makefile | 1 + commands/passwd.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 0 deletions(-) create mode 100644 commands/passwd.c
commands/Kconfig +23 -0
@@ -60,6 +60,29 @@ config CMD_MENU_MANAGEMENT depends on CMD_MENU prompt "menu scripts management" +config CMD_PASSWD + tristate + select PASSWORD + prompt "passwd" + +if CMD_PASSWD + +choice + prompt "passwd mode" + +config PASSWD_MODE_HIDE + bool "Hide" + +config PASSWD_MODE_STAR + bool "Star" + +config PASSWD_MODE_CLEAR + bool "Clear" + +endchoice + +endif + endmenu menu "file commands "
commands/Makefile +1 -0
@@ -51,3 +51,4 @@ obj-$(CONFIG_CMD_UNLZO) += unlzo.o obj-$(CONFIG_CMD_I2C) += i2c.o obj-$(CONFIG_CMD_UBI) += ubi.o obj-$(CONFIG_CMD_MENU) += menu.o +obj-$(CONFIG_CMD_PASSWD) += passwd.o
commands/passwd.c new file +98 -0
98 lines not on this page · raw message
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 7/7 add login support
In reply to Jean-Christophe PLAGNIOL-VILLARD--- commands/Kconfig | 9 ++++++- commands/Makefile | 1 + commands/login.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 commands/login.c
commands/Kconfig +7 -2
@@ -60,12 +60,17 @@ config CMD_MENU_MANAGEMENT depends on CMD_MENU prompt "menu scripts management" -config CMD_PASSWD +config CMD_LOGIN tristate select PASSWORD + prompt "login" + +config CMD_PASSWD + tristate + select CMD_LOGIN prompt "passwd" -if CMD_PASSWD +if CMD_LOGIN || CMD_PASSWD choice prompt "passwd mode"
commands/Makefile +1 -0
@@ -52,3 +52,4 @@ obj-$(CONFIG_CMD_I2C) += i2c.o obj-$(CONFIG_CMD_UBI) += ubi.o obj-$(CONFIG_CMD_MENU) += menu.o obj-$(CONFIG_CMD_PASSWD) += passwd.o +obj-$(CONFIG_CMD_LOGIN) += login.o
commands/login.c new file +63 -0
63 lines not on this page · raw message
Signature · 7 lines
1.7.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Hi,
this patch serie will introduce the support of 2 frameworks
Digest Framework
Which allow you to add easely digest algo
with md5, sha1, sha256
Quoted 6 lines
Login/Passwd Framework
It will allow you to protect your barebox with a password and require it via login command or manange it via passwd This framework use the Digest framework to calculate the checksum to store the password
The following changes since commit 0d35c3c8a0c2a1f1ff06eac20a12af0186753bc4:
menu: simplify usage for clients (2010-08-30 21:06:02 +0200)
are available in the git repository at:
git://git.jcrosoft.org/barebox.git login_passwd
Jean-Christophe PLAGNIOL-VILLARD (7):
add digest framework
add md5 support
add sha1 support
add sha256 support
add password framework
add passwd command
add login support
commands/Kconfig | 28 ++++ commands/Makefile | 2 + commands/login.c | 63 +++++++++ commands/passwd.c | 98 +++++++++++++ common/Kconfig | 28 ++++ common/Makefile | 2 + common/digest.c | 77 ++++++++++ common/password.c | 286 +++++++++++++++++++++++++++++++++++++ include/digest.h | 49 +++++++ include/password.h | 41 ++++++ lib/Kconfig | 17 +++ lib/Makefile | 3 + lib/md5.c | 317 +++++++++++++++++++++++++++++++++++++++++ lib/sha1.c | 396 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/sha256.c | 319 ++++++++++++++++++++++++++++++++++++++++++ 15 files changed, 1726 insertions(+), 0 deletions(-) create mode 100644 commands/login.c create mode 100644 commands/passwd.c create mode 100644 common/digest.c create mode 100644 common/password.c create mode 100644 include/digest.h create mode 100644 include/password.h create mode 100644 lib/md5.c create mode 100644 lib/sha1.c create mode 100644 lib/sha256.c
Best Regards,
J.
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox