Przeglądaj źródła

add compare_testvector()

Steffen Jaeckel 8 lat temu
rodzic
commit
60bb5440fb
2 zmienionych plików z 18 dodań i 0 usunięć
  1. 1 0
      testprof/tomcrypt_test.h
  2. 17 0
      testprof/x86_prof.c

+ 1 - 0
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);

+ 17 - 0
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)