remove dependency of demos to tests/common

This commit is contained in:
Steffen Jaeckel 2017-06-08 11:54:38 +02:00
parent da3b61c7b6
commit fe0b72ef51
9 changed files with 64 additions and 45 deletions

View File

@ -15,8 +15,6 @@
#define basename(x) x #define basename(x) x
#endif #endif
#include "common.h"
#if !defined(PATH_MAX) && defined(_MSC_VER) #if !defined(PATH_MAX) && defined(_MSC_VER)
#include <windows.h> #include <windows.h>
#define PATH_MAX MAX_PATH #define PATH_MAX MAX_PATH
@ -159,7 +157,8 @@ int main(int argc, char **argv)
hashsum = strdup(basename(argv[0])); hashsum = strdup(basename(argv[0]));
/* You need to register algorithms before using them */ /* 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)) { if (argc > 1 && (strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0)) {
die(EXIT_SUCCESS); die(EXIT_SUCCESS);
} }

View File

@ -9,8 +9,6 @@
#include <tomcrypt.h> #include <tomcrypt.h>
#include "common.h"
int usage(char *name) int usage(char *name)
{ {
int x; int x;
@ -38,7 +36,8 @@ int main(int argc, char *argv[])
int err; int err;
/* register algs, so they can be printed */ /* register algs, so they can be printed */
register_algs(); register_all_ciphers();
register_all_hashes();
if (argc < 4) { if (argc < 4) {
if ((argc > 2) && (!strcmp(argv[1], "-t"))) { if ((argc > 2) && (!strcmp(argv[1], "-t"))) {

View File

@ -1,4 +1,12 @@
#include <common.h> #include <tomcrypt.h>
#if defined(_WIN32)
#define PRI64 "I64d"
#else
#define PRI64 "ll"
#endif
static prng_state yarrow_prng;
/* timing */ /* timing */
#define KTIMES 25 #define KTIMES 25
@ -1341,9 +1349,11 @@ static void time_encmacs(void)
int main(void) int main(void)
{ {
int err;
init_timer(); init_timer();
register_algs(); register_all_ciphers();
register_all_hashes();
register_all_prngs();
#ifdef USE_LTM #ifdef USE_LTM
ltc_mp = ltm_desc; ltc_mp = ltm_desc;
@ -1356,6 +1366,11 @@ register_algs();
ltc_mp = EXT_MATH_LIB; ltc_mp = EXT_MATH_LIB;
#endif #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_keysched();
time_cipher_ecb(); time_cipher_ecb();
time_cipher_cbc(); time_cipher_cbc();

View File

@ -1,7 +1,5 @@
#include <tomcrypt.h> #include <tomcrypt.h>
#include "common.h"
void hash_gen(void) void hash_gen(void)
{ {
unsigned char md[MAXBLOCKSIZE], *buf; unsigned char md[MAXBLOCKSIZE], *buf;
@ -736,8 +734,22 @@ void lrw_gen(void)
int main(void) int main(void)
{ {
register_algs(); register_all_ciphers();
setup_math(); 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 hash vectors..."); fflush(stdout); hash_gen(); printf("done\n");
printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n"); printf("Generating cipher vectors..."); fflush(stdout); cipher_gen(); printf("done\n");

View File

@ -58,11 +58,11 @@ ifneq ($V,1)
endif endif
${silent} $(RANLIB) $@ ${silent} $(RANLIB) $@
timing: $(LIBNAME) $(TIMINGS) tests/common.o timing: $(LIBNAME) $(TIMINGS)
ifneq ($V,1) ifneq ($V,1)
@echo " * ${CC} $@" @echo " * ${CC} $@"
endif 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) test: $(LIBNAME) $(TOBJECTS)
ifneq ($V,1) ifneq ($V,1)
@ -72,11 +72,11 @@ endif
# build the demos from a template # build the demos from a template
define DEMO_template define DEMO_template
$(1): demos/$(1).o $$(LIBNAME) tests/common.o $(1): demos/$(1).o $$(LIBNAME)
ifneq ($V,1) ifneq ($V,1)
@echo " * $${CC} $$@" @echo " * $${CC} $$@"
endif 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 endef
$(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo)))) $(foreach demo, $(strip $(DEMOS)), $(eval $(call DEMO_template,$(demo))))

View File

@ -235,16 +235,16 @@ $(LIBMAIN_D) $(LIBMAIN_I): $(OBJECTS)
$(STRIP) -S $(LIBMAIN_D) $(STRIP) -S $(LIBMAIN_D)
#Demo tools/utilities #Demo tools/utilities
hashsum.exe: demos/hashsum.o tests/common.o $(LIBMAIN_S) hashsum.exe: demos/hashsum.o $(LIBMAIN_S)
$(CC) $? $(LTC_LDFLAGS) -o $@ $(CC) demos/hashsum.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
ltcrypt.exe: demos/ltcrypt.o tests/common.o $(LIBMAIN_S) crypt.exe: demos/crypt.o $(LIBMAIN_S)
$(CC) $? $(LTC_LDFLAGS) -o $@ $(CC) demos/crypt.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
small.exe: demos/small.o tests/common.o $(LIBMAIN_S) small.exe: demos/small.o $(LIBMAIN_S)
$(CC) $? $(LTC_LDFLAGS) -o $@ $(CC) demos/small.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
tv_gen.exe: demos/tv_gen.o tests/common.o $(LIBMAIN_S) tv_gen.exe: demos/tv_gen.o $(LIBMAIN_S)
$(CC) $? $(LTC_LDFLAGS) -o $@ $(CC) demos/tv_gen.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
timing.exe: demos/timing.o tests/common.o $(LIBMAIN_S) timing.exe: demos/timing.o $(LIBMAIN_S)
$(CC) $? $(LTC_LDFLAGS) -o $@ $(CC) demos/timing.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
#Tests #Tests
test.exe: $(TOBJECTS) $(LIBMAIN_S) test.exe: $(TOBJECTS) $(LIBMAIN_S)

View File

@ -46,12 +46,12 @@ install_bins: .common_install_bins
test: $(LIBNAME) $(TOBJECTS) test: $(LIBNAME) $(TOBJECTS)
$(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TEST) $(TOBJECTS) $(LIBNAME) $(EXTRALIBS) $(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) $(LT) --mode=link --tag=CC $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $(TIMING) $^ $(EXTRALIBS)
# build the demos from a template # build the demos from a template
define DEMO_template define DEMO_template
$(1): demos/$(1).o tests/common.o $$(LIBNAME) $(1): demos/$(1).o $$(LIBNAME)
ifneq ($V,1) ifneq ($V,1)
@echo " * $${CC} $$@" @echo " * $${CC} $$@"
endif endif

View File

@ -237,16 +237,16 @@ $(LIBMAIN_S): $(OBJECTS)
$(RANLIB) $@ $(RANLIB) $@
#Demo tools/utilities #Demo tools/utilities
hashsum: demos/hashsum.o tests/common.o $(LIBMAIN_S) hashsum: demos/hashsum.o $(LIBMAIN_S)
$(CC) demos/hashsum.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ $(CC) demos/hashsum.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
ltcrypt: demos/ltcrypt.o tests/common.o $(LIBMAIN_S) ltcrypt: demos/ltcrypt.o $(LIBMAIN_S)
$(CC) demos/ltcrypt.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ $(CC) demos/ltcrypt.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
small: demos/small.o tests/common.o $(LIBMAIN_S) small: demos/small.o $(LIBMAIN_S)
$(CC) demos/small.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ $(CC) demos/small.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
tv_gen: demos/tv_gen.o tests/common.o $(LIBMAIN_S) tv_gen: demos/tv_gen.o $(LIBMAIN_S)
$(CC) demos/tv_gen.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ $(CC) demos/tv_gen.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
timing: demos/timing.o tests/common.o $(LIBMAIN_S) timing: demos/timing.o $(LIBMAIN_S)
$(CC) demos/timing.o tests/common.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@ $(CC) demos/timing.o $(LIBMAIN_S) $(LTC_LDFLAGS) -o $@
#Tests #Tests
test: $(TOBJECTS) $(LIBMAIN_S) test: $(TOBJECTS) $(LIBMAIN_S)

View File

@ -3,12 +3,6 @@
#include <tomcrypt.h> #include <tomcrypt.h>
#if defined(_WIN32)
#define PRI64 "I64d"
#else
#define PRI64 "ll"
#endif
extern prng_state yarrow_prng; extern prng_state yarrow_prng;
#ifdef LTC_VERBOSE #ifdef LTC_VERBOSE