re-work debug output of some tests
This commit is contained in:
		
							parent
							
								
									1987a2f975
								
							
						
					
					
						commit
						9585faca2b
					
				| @ -41,8 +41,12 @@ endif | |||||||
| CFLAGS += -Wno-type-limits | CFLAGS += -Wno-type-limits | ||||||
| 
 | 
 | ||||||
| ifdef LTC_DEBUG | ifdef LTC_DEBUG | ||||||
| # compile for DEBUGING (required for ccmalloc checking!!!) | # compile for DEBUGGING (required for ccmalloc checking!!!) | ||||||
| CFLAGS += -g3 -DLTC_NO_ASM | 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 | else | ||||||
| 
 | 
 | ||||||
| ifdef LTC_SMALL | ifdef LTC_SMALL | ||||||
|  | |||||||
| @ -17,10 +17,6 @@ | |||||||
| 
 | 
 | ||||||
| #ifdef LTC_CCM_MODE | #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) | int ccm_test(void) | ||||||
| { | { | ||||||
| #ifndef LTC_TEST | #ifndef LTC_TEST | ||||||
| @ -168,7 +164,7 @@ int ccm_test(void) | |||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (XMEMCMP(buf, tests[x].ct, tests[x].ptlen)) { |       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); |          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); | ||||||
|          print_hex("ct is    ", tag, taglen); |          print_hex("ct is    ", tag, taglen); | ||||||
|          print_hex("ct should", tests[x].tag, taglen); |          print_hex("ct should", tests[x].tag, taglen); | ||||||
| @ -176,14 +172,14 @@ int ccm_test(void) | |||||||
|          return CRYPT_FAIL_TESTVECTOR; |          return CRYPT_FAIL_TESTVECTOR; | ||||||
|       } |       } | ||||||
|       if (tests[x].taglen != taglen) { |       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("\n%d: x=%lu y=%lu\n", __LINE__, x, y); | ||||||
|          printf("taglen %lu (is) %lu (should)\n", taglen, tests[x].taglen); |          printf("taglen %lu (is) %lu (should)\n", taglen, tests[x].taglen); | ||||||
| #endif | #endif | ||||||
|          return CRYPT_FAIL_TESTVECTOR; |          return CRYPT_FAIL_TESTVECTOR; | ||||||
|       } |       } | ||||||
|       if (XMEMCMP(tag, tests[x].tag, tests[x].taglen)) { |       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); |          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); | ||||||
|          print_hex("tag is    ", tag, tests[x].taglen); |          print_hex("tag is    ", tag, tests[x].taglen); | ||||||
|          print_hex("tag should", tests[x].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 (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); |          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); | ||||||
|          print_hex("pt is    ", tag, taglen); |          print_hex("pt is    ", tag, taglen); | ||||||
|          print_hex("pt should", tests[x].tag, taglen); |          print_hex("pt should", tests[x].tag, taglen); | ||||||
| @ -229,7 +225,7 @@ int ccm_test(void) | |||||||
|          return CRYPT_FAIL_TESTVECTOR; |          return CRYPT_FAIL_TESTVECTOR; | ||||||
|       } |       } | ||||||
|       if (XMEMCMP(tag2, tests[x].tag, tests[x].taglen)) { |       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); |          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); | ||||||
|          print_hex("tag is    ", tag, tests[x].taglen); |          print_hex("tag is    ", tag, tests[x].taglen); | ||||||
|          print_hex("tag should", tests[x].tag, tests[x].taglen); |          print_hex("tag should", tests[x].tag, tests[x].taglen); | ||||||
|  | |||||||
| @ -81,6 +81,11 @@ void adler32_finish(adler32_state *ctx, void *hash, unsigned long size); | |||||||
| int adler32_test(void); | int adler32_test(void); | ||||||
| #endif | #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$ */ | /* $Source$ */ | ||||||
| /* $Revision$ */ | /* $Revision$ */ | ||||||
| /* $Date$ */ | /* $Date$ */ | ||||||
|  | |||||||
| @ -603,7 +603,7 @@ int hmac_test(void) | |||||||
|         ++tested; |         ++tested; | ||||||
|         outlen = sizeof(digest); |         outlen = sizeof(digest); | ||||||
|         if((err = hmac_memory(hash, cases[i].key, cases[i].keylen, cases[i].data, cases[i].datalen, digest, &outlen)) != CRYPT_OK) { |         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)); |             printf("HMAC-%s test %s, %s\n", cases[i].algo, cases[i].num, error_to_string(err)); | ||||||
| #endif | #endif | ||||||
|             return err; |             return err; | ||||||
| @ -611,25 +611,17 @@ int hmac_test(void) | |||||||
| 
 | 
 | ||||||
