Skip to content

Commit 1d07689

Browse files
committed
Remove unnecessary casts in the tests
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 1e31c38 commit 1d07689

File tree

3 files changed

+49
-46
lines changed

3 files changed

+49
-46
lines changed

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, (unsigned char*)t->key, t->keylen, "OpenBSD testvectors", i));
128+
DO(do_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: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,8 @@ static void der_set_test(void)
620620
static const unsigned char bin_str[] = { 1, 0, 0, 1 };
621621
static const unsigned long int_val = 12345678UL;
622622

623-
unsigned char strs[10][10], outbuf[128];
623+
char strs[10][10];
624+
unsigned char outbuf[128];
624625
unsigned long x, val, outlen;
625626

626627
/* make structure and encode it */
@@ -655,19 +656,19 @@ static void der_set_test(void)
655656
exit(EXIT_FAILURE);
656657
}
657658

658-
strcpy((char*)strs[0], "one");
659-
strcpy((char*)strs[1], "one2");
660-
strcpy((char*)strs[2], "two");
661-
strcpy((char*)strs[3], "aaa");
662-
strcpy((char*)strs[4], "aaaa");
663-
strcpy((char*)strs[5], "aab");
664-
strcpy((char*)strs[6], "aaab");
665-
strcpy((char*)strs[7], "bbb");
666-
strcpy((char*)strs[8], "bbba");
667-
strcpy((char*)strs[9], "bbbb");
659+
strcpy(strs[0], "one");
660+
strcpy(strs[1], "one2");
661+
strcpy(strs[2], "two");
662+
strcpy(strs[3], "aaa");
663+
strcpy(strs[4], "aaaa");
664+
strcpy(strs[5], "aab");
665+
strcpy(strs[6], "aaab");
666+
strcpy(strs[7], "bbb");
667+
strcpy(strs[8], "bbba");
668+
strcpy(strs[9], "bbbb");
668669

669670
for (x = 0; x < 10; x++) {
670-
LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], XSTRLEN((char*)strs[x]));
671+
LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], XSTRLEN(strs[x]));
671672
}
672673

673674
outlen = sizeof(outbuf);
@@ -682,7 +683,7 @@ static void der_set_test(void)
682683

