[PATCH] sha3sum: New applet, v3

2013-01-08 Thread Lauri Kasanen
Hi

This patch should no longer crash @ ppc. But I think it will still have
wrong results on big-endian, and I'm not sure it's something I can fix
without access to such.

v3:
- Align to 64, just in case
- Use the correct type, size_t, in the update function

- Lauri

-- 
http://www.fastmail.fm - The way an email service should be

From 864e27f3a01ebff916ade68d5706ad0088bc5b40 Mon Sep 17 00:00:00 2001
From: Lauri Kasanen cur...@operamail.com
Date: Thu, 3 Jan 2013 21:10:01 +0200
Subject: [PATCH] sha3sum: New applet, v3

v3:
- Align to 64, just in case
- Use the correct type, size_t, in the update function

v2:
- Sorted the enum by alpha (was sorted by algorithm age)
- Use normal rotate here, xor not needed
- Comment cleanup
- Remove *empty* comments
- Unify one be/le path
- Remove #define round
- Move to if(BB_ENDIAN) instead of #if

Signed-off-by: Lauri Kasanen cur...@operamail.com
---
 coreutils/Config.src |   12 ++-
 coreutils/Kbuild.src |1 +
 coreutils/md5_sha1_sum.c |   17 
 include/applets.src.h|1 +
 include/libbb.h  |7 ++
 libbb/hash_md5_sha.c |  210 ++
 testsuite/sha3sum.tests  |3 +
 7 files changed, 248 insertions(+), 3 deletions(-)
 create mode 100755 testsuite/sha3sum.tests

diff --git a/coreutils/Config.src b/coreutils/Config.src
index a28449b..0c44c4b 100644
--- a/coreutils/Config.src
+++ b/coreutils/Config.src
@@ -514,6 +514,12 @@ config SHA512SUM
 	help
 	  Compute and check SHA512 message digest
 
+config SHA3SUM
+	bool sha3sum
+	default y
+	help
+	  Compute and check SHA3 (512-bit) message digest
+
 config SLEEP
 	bool sleep
 	default y
@@ -766,13 +772,13 @@ config FEATURE_HUMAN_READABLE
 	help
 	  Allow df, du, and ls to have human readable output.
 
-comment Common options for md5sum, sha1sum, sha256sum, sha512sum
-	depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM
+comment Common options for md5sum, sha1sum, sha256sum, sha512sum, sha3sum
+	depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM
 
 config FEATURE_MD5_SHA1_SUM_CHECK
 	bool Enable -c, -s and -w options
 	default y
-	depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM
+	depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM || SHA3SUM
 	help
 	  Enabling the -c options allows files to be checked
 	  against pre-calculated hash values.
diff --git a/coreutils/Kbuild.src b/coreutils/Kbuild.src
index d6453f0..b715b9c 100644
--- a/coreutils/Kbuild.src
+++ b/coreutils/Kbuild.src
@@ -62,6 +62,7 @@ lib-$(CONFIG_SEQ)   += seq.o
 lib-$(CONFIG_SHA1SUM)   += md5_sha1_sum.o
 lib-$(CONFIG_SHA256SUM) += md5_sha1_sum.o
 lib-$(CONFIG_SHA512SUM) += md5_sha1_sum.o
+lib-$(CONFIG_SHA3SUM)   += md5_sha1_sum.o
 lib-$(CONFIG_SLEEP) += sleep.o
 lib-$(CONFIG_SPLIT) += split.o
 lib-$(CONFIG_SORT)  += sort.o
diff --git a/coreutils/md5_sha1_sum.c b/coreutils/md5_sha1_sum.c
index 2cb6dd4..b62e7c2 100644
--- a/coreutils/md5_sha1_sum.c
+++ b/coreutils/md5_sha1_sum.c
@@ -55,6 +55,16 @@
 //usage: \n	-s	Don't output anything, status code shows success
 //usage: \n	-w	Warn about improperly formatted checksum lines
 //usage:	)
+//usage:
+//usage:#define sha3sum_trivial_usage
+//usage:	IF_FEATURE_MD5_SHA1_SUM_CHECK([-c[sw]] )[FILE]...
+//usage:#define sha3sum_full_usage \n\n
+//usage:   Print IF_FEATURE_MD5_SHA1_SUM_CHECK( or check)  SHA3-512 checksums
+//usage:	IF_FEATURE_MD5_SHA1_SUM_CHECK( \n
+//usage: \n	-c	Check sums against list in FILEs
+//usage: \n	-s	Don't output anything, status code shows success
+//usage: \n	-w	Warn about improperly formatted checksum lines
+//usage:	)
 
 #include libbb.h
 
