aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile9
-rw-r--r--common.c11
-rw-r--r--common.h5
-rw-r--r--sha3sum.c68
-rwxr-xr-xtest34
-rw-r--r--xsum.man6
6 files changed, 128 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 7c94a28..32c3dfb 100644
--- a/Makefile
+++ b/Makefile
@@ -10,6 +10,7 @@ BIN =\
keccak-256sum\
keccak-384sum\
keccak-512sum\
+ sha3sum\
sha3-224sum\
sha3-256sum\
sha3-384sum\
@@ -22,11 +23,12 @@ BIN =\
MAN1 = $(BIN:=.1)
HDR = arg.h common.h
+keccaksum = Keccak[]
keccak-224sum = Keccak-224
keccak-256sum = Keccak-256
keccak-384sum = Keccak-384
keccak-512sum = Keccak-512
-keccaksum = Keccak[]
+sha3sum = SHA3
sha3-224sum = SHA3-224
sha3-256sum = SHA3-256
sha3-384sum = SHA3-384
@@ -48,6 +50,11 @@ all: $(BIN) $(MAN1)
%.1: xsum.man
u=$$(printf '%s\n' $* | tr a-z A-Z); \
sed -e 's/xsum/$*/g' -e 's/XSUM/'"$$u"'/g' -e 's/Xsum/$($*)/g' < xsum.man > $@
+ if test $* = sha3sum; then \
+ sed -i 's/^\\# ONLY SHA3: //' $@; \
+ else \
+ sed -i '/^\\# ONLY SHA3: /d' $@; \
+ fi
keccak-%sum.c:
printf '%s\n' '#include "common.h"' 'KECCAK_MAIN($*)' > $@
diff --git a/common.c b/common.c
index e902c29..9601aa5 100644
--- a/common.c
+++ b/common.c
@@ -452,10 +452,11 @@ print_checksum(const char *restrict filename, const struct libkeccak_spec *restr
* @param argv The second argument from `main`
* @param gspec The default algorithm parameters
* @param suffix Message suffix
+ * @param with_a Whether the -a option should be recognised (but ignored)
* @return An appropriate exit value
*/
int
-run(int argc, char *argv[], struct libkeccak_generalised_spec *restrict gspec, const char *restrict suffix)
+run(int argc, char *argv[], struct libkeccak_generalised_spec *restrict gspec, const char *restrict suffix, int with_a)
{
enum representation style = REPRESENTATION_UPPER_CASE;
int verbose = 0, hex = 0, check = 0, nuls = 0;
@@ -465,6 +466,7 @@ run(int argc, char *argv[], struct libkeccak_generalised_spec *restrict gspec, c
struct libkeccak_spec spec;
int r = 0;
+ /* Note: when options are added or removed, also update sha3sum.c */
ARGBEGIN {
case 'R':
gspec->bitrate = atol(EARGF(usage()));
@@ -507,10 +509,15 @@ run(int argc, char *argv[], struct libkeccak_generalised_spec *restrict gspec, c
case 'z':
nuls = 1;
break;
+ case 'a':
+ if (!with_a)
+ usage();
+ (void) EARGF(usage());
+ break;
default:
usage();
} ARGEND;
- /* -cz has been added because the sha1sum, sha256sum &c have
+ /* -cz has been added because the sha1sum, sha256sum, &c have
* it, but I ignore the other crap, mostly because not all
* implemention have them and binary vs text mode is stupid. */
diff --git a/common.h b/common.h
index f116035..66cc429 100644
--- a/common.h
+++ b/common.h
@@ -7,7 +7,7 @@
struct libkeccak_generalised_spec spec;\
libkeccak_generalised_spec_initialise(&spec);\
CONFIGURATION;\
- return run(argc, argv, &spec, SUFFIX);\
+ return run(argc, argv, &spec, SUFFIX, 0);\
}
#define KECCAK_MAIN(N)\
COMMON_MAIN(libkeccak_spec_sha3((struct libkeccak_spec *)&spec, N), "")
@@ -47,6 +47,7 @@ enum representation {
* @param argv The second argument from `main`
* @param gspec The default algorithm parameters
* @param suffix Message suffix
+ * @param with_a Whether the -a option should be recognised (but ignored)
* @return An appropriate exit value
*/
-int run(int argc, char *argv[], struct libkeccak_generalised_spec *restrict gspec, const char *restrict suffix);
+int run(int argc, char *argv[], struct libkeccak_generalised_spec *restrict gspec, const char *restrict suffix, int with_a);
diff --git a/sha3sum.c b/sha3sum.c
new file mode 100644
index 0000000..a34f8aa
--- /dev/null
+++ b/sha3sum.c
@@ -0,0 +1,68 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#include "arg.h"
+
+#include <alloca.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+static void
+usage(void)
+{
+ /*
+ * Since our main in this file validates the arguments,
+ * we can add -a here but leave it left out in common.c,
+ * which we like because the other commands do not have -a.
+ */
+
+ fprintf(stderr, "usage: %s [-u | -l | -b | -c] [-a bits] [-R rate] [-C capacity] "
+ "[-N output-size] [-S state-size] [-W word-size] "
+ "[-Z squeeze-count] [-vxz] [file ...]\n", argv0);
+ exit(2);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int bits = 224, orig_argc = argc;
+ char **orig_argv = alloca((argc + 1) * sizeof(*argv));
+ struct libkeccak_generalised_spec spec;
+
+ libkeccak_generalised_spec_initialise(&spec);
+ memcpy(orig_argv, argv, (argc + 1) * sizeof(*argv));
+
+ ARGBEGIN {
+ case 'R':
+ case 'C':
+ case 'N':
+ case 'O':
+ case 'S':
+ case 'B':
+ case 'W':
+ case 'Z':
+ (void) EARGF(usage());
+ break;
+ case 'u':
+ case 'l':
+ case 'b':
+ case 'c':
+ case 'v':
+ case 'x':
+ case 'z':
+ break;
+ case 'a':
+ bits = atoi(EARGF(usage()));
+ if (bits != 224 && bits != 256 && bits != 384 && bits != 512) {
+ fprintf(stderr, "%s: valid arguments for -a are 224 (default), 256, 384, and 512\n", argv0);
+ return 2;
+ }
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ libkeccak_spec_sha3((struct libkeccak_spec *)&spec, bits);
+ return run(orig_argc, orig_argv, &spec, LIBKECCAK_SHA3_SUFFIX, 1);
+}
diff --git a/test b/test
index f536ae2..5f73f12 100755
--- a/test
+++ b/test
@@ -16,6 +16,13 @@ test "$(printf '' | ./sha3-384sum)" = '0C63A75B845E4F7D01107D852E4C2485C51A50AAA
test "$(printf '' | ./sha3-512sum)" = 'A69F73CCA23A9AC5C8B567DC185A756E97C982164FE25859E0D1DCC1475C80A615B2123AF1F5F94C11E3E9402C3AC558F500199D95B6D3E301758586281DCD26 -'
+test "$(printf '' | ./sha3sum)" = '6B4E03423667DBB73B6E15454F0EB1ABD4597F9A1B078E3F5B5A6BC7 -'
+test "$(printf '' | ./sha3sum -a224)" = '6B4E03423667DBB73B6E15454F0EB1ABD4597F9A1B078E3F5B5A6BC7 -'
+test "$(printf '' | ./sha3sum -a256)" = 'A7FFC6F8BF1ED76651C14756A061D662F580FF4DE43B49FA82D80A4B80F8434A -'
+test "$(printf '' | ./sha3sum -a 384)" = '0C63A75B845E4F7D01107D852E4C2485C51A50AAAA94FC61995E71BBEE983A2AC3713831264ADB47FB6BD1E058D5F004 -'
+test "$(printf '' | ./sha3sum -a 512)" = 'A69F73CCA23A9AC5C8B567DC185A756E97C982164FE25859E0D1DCC1475C80A615B2123AF1F5F94C11E3E9402C3AC558F500199D95B6D3E301758586281DCD26 -'
+
+
test "$(printf '' | ./keccak-224sum)" = 'F71837502BA8E10837BDD8D365ADB85591895602FC552B48B7390ABD -'
test "$(printf '' | ./keccak-256sum)" = 'C5D2460186F7233C927E7DB2DCC703C0E500B653CA82273B7BFAD8045D85A470 -'
test "$(printf '' | ./keccak-384sum)" = '2C23146A63A29ACF99E73B88F8C24EAA7DC60AA771780CCC006AFBFA8FE2479B2DD2B21362337441AC12B515911957FF -'
@@ -53,6 +60,17 @@ test "$(printf 'archery lexicographical equine veered' | ./sha3-224sum)" = 'F0A3
test "$(printf 'splay washbasin opposing there' | ./sha3-224sum)" = '312E7E3C6403AB1A086155FB9A52B22A3D0D257876AFD2B93FB7272E -'
test "$(printf 'faktum desist thundered klen' | ./sha3-224sum)" = '270BA05B764221FF5B5D94ADFB4FDB1F36F07FE7C438904A5F3DF071 -'
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum)" = '22C8017AC8BCF65F59D1B7E92C9D4C6739D25E34CE5CB608B24FF096 -'
+test "$(printf 'intensifierat sturdiness perl-image-exiftool vingla' | ./sha3sum)" = '43808DDE2662143DC4EED5DAC5E98C74B06711829F02A3B121BD74F3 -'
+test "$(printf 'timjan avogadro uppdriven lib32-llvm-amdgpu-snapshot' | ./sha3sum)" = 'D32B4AC86065774DEE5EB5CDD2F67B4E86501086D7373884E8B20A36 -'
+test "$(printf "grilo-plugins auditorium tull dissimilarity's" | ./sha3sum)" = 'EFBD76D45BFA952485148F8AD46143897F17C27FFDC8EB7287F9353B -'
+test "$(printf 'royalty tt yellowstone deficiencies' | ./sha3sum)" = '6705AA36ECF58F333E0E6364AC1D0B7931D402E13282127CFD6F876C -'
+test "$(printf "kdegames-kdiamond tunisisk occurrence's outtalad" | ./sha3sum)" = '803A0FF09DDA0DF306E483A9F91B20A3DBBF9C2EBB8D0A3B28F3B9E0 -'
+test "$(printf "chevalier slat's spindel representations" | ./sha3sum)" = 'A64779ACA943A6AEF1D2E7C9A0F4E997F4DABD1F77112A22121D3ED5 -'
+test "$(printf 'archery lexicographical equine veered' | ./sha3sum)" = 'F0A3E0587AF7723F0AA4719059D3F5107115A5B3667CD5209CC4D867 -'
+test "$(printf 'splay washbasin opposing there' | ./sha3sum)" = '312E7E3C6403AB1A086155FB9A52B22A3D0D257876AFD2B93FB7272E -'
+test "$(printf 'faktum desist thundered klen' | ./sha3sum)" = '270BA05B764221FF5B5D94ADFB4FDB1F36F07FE7C438904A5F3DF071 -'
+
printf 'withdrew hypothesis snakebird qmc2' > .testdir/x
test "$(./sha3-224sum < .testdir/x)" = '22C8017AC8BCF65F59D1B7E92C9D4C6739D25E34CE5CB608B24FF096 -'
@@ -93,6 +111,22 @@ test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3-224sum -Z 3)" = '0B
test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3-224sum -Z 4)" = '1E03B4CD9EEF3892A7B5E865FCE393C4BC90120D9AEA84D0A0DFF3B8 -'
test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3-224sum -Z 5)" = 'AAC92FBFD22CE62E83DDAF2E61BD7BF696326E46D1327DEFA4530E20 -'
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum -Z 2)" = '03FE12B4B51D56D96377D927E5CD498FC4BC3AEE389B2F2FF8393AA5 -'
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum -Z 3)" = '0B8FB64EE5D8836956F49CBE4577AFBC638C855C1D553452FC1ECEB8 -'
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum -Z 4)" = '1E03B4CD9EEF3892A7B5E865FCE393C4BC90120D9AEA84D0A0DFF3B8 -'
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum -Z 5)" = 'AAC92FBFD22CE62E83DDAF2E61BD7BF696326E46D1327DEFA4530E20 -'
+
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum -a 224 -Z 2)" = '03FE12B4B51D56D96377D927E5CD498FC4BC3AEE389B2F2FF8393AA5 -'
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum -a 224 -Z 3)" = '0B8FB64EE5D8836956F49CBE4577AFBC638C855C1D553452FC1ECEB8 -'
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum -a 224 -Z 4)" = '1E03B4CD9EEF3892A7B5E865FCE393C4BC90120D9AEA84D0A0DFF3B8 -'
+test "$(printf 'withdrew hypothesis snakebird qmc2' | ./sha3sum -a 224 -Z 5)" = 'AAC92FBFD22CE62E83DDAF2E61BD7BF696326E46D1327DEFA4530E20 -'
+
+test "$(printf 'abc xyz' | ./sha3sum -a 256)" = "$(printf 'abc xyz' | ./sha3-256sum)"
+test "$(printf 'abc xyz' | ./sha3sum -a 384)" = "$(printf 'abc xyz' | ./sha3-384sum)"
+test "$(printf 'abc xyz' | ./sha3sum -a 512)" = "$(printf 'abc xyz' | ./sha3-512sum)"
+
+! printf '' | ./sha3sum -a 500 >/dev/null 2>/dev/null
+
printf 'alef' > .testdir/a
printf 'bet' > .testdir/b
diff --git a/xsum.man b/xsum.man
index dc1c0fd..fe11cd3 100644
--- a/xsum.man
+++ b/xsum.man
@@ -4,6 +4,8 @@ xsum - Compute and check Xsum message digests
.SH SYNOPSIS
.B xsum
[-u | -l | -b | -c]
+\# ONLY SHA3: [-a
+\# ONLY SHA3: .IR bits ]
[-R
.IR rate ]
[-C
@@ -44,6 +46,10 @@ contain a line feed, carriage return or form feed,
unless the
.B -z
option is also used.
+\# ONLY SHA3: .TP
+\# ONLY SHA3: .BI -a\ bits
+\# ONLY SHA3: Select version of the SHA3 algorithm. Valid values
+\# ONLY SHA3: are 224 (default), 256, 384, and 512.
.TP
.B -v
Print the hashing parameters.