diff options
author | Mattias Andrée <maandree@kth.se> | 2020-10-21 16:22:41 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2020-10-21 16:22:41 +0200 |
commit | 1f16c1b20cc63bcf2adb91ab89098252ddcf005e (patch) | |
tree | 29f7545920cb88f015348b72db8c852bd5ffafc1 /sha3sum.c | |
parent | Add -z (diff) | |
download | sha3sum-1f16c1b20cc63bcf2adb91ab89098252ddcf005e.tar.gz sha3sum-1f16c1b20cc63bcf2adb91ab89098252ddcf005e.tar.bz2 sha3sum-1f16c1b20cc63bcf2adb91ab89098252ddcf005e.tar.xz |
Add sha3sum for compatibility with busybox (-w and -s are however not support)
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'sha3sum.c')
-rw-r--r-- | sha3sum.c | 68 |
1 files changed, 68 insertions, 0 deletions
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); +} |