@@ -65,6 +75,7 @@ enum {
 	HASH_MD5 = 's', /* md5sum */
 	HASH_SHA1 = '1',
 	HASH_SHA256 = '2',
+	HASH_SHA3 = '3',
 	HASH_SHA512 = '5',
 };
 
@@ -86,6 +97,7 @@ static uint8_t *hash_file(const char *filename)
 {
 	int src_fd, hash_len, count;
 	union _ctx_ {
+		sha3_ctx_t sha3;
 		sha512_ctx_t sha512;
 		sha256_ctx_t sha256;
 		sha1_ctx_t sha1;
@@ -124,6 +136,11 @@ static uint8_t *hash_file(const char *filename)
 		update = (void*)sha512_hash;
 		final = (void*)sha512_end;
 		hash_len = 64;
+	} else if (ENABLE_SHA3SUM  hash_algo == HASH_SHA3) {
+		sha3_begin(context.sha3);
+		update = (void*)sha3_hash;
+		final = (void*)sha3_end;
+		hash_len = 64;
 	} else {
 		xfunc_die(); /* can't reach this */
 	}
diff --git a/include/applets.src.h b/include/applets.src.h
index 597b1c9..29ab167 100644
--- a/include/applets.src.h
+++ b/include/applets.src.h
@@ -328,6 +328,7 @@ IF_SETSEBOOL(APPLET(setsebool, BB_DIR_USR_SBIN, BB_SUID_DROP))
 IF_SETSID(APPLET(setsid, BB_DIR_USR_BIN, BB_SUID_DROP))
 IF_SETUIDGID(APPLET_ODDNAME(setuidgid, chpst, BB_DIR_USR_BIN, BB_SUID_DROP, setuidgid))
 IF_SHA1SUM(APPLET_NOEXEC(sha1sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha1sum))
+IF_SHA3SUM(APPLET_NOEXEC(sha3sum, md5_sha1_sum, BB_DIR_USR_BIN, BB_SUID_DROP, sha3sum))
 IF_SHA256SUM(APPLET_NOEXEC(sha256sum, md5_sha1_sum, BB_DIR_USR_BIN

Re: [PATCH] sha3sum: New applet, v3

2013-01-08 Thread Baruch Siach
Hi Lauri,

On Tue, Jan 08, 2013 at 04:40:04PM +0200, Lauri Kasanen wrote:
 This patch should no longer crash @ ppc. But I think it will still have
 wrong results on big-endian, and I'm not sure it's something I can fix
 without access to such.

This version doesn't crash anymore, but the results on PowerPC are not in-line 
with x86_64 and the samples of http://en.wikipedia.org/wiki/Sha3:

# echo -n The quick brown fox jumps over the lazy dog |./busybox sha3sum 
a753cd80313d095c37641af35cf24fa2ea1e4f94200fb82676c24faa5abdbe6e2626bfff79014a882fc7ad55319b3e6894dfc1f5f4672de365957ff428944355
  -

The x86_64 build correctly gives me:

$ echo -n The quick brown fox jumps over the lazy dog |./busybox sha3sum
d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609
  -

You can send me a debug prints augmented version of your patch to run on my 
PowerPC board if you like.

baruch

-- 
 http://baruch.siach.name/blog/  ~. .~   Tk Open Systems
=}ooO--U--Ooo{=
   - bar...@tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] sha3sum: New applet, v3

2013-01-08 Thread Lauri Kasanen
 You can send me a debug prints augmented version of your patch to run on
 my PowerPC board if you like.

Thanks. Before we go to that, is the empty string example also wrong on
ppc? echo -n 

- Lauri

-- 
http://www.fastmail.fm - Send your email first class

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] sha3sum: New applet, v3

2013-01-08 Thread Matthew Stoltenberg
 # echo -n The quick brown fox jumps over the lazy dog |./busybox sha3sum
 a753cd80313d095c37641af35cf24fa2ea1e4f94200fb82676c24faa5abdbe6e2626bfff79014a882fc7ad55319b3e6894dfc1f5f4672de365957ff428944355
   -

I see the same results on big endien mips64.

Here's the blank output:
# echo -n  |./busybox sha3sum
f6ad23d035c22bbc2ef310794fa9ed41667cc821eff071962b842beb56c24db022aa10387a0738be43f642b41bd8526f545ce911db85d61c5711b59dd9841667
 -


 You can send me a debug prints augmented version of your patch to run on my
 PowerPC board if you like.

Ditto for mips.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox