From fe0b72ef515e4b673a26a16fc0d49190188a10f6 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 8 Jun 2017 11:54:38 +0200 Subject: [PATCH] remove dependency of demos to tests/common --- demos/hashsum.c | 5 ++--- demos/ltcrypt.c | 5 ++--- demos/timing.c | 21 ++++++++++++++++++--- demos/tv_gen.c | 20 ++++++++++++++++---- makefile | 8 ++++---- makefile.mingw | 20 ++++++++++---------- makefile.shared | 4 ++-- makefile.unix | 20 ++++++++++---------- tests/common.h | 6 ------ 9 files changed, 64 insertions(+), 45 deletions(-) diff --git a/demos/hashsum.c b/demos/hashsum.c index b6e932e..24373f4 100644 --- a/demos/hashsum.c +++ b/demos/hashsum.c @@ -15,8 +15,6 @@ #define basename(x) x #endif -#include "common.h" - #if !defined(PATH_MAX) && defined(_MSC_VER) #include #define PATH_MAX MAX_PATH @@ -159,7 +157,8 @@ int main(int argc, char **argv) hashsum = strdup(basename(argv[0])); /* You need to register algorithms before using them */ - register_algs(); + register_all_ciphers(); + register_all_hashes(); if (argc > 1 && (strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0)) { die(EXIT_SUCCESS); } diff --git a/demos/ltcrypt.c b/demos/ltcrypt.c index 91c1e96..d4f16d8 100644 --- a/demos/ltcrypt.c +++ b/demos/ltcrypt.c @@ -9,8 +9,6 @@ #include -#include "common.h" - int usage(char *name) { int x; @@ -38,7 +36,8 @@ int main(int argc, char *argv[]) int err; /* register algs, so they can be printed */ - register_algs(); + register_all_ciphers(); + register_all_hashes(); if (argc < 4) { if ((argc > 2) && (!strcmp(argv[1], "-t"))) { diff --git a/demos/timing.c b/demos/timing.c index 91890ae..f03d74f 100644 --- a/demos/timing.c +++ b/demos/timing.c @@ -1,4 +1,12 @@ -#include +#include + +#if defined(_WIN32) + #define PRI64 "I64d" +#else + #define PRI64 "ll" +#endif + +static prng_state yarrow_prng; /* timing */ #define KTIMES 25 @@ -1341,9 +1349,11 @@ static void time_encmacs(void) int main(void) { - +int err; init_timer(); -register_algs(); +register_all_ciphers(); +register_all_hashes(); +register_all_prngs(); #ifdef USE_LTM ltc_mp = ltm_desc; @@ -1356,6 +1366,11 @@ register_algs(); ltc_mp = EXT_MATH_LIB; #endif +if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT_OK) { + fprintf(stderr, "rng_make_prng failed: %s\n", error_to_string(err)); + exit(EXIT_FAILURE); +} + time_keysched(); time_cipher_ecb(); time_cipher_cbc(); diff --git a/demos/tv_gen.c b/demos/tv_gen.c index 5cb61f1..93de2db 100644 --- a/demos/tv_gen.c +++ b/demos/tv_gen.c @@ -1,7 +1,5 @@ #include -#include "common.h" - void hash_gen(void) { unsigned char md[MAXBLOCKSIZE], *buf; @@ -736,8 +734,22 @@ void lrw_gen(void) int main(void) { - register_algs(); - setup_math(); + register_all_ciphers(); + register_all_hashes(); + register_all_prngs(); +#ifdef USE_LTM + ltc_mp = ltm_desc; +#elif defined(USE_TFM) + ltc_mp = tfm_desc; +#elif defined(USE_GMP) + ltc_mp = gmp_desc; +#elif defined(EXT_MATH_LIB) + extern ltc_math_descriptor EXT_MATH_LIB; + ltc_mp = EXT_MATH_LIB; +#else + fprintf(stderr, "No MPI provider available\n"); + exit(EXIT_FAILURE); +#endif printf("Generating hash vectors..."); fflush(stdout); hash_gen(); printf("done\n"); printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n"); diff --git a/makefile b/makefile index b670239..4620b86 100644 --- a/makefile +++ b/makefile @@ -58,11 +58,11 @@ ifneq ($V,1) endif ${silent} $(RANLIB) $@ -timing: $(LIBNAME) $(TIMINGS) tests/common.o +timing: $(LIBNAME) $(TIMINGS) ifneq ($V,1) @echo " * ${CC} $@" endif - ${silent} $(CC) $(LDFLAGS) $(TIMINGS) tests/common.o $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING) + ${silent} $(CC) $(LDFLAGS) $(TIMINGS) $(LIB_PRE) $(LIBNAME) $(LIB_POST) $(EXTRALIBS) -o $(TIMING) test: $(LIBNAME) $(TOBJECTS) ifneq ($V,1) @@ -72,11 +72,11 @@ endif # build the demos from a template define DEMO_template -$(1): demos/$(1).o $$(LIBNAME) tests/common.o +$(1): demos/$(1).o $$(LIBNAME) ifneq ($V,1) @echo " * $${CC} $$@" endif - $${silent} $$(CC) $$(CFLAGS) $$< tests/common.o $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1) + $${silent} $$(CC) $$(CFLAGS) $$< $$(LIB_PRE) $$(LIBNAME) $$(LIB_POST) $$(EXTRALIBS) -o $(1) endef $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) diff --git a/makefile.mingw b/makefile.mingw index d3ce92a..6ca85bc 100644 --- a/makefile.mingw +++ b/makefile.mingw @@ -235,16 +235,16 @@ $(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS) $(STRIP) -S $(LIBMAIN_D) #Demo tools/utilities -hashsum.exe: demos/hashsum.o tests/common.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ -ltcrypt.exe: demos/ltcrypt.o tests/common.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ -small.exe: demos/small.o tests/common.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ -tv_gen.exe: demos/tv_gen.o tests/common.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ -timing.exe: demos/timing.o tests/common.o $(LIBMAIN_S) - $(CC) $? $(LTC_LDFLAGS) -o $@ +hashsum.exe: demos/hashsum.o $(LIBMAIN_S) + $(CC) demos/hashsum.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +crypt.exe: demos/crypt.o $(LIBMAIN_S) + $(CC) demos/crypt.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +small.exe: demos/small.o $(LIBMAIN_S) + $(CC) demos/small.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +tv_gen.exe: demos/tv_gen.o $(LIBMAIN_S) + $(CC) demos/tv_gen.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +timing.exe: demos/timing.o $(LIBMAIN_S) + $(CC) demos/timing.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ #Tests test.exe: $(TOBJECTS) $(LIBMAIN_S) diff --git a/makefile.shared b/makefile.shared index 68083cd..e6be085 100644 --- a/makefile.shared +++ b/makefile.shared @@ -46,12 +46,12 @@ install_bins: .common_install_bins test: $(LIBNAME) $(TOBJECTS) $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS) -timing: $(TIMINGS) tests/common.o $(LIBNAME) +timing: $(TIMINGS) $(LIBNAME) $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TIMING) $^ $(EXTRALIBS) # build the demos from a template define DEMO_template -$(1): demos/$(1).o tests/common.o $$(LIBNAME) +$(1): demos/$(1).o $$(LIBNAME) ifneq ($V,1) @echo " * $${CC} $$@" endif diff --git a/makefile.unix b/makefile.unix index f1507a4..cd86330 100644 --- a/makefile.unix +++ b/makefile.unix @@ -237,16 +237,16 @@ $(LIBMAIN_S): $(OBJECTS) $(RANLIB) $@ #Demo tools/utilities -hashsum: demos/hashsum.o tests/common.o $(LIBMAIN_S) - $(CC) demos/hashsum.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ -ltcrypt: demos/ltcrypt.o tests/common.o $(LIBMAIN_S) - $(CC) demos/ltcrypt.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ -small: demos/small.o tests/common.o $(LIBMAIN_S) - $(CC) demos/small.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ -tv_gen: demos/tv_gen.o tests/common.o $(LIBMAIN_S) - $(CC) demos/tv_gen.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ -timing: demos/timing.o tests/common.o $(LIBMAIN_S) - $(CC) demos/timing.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +hashsum: demos/hashsum.o $(LIBMAIN_S) + $(CC) demos/hashsum.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +ltcrypt: demos/ltcrypt.o $(LIBMAIN_S) + $(CC) demos/ltcrypt.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +small: demos/small.o $(LIBMAIN_S) + $(CC) demos/small.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +tv_gen: demos/tv_gen.o $(LIBMAIN_S) + $(CC) demos/tv_gen.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ +timing: demos/timing.o $(LIBMAIN_S) + $(CC) demos/timing.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ #Tests test: $(TOBJECTS) $(LIBMAIN_S) diff --git a/tests/common.h b/tests/common.h index 483060f..8167233 100644 --- a/tests/common.h +++ b/tests/common.h @@ -3,12 +3,6 @@ #include -#if defined(_WIN32) - #define PRI64 "I64d" -#else - #define PRI64 "ll" -#endif - extern prng_state yarrow_prng; #ifdef LTC_VERBOSE