|         if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0)  { |         if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0)  { | ||||||
|             failed++; |             failed++; | ||||||
| #ifdef LTC_HMAC_TEST_DBG | #ifdef LTC_TEST_DBG | ||||||
|           { |           { | ||||||
|             unsigned int j; |             printf("\nHMAC-%s test %s: Failed\n", cases[i].algo, cases[i].num); | ||||||
|             printf("\nHMAC-%s test %s:\n", cases[i].algo, cases[i].num); |             print_hex("is", digest, hash_descriptor[hash].hashsize); | ||||||
|             printf(  "Result:  0x"); |             print_hex("should", cases[i].digest, hash_descriptor[hash].hashsize); | ||||||
|             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"); |  | ||||||
|             return CRYPT_FAIL_TESTVECTOR; |             return CRYPT_FAIL_TESTVECTOR; | ||||||
|           } |           } | ||||||
| #endif | #if LTC_TEST_DBG > 1 | ||||||
| #ifdef LTC_HMAC_TEST_DBG |  | ||||||
|         } else { |         } else { | ||||||
|             printf("HMAC-%s test %s: Passed\n", cases[i].algo, cases[i].num); |             printf("HMAC-%s test %s: Passed\n", cases[i].algo, cases[i].num); | ||||||
|  | #endif | ||||||
| #endif | #endif | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -120,7 +120,7 @@ int pkcs_5_test (void) | |||||||
|     int hash = find_hash("sha1"); |     int hash = find_hash("sha1"); | ||||||
|     if (hash == -1) |     if (hash == -1) | ||||||
|     { |     { | ||||||
| #ifdef LTC_PKCS_5_TEST_DBG | #ifdef LTC_TEST_DBG | ||||||
|       printf("PKCS#5 test: 'sha1' hash not found\n"); |       printf("PKCS#5 test: 'sha1' hash not found\n"); | ||||||
| #endif | #endif | ||||||
|       return CRYPT_ERROR; |       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, |                               (unsigned char*)cases_5_2[i].S, cases_5_2[i].S_len, | ||||||
|                               cases_5_2[i].c, hash, |                               cases_5_2[i].c, hash, | ||||||
|                               DK, &dkLen)) != CRYPT_OK) { |                               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)); |             printf("PKCS#5 test #%d: %s\n", i, error_to_string(err)); | ||||||
| #endif | #endif | ||||||
|             return err; |             return err; | ||||||
| @ -140,7 +140,7 @@ int pkcs_5_test (void) | |||||||
| 
 | 
 | ||||||
|         if (dkLen != cases_5_2[i].dkLen) |         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); |           printf("PKCS#5 test #%d: %lu != %lu\n", i, dkLen, cases_5_2[i].dkLen); | ||||||
| #endif | #endif | ||||||
|           return CRYPT_FAIL_TESTVECTOR; |           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)  { |         if(XMEMCMP(DK, cases_5_2[i].DK, (size_t)cases_5_2[i].dkLen) != 0)  { | ||||||
|             ++failed; |             ++failed; | ||||||
| #ifdef LTC_PKCS_5_TEST_DBG | #ifdef LTC_TEST_DBG | ||||||
|           { |           { | ||||||
|             unsigned int j; |             printf("\nPKCS#5 test #%d: Failed\n", i); | ||||||
|             printf("\nPKCS#5 test #%d:\n", i); |             print_hex("is", DK, cases_5_2[i].dkLen); | ||||||
|             printf(  "Result:  0x"); |             print_hex("should", cases_5_2[i].DK, cases_5_2[i].dkLen); | ||||||
|             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"); |  | ||||||
|             return CRYPT_FAIL_TESTVECTOR; |             return CRYPT_FAIL_TESTVECTOR; | ||||||
|           } |           } | ||||||
| #endif | #if LTC_TEST_DBG > 1 | ||||||
| #ifdef LTC_PKCS_5_TEST_DBG |  | ||||||
|         } else { |         } else { | ||||||
|             printf("PKCS#5 test #%d: Passed\n", i); |             printf("PKCS#5 test #%d: Passed\n", i); | ||||||
|  | #endif | ||||||
| #endif | #endif | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -12,10 +12,6 @@ | |||||||
| 
 | 
 | ||||||
| #ifdef LTC_XTS_MODE | #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 |   Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects | ||||||
|   Returns CRYPT_OK upon success. |   Returns CRYPT_OK upon success. | ||||||
| @ -188,9 +184,6 @@ int xts_test(void) | |||||||
|            } |            } | ||||||
|          } |          } | ||||||
|          else { |          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); |            err = xts_encrypt(tests[i].PTX, len, OUT, T, &xts); | ||||||
|            if (err != CRYPT_OK) { |            if (err != CRYPT_OK) { | ||||||
|               xts_done(&xts); |               xts_done(&xts); | ||||||
| @ -204,7 +197,8 @@ int xts_test(void) | |||||||
|          } |          } | ||||||
| 
 | 
 | ||||||
|          if (XMEMCMP(OUT, tests[i].CTX, tests[i].PTLEN)) { |          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"); |             printf("\nencrypt\n"); | ||||||
|             print_hex("should", tests[i].CTX, tests[i].PTLEN); |             print_hex("should", tests[i].CTX, tests[i].PTLEN); | ||||||
|             print_hex("is", OUT, 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)) { |          if (XMEMCMP(OUT, tests[i].PTX, tests[i].PTLEN)) { | ||||||
| #ifdef LTC_XTS_TEST_DBG | #ifdef LTC_TEST_DBG | ||||||
|             printf("\ndecrypt\n"); |             printf("\ndecrypt\n"); | ||||||
|             print_hex("should", tests[i].PTX, tests[i].PTLEN); |             print_hex("should", tests[i].PTX, tests[i].PTLEN); | ||||||
|             print_hex("is", OUT, tests[i].PTLEN); |             print_hex("is", OUT, tests[i].PTLEN); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user