Browse Source

re-work debug output of some tests

Steffen Jaeckel 10 years ago
parent
commit
9585faca2b

+ 6 - 2
makefile.include

@@ -41,8 +41,12 @@ endif
 CFLAGS += -Wno-type-limits
 
 ifdef LTC_DEBUG
-# compile for DEBUGING (required for ccmalloc checking!!!)
-CFLAGS += -g3 -DLTC_NO_ASM
+# compile for DEBUGGING (required for ccmalloc checking!!!)
+ifneq (,$(strip $(LTC_DEBUG)))
+CFLAGS += -g3 -DLTC_NO_ASM -DLTC_TEST_DBG=$(LTC_DEBUG)
+else
+CFLAGS += -g3 -DLTC_NO_ASM -DLTC_TEST_DBG
+endif
 else
 
 ifdef LTC_SMALL

+ 5 - 9
src/encauth/ccm/ccm_test.c

@@ -17,10 +17,6 @@
 
 #ifdef LTC_CCM_MODE
 
-#if defined(LTC_CCM_TEST_DBG) && !defined(LTC_NO_TEST)
-void print_hex(const char* what, const unsigned char* p, const unsigned long l);
-#endif
-
 int ccm_test(void)
 {
 #ifndef LTC_TEST
@@ -168,7 +164,7 @@ int ccm_test(void)
       }
 
       if (XMEMCMP(buf, tests[x].ct, tests[x].ptlen)) {
-#if defined(LTC_CCM_TEST_DBG)
+#if defined(LTC_TEST_DBG)
          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y);
          print_hex("ct is    ", tag, taglen);
          print_hex("ct should", tests[x].tag, taglen);
@@ -176,14 +172,14 @@ int ccm_test(void)
          return CRYPT_FAIL_TESTVECTOR;
       }
       if (tests[x].taglen != taglen) {
-#if defined(LTC_CCM_TEST_DBG)
+#if defined(LTC_TEST_DBG)
          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y);
          printf("taglen %lu (is) %lu (should)\n", taglen, tests[x].taglen);
 #endif
          return CRYPT_FAIL_TESTVECTOR;
       }
       if (XMEMCMP(tag, tests[x].tag, tests[x].taglen)) {
-#if defined(LTC_CCM_TEST_DBG)
+#if defined(LTC_TEST_DBG)
          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y);
          print_hex("tag is    ", tag, tests[x].taglen);
          print_hex("tag should", tests[x].tag, tests[x].taglen);
@@ -221,7 +217,7 @@ int ccm_test(void)
       }
 
       if (XMEMCMP(buf2, tests[x].pt, tests[x].ptlen)) {
-#if defined(LTC_CCM_TEST_DBG)
+#if defined(LTC_TEST_DBG)
          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y);
          print_hex("pt is    ", tag, taglen);
          print_hex("pt should", tests[x].tag, taglen);
@@ -229,7 +225,7 @@ int ccm_test(void)
          return CRYPT_FAIL_TESTVECTOR;
       }
       if (XMEMCMP(tag2, tests[x].tag, tests[x].taglen)) {
-#if defined(LTC_CCM_TEST_DBG)
+#if defined(LTC_TEST_DBG)
          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y);
          print_hex("tag is    ", tag, tests[x].taglen);
          print_hex("tag should", tests[x].tag, tests[x].taglen);

+ 5 - 0
src/headers/tomcrypt_misc.h

@@ -81,6 +81,11 @@ void adler32_finish(adler32_state *ctx, void *hash, unsigned long size);
 int adler32_test(void);
 #endif
 
+/* yeah it's not exactly in misc in the library, but in testprof/x86_prof.c */
+#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
+void print_hex(const char* what, const unsigned char* p, const unsigned long l);
+#endif
+
 /* $Source$ */
 /* $Revision$ */
 /* $Date$ */

+ 7 - 15
src/mac/hmac/hmac_test.c

@@ -603,7 +603,7 @@ int hmac_test(void)
         ++tested;
         outlen = sizeof(digest);
         if((err = hmac_memory(hash, cases[i].key, cases[i].keylen, cases[i].data, cases[i].datalen, digest, &outlen)) != CRYPT_OK) {
-#ifdef LTC_HMAC_TEST_DBG
+#ifdef LTC_TEST_DBG
             printf("HMAC-%s test %s, %s\n", cases[i].algo, cases[i].num, error_to_string(err));
 #endif
             return err;
@@ -611,25 +611,17 @@ int hmac_test(void)
 
         if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0)  {
             failed++;
-#ifdef LTC_HMAC_TEST_DBG
+#ifdef LTC_TEST_DBG
           {
-            unsigned int j;
-            printf("\nHMAC-%s test %s:\n", cases[i].algo, cases[i].num);
-            printf(  "Result:  0x");
-            for(j=0; j < hash_descriptor[hash].hashsize; j++) {
-                printf("%2x ", digest[j]);
-            }
-            printf("\nCorrect: 0x");
-            for(j=0; j < hash_descriptor[hash].hashsize; j++) {
-               printf("%2x ", cases[i].digest[j]);
-            }
-            printf("\n");
+            printf("\nHMAC-%s test %s: Failed\n", cases[i].algo, cases[i].num);
+            print_hex("is", digest, hash_descriptor[hash].hashsize);
+            print_hex("should", cases[i].digest, hash_descriptor[hash].hashsize);
             return CRYPT_FAIL_TESTVECTOR;
           }
-#endif
-#ifdef LTC_HMAC_TEST_DBG
+#if LTC_TEST_DBG > 1
         } else {
             printf("HMAC-%s test %s: Passed\n", cases[i].algo, cases[i].num);
+#endif
 #endif
         }
     }

