aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-10-14 13:33:07 +0200
committerMattias Andrée <maandree@kth.se>2017-10-14 13:33:07 +0200
commitb5612bbbcbfd4fff7e8552579a7dd81a141d90d3 (patch)
tree1ed81a17345ac89a5ce89e232ac478b84297a4ce
parentUse arg.h instead of argparser (diff)
downloadsha3sum-b5612bbbcbfd4fff7e8552579a7dd81a141d90d3.tar.gz
sha3sum-b5612bbbcbfd4fff7e8552579a7dd81a141d90d3.tar.bz2
sha3sum-b5612bbbcbfd4fff7e8552579a7dd81a141d90d3.tar.xz
Generate all C files except common.c and keccaksum.c
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--.gitignore4
-rw-r--r--Makefile14
-rw-r--r--common.c4
-rw-r--r--common.h23
-rw-r--r--keccak-224sum.c11
-rw-r--r--keccak-256sum.c11
-rw-r--r--keccak-384sum.c11
-rw-r--r--keccak-512sum.c11
-rw-r--r--keccaksum.c9
-rw-r--r--rawshake256sum.c11
-rw-r--r--rawshake512sum.c11
-rw-r--r--sha3-224sum.c11
-rw-r--r--sha3-256sum.c11
-rw-r--r--sha3-384sum.c11
-rw-r--r--sha3-512sum.c11
-rw-r--r--shake256sum.c11
-rw-r--r--shake512sum.c11
17 files changed, 36 insertions, 150 deletions
diff --git a/.gitignore b/.gitignore
index 575cf5b..1829cd3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,7 @@
*.1
!/xsum.1
/*sum
+/keccak-*sum.c
+/sha3-*sum.c
+/rawshake*sum.c
+/shake*sum.c
diff --git a/Makefile b/Makefile
index 8981243..ca8a99d 100644
--- a/Makefile
+++ b/Makefile
@@ -49,6 +49,18 @@ all: $(BIN) $(MAN1)
u=$$(printf '%s\n' $* | tr a-z A-Z); \
sed -e 's/xsum/$*/g' -e 's/XSUM/'"$$u"'/g' -e 's/Xsum/$($*)/g' < xsum.1 > $@
+keccak-%sum.c:
+ printf '%s\n' '#include "common.h"' 'KECCAK_MAIN($*)' > $@
+
+sha3-%sum.c:
+ printf '%s\n' '#include "common.h"' 'SHA3_MAIN($*)' > $@
+
+rawshake%sum.c:
+ printf '%s\n' '#include "common.h"' 'RAWSHAKE_MAIN($*)' > $@
+
+shake%sum.c:
+ printf '%s\n' '#include "common.h"' 'SHAKE_MAIN($*)' > $@
+
install:
mkdir -p -- "$(DESTDIR)$(PREFIX)/bin"
mkdir -p -- "$(DESTDIR)$(MANPREFIX)/man1"
@@ -64,7 +76,7 @@ uninstall:
-rmdir -- "$(DESTDIR)$(PREFIX)/share/licenses/sha3sum"
clean:
- -rm -r -- $(MAN1) $(BIN)
+ -rm -r -- $(MAN1) $(BIN) keccak-*sum.c sha3-*sum.c rawshake*sum.c shake*sum.c
.SUFFIXES:
diff --git a/common.c b/common.c
index 53d25ad..1c16dd2 100644
--- a/common.c
+++ b/common.c
@@ -122,7 +122,7 @@ make_spec(libkeccak_generalised_spec_t *restrict gspec, libkeccak_spec_t *restri
{
int r;
-#define TEST(CASE, STR) case LIBKECCAK_GENERALISED_SPEC_ERROR_##CASE: return USER_ERROR(STR)
+#define TEST(CASE, STR) case LIBKECCAK_GENERALISED_SPEC_ERROR_##CASE: return USER_ERROR(STR)
if (r = libkeccak_degeneralise_spec(gspec, spec), r) {
switch (r) {
TEST (STATE_NONPOSITIVE, "the state size must be positive");
@@ -142,7 +142,7 @@ make_spec(libkeccak_generalised_spec_t *restrict gspec, libkeccak_spec_t *restri
}
#undef TEST
-#define TEST(CASE, STR) case LIBKECCAK_SPEC_ERROR_##CASE: return USER_ERROR(STR)
+#define TEST(CASE, STR) case LIBKECCAK_SPEC_ERROR_##CASE: return USER_ERROR(STR)
if (r = libkeccak_spec_check(spec), r) {
switch (r) {
TEST (BITRATE_NONPOSITIVE, "the rate size must be positive");
diff --git a/common.h b/common.h
index f4fff6b..d503811 100644
--- a/common.h
+++ b/common.h
@@ -1,13 +1,22 @@
/* See LICENSE file for copyright and license details. */
#include <libkeccak.h>
-/**
- * Wrapper for `run` that also initialises the command line parser
- *
- * @param suffix The message suffix
- */
-#define RUN(suffix)\
- (run(argc, argv, &spec, suffix))
+
+#define COMMON_MAIN(CONFIGURATION, SUFFIX)\
+ int main(int argc, char *argv[]) {\
+ libkeccak_generalised_spec_t spec;\
+ libkeccak_generalised_spec_initialise(&spec);\
+ CONFIGURATION;\
+ return run(argc, argv, &spec, SUFFIX);\
+ }
+#define KECCAK_MAIN(N)\
+ COMMON_MAIN(libkeccak_spec_sha3((libkeccak_spec_t *)&spec, N), "")
+#define SHA3_MAIN(N)\
+ COMMON_MAIN(libkeccak_spec_sha3((libkeccak_spec_t *)&spec, N), LIBKECCAK_SHA3_SUFFIX)
+#define RAWSHAKE_MAIN(N)\
+ COMMON_MAIN(libkeccak_spec_rawshake((libkeccak_spec_t *)&spec, N, N), LIBKECCAK_RAWSHAKE_SUFFIX)
+#define SHAKE_MAIN(N)\
+ COMMON_MAIN(libkeccak_spec_shake((libkeccak_spec_t *)&spec, N, N), LIBKECCAK_SHAKE_SUFFIX)
/**
diff --git a/keccak-224sum.c b/keccak-224sum.c
deleted file mode 100644
index c9c2294..0000000
--- a/keccak-224sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_sha3((libkeccak_spec_t *)&spec, 224);
- return RUN("");
-}
diff --git a/keccak-256sum.c b/keccak-256sum.c
deleted file mode 100644
index 8e780d8..0000000
--- a/keccak-256sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_sha3((libkeccak_spec_t *)&spec, 256);
- return RUN("");
-}
diff --git a/keccak-384sum.c b/keccak-384sum.c
deleted file mode 100644
index 39e74f8..0000000
--- a/keccak-384sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_sha3((libkeccak_spec_t *)&spec, 384);
- return RUN("");
-}
diff --git a/keccak-512sum.c b/keccak-512sum.c
deleted file mode 100644
index cd1a302..0000000
--- a/keccak-512sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_sha3((libkeccak_spec_t *)&spec, 512);
- return RUN("");
-}
diff --git a/keccaksum.c b/keccaksum.c
index 54a9cee..4bb2f3d 100644
--- a/keccaksum.c
+++ b/keccaksum.c
@@ -1,10 +1,3 @@
/* See LICENSE file for copyright and license details. */
#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- return RUN("");
-}
+COMMON_MAIN(, "")
diff --git a/rawshake256sum.c b/rawshake256sum.c
deleted file mode 100644
index 207d075..0000000
--- a/rawshake256sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_rawshake((libkeccak_spec_t *)&spec, 256, 256);
- return RUN(LIBKECCAK_RAWSHAKE_SUFFIX);
-}
diff --git a/rawshake512sum.c b/rawshake512sum.c
deleted file mode 100644
index fce679f..0000000
--- a/rawshake512sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_rawshake((libkeccak_spec_t *)&spec, 512, 512);
- return RUN(LIBKECCAK_RAWSHAKE_SUFFIX);
-}
diff --git a/sha3-224sum.c b/sha3-224sum.c
deleted file mode 100644
index 1a09b85..0000000
--- a/sha3-224sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_sha3((libkeccak_spec_t *)&spec, 224);
- return RUN(LIBKECCAK_SHA3_SUFFIX);
-}
diff --git a/sha3-256sum.c b/sha3-256sum.c
deleted file mode 100644
index 6e976d1..0000000
--- a/sha3-256sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_sha3((libkeccak_spec_t *)&spec, 256);
- return RUN(LIBKECCAK_SHA3_SUFFIX);
-}
diff --git a/sha3-384sum.c b/sha3-384sum.c
deleted file mode 100644
index 200f564..0000000
--- a/sha3-384sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_sha3((libkeccak_spec_t *)&spec, 384);
- return RUN(LIBKECCAK_SHA3_SUFFIX);
-}
diff --git a/sha3-512sum.c b/sha3-512sum.c
deleted file mode 100644
index 3ae6c54..0000000
--- a/sha3-512sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_sha3((libkeccak_spec_t *)&spec, 512);
- return RUN(LIBKECCAK_SHA3_SUFFIX);
-}
diff --git a/shake256sum.c b/shake256sum.c
deleted file mode 100644
index ff3af9f..0000000
--- a/shake256sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_shake((libkeccak_spec_t *)&spec, 256, 256);
- return RUN(LIBKECCAK_SHAKE_SUFFIX);
-}
diff --git a/shake512sum.c b/shake512sum.c
deleted file mode 100644
index ad39ab2..0000000
--- a/shake512sum.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#include "common.h"
-
-int
-main(int argc, char *argv[])
-{
- libkeccak_generalised_spec_t spec;
- libkeccak_generalised_spec_initialise(&spec);
- libkeccak_spec_shake((libkeccak_spec_t *)&spec, 512, 512);
- return RUN(LIBKECCAK_SHAKE_SUFFIX);
-}