Skip to content

Commit 6155a33

Browse files
committed
Use COMPARE_TESTVECTOR() consistently
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent cb12f2e commit 6155a33

13 files changed

Lines changed: 71 additions & 71 deletions

tests/base16_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ int base16_test(void)
2525
DO(base16_encode(in, x, out, &l1, idx));
2626
l2 = sizeof(tmp);
2727
DO(base16_decode(out, l1, tmp, &l2));
28-
DO(do_compare_testvector(tmp, l2, in, x, "random base16", idx * 100 + x));
28+
COMPARE_TESTVECTOR(tmp, l2, in, x, "random base16", idx * 100 + x);
2929
}
3030
}
3131

3232
for (idx = 0; idx < 2; idx++) {
3333
l1 = sizeof(out);
3434
DO(base16_encode(testin, sizeof(testin), out, &l1, idx));
35-
DO(do_compare_testvector(out, XSTRLEN(out), testout[idx], XSTRLEN(testout[idx]), "testout base16", idx));
35+
COMPARE_TESTVECTOR(out, XSTRLEN(out), testout[idx], XSTRLEN(testout[idx]), "testout base16", idx);
3636
l2 = sizeof(tmp);
3737
DO(base16_decode(out, l1, tmp, &l2));
38-
DO(do_compare_testvector(tmp, l2, testin, sizeof(testin), "testin base16", idx));
38+
COMPARE_TESTVECTOR(tmp, l2, testin, sizeof(testin), "testin base16", idx);
3939
}
4040

4141
l1 = 4;

tests/base32_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ int base32_test(void)
3232
DO(base32_encode(in, x, out, &l1, testid[idx]));
3333
l2 = sizeof(tmp);
3434
DO(base32_decode(out, l1, tmp, &l2, testid[idx]));
35-
DO(do_compare_testvector(tmp, l2, in, x, "random base32", idx * 100 + x));
35+
COMPARE_TESTVECTOR(tmp, l2, in, x, "random base32", idx * 100 + x);
3636
}
3737
}
3838

3939
for (idx = 0; idx < 4; idx++) {
4040
l1 = sizeof(out);
4141
DO(base32_encode(testin, sizeof(testin), out, &l1, testid[idx]));
42-
DO(do_compare_testvector(out, l1, testout[idx], XSTRLEN(testout[idx]), "testout base32", idx));
42+
COMPARE_TESTVECTOR(out, l1, testout[idx], XSTRLEN(testout[idx]), "testout base32", idx);
4343
l2 = sizeof(tmp);
4444
DO(base32_decode(out, l1, tmp, &l2, testid[idx]));
45-
DO(do_compare_testvector(tmp, l2, testin, sizeof(testin), "testin base32", idx));
45+
COMPARE_TESTVECTOR(tmp, l2, testin, sizeof(testin), "testin base32", idx);
4646
}
4747

4848
return CRYPT_OK;