683684
/* now compare */
684685
for (x = 1; x < 10; x++) {
685-
if (!(XSTRLEN((char*)strs[x-1]) <= XSTRLEN((char*)strs[x])) && strcmp((char*)strs[x-1], (char*)strs[x]) >= 0) {
686+
if (!(XSTRLEN(strs[x-1]) <= XSTRLEN(strs[x])) && strcmp(strs[x-1], strs[x]) >= 0) {
686687
fprintf(stderr, "error SET OF order at %lu is wrong\n", x);
687688
exit(EXIT_FAILURE);
688689
}
@@ -1626,30 +1627,32 @@ int der_test(void)
16261627
unsigned char buf[3][2048];
16271628
void *a, *b, *c, *d, *e, *f, *g;
16281629

1629-
static const unsigned char rsa_oid_der[] = { 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d };
1630-
static const unsigned long rsa_oid[] = { 1, 2, 840, 113549 };
1630+
const unsigned char rsa_oid_der[] = { 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d };
1631+
const unsigned long rsa_oid[] = { 1, 2, 840, 113549 };
16311632

1632-
static const unsigned char rsa_ia5[] = "test1@rsa.com";
1633-
static const unsigned char rsa_ia5_der[] = { 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x31,
1633+
const unsigned char rsa_ia5[] = "test1@rsa.com";
1634+
const unsigned char rsa_ia5_der[] = { 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x31,
16341635
0x40, 0x72, 0x73, 0x61, 0x2e, 0x63, 0x6f, 0x6d };
1636+
unsigned long rsa_ia5_len = XSTRLEN((char*)rsa_ia5);
16351637

1636-
static const unsigned char rsa_printable[] = "Test User 1";
1637-
static const unsigned char rsa_printable_der[] = { 0x13, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55,
1638+
const unsigned char rsa_printable[] = "Test User 1";
1639+
const unsigned char rsa_printable_der[] = { 0x13, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55,
16381640
0x73, 0x65, 0x72, 0x20, 0x31 };
1641+
unsigned long rsa_printable_len = XSTRLEN((char*)rsa_printable);
16391642

1640-
static const ltc_utctime rsa_time1 = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
1641-
static const ltc_utctime rsa_time2 = { 91, 5, 6, 23, 45, 40, 0, 0, 0 };
1643+
const ltc_utctime rsa_time1 = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
1644+
const ltc_utctime rsa_time2 = { 91, 5, 6, 23, 45, 40, 0, 0, 0 };
16421645
ltc_utctime tmp_time;
16431646

1644-
static const unsigned char rsa_time1_der[] = { 0x17, 0x11, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x31, 0x36, 0x34, 0x35, 0x34, 0x30, 0x2D, 0x30, 0x37, 0x30, 0x30 };
1645-
static const unsigned char rsa_time2_der[] = { 0x17, 0x0d, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x32, 0x33, 0x34, 0x35, 0x34, 0x30, 0x5a };
1647+
const unsigned char rsa_time1_der[] = { 0x17, 0x11, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x31, 0x36, 0x34, 0x35, 0x34, 0x30, 0x2D, 0x30, 0x37, 0x30, 0x30 };
1648+
const unsigned char rsa_time2_der[] = { 0x17, 0x0d, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x32, 0x33, 0x34, 0x35, 0x34, 0x30, 0x5a };
16461649

1647-
static const wchar_t utf8_1[] = { 0x0041, 0x2262, 0x0391, 0x002E };
1648-
static const unsigned char utf8_1_der[] = { 0x0C, 0x07, 0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E };
1649-
static const wchar_t utf8_2[] = { 0xD55C, 0xAD6D, 0xC5B4 };
1650-
static const unsigned char utf8_2_der[] = { 0x0C, 0x09, 0xED, 0x95, 0x9C, 0xEA, 0xB5, 0xAD, 0xEC, 0x96, 0xB4 };
1651-
static const wchar_t utf8_3[] = { 0x05E9, 0x05DC, 0x05D5, 0x05DD };
1652-
static const unsigned char utf8_3_der[] = { 0x0C, 0x08, 0xD7, 0xA9, 0xD7, 0x9C, 0xD7, 0x95, 0xD7, 0x9D };
1650+
const wchar_t utf8_1[] = { 0x0041, 0x2262, 0x0391, 0x002E };
1651+
const unsigned char utf8_1_der[] = { 0x0C, 0x07, 0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E };
1652+
const wchar_t utf8_2[] = { 0xD55C, 0xAD6D, 0xC5B4 };
1653+
const unsigned char utf8_2_der[] = { 0x0C, 0x09, 0xED, 0x95, 0x9C, 0xEA, 0xB5, 0xAD, 0xEC, 0x96, 0xB4 };
1654+
const wchar_t utf8_3[] = { 0x05E9, 0x05DC, 0x05D5, 0x05DD };
1655+
const unsigned char utf8_3_der[] = { 0x0C, 0x08, 0xD7, 0xA9, 0xD7, 0x9C, 0xD7, 0x95, 0xD7, 0x9D };
16531656

16541657
unsigned char utf8_buf[32];
16551658
wchar_t utf8_out[32];
@@ -1863,38 +1866,38 @@ int der_test(void)
18631866

18641867
/* IA5 string */
18651868
x = sizeof(buf[0]);
1866-
DO(der_encode_ia5_string(rsa_ia5, XSTRLEN((char*)rsa_ia5), buf[0], &x));
1869+
DO(der_encode_ia5_string(rsa_ia5, rsa_ia5_len, buf[0], &x));
18671870
if (x != sizeof(rsa_ia5_der) || memcmp(buf[0], rsa_ia5_der, x)) {
18681871
fprintf(stderr, "IA5 encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_ia5_der));
18691872
return 1;
18701873
}
1871-
DO(der_length_ia5_string(rsa_ia5, XSTRLEN((char*)rsa_ia5), &y));
1874+
DO(der_length_ia5_string(rsa_ia5, rsa_ia5_len, &y));
18721875
if (y != x) {
18731876
fprintf(stderr, "IA5 length failed to match: %lu, %lu\n", x, y);
18741877
return 1;
18751878
}
18761879
y = sizeof(buf[1]);
18771880
DO(der_decode_ia5_string(buf[0], x, buf[1], &y));
1878-
if (y != XSTRLEN((char*)rsa_ia5) || memcmp(buf[1], rsa_ia5, XSTRLEN((char*)rsa_ia5))) {
1881+
if (y != rsa_ia5_len || memcmp(buf[1], rsa_ia5, rsa_ia5_len)) {
18791882
fprintf(stderr, "DER IA5 failed test vector\n");
18801883
return 1;
18811884
}
18821885

18831886
/* Printable string */
18841887
x = sizeof(buf[0]);
1885-
DO(der_encode_printable_string(rsa_printable, XSTRLEN((char*)rsa_printable), buf[0], &x));
1888+
DO(der_encode_printable_string(rsa_printable, rsa_printable_len, buf[0], &x));
18861889
if (x != sizeof(rsa_printable_der) || memcmp(buf[0], rsa_printable_der, x)) {
18871890
fprintf(stderr, "PRINTABLE encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_printable_der));
18881891
return 1;
18891892
}
1890-
DO(der_length_printable_string(rsa_printable, XSTRLEN((char*)rsa_printable), &y));
1893+
DO(der_length_printable_string(rsa_printable, rsa_printable_len, &y));
18911894
if (y != x) {
18921895
fprintf(stderr, "printable length failed to match: %lu, %lu\n", x, y);
18931896
return 1;
18941897
}
18951898
y = sizeof(buf[1]);
18961899
DO(der_decode_printable_string(buf[0], x, buf[1], &y));
1897-
if (y != XSTRLEN((char*)rsa_printable) || memcmp(buf[1], rsa_printable, XSTRLEN((char*)rsa_printable))) {
1900+
if (y != rsa_printable_len || memcmp(buf[1], rsa_printable, rsa_printable_len)) {
18981901
fprintf(stderr, "DER printable failed test vector\n");
18991902
return 1;
19001903
}

tests/ecc_test.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ static int s_ecc_issue108(void)
261261
/* ECC-224 AKA SECP224R1 */
262262
if ((err = ecc_find_curve("SECP224R1", &dp)) != CRYPT_OK) { goto done; }
263263
/* read A */
264-
if ((err = mp_read_radix(a, (char *)dp->A, 16)) != CRYPT_OK) { goto done; }
264+
if ((err = mp_read_radix(a, dp->A, 16)) != CRYPT_OK) { goto done; }
265265
/* read modulus */
266-
if ((err = mp_read_radix(modulus, (char *)dp->prime, 16)) != CRYPT_OK) { goto done; }
266+
if ((err = mp_read_radix(modulus, dp->prime, 16)) != CRYPT_OK) { goto done; }
267267
/* read order */
268-
if ((err = mp_read_radix(order, (char *)dp->order, 16)) != CRYPT_OK) { goto done; }
268+
if ((err = mp_read_radix(order, dp->order, 16)) != CRYPT_OK) { goto done; }
269269
/* read Q */
270-
if ((err = mp_read_radix(Q->x, (char *)"EA3745501BBC6A70BBFDD8AEEDB18CF5073C6DC9AA7CBB5915170D60", 16)) != CRYPT_OK) { goto done; }
271-
if ((err = mp_read_radix(Q->y, (char *)"6C9CB8E68AABFEC989CAC5E2326E0448B7E69C3E56039BA21A44FDAC", 16)) != CRYPT_OK) { goto done; }
270+
if ((err = mp_read_radix(Q->x, "EA3745501BBC6A70BBFDD8AEEDB18CF5073C6DC9AA7CBB5915170D60", 16)) != CRYPT_OK) { goto done; }
271+
if ((err = mp_read_radix(Q->y, "6C9CB8E68AABFEC989CAC5E2326E0448B7E69C3E56039BA21A44FDAC", 16)) != CRYPT_OK) { goto done; }
272272
mp_set(Q->z, 1);
273273
/* calculate nQ */
274274
if ((err = ltc_mp.ecc_ptmul(order, Q, Result, a, modulus, 1)) != CRYPT_OK) { goto done; }
@@ -353,9 +353,9 @@ static int s_ecc_test_mp(void)
353353
err = CRYPT_OK;
354354

355355
for (i = 0; ltc_ecc_curves[i].prime != NULL; i++) {
356-
DO(mp_read_radix(a, (char *)ltc_ecc_curves[i].A, 16));
357-
DO(mp_read_radix(modulus, (char *)ltc_ecc_curves[i].prime, 16));
358-
DO(mp_read_radix(order, (char *)ltc_ecc_curves[i].order, 16));
356+
DO(mp_read_radix(a, ltc_ecc_curves[i].A, 16));
357+
DO(mp_read_radix(modulus, ltc_ecc_curves[i].prime, 16));
358+
DO(mp_read_radix(order, ltc_ecc_curves[i].order, 16));
359359

360360
/* is prime actually prime? */
361361
DO(mp_prime_is_prime(modulus, 8, &primality));
@@ -373,8 +373,8 @@ static int s_ecc_test_mp(void)
373373
printf("Order failed prime check: %s\n", buf);
374374
}
375375

376-
DO(mp_read_radix(G->x, (char *)ltc_ecc_curves[i].Gx, 16));
377-
DO(mp_read_radix(G->y, (char *)ltc_ecc_curves[i].Gy, 16));
376+
DO(mp_read_radix(G->x, ltc_ecc_curves[i].Gx, 16));
377+
DO(mp_read_radix(G->y, ltc_ecc_curves[i].Gy, 16));
378378
mp_set(G->z, 1);
379379

380380
/* then we should have G == (order + 1)G */

0 commit comments

Comments
 (0)