diff --git a/src/encauth/ccm/ccm_test.c b/src/encauth/ccm/ccm_test.c index 51bc4af..1177a0f 100644 --- a/src/encauth/ccm/ccm_test.c +++ b/src/encauth/ccm/ccm_test.c @@ -165,27 +165,10 @@ int ccm_test(void) } } - if (XMEMCMP(buf, tests[x].ct, tests[x].ptlen)) { -#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 + if (compare_testvector(buf, tests[x].ptlen, tests[x].ct, tests[x].ptlen, "CCM encrypt data", x)) { return CRYPT_FAIL_TESTVECTOR; } - if (tests[x].taglen != taglen) { -#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 + if (compare_testvector(tag, taglen, tests[x].tag, tests[x].taglen, "CCM encrypt tag", x)) { 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) - 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 + + if (compare_testvector(buf2, tests[x].ptlen, tests[x].pt, tests[x].ptlen, "CCM decrypt data", x)) { return CRYPT_FAIL_TESTVECTOR; } if (y == 0) { @@ -243,27 +222,12 @@ int ccm_test(void) tag3, &taglen, 1 )) != CRYPT_ERROR) { return CRYPT_FAIL_TESTVECTOR; } - if (XMEMCMP(buf2, zero, tests[x].ptlen)) { -#if defined(LTC_CCM_TEST_DBG) - 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; + if (compare_testvector(buf2, tests[x].ptlen, zero, tests[x].ptlen, "CCM decrypt wrong tag", x)) { + return CRYPT_FAIL_TESTVECTOR; } } else { - /* FIXME: Only check the tag if ccm_memory was not called: ccm_memory already - validates the tag. ccm_process and ccm_done should somehow do the same, - 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; + if (compare_testvector(tag2, taglen, tests[x].tag, tests[x].taglen, "CCM decrypt tag", x)) { + return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/mac/hmac/hmac_test.c b/src/mac/hmac/hmac_test.c index 0c311c6..f0b5e20 100644 --- a/src/mac/hmac/hmac_test.c +++ b/src/mac/hmac/hmac_test.c @@ -609,20 +609,8 @@ int hmac_test(void) 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++; -#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 } } diff --git a/src/misc/crypt/crypt_inits.c b/src/misc/crypt/crypt_inits.c index cc92f52..4df6051 100644 --- a/src/misc/crypt/crypt_inits.c +++ b/src/misc/crypt/crypt_inits.c @@ -19,24 +19,25 @@ #ifdef LTM_DESC -void init_LTM(void) { +void init_LTM(void) +{ ltc_mp = ltm_desc; } #endif #ifdef TFM_DESC -void init_TFM(void) { +void init_TFM(void) +{ ltc_mp = tfm_desc; } #endif -/* *** use of GMP is untested *** #ifdef GMP_DESC -void init_GMP(void) { +void init_GMP(void) +{ ltc_mp = gmp_desc; } #endif -*/ /* $Source$ */ diff --git a/src/misc/pkcs5/pkcs_5_test.c b/src/misc/pkcs5/pkcs_5_test.c index 46a8931..c247fe8 100644 --- a/src/misc/pkcs5/pkcs_5_test.c +++ b/src/misc/pkcs5/pkcs_5_test.c @@ -161,7 +161,9 @@ int pkcs_5_test (void) int hash = find_hash("sha1"); if (hash == -1) { +#ifdef LTC_TEST_DBG printf("PKCS#5 test failed: 'sha1' hash not found\n"); +#endif 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, cases_5_2[i].c, hash, DK, &dkLen)) != CRYPT_OK) { +#ifdef LTC_TEST_DBG printf("\nPKCS#5_2 test #%d: Failed/1\n", i); 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 ++failed; -#ifdef LTC_TEST_DBG - } else { - printf("PKCS#5_2 test #%d: Passed\n", i); -#endif + } + else if (compare_testvector(DK, dkLen, cases_5_2[i].DK, cases_5_2[i].dkLen, "PKCS#5_2", i)) { + ++failed; } } @@ -204,24 +193,15 @@ int pkcs_5_test (void) (unsigned char*)cases_5_1[i].S, cases_5_1[i].c, hash, DK, &dkLen)) != CRYPT_OK) { +#ifdef LTC_TEST_DBG printf("\nPKCS#5_1 test #%d: Failed/1\n", i); 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 ++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 */ @@ -231,24 +211,15 @@ int pkcs_5_test (void) (unsigned char*)cases_5_1o[i].S, cases_5_1o[i].c, hash, DK, &dkLen)) != CRYPT_OK) { +#ifdef LTC_TEST_DBG printf("\nPKCS#5_1o test #%d: Failed/1\n", i); 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 ++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; diff --git a/src/modes/xts/xts_test.c b/src/modes/xts/xts_test.c index 7826d22..87c82b5 100644 --- a/src/modes/xts/xts_test.c +++ b/src/modes/xts/xts_test.c @@ -262,15 +262,7 @@ int xts_test(void) } } - if (XMEMCMP(OUT, tests[i].CTX, tests[i].PTLEN)) { -#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 + if (compare_testvector(OUT, tests[i].PTLEN, tests[i].CTX, tests[i].PTLEN, "XTS encrypt", i)) { xts_done(&xts); return CRYPT_FAIL_TESTVECTOR; } @@ -295,12 +287,7 @@ int xts_test(void) } } - if (XMEMCMP(OUT, tests[i].PTX, tests[i].PTLEN)) { -#ifdef LTC_TEST_DBG - printf("\ndecrypt\n"); - print_hex("should", tests[i].PTX, tests[i].PTLEN); - print_hex("is", OUT, tests[i].PTLEN); -#endif + if (compare_testvector(OUT, tests[i].PTLEN, tests[i].PTX, tests[i].PTLEN, "XTS decrypt", i)) { xts_done(&xts); return CRYPT_FAIL_TESTVECTOR; }