tests/base64_test.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,24 @@ int base64_test(void)
7676
l1 = sizeof(tmp);
7777
if(url_cases[x].flag == strict) {
7878
DO(base64url_strict_decode(url_cases[x].s, slen1, tmp, &l1));
79-
DO(do_compare_testvector(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_strict_decode", x));
79+
COMPARE_TESTVECTOR(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_strict_decode", x);
8080
DO(base64url_sane_decode(url_cases[x].s, slen1, tmp, &l1));
81-
DO(do_compare_testvector(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_sane_decode/strict", x));
81+
COMPARE_TESTVECTOR(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_sane_decode/strict", x);
8282
DO(base64url_decode(url_cases[x].s, slen1, tmp, &l1));
83-
DO(do_compare_testvector(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_decode/strict", x));
83+
COMPARE_TESTVECTOR(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_decode/strict", x);
8484
}
8585
else if(url_cases[x].flag == relaxed) {
8686
DO(base64url_strict_decode(url_cases[x].s, slen1, tmp, &l1) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR);
8787
DO(base64url_sane_decode(url_cases[x].s, slen1, tmp, &l1));
88-
DO(do_compare_testvector(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_sane_decode/relaxed", x));
88+
COMPARE_TESTVECTOR(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_sane_decode/relaxed", x);
8989
DO(base64url_decode(url_cases[x].s, slen1, tmp, &l1));
90-
DO(do_compare_testvector(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_decode/relaxed", x));
90+
COMPARE_TESTVECTOR(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_decode/relaxed", x);
9191
}
9292
else if(url_cases[x].flag == insane) {
9393
DO(base64url_strict_decode(url_cases[x].s, slen1, tmp, &l1) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR);
9494
DO(base64url_sane_decode(url_cases[x].s, slen1, tmp, &l1) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR);
9595
DO(base64url_decode(url_cases[x].s, slen1, tmp, &l1));
96-
DO(do_compare_testvector(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_decode/insane", x));
96+
COMPARE_TESTVECTOR(tmp, l1, special_case, sizeof(special_case) - 1, "base64url_decode/insane", x);
9797
}
9898
else { /* invalid */
9999
DO(base64url_strict_decode(url_cases[x].s, slen1, tmp, &l1) == CRYPT_INVALID_PACKET ? CRYPT_OK : CRYPT_FAIL_TESTVECTOR);
@@ -103,11 +103,11 @@ int base64_test(void)
103103
l2 = sizeof(out);
104104
if(x == 0) {
105105
DO(base64url_encode(tmp, l1, out, &l2));
106-
DO(do_compare_testvector(out, l2, url_cases[x].s, XSTRLEN(url_cases[x].s), "base64url_encode", x));
106+
COMPARE_TESTVECTOR(out, l2, url_cases[x].s, XSTRLEN(url_cases[x].s), "base64url_encode", x);
107107
}
108108
if(x == 1) {
109109
DO(base64url_strict_encode(tmp, l1, out, &l2));
110-
DO(do_compare_testvector(out, l2, url_cases[x].s, XSTRLEN(url_cases[x].s), "base64url_strict_encode", x));
110+
COMPARE_TESTVECTOR(out, l2, url_cases[x].s, XSTRLEN(url_cases[x].s), "base64url_strict_encode", x);
111111
}
112112
}
113113
#endif
@@ -119,14 +119,14 @@ int base64_test(void)
119119
slen1 = XSTRLEN(cases[x].s);
120120
l1 = sizeof(out);
121121
DO(base64_encode((unsigned char*)cases[x].s, slen1, out, &l1));
122-
DO(do_compare_testvector(out, l1, cases[x].b64, XSTRLEN(cases[x].b64), "base64_encode", x));
122+
COMPARE_TESTVECTOR(out, l1, cases[x].b64, XSTRLEN(cases[x].b64), "base64_encode", x);
123123
l2 = sizeof(tmp);
124124
DO(base64_strict_decode(out, l1, tmp, &l2));
125-
DO(do_compare_testvector(tmp, l2, cases[x].s, slen1, "base64_strict_decode", x));
125+
COMPARE_TESTVECTOR(tmp, l2, cases[x].s, slen1, "base64_strict_decode", x);
126126
DO(base64_sane_decode(out, l1, tmp, &l2));
127-
DO(do_compare_testvector(tmp, l2, cases[x].s, slen1, "base64_sane_decode", x));
127+
COMPARE_TESTVECTOR(tmp, l2, cases[x].s, slen1, "base64_sane_decode", x);
128128
DO(base64_decode(out, l1, tmp, &l2));
129-
DO(do_compare_testvector(tmp, l2, cases[x].s, slen1, "base64_decode", x));
129+
COMPARE_TESTVECTOR(tmp, l2, cases[x].s, slen1, "base64_decode", x);
130130
}
131131

132132
for (x = 0; x < 64; x++) {
@@ -135,7 +135,7 @@ int base64_test(void)
135135
DO(base64_encode(in, x, out, &l1));
136136
l2 = sizeof(tmp);
137137
DO(base64_decode(out, l1, tmp, &l2));
138-
DO(do_compare_testvector(tmp, x, in, x, "random base64", x));
138+
COMPARE_TESTVECTOR(tmp, x, in, x, "random base64", x);
139139
}
140140

141141
x--;

tests/bcrypt_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int bcrypt_test(void)
125125
l = t->keylen;
126126
XMEMSET(key, 0, sizeof(key));
127127
DO(bcrypt_pbkdf_openbsd(t->password, t->passlen, (unsigned char*)t->salt, t->saltlen, t->rounds, idx, key, &l));
128-
DO(do_compare_testvector(key, l, t->key, t->keylen, "OpenBSD testvectors", i));
128+
COMPARE_TESTVECTOR(key, l, t->key, t->keylen, "OpenBSD testvectors", i);
129129

130130
#if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1
131131
printf("BCRYPT test #%d OK\n", i);

tests/der_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ static void s_der_oid_test(void)
733733
DO(der_encode_object_identifier(decoded_list->data, decoded_list->size, buf, &len));
734734
der_sequence_free(decoded_list);
735735

736-
DO(do_compare_testvector(buf, len, oid_x690_8_19_5_example, sizeof(oid_x690_8_19_5_example), "OID X6.90 Ch. 8.19.5 Example", 0));
736+
COMPARE_TESTVECTOR(buf, len, oid_x690_8_19_5_example, sizeof(oid_x690_8_19_5_example), "OID X6.90 Ch. 8.19.5 Example", 0);
737737

738738
oid[0] = 3;
739739
oid[1] = 4;
@@ -1295,7 +1295,7 @@ static void der_Xcode_run(const der_Xcode_t* x)
12951295
d2 = XREALLOC(d2, l2 * x->type_sz);
12961296
}
12971297
DO(x->decode(d1, l1, d2, &l2));
1298-
DO(do_compare_testvector(d2, (l2/x->factor) * x->type_sz, x->in, x->in_sz, x->what, __LINE__));
1298+
COMPARE_TESTVECTOR(d2, (l2/x->factor) * x->type_sz, x->in, x->in_sz, x->what, __LINE__);
12991299
XFREE(d2);
13001300
XFREE(d1);
13011301
}

tests/dh_test.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static int s_dhparam_test(void)
125125
return CRYPT_ERROR;
126126
}
127127
DO(ltc_mp_to_unsigned_bin(k.prime, buf));
128-
DO(do_compare_testvector(buf, sizeof(prime), prime, sizeof(prime), "dhparam_test: prime mismatch", 1));
128+
COMPARE_TESTVECTOR(buf, sizeof(prime), prime, sizeof(prime), "dhparam_test: prime mismatch", 1);
129129
if (ltc_mp_cmp_d(k.base, 2) != LTC_MP_EQ) {
130130
printf("dhparam_test: base mismatch\n");
131131
dh_free(&k);
@@ -259,49 +259,49 @@ static int s_set_test(void)
259259

260260
len = sizeof(buf);
261261
DO(dh_export(buf, &len, PK_PRIVATE, &k1));
262-
DO(do_compare_testvector(buf, len, export_private, sizeof(export_private), "radix_test: dh_export+PK_PRIVATE mismatch", i*10 + 0));
262+
COMPARE_TESTVECTOR(buf, len, export_private, sizeof(export_private), "radix_test: dh_export+PK_PRIVATE mismatch", i*10 + 0);
263263
len = sizeof(buf);
264264
DO(dh_export(buf, &len, PK_PUBLIC, &k1));
265-
DO(do_compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 1));
265+
COMPARE_TESTVECTOR(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 1);
266266
len = sizeof(buf);
267267
DO(dh_export_key(buf, &len, PK_PRIVATE, &k1));
268-
DO(do_compare_testvector(buf, len, xbin, sizeof(xbin), "radix_test: dh_export+PK_PRIVATE mismatch", i*10 + 2));
268+
COMPARE_TESTVECTOR(buf, len, xbin, sizeof(xbin), "radix_test: dh_export+PK_PRIVATE mismatch", i*10 + 2);
269269
len = sizeof(buf);
270270
DO(dh_export_key(buf, &len, PK_PUBLIC, &k1));
271-
DO(do_compare_testvector(buf, len, ybin, sizeof(ybin), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 3));
271+
COMPARE_TESTVECTOR(buf, len, ybin, sizeof(ybin), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 3);
272272
dh_free(&k1);
273273

274274
DO(dh_set_pg(test[i].p, test[i].plen, test[i].g, test[i].glen, &k1));
275275
DO(dh_set_key(test[i].x, test[i].xlen, PK_PRIVATE, &k1));
276276

277277
len = sizeof(buf);
278278
DO(dh_export(buf, &len, PK_PRIVATE, &k1));
279-
DO(do_compare_testvector(buf, len, export_private, sizeof(export_private), "radix_test: dh_export+PK_PRIVATE mismatc", i*10 + 4));
279+
COMPARE_TESTVECTOR(buf, len, export_private, sizeof(export_private), "radix_test: dh_export+PK_PRIVATE mismatc", i*10 + 4);
280280
len = sizeof(buf);
281281
DO(dh_export(buf, &len, PK_PUBLIC, &k1));
282-
DO(do_compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 5));
282+
COMPARE_TESTVECTOR(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 5);
283283
dh_free(&k1);
284284

285285
DO(dh_set_pg(test[i].p, test[i].plen, test[i].g, test[i].glen, &k2));
286286
DO(dh_set_key(test[i].y, test[i].ylen, PK_PUBLIC, &k2));
287287

288288
len = sizeof(buf);
289289
DO(dh_export(buf, &len, PK_PUBLIC, &k2));
290-
DO(do_compare_testvector(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 6));
290+
COMPARE_TESTVECTOR(buf, len, export_public, sizeof(export_public), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 6);
291291
len = sizeof(buf);
292292
DO(dh_export_key(buf, &len, PK_PUBLIC, &k2));
293-
DO(do_compare_testvector(buf, len, ybin, sizeof(ybin), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 7));
293+
COMPARE_TESTVECTOR(buf, len, ybin, sizeof(ybin), "radix_test: dh_export+PK_PUBLIC mismatch", i*10 + 7);
294294
dh_free(&k2);
295295

296296
DO(dh_set_pg(test[i].p, test[i].plen, test[i].g, test[i].glen, &k3));
297297
DO(dh_generate_key(&yarrow_prng, find_prng("yarrow"), &k3));
298298

299299
len = ltc_mp_unsigned_bin_size(k3.prime);
300300
DO(ltc_mp_to_unsigned_bin(k3.prime, buf));
301-
DO(do_compare_testvector(buf, len, pbin, sizeof(pbin), "radix_test: dh_make_key_ex prime mismatch", i*10 + 8));
301+
COMPARE_TESTVECTOR(buf, len, pbin, sizeof(pbin), "radix_test: dh_make_key_ex prime mismatch", i*10 + 8);
302302
len = ltc_mp_unsigned_bin_size(k3.base);
303303
DO(ltc_mp_to_unsigned_bin(k3.base, buf));
304-
DO(do_compare_testvector(buf, len, gbin, sizeof(gbin), "radix_test: dh_make_key_ex base mismatch", i*10 + 9));
304+
COMPARE_TESTVECTOR(buf, len, gbin, sizeof(gbin), "radix_test: dh_make_key_ex base mismatch", i*10 + 9);
305305
dh_free(&k3);
306306
}
307307

tests/dsa_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,20 @@ static int s_dsa_compat_test(void)
151151

152152
x = sizeof(tmp);
153153
DO(dsa_export(tmp, &x, PK_PRIVATE | PK_STD, &key));
154-
DO(do_compare_testvector(tmp, x, ltc_dsa_private_test_key, sizeof(ltc_dsa_private_test_key),
154+
COMPARE_TESTVECTOR(tmp, x, ltc_dsa_private_test_key, sizeof(ltc_dsa_private_test_key),
155155
"DSA private export from dsa_import(priv_key)\n", __LINE__);
156156

157157
x = sizeof(tmp);
158158
DO(dsa_export(tmp, &x, PK_PUBLIC | PK_STD, &key));
159-
DO(do_compare_testvector(tmp, x, openssl_pub_dsa, sizeof(openssl_pub_dsa),
159+
COMPARE_TESTVECTOR(tmp, x, openssl_pub_dsa, sizeof(openssl_pub_dsa),
160160
"DSA public export from dsa_import(priv_key)\n", __LINE__);
161161
dsa_free(&key);
162162

163163
DO(dsa_import(openssl_pub_dsa, sizeof(openssl_pub_dsa), &key));
164164

165165
x = sizeof(tmp);
166166
DO(dsa_export(tmp, &x, PK_PUBLIC | PK_STD, &key));
167-
DO(do_compare_testvector(tmp, x, openssl_pub_dsa, sizeof(openssl_pub_dsa),
167+
COMPARE_TESTVECTOR(tmp, x, openssl_pub_dsa, sizeof(openssl_pub_dsa),
168168
"DSA public export from dsa_import(pub_key)\n", __LINE__);
169169
dsa_free(&key);
170170

tests/ecc_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static int s_ecc_old_api(void)
420420
y = sizeof(buf[1]);
421421
DO(ecc_shared_secret (&userb, &usera, buf[1], &y));
422422

423-
DO(do_compare_testvector(buf[0], x, buf[1], y, "ecc Shared keys", s));
423+
COMPARE_TESTVECTOR(buf[0], x, buf[1], y, "ecc Shared keys", s);
424424

425425
/* now export userb */
426426
y = sizeof(buf[0]);

tests/ed25519_test.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static int s_rfc_8410_10_test(void)
9292
DO(ed25519_export(buf, &buflen, rfc_8410_10[n].type, &key));
9393
tmplen = sizeof(tmp);
9494
DO(base64_encode(buf, buflen, tmp, &tmplen));
95-
DO(do_compare_testvector(tmp, tmplen, rfc_8410_10[n].b64, XSTRLEN(rfc_8410_10[n].b64), "Ed25519 export-import", n));
95+
COMPARE_TESTVECTOR(tmp, tmplen, rfc_8410_10[n].b64, XSTRLEN(rfc_8410_10[n].b64), "Ed25519 export-import", n);
9696
}
9797
}
9898
return CRYPT_OK;
@@ -225,9 +225,9 @@ static int s_rfc_8032_7_1_test(void)
225225
DO(ed25519_import_raw(sec, slen, PK_PRIVATE, &key));
226226
buflen = sizeof(buf);
227227
DO(ed25519_sign(msg, mlen, buf, &buflen, &key));
228-
DO(do_compare_testvector(buf, buflen, sig, siglen, "Ed25519 RFC8032 7.1 - sign", n));
228+
COMPARE_TESTVECTOR(buf, buflen, sig, siglen, "Ed25519 RFC8032 7.1 - sign", n);
229229
DO(ed25519_verify(msg, mlen, sig, siglen, &ret, &key));
230-
DO(do_compare_testvector(&ret, sizeof(ret), &should, sizeof(should), "Ed25519 RFC8032 7.1 - verify w/ privkey", n));
230+
COMPARE_TESTVECTOR(&ret, sizeof(ret), &should, sizeof(should), "Ed25519 RFC8032 7.1 - verify w/ privkey", n);
231231

232232
xor_shuffle(sig, siglen, 0x8u);
233233
DO( ed25519_verify(msg, mlen, sig, siglen, &ret, &key));
@@ -244,7 +244,7 @@ static int s_rfc_8032_7_1_test(void)
244244
DO(base16_decode(rfc_8032_7_1[n].signature, XSTRLEN(rfc_8032_7_1[n].signature), sig, &siglen));
245245
DO(ed25519_import_raw(pub, plen, PK_PUBLIC, &key2));
246246
DO(ed25519_verify(msg, mlen, sig, siglen, &ret, &key2));
247-
DO(do_compare_testvector(&ret, sizeof(ret), &should, sizeof(should), "Ed25519 RFC8032 7.1 - verify w/ pubkey", n));
247+
COMPARE_TESTVECTOR(&ret, sizeof(ret), &should, sizeof(should), "Ed25519 RFC8032 7.1 - verify w/ pubkey", n);
248248

249249
zeromem(&key, sizeof(key));
250250
zeromem(&key2, sizeof(key2));
@@ -331,7 +331,7 @@ static int s_rfc_8032_7_2_test(void)
331331

332332
DO(ed25519_import_raw(sec, slen, PK_PRIVATE, &key));
333333
DO(ed25519ctx_sign(msg, mlen, buf, &buflen, ctx, ctxlen, &key));
334-
DO(do_compare_testvector(buf, buflen, sig, siglen, "Ed25519 RFC8032 7.2 - sign", n));
334+
COMPARE_TESTVECTOR(buf, buflen, sig, siglen, "Ed25519 RFC8032 7.2 - sign", n);
335335
DO(ed25519ctx_verify(msg, mlen, buf, buflen, ctx, ctxlen, &ret, &key));
336336
ENSUREX(ret == should, "Ed25519 RFC8032 7.2 - verify w/ privkey");
337337

@@ -389,7 +389,7 @@ static int s_rfc_8032_7_3_test(void)
389389

390390
DO(ed25519_import_raw(sec, slen, PK_PRIVATE, &key));
391391
DO(ed25519ph_sign(msg, mlen, buf, &buflen, NULL, 0, &key));
392-
DO(do_compare_testvector(buf, buflen, sig, siglen, "Ed25519 RFC8032 7.3 - sign", 0));
392+
COMPARE_TESTVECTOR(buf, buflen, sig, siglen, "Ed25519 RFC8032 7.3 - sign", 0);
393393
DO(ed25519ph_verify(msg, mlen, buf, buflen, NULL, 0, &ret, &key));
394394
ENSUREX(ret == should, "Ed25519 RFC8032 7.3 - verify w/ privkey");
395395

0 commit comments

Comments
 (0)