don't use print_hex() from library
This commit is contained in:
		
							parent
							
								
									fe0b72ef51
								
							
						
					
					
						commit
						4e971a8518
					
				| @ -165,27 +165,10 @@ int ccm_test(void) | |||||||
|          } |          } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (XMEMCMP(buf, tests[x].ct, tests[x].ptlen)) { |       if (compare_testvector(buf, tests[x].ptlen, tests[x].ct, tests[x].ptlen, "CCM encrypt data", x)) { | ||||||
| #if defined(LTC_TEST_DBG) |  | ||||||
|          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); |  | ||||||
|          print_hex("ct is    ", buf, tests[x].ptlen); |  | ||||||
|          print_hex("ct should", tests[x].ct, tests[x].ptlen); |  | ||||||
| #endif |  | ||||||
|          return CRYPT_FAIL_TESTVECTOR; |          return CRYPT_FAIL_TESTVECTOR; | ||||||
|       } |       } | ||||||
|       if (tests[x].taglen != taglen) { |       if (compare_testvector(tag, taglen, tests[x].tag, tests[x].taglen, "CCM encrypt tag", x)) { | ||||||
| #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_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); |  | ||||||
| #endif |  | ||||||
|          return CRYPT_FAIL_TESTVECTOR; |          return CRYPT_FAIL_TESTVECTOR; | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
| @ -220,12 +203,8 @@ int ccm_test(void) | |||||||
|          } |          } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|       if (XMEMCMP(buf2, tests[x].pt, tests[x].ptlen)) { | 
 | ||||||
| #if defined(LTC_TEST_DBG) |       if (compare_testvector(buf2, tests[x].ptlen, tests[x].pt, tests[x].ptlen, "CCM decrypt data", x)) { | ||||||
|          printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); |  | ||||||
|          print_hex("pt is    ", buf2, tests[x].ptlen); |  | ||||||
|          print_hex("pt should", tests[x].pt, tests[x].ptlen); |  | ||||||
| #endif |  | ||||||
|          return CRYPT_FAIL_TESTVECTOR; |          return CRYPT_FAIL_TESTVECTOR; | ||||||
|       } |       } | ||||||
|       if (y == 0) { |       if (y == 0) { | ||||||
| @ -243,27 +222,12 @@ int ccm_test(void) | |||||||
|                               tag3, &taglen, 1   )) != CRYPT_ERROR) { |                               tag3, &taglen, 1   )) != CRYPT_ERROR) { | ||||||
|           return CRYPT_FAIL_TESTVECTOR; |           return CRYPT_FAIL_TESTVECTOR; | ||||||
|         } |         } | ||||||
|         if (XMEMCMP(buf2, zero, tests[x].ptlen)) { |         if (compare_testvector(buf2, tests[x].ptlen, zero, tests[x].ptlen, "CCM decrypt wrong tag", x)) { | ||||||
| #if defined(LTC_CCM_TEST_DBG) |            return CRYPT_FAIL_TESTVECTOR; | ||||||
|           printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); |  | ||||||
|           print_hex("pt is    ", buf2, tests[x].ptlen); |  | ||||||
|           print_hex("pt should", zero, tests[x].ptlen); |  | ||||||
| #endif |  | ||||||
|           return CRYPT_FAIL_TESTVECTOR; |  | ||||||
|         } |         } | ||||||
|       } else { |       } else { | ||||||
|         /* FIXME: Only check the tag if ccm_memory was not called: ccm_memory already
 |         if (compare_testvector(tag2, taglen, tests[x].tag, tests[x].taglen, "CCM decrypt tag", x)) { | ||||||
|            validates the tag. ccm_process and ccm_done should somehow do the same, |            return CRYPT_FAIL_TESTVECTOR; | ||||||
|            although with current setup it is impossible to keep the plaintext hidden |  | ||||||
|            if the tag is incorrect. |  | ||||||
|         */ |  | ||||||
|         if (XMEMCMP(tag2, tests[x].tag, tests[x].taglen)) { |  | ||||||
| #if defined(LTC_TEST_DBG) |  | ||||||
|           printf("\n%d: x=%lu y=%lu\n", __LINE__, x, y); |  | ||||||
|           print_hex("tag is    ", tag2, tests[x].taglen); |  | ||||||
|           print_hex("tag should", tests[x].tag, tests[x].taglen); |  | ||||||
| #endif |  | ||||||
|           return CRYPT_FAIL_TESTVECTOR; |  | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -609,20 +609,8 @@ int hmac_test(void) | |||||||
|             return err; |             return err; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if(XMEMCMP(digest, cases[i].digest, (size_t)hash_descriptor[hash].hashsize) != 0)  { |         if(compare_testvector(digest, outlen, cases[i].digest, (size_t)hash_descriptor[hash].hashsize, cases[i].num, i)) { | ||||||
|             failed++; |             failed++; | ||||||
| #ifdef LTC_TEST_DBG |  | ||||||
|           { |  | ||||||
|             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; |  | ||||||
|           } |  | ||||||
| #if LTC_TEST_DBG > 1 |  | ||||||
|         } else { |  | ||||||
|             printf("HMAC-%s test %s: Passed\n", cases[i].algo, cases[i].num); |  | ||||||
| #endif |  | ||||||
| #endif |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -19,24 +19,25 @@ | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| #ifdef LTM_DESC | #ifdef LTM_DESC | ||||||
| void init_LTM(void) { | void init_LTM(void) | ||||||
|  | { | ||||||
|     ltc_mp = ltm_desc; |     ltc_mp = ltm_desc; | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef TFM_DESC | #ifdef TFM_DESC | ||||||
| void init_TFM(void) { | void init_TFM(void) | ||||||
|  | { | ||||||
|     ltc_mp = tfm_desc; |     ltc_mp = tfm_desc; | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| /*                          *** use of GMP is untested ***
 |  | ||||||
| #ifdef GMP_DESC | #ifdef GMP_DESC | ||||||
| void init_GMP(void) { | void init_GMP(void) | ||||||
|  | { | ||||||
|     ltc_mp = gmp_desc; |     ltc_mp = gmp_desc; | ||||||
| } | } | ||||||
| #endif | #endif | ||||||
| */ |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /* $Source$ */ | /* $Source$ */ | ||||||
|  | |||||||
| @ -161,7 +161,9 @@ int pkcs_5_test (void) | |||||||
|     int hash = find_hash("sha1"); |     int hash = find_hash("sha1"); | ||||||
|     if (hash == -1) |     if (hash == -1) | ||||||
|     { |     { | ||||||
|  | #ifdef LTC_TEST_DBG | ||||||
|       printf("PKCS#5 test failed: 'sha1' hash not found\n"); |       printf("PKCS#5 test failed: 'sha1' hash not found\n"); | ||||||
|  | #endif | ||||||
|       return CRYPT_ERROR; |       return CRYPT_ERROR; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -173,27 +175,14 @@ 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_TEST_DBG | ||||||
|             printf("\nPKCS#5_2 test #%d: Failed/1\n", i); |             printf("\nPKCS#5_2 test #%d: Failed/1\n", i); | ||||||
|             printf("err=%d\n", err); |             printf("err=%d\n", err); | ||||||
|             ++failed; |  | ||||||
|         } |  | ||||||
|         else if (dkLen != cases_5_2[i].dkLen) { |  | ||||||
|             printf("\nPKCS#5_2 test #%d: Failed/2\n", i); |  | ||||||
|             printf("len is %d\n", (int)dkLen); |  | ||||||
|             printf("len should %d\n", (int)cases_5_2[i].dkLen); |  | ||||||
|             ++failed; |  | ||||||
|         } |  | ||||||
|         else if(XMEMCMP(DK, cases_5_2[i].DK, (size_t)cases_5_2[i].dkLen) != 0) { |  | ||||||
|             printf("\nPKCS#5_2 test #%d: Failed/3\n", i); |  | ||||||
| #ifdef LTC_TEST_DBG |  | ||||||
|             print_hex("is", DK, cases_5_2[i].dkLen); |  | ||||||
|             print_hex("should", cases_5_2[i].DK, cases_5_2[i].dkLen); |  | ||||||
| #endif | #endif | ||||||
|             ++failed; |             ++failed; | ||||||
| #ifdef LTC_TEST_DBG |         } | ||||||
|         } else { |         else if (compare_testvector(DK, dkLen, cases_5_2[i].DK, cases_5_2[i].dkLen, "PKCS#5_2", i)) { | ||||||
|             printf("PKCS#5_2 test #%d: Passed\n", i); |             ++failed; | ||||||
| #endif |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -204,24 +193,15 @@ int pkcs_5_test (void) | |||||||
|                               (unsigned char*)cases_5_1[i].S, |                               (unsigned char*)cases_5_1[i].S, | ||||||
|                               cases_5_1[i].c, hash, |                               cases_5_1[i].c, hash, | ||||||
|                               DK, &dkLen)) != CRYPT_OK) { |                               DK, &dkLen)) != CRYPT_OK) { | ||||||
|  | #ifdef LTC_TEST_DBG | ||||||
|             printf("\nPKCS#5_1 test #%d: Failed/1\n", i); |             printf("\nPKCS#5_1 test #%d: Failed/1\n", i); | ||||||
|             printf("err=%d\n", err); |             printf("err=%d\n", err); | ||||||
|             ++failed; |  | ||||||
|         } |  | ||||||
|         else if (dkLen != cases_5_1[i].dkLen) { |  | ||||||
|             printf("\nPKCS#5_1 test #%d: Failed/2\n", i); |  | ||||||
|             printf("len is %d\n", (int)dkLen); |  | ||||||
|             printf("len should %d\n", (int)cases_5_1[i].dkLen); |  | ||||||
|             ++failed; |  | ||||||
|         } |  | ||||||
|         else if (XMEMCMP(DK, cases_5_1[i].DK, (size_t)cases_5_1[i].dkLen) != 0) { |  | ||||||
|             printf("\nPKCS#5_1 test #%d: Failed/3\n", i); |  | ||||||
| #ifdef LTC_TEST_DBG |  | ||||||
|             print_hex("is", DK, cases_5_1[i].dkLen); |  | ||||||
|             print_hex("should", cases_5_1[i].DK, cases_5_1[i].dkLen); |  | ||||||
| #endif | #endif | ||||||
|             ++failed; |             ++failed; | ||||||
|         } |         } | ||||||
|  |         else if (compare_testvector(DK, dkLen, cases_5_1[i].DK, cases_5_1[i].dkLen, "PKCS#5_1", i)) { | ||||||
|  |             ++failed; | ||||||
|  |        } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* testing alg 1_openssl */ |     /* testing alg 1_openssl */ | ||||||
| @ -231,24 +211,15 @@ int pkcs_5_test (void) | |||||||
|                                        (unsigned char*)cases_5_1o[i].S, |                                        (unsigned char*)cases_5_1o[i].S, | ||||||
|                                        cases_5_1o[i].c, hash, |                                        cases_5_1o[i].c, hash, | ||||||
|                                        DK, &dkLen)) != CRYPT_OK) { |                                        DK, &dkLen)) != CRYPT_OK) { | ||||||
|  | #ifdef LTC_TEST_DBG | ||||||
|             printf("\nPKCS#5_1o test #%d: Failed/1\n", i); |             printf("\nPKCS#5_1o test #%d: Failed/1\n", i); | ||||||
|             printf("err=%d\n", err); |             printf("err=%d\n", err); | ||||||
|             ++failed; |  | ||||||
|         } |  | ||||||
|         else if (dkLen != cases_5_1o[i].dkLen) { |  | ||||||
|             printf("\nPKCS#5_1o test #%d: Failed/2\n", i); |  | ||||||
|             printf("len is %d\n", (int)dkLen); |  | ||||||
|             printf("len should %d\n", (int)cases_5_1o[i].dkLen); |  | ||||||
|             ++failed; |  | ||||||
|         } |  | ||||||
|         else if (XMEMCMP(DK, cases_5_1o[i].DK, (size_t)cases_5_1o[i].dkLen) != 0) { |  | ||||||
|             printf("\nPKCS#5_1o test #%d: Failed/3\n", i); |  | ||||||
| #ifdef LTC_TEST_DBG |  | ||||||
|             print_hex("is", DK, cases_5_1o[i].dkLen); |  | ||||||
|             print_hex("should", cases_5_1o[i].DK, cases_5_1o[i].dkLen); |  | ||||||
| #endif | #endif | ||||||
|             ++failed; |             ++failed; | ||||||
|         } |         } | ||||||
|  |         else if (compare_testvector(DK, dkLen, cases_5_1o[i].DK, cases_5_1o[i].dkLen, "PKCS#5_1o", i)) { | ||||||
|  |             ++failed; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return (failed != 0) ? CRYPT_FAIL_TESTVECTOR : CRYPT_OK; |     return (failed != 0) ? CRYPT_FAIL_TESTVECTOR : CRYPT_OK; | ||||||
|  | |||||||
| @ -262,15 +262,7 @@ int xts_test(void) | |||||||
|                } |                } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (XMEMCMP(OUT, tests[i].CTX, tests[i].PTLEN)) { |             if (compare_testvector(OUT, tests[i].PTLEN, tests[i].CTX, tests[i].PTLEN, "XTS encrypt", i)) { | ||||||
| #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); |  | ||||||
| #endif |  | ||||||
|                xts_done(&xts); |                xts_done(&xts); | ||||||
|                return CRYPT_FAIL_TESTVECTOR; |                return CRYPT_FAIL_TESTVECTOR; | ||||||
|             } |             } | ||||||
| @ -295,12 +287,7 @@ int xts_test(void) | |||||||
|                } |                } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (XMEMCMP(OUT, tests[i].PTX, tests[i].PTLEN)) { |             if (compare_testvector(OUT, tests[i].PTLEN, tests[i].PTX, tests[i].PTLEN, "XTS decrypt", i)) { | ||||||
| #ifdef LTC_TEST_DBG |  | ||||||
|                printf("\ndecrypt\n"); |  | ||||||
|                print_hex("should", tests[i].PTX, tests[i].PTLEN); |  | ||||||
|                print_hex("is", OUT, tests[i].PTLEN); |  | ||||||
| #endif |  | ||||||
|                xts_done(&xts); |                xts_done(&xts); | ||||||
|                return CRYPT_FAIL_TESTVECTOR; |                return CRYPT_FAIL_TESTVECTOR; | ||||||
|             } |             } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user