浏览代码

tests: add function print_hex()

Steffen Jaeckel 11 年之前
父节点
当前提交
efc6844f9c
共有 3 个文件被更改,包括 20 次插入19 次删除
  1. 6 19
      testprof/rsa_test.c
  2. 1 0
      testprof/tomcrypt_test.h
  3. 13 0
      testprof/x86_prof.c

+ 6 - 19
testprof/rsa_test.c

@@ -100,19 +100,6 @@ static int rsa_compat_test(void)
    return 0;
 }
 
-static void _rsa_testPrint(const char* what, const unsigned char* p, const unsigned long l)
-{
-  unsigned long x;
-  fprintf(stderr, "%s contents: \n", what);
-  for (x = 0; x < l; ) {
-      fprintf(stderr, "%02x ", p[x]);
-      if (!(++x % 16)) {
-         fprintf(stderr, "\n");
-      }
-  }
-  fprintf(stderr, "\n");
-}
-
 int rsa_test(void)
 {
    unsigned char in[1024], out[1024], tmp[1024];
@@ -200,8 +187,8 @@ for (cnt = 0; cnt < len; ) {
       }
       if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
          fprintf(stderr, "\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
-         _rsa_testPrint("Original", in, rsa_msgsize);
-         _rsa_testPrint("Output", tmp, len2);
+         print_hex("Original", in, rsa_msgsize);
+         print_hex("Output", tmp, len2);
          return 1;
       }
    }
@@ -230,8 +217,8 @@ for (cnt = 0; cnt < len; ) {
       }
       if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
          fprintf(stderr, "rsa_decrypt_key mismatch len %lu", len2);
-         _rsa_testPrint("Original", in, rsa_msgsize);
-         _rsa_testPrint("Output", tmp, len2);
+         print_hex("Original", in, rsa_msgsize);
+         print_hex("Output", tmp, len2);
          return 1;
       }
    }
@@ -256,8 +243,8 @@ for (cnt = 0; cnt < len; ) {
       }
       if (memcmp(tmp, in, rsa_msgsize)) {
          fprintf(stderr, "rsa_decrypt_key_ex mismatch data");
-         _rsa_testPrint("Original", in, rsa_msgsize);
-         _rsa_testPrint("Output", tmp, rsa_msgsize);
+         print_hex("Original", in, rsa_msgsize);
+         print_hex("Output", tmp, rsa_msgsize);
          return 1;
       }
    }

+ 1 - 0
testprof/tomcrypt_test.h

@@ -80,6 +80,7 @@ extern int no_results;
 extern const struct ltc_prng_descriptor no_prng_desc;
 #endif
 
+void print_hex(const char* what, const unsigned char* p, const unsigned long l);
 int sorter(const void *a, const void *b);
 void tally_results(int type);
 ulong64 rdtsc (void);

+ 13 - 0
testprof/x86_prof.c

@@ -2,6 +2,19 @@
 
 prng_state yarrow_prng;
 
+void print_hex(const char* what, const unsigned char* p, const unsigned long l)
+{
+  unsigned long x;
+  fprintf(stderr, "%s contents: \n", what);
+  for (x = 0; x < l; ) {
+      fprintf(stderr, "%02x ", p[x]);
+      if (!(++x % 16)) {
+         fprintf(stderr, "\n");
+      }
+  }
+  fprintf(stderr, "\n");
+}
+
 struct list results[100];
 int no_results;
 int sorter(const void *a, const void *b)