diff --git a/src/ciphers/aes/aes.c b/src/ciphers/aes/aes.c index dea13bb..5c1dcd1 100644 --- a/src/ciphers/aes/aes.c +++ b/src/ciphers/aes/aes.c @@ -685,23 +685,8 @@ int ECB_TEST(void) rijndael_ecb_encrypt(tests[i].pt, tmp[0], &key); rijndael_ecb_decrypt(tmp[0], tmp[1], &key); - if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) { -#if 0 - printf("\n\nTest %d failed\n", i); - if (XMEMCMP(tmp[0], tests[i].ct, 16)) { - printf("CT: "); - for (i = 0; i < 16; i++) { - printf("%02x ", tmp[0][i]); - } - printf("\n"); - } else { - printf("PT: "); - for (i = 0; i < 16; i++) { - printf("%02x ", tmp[1][i]); - } - printf("\n"); - } -#endif + if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "AES Encrypt", i) || + compare_testvector(tmp[1], 16, tests[i].pt, 16, "AES Decrypt", i)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/anubis.c b/src/ciphers/anubis.c index 2a9b1c0..a28c7e1 100644 --- a/src/ciphers/anubis.c +++ b/src/ciphers/anubis.c @@ -1498,13 +1498,14 @@ int anubis_test(void) anubis_setup(tests[x].key, tests[x].keylen, 0, &skey); anubis_ecb_encrypt(tests[x].pt, buf[0], &skey); anubis_ecb_decrypt(buf[0], buf[1], &skey); - if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) { + if (compare_testvector(buf[0], 16, tests[x].ct, 16, "Anubis Encrypt", x) || + compare_testvector(buf[1], 16, tests[x].pt, 16, "Anubis Decrypt", x)) { return CRYPT_FAIL_TESTVECTOR; } for (y = 0; y < 1000; y++) anubis_ecb_encrypt(buf[0], buf[0], &skey); for (y = 0; y < 1000; y++) anubis_ecb_decrypt(buf[0], buf[0], &skey); - if (XMEMCMP(buf[0], tests[x].ct, 16)) { + if (compare_testvector(buf[0], 16, tests[x].ct, 16, "Anubis 1000", 1000)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/blowfish.c b/src/ciphers/blowfish.c index 994ab36..a1945ae 100644 --- a/src/ciphers/blowfish.c +++ b/src/ciphers/blowfish.c @@ -546,7 +546,8 @@ int blowfish_test(void) blowfish_ecb_decrypt(tmp[0], tmp[1], &key); /* compare */ - if ((XMEMCMP(tmp[0], tests[x].ct, 8) != 0) || (XMEMCMP(tmp[1], tests[x].pt, 8) != 0)) { + if ((compare_testvector(tmp[0], 8, tests[x].ct, 8, "Blowfish Encrypt", x) != 0) || + (compare_testvector(tmp[1], 8, tests[x].pt, 8, "Blowfish Decrypt", x) != 0)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/camellia.c b/src/ciphers/camellia.c index e159104..0a75087 100644 --- a/src/ciphers/camellia.c +++ b/src/ciphers/camellia.c @@ -697,22 +697,8 @@ int camellia_test(void) return err; } camellia_done(&skey); - if (XMEMCMP(tests[x].ct, buf[0], 16) || XMEMCMP(tests[x].pt, buf[1], 16)) { -#if 0 - int i, j; - printf ("\n\nLTC_CAMELLIA failed for x=%d, I got:\n", x); - for (i = 0; i < 2; i++) { - const unsigned char *expected, *actual; - expected = (i ? tests[x].pt : tests[x].ct); - actual = buf[i]; - printf ("expected actual (%s)\n", (i ? "plaintext" : "ciphertext")); - for (j = 0; j < 16; j++) { - const char *eq = (expected[j] == actual[j] ? "==" : "!="); - printf (" %02x %s %02x\n", expected[j], eq, actual[j]); - } - printf ("\n"); - } -#endif + if (compare_testvector(tests[x].ct, 16, buf[0], 16, "Camellia Encrypt", x) || + compare_testvector(tests[x].pt, 16, buf[1], 16, "Camellia Decrypt", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/ciphers/cast5.c b/src/ciphers/cast5.c index e0501d1..43ca580 100644 --- a/src/ciphers/cast5.c +++ b/src/ciphers/cast5.c @@ -674,7 +674,8 @@ int cast5_test(void) } cast5_ecb_encrypt(tests[i].pt, tmp[0], &key); cast5_ecb_decrypt(tmp[0], tmp[1], &key); - if ((XMEMCMP(tmp[0], tests[i].ct, 8) != 0) || (XMEMCMP(tmp[1], tests[i].pt, 8) != 0)) { + if ((compare_testvector(tmp[0], 8, tests[i].ct, 8, "CAST5 Encrypt", i) != 0) || + (compare_testvector(tmp[1], 8, tests[i].pt, 8, "CAST5 Decrypt", i) != 0)) { return CRYPT_FAIL_TESTVECTOR; } /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ diff --git a/src/ciphers/des.c b/src/ciphers/des.c index 0993d6b..cbb20e3 100644 --- a/src/ciphers/des.c +++ b/src/ciphers/des.c @@ -1977,7 +1977,7 @@ int des_test(void) des_ecb_decrypt(cases[i].txt, tmp, &des); } - if (XMEMCMP(cases[i].out, tmp, sizeof(tmp)) != 0) { + if (compare_testvector(cases[i].out, sizeof(tmp), tmp, sizeof(tmp), "DES", i) != 0) { return CRYPT_FAIL_TESTVECTOR; } @@ -2020,7 +2020,7 @@ int des3_test(void) des3_ecb_encrypt(pt, ct, &skey); des3_ecb_decrypt(ct, tmp, &skey); - if (XMEMCMP(pt, tmp, 8) != 0) { + if (compare_testvector(pt, 8, tmp, 8, "3DES", 0) != 0) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/kasumi.c b/src/ciphers/kasumi.c index 432313b..7c2add5 100644 --- a/src/ciphers/kasumi.c +++ b/src/ciphers/kasumi.c @@ -302,7 +302,8 @@ int kasumi_test(void) if ((err = kasumi_ecb_decrypt(tests[x].ct, buf[1], &key)) != CRYPT_OK) { return err; } - if (XMEMCMP(tests[x].pt, buf[1], 8) || XMEMCMP(tests[x].ct, buf[0], 8)) { + if (compare_testvector(buf[1], 8, tests[x].pt, 8, "Kasumi Decrypt", x) || + compare_testvector(buf[0], 8, tests[x].ct, 8, "Kasumi Encrypt", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/ciphers/khazad.c b/src/ciphers/khazad.c index 960b734..4d1f2ce 100644 --- a/src/ciphers/khazad.c +++ b/src/ciphers/khazad.c @@ -808,13 +808,14 @@ int khazad_test(void) khazad_setup(tests[x].key, 16, 0, &skey); khazad_ecb_encrypt(tests[x].pt, buf[0], &skey); khazad_ecb_decrypt(buf[0], buf[1], &skey); - if (XMEMCMP(buf[0], tests[x].ct, 8) || XMEMCMP(buf[1], tests[x].pt, 8)) { + if (compare_testvector(buf[0], 8, tests[x].ct, 8, "Khazad Encrypt", x) || + compare_testvector(buf[1], 8, tests[x].pt, 8, "Khazad Decrypt", x)) { return CRYPT_FAIL_TESTVECTOR; } for (y = 0; y < 1000; y++) khazad_ecb_encrypt(buf[0], buf[0], &skey); for (y = 0; y < 1000; y++) khazad_ecb_decrypt(buf[0], buf[0], &skey); - if (XMEMCMP(buf[0], tests[x].ct, 8)) { + if (compare_testvector(buf[0], 8, tests[x].ct, 8, "Khazad 1000", 1000)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/kseed.c b/src/ciphers/kseed.c index f1c15dd..e12fdc7 100644 --- a/src/ciphers/kseed.c +++ b/src/ciphers/kseed.c @@ -344,22 +344,8 @@ int kseed_test(void) kseed_setup(tests[x].key, 16, 0, &skey); kseed_ecb_encrypt(tests[x].pt, buf[0], &skey); kseed_ecb_decrypt(buf[0], buf[1], &skey); - if (XMEMCMP(buf[0], tests[x].ct, 16) || XMEMCMP(buf[1], tests[x].pt, 16)) { -#if 0 - int i, j; - printf ("\n\nLTC_KSEED failed for x=%d, I got:\n", x); - for (i = 0; i < 2; i++) { - const unsigned char *expected, *actual; - expected = (i ? tests[x].pt : tests[x].ct); - actual = buf[i]; - printf ("expected actual (%s)\n", (i ? "plaintext" : "ciphertext")); - for (j = 0; j < 16; j++) { - const char *eq = (expected[j] == actual[j] ? "==" : "!="); - printf (" %02x %s %02x\n", expected[j], eq, actual[j]); - } - printf ("\n"); - } -#endif + if (compare_testvector(buf[0], 16, tests[x].ct, 16, "KSEED Encrypt", x) || + compare_testvector(buf[1], 16, tests[x].pt, 16, "KSEED Decrypt", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/ciphers/multi2.c b/src/ciphers/multi2.c index 2378e2d..86c1812 100644 --- a/src/ciphers/multi2.c +++ b/src/ciphers/multi2.c @@ -256,14 +256,14 @@ int multi2_test(void) return err; } - if (XMEMCMP(buf, tests[x].ct, 8)) { + if (compare_testvector(buf, 8, tests[x].ct, 8, "Multi2 Encrypt", x)) { return CRYPT_FAIL_TESTVECTOR; } if ((err = multi2_ecb_decrypt(buf, buf, &skey)) != CRYPT_OK) { return err; } - if (XMEMCMP(buf, tests[x].pt, 8)) { + if (compare_testvector(buf, 8, tests[x].pt, 8, "Multi2 Decrypt", x)) { return CRYPT_FAIL_TESTVECTOR; } } @@ -280,7 +280,7 @@ int multi2_test(void) if ((err = multi2_ecb_decrypt(ct, buf, &skey)) != CRYPT_OK) { return err; } - if (XMEMCMP(buf, tests[0].pt, 8)) { + if (compare_testvector(buf, 8, tests[0].pt, 8, "Multi2 Rounds", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/ciphers/noekeon.c b/src/ciphers/noekeon.c index 21e645c..13720d1 100644 --- a/src/ciphers/noekeon.c +++ b/src/ciphers/noekeon.c @@ -281,23 +281,8 @@ int noekeon_test(void) noekeon_ecb_encrypt(tests[i].pt, tmp[0], &key); noekeon_ecb_decrypt(tmp[0], tmp[1], &key); - if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) { -#if 0 - printf("\n\nTest %d failed\n", i); - if (XMEMCMP(tmp[0], tests[i].ct, 16)) { - printf("CT: "); - for (i = 0; i < 16; i++) { - printf("%02x ", tmp[0][i]); - } - printf("\n"); - } else { - printf("PT: "); - for (i = 0; i < 16; i++) { - printf("%02x ", tmp[1][i]); - } - printf("\n"); - } -#endif + if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "Noekeon Encrypt", i) || + compare_testvector(tmp[1], 16, tests[i].pt, 16, "Noekeon Decrypt", i)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/rc5.c b/src/ciphers/rc5.c index e3e2ad6..bda537f 100644 --- a/src/ciphers/rc5.c +++ b/src/ciphers/rc5.c @@ -273,7 +273,8 @@ int rc5_test(void) rc5_ecb_decrypt(tmp[0], tmp[1], &key); /* compare */ - if (XMEMCMP(tmp[0], tests[x].ct, 8) != 0 || XMEMCMP(tmp[1], tests[x].pt, 8) != 0) { + if (compare_testvector(tmp[0], 8, tests[x].ct, 8, "RC5 Encrypt", x) != 0 || + compare_testvector(tmp[1], 8, tests[x].pt, 8, "RC5 Decrypt", x) != 0) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/rc6.c b/src/ciphers/rc6.c index cd192d4..56ca705 100644 --- a/src/ciphers/rc6.c +++ b/src/ciphers/rc6.c @@ -283,24 +283,8 @@ int rc6_test(void) rc6_ecb_decrypt(tmp[0], tmp[1], &key); /* compare */ - if (XMEMCMP(tmp[0], tests[x].ct, 16) || XMEMCMP(tmp[1], tests[x].pt, 16)) { -#if 0 - printf("\n\nFailed test %d\n", x); - if (XMEMCMP(tmp[0], tests[x].ct, 16)) { - printf("Ciphertext: "); - for (y = 0; y < 16; y++) printf("%02x ", tmp[0][y]); - printf("\nExpected : "); - for (y = 0; y < 16; y++) printf("%02x ", tests[x].ct[y]); - printf("\n"); - } - if (XMEMCMP(tmp[1], tests[x].pt, 16)) { - printf("Plaintext: "); - for (y = 0; y < 16; y++) printf("%02x ", tmp[0][y]); - printf("\nExpected : "); - for (y = 0; y < 16; y++) printf("%02x ", tests[x].pt[y]); - printf("\n"); - } -#endif + if (compare_testvector(tmp[0], 16, tests[x].ct, 16, "RC6 Encrypt", x) || + compare_testvector(tmp[1], 16, tests[x].pt, 16, "RC6 Decrypt", x)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/safer/safer.c b/src/ciphers/safer/safer.c index af1a8a2..9eefcfb 100644 --- a/src/ciphers/safer/safer.c +++ b/src/ciphers/safer/safer.c @@ -395,7 +395,8 @@ int safer_k64_test(void) safer_ecb_encrypt(k64_pt, buf[0], &skey); safer_ecb_decrypt(buf[0], buf[1], &skey); - if (XMEMCMP(buf[0], k64_ct, 8) != 0 || XMEMCMP(buf[1], k64_pt, 8) != 0) { + if (compare_testvector(buf[0], 8, k64_ct, 8, "Safer K64 Encrypt", 0) != 0 || + compare_testvector(buf[1], 8, k64_pt, 8, "Safer K64 Decrypt", 0) != 0) { return CRYPT_FAIL_TESTVECTOR; } @@ -425,7 +426,8 @@ int safer_sk64_test(void) safer_ecb_encrypt(sk64_pt, buf[0], &skey); safer_ecb_decrypt(buf[0], buf[1], &skey); - if (XMEMCMP(buf[0], sk64_ct, 8) != 0 || XMEMCMP(buf[1], sk64_pt, 8) != 0) { + if (compare_testvector(buf[0], 8, sk64_ct, 8, "Safer SK64 Encrypt", 0) != 0 || + compare_testvector(buf[1], 8, sk64_pt, 8, "Safer SK64 Decrypt", 0) != 0) { return CRYPT_FAIL_TESTVECTOR; } @@ -468,7 +470,8 @@ int safer_sk128_test(void) safer_ecb_encrypt(sk128_pt, buf[0], &skey); safer_ecb_decrypt(buf[0], buf[1], &skey); - if (XMEMCMP(buf[0], sk128_ct, 8) != 0 || XMEMCMP(buf[1], sk128_pt, 8) != 0) { + if (compare_testvector(buf[0], 8, sk128_ct, 8, "Safer SK128 Encrypt", 0) != 0 || + compare_testvector(buf[1], 8, sk128_pt, 8, "Safer SK128 Decrypt", 0) != 0) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/safer/saferp.c b/src/ciphers/safer/saferp.c index fab3518..116590f 100644 --- a/src/ciphers/safer/saferp.c +++ b/src/ciphers/safer/saferp.c @@ -514,7 +514,8 @@ int saferp_test(void) saferp_ecb_decrypt(tmp[0], tmp[1], &skey); /* compare */ - if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) { + if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "Safer+ Encrypt", i) || + compare_testvector(tmp[1], 16, tests[i].pt, 16, "Safer+ Decrypt", i)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/skipjack.c b/src/ciphers/skipjack.c index 0d28ec1..d47f2d3 100644 --- a/src/ciphers/skipjack.c +++ b/src/ciphers/skipjack.c @@ -296,7 +296,8 @@ int skipjack_test(void) skipjack_ecb_decrypt(buf[0], buf[1], &key); /* compare */ - if (XMEMCMP(buf[0], tests[x].ct, 8) != 0 || XMEMCMP(buf[1], tests[x].pt, 8) != 0) { + if (compare_testvector(buf[0], 8, tests[x].ct, 8, "Skipjack Encrypt", x) != 0 || + compare_testvector(buf[1], 8, tests[x].pt, 8, "Skipjack Decrypt", x) != 0) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/ciphers/twofish/twofish.c b/src/ciphers/twofish/twofish.c index a8a1167..b1584d1 100644 --- a/src/ciphers/twofish/twofish.c +++ b/src/ciphers/twofish/twofish.c @@ -657,10 +657,8 @@ int twofish_test(void) } twofish_ecb_encrypt(tests[i].pt, tmp[0], &key); twofish_ecb_decrypt(tmp[0], tmp[1], &key); - if (XMEMCMP(tmp[0], tests[i].ct, 16) != 0 || XMEMCMP(tmp[1], tests[i].pt, 16) != 0) { -#if 0 - printf("Twofish failed test %d, %d, %d\n", i, XMEMCMP(tmp[0], tests[i].ct, 16), XMEMCMP(tmp[1], tests[i].pt, 16)); -#endif + if (compare_testvector(tmp[0], 16, tests[i].ct, 16, "Twofish Encrypt", i) != 0 || + compare_testvector(tmp[1], 16, tests[i].pt, 16, "Twofish Decrypt", i) != 0) { return CRYPT_FAIL_TESTVECTOR; } /* now see if we can encrypt all zero bytes 1000 times, decrypt and come back where we started */ diff --git a/src/ciphers/xtea.c b/src/ciphers/xtea.c index 77a9346..fe26f98 100644 --- a/src/ciphers/xtea.c +++ b/src/ciphers/xtea.c @@ -211,23 +211,8 @@ int xtea_test(void) xtea_ecb_encrypt(tests[i].pt, tmp[0], &skey); xtea_ecb_decrypt(tmp[0], tmp[1], &skey); - if (XMEMCMP(tmp[0], tests[i].ct, 8) != 0 || XMEMCMP(tmp[1], tests[i].pt, 8) != 0) { -#if 0 - printf("\n\nTest %d failed\n", i); - if (XMEMCMP(tmp[0], tests[i].ct, 8)) { - printf("CT: "); - for (i = 0; i < 8; i++) { - printf("%02x ", tmp[0][i]); - } - printf("\n"); - } else { - printf("PT: "); - for (i = 0; i < 8; i++) { - printf("%02x ", tmp[1][i]); - } - printf("\n"); - } -#endif + if (compare_testvector(tmp[0], 8, tests[i].ct, 8, "XTEA Encrypt", i) != 0 || + compare_testvector(tmp[1], 8, tests[i].pt, 8, "XTEA Decrypt", i) != 0) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/encauth/eax/eax_test.c b/src/encauth/eax/eax_test.c index 8c57c97..d3f5533 100644 --- a/src/encauth/eax/eax_test.c +++ b/src/encauth/eax/eax_test.c @@ -229,22 +229,8 @@ int eax_test(void) tests[x].plaintext, tests[x].msglen, outct, outtag, &len)) != CRYPT_OK) { return err; } - if (XMEMCMP(outct, tests[x].ciphertext, tests[x].msglen) || XMEMCMP(outtag, tests[x].tag, len)) { -#if 0 - unsigned long y; - printf("\n\nFailure: \nCT:\n"); - for (y = 0; y < (unsigned long)tests[x].msglen; ) { - printf("0x%02x", outct[y]); - if (y < (unsigned long)(tests[x].msglen-1)) printf(", "); - if (!(++y % 8)) printf("\n"); - } - printf("\nTAG:\n"); - for (y = 0; y < len; ) { - printf("0x%02x", outtag[y]); - if (y < len-1) printf(", "); - if (!(++y % 8)) printf("\n"); - } -#endif + if (compare_testvector(outtag, len, tests[x].tag, len, "EAX Tag", x) || + compare_testvector(outct, tests[x].msglen, tests[x].ciphertext, tests[x].msglen, "EAX CT", x)) { return CRYPT_FAIL_TESTVECTOR; } @@ -254,16 +240,10 @@ int eax_test(void) outct, tests[x].msglen, outct, outtag, len, &res)) != CRYPT_OK) { return err; } - if ((res != 1) || XMEMCMP(outct, tests[x].plaintext, tests[x].msglen)) { -#if 0 - unsigned long y; - printf("\n\nFailure (res == %d): \nPT:\n", res); - for (y = 0; y < (unsigned long)tests[x].msglen; ) { - printf("0x%02x", outct[y]); - if (y < (unsigned long)(tests[x].msglen-1)) printf(", "); - if (!(++y % 8)) printf("\n"); - } - printf("\n\n"); + if ((res != 1) || compare_testvector(outct, tests[x].msglen, tests[x].plaintext, tests[x].msglen, "EAX", x)) { +#ifdef LTC_TEST_DBG + printf("\n\nEAX: Failure-decrypt\n"); + printf("\nres = %d\n\n", res); #endif return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/encauth/gcm/gcm_test.c b/src/encauth/gcm/gcm_test.c index d7fc00a..e09e50c 100644 --- a/src/encauth/gcm/gcm_test.c +++ b/src/encauth/gcm/gcm_test.c @@ -345,25 +345,11 @@ int gcm_test(void) return err; } - if (XMEMCMP(out[0], tests[x].C, tests[x].ptlen)) { -#if 0 - printf("\nCiphertext wrong %lu\n", x); - for (y = 0; y < tests[x].ptlen; y++) { - printf("%02x", out[0][y] & 255); - } - printf("\n"); -#endif + if (compare_testvector(out[0], tests[x].ptlen, tests[x].C, tests[x].ptlen, "GCM CT", x)) { return CRYPT_FAIL_TESTVECTOR; } - if (XMEMCMP(T[0], tests[x].T, 16)) { -#if 0 - printf("\nTag on plaintext wrong %lu\n", x); - for (y = 0; y < 16; y++) { - printf("%02x", T[0][y] & 255); - } - printf("\n"); -#endif + if (compare_testvector(T[0], y, tests[x].T, 16, "GCM Encrypt Tag", x)) { return CRYPT_FAIL_TESTVECTOR; } @@ -376,25 +362,11 @@ int gcm_test(void) return err; } - if (XMEMCMP(out[1], tests[x].P, tests[x].ptlen)) { -#if 0 - printf("\nplaintext wrong %lu\n", x); - for (y = 0; y < tests[x].ptlen; y++) { - printf("%02x", out[0][y] & 255); - } - printf("\n"); -#endif + if (compare_testvector(out[1], tests[x].ptlen, tests[x].P, tests[x].ptlen, "GCM PT", x)) { return CRYPT_FAIL_TESTVECTOR; } - if (XMEMCMP(T[1], tests[x].T, 16)) { -#if 0 - printf("\nTag on ciphertext wrong %lu\n", x); - for (y = 0; y < 16; y++) { - printf("%02x", T[1][y] & 255); - } - printf("\n"); -#endif + if (compare_testvector(T[1], y, tests[x].T, 16, "GCM Decrypt Tag", x)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/encauth/ocb/ocb_test.c b/src/encauth/ocb/ocb_test.c index aba4cf4..d39dbb9 100644 --- a/src/encauth/ocb/ocb_test.c +++ b/src/encauth/ocb/ocb_test.c @@ -180,22 +180,8 @@ int ocb_test(void) return err; } - if (XMEMCMP(outtag, tests[x].tag, len) || XMEMCMP(outct, tests[x].ct, tests[x].ptlen)) { -#if 0 - unsigned long y; - printf("\n\nFailure: \nCT:\n"); - for (y = 0; y < (unsigned long)tests[x].ptlen; ) { - printf("0x%02x", outct[y]); - if (y < (unsigned long)(tests[x].ptlen-1)) printf(", "); - if (!(++y % 8)) printf("\n"); - } - printf("\nTAG:\n"); - for (y = 0; y < len; ) { - printf("0x%02x", outtag[y]); - if (y < len-1) printf(", "); - if (!(++y % 8)) printf("\n"); - } -#endif + if (compare_testvector(outtag, len, tests[x].tag, sizeof(tests[x].tag), "OCB Tag", x) || + compare_testvector(outct, tests[x].ptlen, tests[x].ct, tests[x].ptlen, "OCB CT", x)) { return CRYPT_FAIL_TESTVECTOR; } @@ -203,17 +189,12 @@ int ocb_test(void) outct, tests[x].tag, len, &res)) != CRYPT_OK) { return err; } - if ((res != 1) || XMEMCMP(tests[x].pt, outct, tests[x].ptlen)) { -#if 0 - unsigned long y; - printf("\n\nFailure-decrypt: \nPT:\n"); - for (y = 0; y < (unsigned long)tests[x].ptlen; ) { - printf("0x%02x", outct[y]); - if (y < (unsigned long)(tests[x].ptlen-1)) printf(", "); - if (!(++y % 8)) printf("\n"); - } + if ((res != 1) || compare_testvector(outct, tests[x].ptlen, tests[x].pt, tests[x].ptlen, "OCB", x)) { +#ifdef LTC_TEST_DBG + printf("\n\nOCB: Failure-decrypt\n"); printf("\nres = %d\n\n", res); #endif + return CRYPT_FAIL_TESTVECTOR; } } return CRYPT_OK; diff --git a/src/encauth/ocb3/ocb3_test.c b/src/encauth/ocb3/ocb3_test.c index 4cd16e8..d6b9d6f 100644 --- a/src/encauth/ocb3/ocb3_test.c +++ b/src/encauth/ocb3/ocb3_test.c @@ -186,22 +186,8 @@ int ocb3_test(void) return err; } - if (XMEMCMP(outtag, tests[x].tag, len) || XMEMCMP(outct, tests[x].ct, tests[x].ptlen)) { -#if 0 - unsigned long y; - printf("\n\nFailure: \nCT:\n"); - for (y = 0; y < (unsigned long)tests[x].ptlen; ) { - printf("0x%02x", outct[y]); - if (y < (unsigned long)(tests[x].ptlen-1)) printf(", "); - if (!(++y % 8)) printf("\n"); - } - printf("\nTAG:\n"); - for (y = 0; y < len; ) { - printf("0x%02x", outtag[y]); - if (y < len-1) printf(", "); - if (!(++y % 8)) printf("\n"); - } -#endif + if (compare_testvector(outtag, len, tests[x].tag, sizeof(tests[x].tag), "OCB3 Tag", x) || + compare_testvector(outct, tests[x].ptlen, tests[x].ct, tests[x].ptlen, "OCB3 CT", x)) { return CRYPT_FAIL_TESTVECTOR; } @@ -213,17 +199,12 @@ int ocb3_test(void) outct, tests[x].tag, len, &res)) != CRYPT_OK) { return err; } - if ((res != 1) || XMEMCMP(tests[x].pt, outct, tests[x].ptlen)) { -#if 0 - unsigned long y; - printf("\n\nFailure-decrypt: \nPT:\n"); - for (y = 0; y < (unsigned long)tests[x].ptlen; ) { - printf("0x%02x", outct[y]); - if (y < (unsigned long)(tests[x].ptlen-1)) printf(", "); - if (!(++y % 8)) printf("\n"); - } + if ((res != 1) || compare_testvector(outct, tests[x].ptlen, tests[x].pt, tests[x].ptlen, "OCB3", x)) { +#ifdef LTC_TEST_DBG + printf("\n\nOCB3: Failure-decrypt\n"); printf("\nres = %d\n\n", res); #endif + return CRYPT_FAIL_TESTVECTOR; } } return CRYPT_OK; diff --git a/src/mac/f9/f9_test.c b/src/mac/f9/f9_test.c index 75f5ba7..ca23acc 100644 --- a/src/mac/f9/f9_test.c +++ b/src/mac/f9/f9_test.c @@ -59,7 +59,7 @@ int f9_test(void) if ((err = f9_memory(idx, tests[x].K, 16, tests[x].M, tests[x].msglen, T, &taglen)) != CRYPT_OK) { return err; } - if (taglen != 4 || XMEMCMP(T, tests[x].T, 4)) { + if (compare_testvector(T, taglen, tests[x].T, 4, "F9", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/mac/omac/omac_test.c b/src/mac/omac/omac_test.c index 10fb92e..9bf392c 100644 --- a/src/mac/omac/omac_test.c +++ b/src/mac/omac/omac_test.c @@ -88,12 +88,7 @@ int omac_test(void) return err; } - if (XMEMCMP(out, tests[x].tag, 16) != 0) { -#if 0 - int y; - printf("\n\nTag: "); - for (y = 0; y < 16; y++) printf("%02x", out[y]); printf("\n\n"); -#endif + if (compare_testvector(out, len, tests[x].tag, sizeof(tests[x].tag), "OMAC", x) != 0) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/mac/pelican/pelican_test.c b/src/mac/pelican/pelican_test.c index 5fe28f9..32a7df3 100644 --- a/src/mac/pelican/pelican_test.c +++ b/src/mac/pelican/pelican_test.c @@ -97,12 +97,7 @@ int pelican_test(void) return err; } - if (XMEMCMP(out, tests[x].T, 16)) { -#if 0 - int y; - printf("\nFailed test %d\n", x); - printf("{ "); for (y = 0; y < 16; ) { printf("0x%02x, ", out[y]); if (!(++y & 7)) printf("\n"); } printf(" }\n"); -#endif + if (compare_testvector(out, 16, tests[x].T, 16, "PELICAN", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/mac/pmac/pmac_test.c b/src/mac/pmac/pmac_test.c index a96f106..19329c6 100644 --- a/src/mac/pmac/pmac_test.c +++ b/src/mac/pmac/pmac_test.c @@ -136,16 +136,7 @@ int pmac_test(void) return err; } - if (XMEMCMP(outtag, tests[x].tag, len)) { -#if 0 - unsigned long y; - printf("\nTAG:\n"); - for (y = 0; y < len; ) { - printf("0x%02x", outtag[y]); - if (y < len-1) printf(", "); - if (!(++y % 8)) printf("\n"); - } -#endif + if (compare_testvector(outtag, len, tests[x].tag, sizeof(tests[x].tag), "PMAC", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/mac/xcbc/xcbc_test.c b/src/mac/xcbc/xcbc_test.c index e237a45..6a0ecdf 100644 --- a/src/mac/xcbc/xcbc_test.c +++ b/src/mac/xcbc/xcbc_test.c @@ -109,7 +109,7 @@ int xcbc_test(void) if ((err = xcbc_memory(idx, tests[x].K, 16, tests[x].M, tests[x].msglen, T, &taglen)) != CRYPT_OK) { return err; } - if (taglen != 16 || XMEMCMP(T, tests[x].T, 16)) { + if (compare_testvector(T, taglen, tests[x].T, 16, "XCBC", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/misc/adler32.c b/src/misc/adler32.c index 7e312bb..8bbf2ac 100644 --- a/src/misc/adler32.c +++ b/src/misc/adler32.c @@ -118,13 +118,7 @@ int adler32_test(void) adler32_init(&ctx); adler32_update(&ctx, in, strlen(in)); adler32_finish(&ctx, out, 4); - if (XMEMCMP(adler32, out, 4)) { -#ifdef LTC_TEST_DBG - ulong32 _out, _adler32; - LOAD32H(_out, out); - LOAD32H(_adler32, adler32); - printf("adler32 fail! Is: 0x%x Should: 0x%x\n", _out, _adler32); -#endif + if (compare_testvector(adler32, 4, out, 4, "adler32", 0)) { return CRYPT_FAIL_TESTVECTOR; } return CRYPT_OK; diff --git a/src/misc/crc32.c b/src/misc/crc32.c index 1f78abb..beb54fc 100644 --- a/src/misc/crc32.c +++ b/src/misc/crc32.c @@ -189,13 +189,7 @@ int crc32_test(void) crc32_init(&ctx); crc32_update(&ctx, in, strlen(in)); crc32_finish(&ctx, out, 4); - if (XMEMCMP(crc32, out, 4)) { -#ifdef LTC_TEST_DBG - ulong32 _out, _crc32; - LOAD32H(_out, out); - LOAD32H(_crc32, crc32); - printf("crc32 fail! Is: 0x%x Should: 0x%x\n", _out, _crc32); -#endif + if (compare_testvector(crc32, 4, out, 4, "CRC32", 0)) { return CRYPT_FAIL_TESTVECTOR; } return CRYPT_OK; diff --git a/src/misc/hkdf/hkdf_test.c b/src/misc/hkdf/hkdf_test.c index ca04ebb..5879323 100644 --- a/src/misc/hkdf/hkdf_test.c +++ b/src/misc/hkdf/hkdf_test.c @@ -265,33 +265,17 @@ int hkdf_test(void) cases[i].info, cases[i].info_l, cases[i].IKM, cases[i].IKM_l, OKM, cases[i].OKM_l)) != CRYPT_OK) { -#ifdef LTC_TEST_DBG +#if LTC_TEST_DBG > 1 printf("LTC_HKDF-%s test #%d, %s\n", cases[i].Hash, i, error_to_string(err)); #endif return err; } - if(XMEMCMP(OKM, cases[i].OKM, (size_t)cases[i].OKM_l) != 0) { + if(compare_testvector(OKM, cases[i].OKM_l, cases[i].OKM, (size_t)cases[i].OKM_l, "HKDF", cases[i].num)) { failed++; -#ifdef LTC_TEST_DBG - { - unsigned int j; - printf("\nLTC_HKDF-%s test #%d:\n", cases[i].Hash, cases[i].num); - printf( "Result: 0x"); - for(j=0; j < cases[i].OKM_l; j++) { - printf("%02x ", OKM[j]); - } - printf("\nCorrect: 0x"); - for(j=0; j < cases[i].OKM_l; j++) { - printf("%02x ", cases[i].OKM[j]); - } - printf("\n"); - return CRYPT_ERROR; - } #if LTC_TEST_DBG > 1 } else { printf("LTC_HKDF-%s test #%d: Passed\n", cases[i].Hash, cases[i].num); -#endif #endif } } diff --git a/src/modes/ctr/ctr_test.c b/src/modes/ctr/ctr_test.c index 6574ef2..878d425 100644 --- a/src/modes/ctr/ctr_test.c +++ b/src/modes/ctr/ctr_test.c @@ -65,7 +65,7 @@ int ctr_test(void) return err; } ctr_done(&ctr); - if (XMEMCMP(buf, tests[x].ct, tests[x].msglen)) { + if (compare_testvector(buf, tests[x].msglen, tests[x].ct, tests[x].msglen, "CTR", x)) { return CRYPT_FAIL_TESTVECTOR; } } diff --git a/src/modes/f8/f8_test_mode.c b/src/modes/f8/f8_test_mode.c index d9d0ccd..778cd35 100644 --- a/src/modes/f8/f8_test_mode.c +++ b/src/modes/f8/f8_test_mode.c @@ -59,7 +59,7 @@ int f8_test_mode(void) f8_done(&f8); /* compare */ - if (XMEMCMP(buf, ct, sizeof(ct))) { + if (compare_testvector(buf, sizeof(ct), ct, sizeof(ct), "f8", 0)) { return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/modes/lrw/lrw_test.c b/src/modes/lrw/lrw_test.c index 10ff919..7762d47 100644 --- a/src/modes/lrw/lrw_test.c +++ b/src/modes/lrw/lrw_test.c @@ -86,7 +86,7 @@ int lrw_test(void) } /* check pad against expected tweak */ - if (XMEMCMP(tests[x].expected_tweak, lrw.pad, 16)) { + if (compare_testvector(tests[x].expected_tweak, 16, lrw.pad, 16, "LRW Tweak", x)) { lrw_done(&lrw); return CRYPT_FAIL_TESTVECTOR; } @@ -97,7 +97,7 @@ int lrw_test(void) return err; } - if (XMEMCMP(buf[0], tests[x].C, 16)) { + if (compare_testvector(buf[0], 16, tests[x].C, 16, "LRW Encrypt", x)) { lrw_done(&lrw); return CRYPT_FAIL_TESTVECTOR; } @@ -113,7 +113,7 @@ int lrw_test(void) return err; } - if (XMEMCMP(buf[1], tests[x].P, 16)) { + if (compare_testvector(buf[1], 16, tests[x].P, 16, "LRW Decrypt", x)) { lrw_done(&lrw); return CRYPT_FAIL_TESTVECTOR; } diff --git a/src/stream/rc4/rc4_test.c b/src/stream/rc4/rc4_test.c index 4167a6c..a7e4887 100644 --- a/src/stream/rc4/rc4_test.c +++ b/src/stream/rc4/rc4_test.c @@ -25,7 +25,7 @@ int rc4_stream_test(void) if ((err = rc4_stream_setup(&st, key, sizeof(key))) != CRYPT_OK) return err; if ((err = rc4_stream_crypt(&st, pt, sizeof(pt), buf)) != CRYPT_OK) return err; - if (XMEMCMP(buf, ct, sizeof(ct))) return CRYPT_FAIL_TESTVECTOR; + if (compare_testvector(buf, sizeof(ct), ct, sizeof(ct), "RC4", 0)) return CRYPT_FAIL_TESTVECTOR; if ((err = rc4_stream_done(&st)) != CRYPT_OK) return err; return CRYPT_OK; diff --git a/src/stream/sober128/sober128_test.c b/src/stream/sober128/sober128_test.c index fa3f852..32ea461 100644 --- a/src/stream/sober128/sober128_test.c +++ b/src/stream/sober128/sober128_test.c @@ -31,15 +31,7 @@ int sober128_stream_test(void) if ((err = sober128_stream_setiv(&st, iv, sizeof(iv))) != CRYPT_OK) return err; if ((err = sober128_stream_crypt(&st, src, len, dst)) != CRYPT_OK) return err; if ((err = sober128_stream_done(&st)) != CRYPT_OK) return err; - if (XMEMCMP(dst, out, len)) { -#if 0 - int y; - printf("\nLTC_SOBER128 failed, I got:\n"); - for (y = 0; y < len; y++) printf("%02x ", dst[y]); - printf("\nLTC_SOBER128 failed, expected:\n"); - for (y = 0; y < len; y++) printf("%02x ", out[y]); - printf("\n"); -#endif + if (compare_testvector(dst, len, out, len, "SOBER-128", 0)) { return CRYPT_FAIL_TESTVECTOR; } return CRYPT_OK;