Browse Source

always provide `compare_testvector()` as a function

Steffen Jaeckel 8 years ago
parent
commit
4bbce780c4
2 changed files with 7 additions and 10 deletions
  1. 0 6
      src/headers/tomcrypt_misc.h
  2. 7 4
      src/misc/compare_testvector.c

+ 0 - 6
src/headers/tomcrypt_misc.h

@@ -99,13 +99,7 @@ void crc32_finish(crc32_state *ctx, void *hash, unsigned long size);
 int crc32_test(void);
 int crc32_test(void);
 #endif
 #endif
 
 
-#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
-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 compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which);
-#else
-#define compare_testvector(is, is_len, should, should_len, what, which) \
-   ((((is_len) != (should_len)) || (XMEMCMP((is), (should), (is_len)) != 0)) ? 1 : 0)
-#endif
 
 
 /* $Source$ */
 /* $Source$ */
 /* $Revision$ */
 /* $Revision$ */

+ 7 - 4
src/misc/compare_testvector.c

@@ -15,8 +15,7 @@
   Function to compare two testvectors and print a (detailed) error-message if required, Steffen Jaeckel
   Function to compare two testvectors and print a (detailed) error-message if required, Steffen Jaeckel
 */
 */
 
 
-#ifndef compare_testvector
-
+#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
 static void _print_hex(const char* what, const void* v, const unsigned long l)
 static void _print_hex(const char* what, const void* v, const unsigned long l)
 {
 {
   const unsigned char* p = v;
   const unsigned char* p = v;
@@ -49,6 +48,7 @@ static void _print_hex(const char* what, const void* v, const unsigned long l)
       }
       }
   }
   }
 }
 }
+#endif
 
 
 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 compare_testvector(const void* is, const unsigned long is_len, const void* should, const unsigned long should_len, const char* what, int which)
 {
 {
@@ -58,16 +58,19 @@ int compare_testvector(const void* is, const unsigned long is_len, const void* s
    else
    else
       res = XMEMCMP(is, should, MAX(is_len, should_len));
       res = XMEMCMP(is, should, MAX(is_len, should_len));
 
 
+#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
    if (res != 0) {
    if (res != 0) {
       fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);
       fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);
       _print_hex("SHOULD", should, should_len);
       _print_hex("SHOULD", should, should_len);
       _print_hex("IS    ", is, is_len);
       _print_hex("IS    ", is, is_len);
    }
    }
+#else
+   LTC_UNUSED_PARAM(which);
+   LTC_UNUSED_PARAM(what);
+#endif
 
 
    return res;
    return res;
 }
 }
-#endif
-
 
 
 /* $Source$ */
 /* $Source$ */
 /* $Revision$ */
 /* $Revision$ */