aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/Config.src12
-rw-r--r--coreutils/Kbuild.src1
-rw-r--r--coreutils/md5_sha1_sum.c17
3 files changed, 27 insertions, 3 deletions
diff --git a/coreutils/Config.src b/coreutils/Config.src
index a28449b11..0c44c4b51 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 d6453f014..b715b9c47 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 59b520fce..92a4d4462 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', /* "md5>s<um" */
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 */
}