+ 9 - 17
src/misc/pkcs5/pkcs_5_test.c

@@ -120,7 +120,7 @@ int pkcs_5_test (void)
     int hash = find_hash("sha1");
     if (hash == -1)
     {
-#ifdef LTC_PKCS_5_TEST_DBG
+#ifdef LTC_TEST_DBG
       printf("PKCS#5 test: 'sha1' hash not found\n");
 #endif
       return CRYPT_ERROR;
@@ -132,7 +132,7 @@ int pkcs_5_test (void)
                               (unsigned char*)cases_5_2[i].S, cases_5_2[i].S_len,
                               cases_5_2[i].c, hash,
                               DK, &dkLen)) != CRYPT_OK) {
-#ifdef LTC_PKCS_5_TEST_DBG
+#ifdef LTC_TEST_DBG
             printf("PKCS#5 test #%d: %s\n", i, error_to_string(err));
 #endif
             return err;
@@ -140,7 +140,7 @@ int pkcs_5_test (void)
 
         if (dkLen != cases_5_2[i].dkLen)
         {
-#ifdef LTC_PKCS_5_TEST_DBG
+#ifdef LTC_TEST_DBG
           printf("PKCS#5 test #%d: %lu != %lu\n", i, dkLen, cases_5_2[i].dkLen);
 #endif
           return CRYPT_FAIL_TESTVECTOR;
@@ -148,25 +148,17 @@ int pkcs_5_test (void)
 
         if(XMEMCMP(DK, cases_5_2[i].DK, (size_t)cases_5_2[i].dkLen) != 0)  {
             ++failed;
-#ifdef LTC_PKCS_5_TEST_DBG
+#ifdef LTC_TEST_DBG
           {
-            unsigned int j;
-            printf("\nPKCS#5 test #%d:\n", i);
-            printf(  "Result:  0x");
-            for(j=0; j < cases_5_2[i].dkLen; j++) {
-                printf("%02x ", DK[j]);
-            }
-            printf("\nCorrect: 0x");
-            for(j=0; j < cases_5_2[i].dkLen; j++) {
-               printf("%02x ", cases_5_2[i].DK[j]);
-            }
-            printf("\n");
+            printf("\nPKCS#5 test #%d: Failed\n", i);
+            print_hex("is", DK, cases_5_2[i].dkLen);
+            print_hex("should", cases_5_2[i].DK, cases_5_2[i].dkLen);
             return CRYPT_FAIL_TESTVECTOR;
           }
-#endif
-#ifdef LTC_PKCS_5_TEST_DBG
+#if LTC_TEST_DBG > 1
         } else {
             printf("PKCS#5 test #%d: Passed\n", i);
+#endif
 #endif
         }
     }

+ 3 - 9
src/modes/xts/xts_test.c

@@ -12,10 +12,6 @@
 
 #ifdef LTC_XTS_MODE
 
-#if defined(LTC_XTS_TEST_DBG) && !defined(LTC_NO_TEST)
-void print_hex(const char* what, const unsigned char* p, const unsigned long l);
-#endif
-
 /**
   Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
   Returns CRYPT_OK upon success.
@@ -188,9 +184,6 @@ int xts_test(void)
            }
          }
          else {
-#ifdef LTC_XTS_TEST_DBG
-           printf("\nTestcase #%d with original length %lu and half of it %lu\n", i, tests[i].PTLEN, len);
-#endif
            err = xts_encrypt(tests[i].PTX, len, OUT, T, &xts);
            if (err != CRYPT_OK) {
               xts_done(&xts);
@@ -204,7 +197,8 @@ int xts_test(void)
          }
 
          if (XMEMCMP(OUT, tests[i].CTX, tests[i].PTLEN)) {
-#ifdef LTC_XTS_TEST_DBG
+#ifdef LTC_TEST_DBG
+            printf("\nTestcase #%d with original length %lu and half of it %lu\n", i, tests[i].PTLEN, len);
             printf("\nencrypt\n");
             print_hex("should", tests[i].CTX, tests[i].PTLEN);
             print_hex("is", OUT, tests[i].PTLEN);
@@ -235,7 +229,7 @@ int xts_test(void)
          }
 
          if (XMEMCMP(OUT, tests[i].PTX, tests[i].PTLEN)) {
-#ifdef LTC_XTS_TEST_DBG
+#ifdef LTC_TEST_DBG
             printf("\ndecrypt\n");
             print_hex("should", tests[i].PTX, tests[i].PTLEN);
             print_hex("is", OUT, tests[i].PTLEN);