From 60bb5440fb9b666ed6723e998b0be3507ef0eca0 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Sat, 18 Feb 2017 14:42:16 +0100 Subject: [PATCH] add compare_testvector() --- testprof/tomcrypt_test.h | 1 + testprof/x86_prof.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/testprof/tomcrypt_test.h b/testprof/tomcrypt_test.h index abb5fc8..776580e 100644 --- a/testprof/tomcrypt_test.h +++ b/testprof/tomcrypt_test.h @@ -81,6 +81,7 @@ extern const struct ltc_prng_descriptor no_prng_desc; #endif void print_hex(const char* what, const void* v, const unsigned long l); +int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which); int sorter(const void *a, const void *b); void tally_results(int type); ulong64 rdtsc (void); diff --git a/testprof/x86_prof.c b/testprof/x86_prof.c index baf03d2..451a58c 100644 --- a/testprof/x86_prof.c +++ b/testprof/x86_prof.c @@ -16,6 +16,23 @@ void print_hex(const char* what, const void* v, const unsigned long l) fprintf(stderr, "\n"); } +int compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which) +{ + int res = 0; + if(is_len != should_len) + res = is_len > should_len ? -1 : 1; + else + res = XMEMCMP(is, should, MAX(is_len, should_len)); + + if (res != 0) { + fprintf(stderr, "Testvector #%i of %s failed:\n", which, what); + print_hex("SHOULD", should, should_len); + print_hex("IS ", is, is_len); + } + + return res; +} + struct list results[100]; int no_results; int sorter(const void *a, const void *b)