use compare_testvector() instead of XMEMCMP() in tests

This commit is contained in:
Steffen Jaeckel 2017-06-20 19:06:26 +02:00
parent 05e28d6cfa
commit 27b3ffc627
35 changed files with 81 additions and 302 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;