use compare_testvector() instead of XMEMCMP() in tests
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user