Browse Source

Remove unnecessary casts in the tests

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 1 year ago
parent
commit
1d07689581
3 changed files with 49 additions and 46 deletions
  1. 1 1
      tests/bcrypt_test.c
  2. 38 35
      tests/der_test.c
  3. 10 10
      tests/ecc_test.c

+ 1 - 1
tests/bcrypt_test.c

@@ -125,7 +125,7 @@ int bcrypt_test(void)
       l = t->keylen;
       XMEMSET(key, 0, sizeof(key));
       DO(bcrypt_pbkdf_openbsd(t->password, t->passlen, (unsigned char*)t->salt, t->saltlen, t->rounds, idx, key, &l));
-      DO(do_compare_testvector(key, l, (unsigned char*)t->key, t->keylen, "OpenBSD testvectors", i));
+      DO(do_compare_testvector(key, l, t->key, t->keylen, "OpenBSD testvectors", i));
 
 #if defined(LTC_TEST_DBG) && LTC_TEST_DBG > 1
       printf("BCRYPT test #%d OK\n", i);

+ 38 - 35
tests/der_test.c

@@ -620,7 +620,8 @@ static void der_set_test(void)
    static const unsigned char bin_str[] = { 1, 0, 0, 1 };
    static const unsigned long int_val   = 12345678UL;
 
-   unsigned char strs[10][10], outbuf[128];
+   char strs[10][10];
+   unsigned char outbuf[128];
    unsigned long x, val, outlen;
 
    /* make structure and encode it */
@@ -655,19 +656,19 @@ static void der_set_test(void)
       exit(EXIT_FAILURE);
    }
 
-   strcpy((char*)strs[0], "one");
-   strcpy((char*)strs[1], "one2");
-   strcpy((char*)strs[2], "two");
-   strcpy((char*)strs[3], "aaa");
-   strcpy((char*)strs[4], "aaaa");
-   strcpy((char*)strs[5], "aab");
-   strcpy((char*)strs[6], "aaab");
-   strcpy((char*)strs[7], "bbb");
-   strcpy((char*)strs[8], "bbba");
-   strcpy((char*)strs[9], "bbbb");
+   strcpy(strs[0], "one");
+   strcpy(strs[1], "one2");
+   strcpy(strs[2], "two");
+   strcpy(strs[3], "aaa");
+   strcpy(strs[4], "aaaa");
+   strcpy(strs[5], "aab");
+   strcpy(strs[6], "aaab");
+   strcpy(strs[7], "bbb");
+   strcpy(strs[8], "bbba");
+   strcpy(strs[9], "bbbb");
 
    for (x = 0; x < 10; x++) {
-       LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], XSTRLEN((char*)strs[x]));
+       LTC_SET_ASN1(list, x, LTC_ASN1_PRINTABLE_STRING, strs[x], XSTRLEN(strs[x]));
    }
 
    outlen = sizeof(outbuf);
@@ -682,7 +683,7 @@ static void der_set_test(void)
 
    /* now compare */
    for (x = 1; x < 10; x++) {
-      if (!(XSTRLEN((char*)strs[x-1]) <= XSTRLEN((char*)strs[x])) && strcmp((char*)strs[x-1], (char*)strs[x]) >= 0) {
+      if (!(XSTRLEN(strs[x-1]) <= XSTRLEN(strs[x])) && strcmp(strs[x-1], strs[x]) >= 0) {
          fprintf(stderr, "error SET OF order at %lu is wrong\n", x);
          exit(EXIT_FAILURE);
       }
@@ -1626,30 +1627,32 @@ int der_test(void)
    unsigned char buf[3][2048];
    void *a, *b, *c, *d, *e, *f, *g;
 
-   static const unsigned char rsa_oid_der[] = { 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d };
-   static const unsigned long rsa_oid[]     = { 1, 2, 840, 113549 };
+   const unsigned char rsa_oid_der[] = { 0x06, 0x06, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d };
+   const unsigned long rsa_oid[]     = { 1, 2, 840, 113549 };
 
-   static const unsigned char rsa_ia5[]     = "[email protected]";
-   static const unsigned char rsa_ia5_der[] = { 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x31,
+   const unsigned char rsa_ia5[]     = "[email protected]";
+   const unsigned char rsa_ia5_der[] = { 0x16, 0x0d, 0x74, 0x65, 0x73, 0x74, 0x31,
                                                 0x40, 0x72, 0x73, 0x61, 0x2e, 0x63, 0x6f, 0x6d };
+   unsigned long rsa_ia5_len = XSTRLEN((char*)rsa_ia5);
 
-   static const unsigned char rsa_printable[] = "Test User 1";
-   static const unsigned char rsa_printable_der[] = { 0x13, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55,
+   const unsigned char rsa_printable[] = "Test User 1";
+   const unsigned char rsa_printable_der[] = { 0x13, 0x0b, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55,
                                                       0x73, 0x65, 0x72, 0x20, 0x31 };
+   unsigned long rsa_printable_len = XSTRLEN((char*)rsa_printable);
 
-   static const ltc_utctime   rsa_time1 = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
-   static const ltc_utctime   rsa_time2 = { 91, 5, 6, 23, 45, 40, 0, 0, 0 };
+   const ltc_utctime   rsa_time1 = { 91, 5, 6, 16, 45, 40, 1, 7, 0 };
+   const ltc_utctime   rsa_time2 = { 91, 5, 6, 23, 45, 40, 0, 0, 0 };
    ltc_utctime                tmp_time;
 
-   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 };
-   static const unsigned char rsa_time2_der[] = { 0x17, 0x0d, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x32, 0x33, 0x34, 0x35, 0x34, 0x30, 0x5a };
+   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 };
+   const unsigned char rsa_time2_der[] = { 0x17, 0x0d, 0x39, 0x31, 0x30, 0x35, 0x30, 0x36, 0x32, 0x33, 0x34, 0x35, 0x34, 0x30, 0x5a };
 
-   static const wchar_t utf8_1[]           = { 0x0041, 0x2262, 0x0391, 0x002E };
-   static const unsigned char utf8_1_der[] = { 0x0C, 0x07, 0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E };
-   static const wchar_t utf8_2[]           = { 0xD55C, 0xAD6D, 0xC5B4 };
-   static const unsigned char utf8_2_der[] = { 0x0C, 0x09, 0xED, 0x95, 0x9C, 0xEA, 0xB5, 0xAD, 0xEC, 0x96, 0xB4 };
-   static const wchar_t utf8_3[]           = { 0x05E9, 0x05DC, 0x05D5, 0x05DD };
-   static const unsigned char utf8_3_der[] = { 0x0C, 0x08, 0xD7, 0xA9, 0xD7, 0x9C, 0xD7, 0x95, 0xD7, 0x9D };
+   const wchar_t utf8_1[]           = { 0x0041, 0x2262, 0x0391, 0x002E };
+   const unsigned char utf8_1_der[] = { 0x0C, 0x07, 0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E };
+   const wchar_t utf8_2[]           = { 0xD55C, 0xAD6D, 0xC5B4 };
+   const unsigned char utf8_2_der[] = { 0x0C, 0x09, 0xED, 0x95, 0x9C, 0xEA, 0xB5, 0xAD, 0xEC, 0x96, 0xB4 };
+   const wchar_t utf8_3[]           = { 0x05E9, 0x05DC, 0x05D5, 0x05DD };
+   const unsigned char utf8_3_der[] = { 0x0C, 0x08, 0xD7, 0xA9, 0xD7, 0x9C, 0xD7, 0x95, 0xD7, 0x9D };
 
    unsigned char utf8_buf[32];
    wchar_t utf8_out[32];
@@ -1863,38 +1866,38 @@ int der_test(void)
 
 /* IA5 string */
    x = sizeof(buf[0]);
-   DO(der_encode_ia5_string(rsa_ia5, XSTRLEN((char*)rsa_ia5), buf[0], &x));
+   DO(der_encode_ia5_string(rsa_ia5, rsa_ia5_len, buf[0], &x));
    if (x != sizeof(rsa_ia5_der) || memcmp(buf[0], rsa_ia5_der, x)) {
       fprintf(stderr, "IA5 encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_ia5_der));
       return 1;
    }
-   DO(der_length_ia5_string(rsa_ia5, XSTRLEN((char*)rsa_ia5), &y));
+   DO(der_length_ia5_string(rsa_ia5, rsa_ia5_len, &y));
    if (y != x) {
       fprintf(stderr, "IA5 length failed to match: %lu, %lu\n", x, y);
       return 1;
    }
    y = sizeof(buf[1]);
    DO(der_decode_ia5_string(buf[0], x, buf[1], &y));
-   if (y != XSTRLEN((char*)rsa_ia5) || memcmp(buf[1], rsa_ia5, XSTRLEN((char*)rsa_ia5))) {
+   if (y != rsa_ia5_len || memcmp(buf[1], rsa_ia5, rsa_ia5_len)) {
        fprintf(stderr, "DER IA5 failed test vector\n");
        return 1;
    }
 
 /* Printable string */
    x = sizeof(buf[0]);
-   DO(der_encode_printable_string(rsa_printable, XSTRLEN((char*)rsa_printable), buf[0], &x));
+   DO(der_encode_printable_string(rsa_printable, rsa_printable_len, buf[0], &x));
    if (x != sizeof(rsa_printable_der) || memcmp(buf[0], rsa_printable_der, x)) {
       fprintf(stderr, "PRINTABLE encode failed: %lu, %lu\n", x, (unsigned long)sizeof(rsa_printable_der));
       return 1;
    }
-   DO(der_length_printable_string(rsa_printable, XSTRLEN((char*)rsa_printable), &y));
+   DO(der_length_printable_string(rsa_printable, rsa_printable_len, &y));
    if (y != x) {
       fprintf(stderr, "printable length failed to match: %lu, %lu\n", x, y);
       return 1;
    }
    y = sizeof(buf[1]);
    DO(der_decode_printable_string(buf[0], x, buf[1], &y));
-   if (y != XSTRLEN((char*)rsa_printable) || memcmp(buf[1], rsa_printable, XSTRLEN((char*)rsa_printable))) {
+   if (y != rsa_printable_len || memcmp(buf[1], rsa_printable, rsa_printable_len)) {
        fprintf(stderr, "DER printable failed test vector\n");
        return 1;
    }

+ 10 - 10
tests/ecc_test.c

@@ -261,14 +261,14 @@ static int s_ecc_issue108(void)
    /* ECC-224 AKA SECP224R1 */
    if ((err = ecc_find_curve("SECP224R1", &dp)) != CRYPT_OK)              { goto done; }
    /* read A */
-   if ((err = mp_read_radix(a, (char *)dp->A,  16)) != CRYPT_OK)          { goto done; }
+   if ((err = mp_read_radix(a, dp->A,  16)) != CRYPT_OK)          { goto done; }
    /* read modulus */
-   if ((err = mp_read_radix(modulus, (char *)dp->prime, 16)) != CRYPT_OK) { goto done; }
+   if ((err = mp_read_radix(modulus, dp->prime, 16)) != CRYPT_OK) { goto done; }
    /* read order */
-   if ((err = mp_read_radix(order, (char *)dp->order, 16)) != CRYPT_OK)   { goto done; }
+   if ((err = mp_read_radix(order, dp->order, 16)) != CRYPT_OK)   { goto done; }
    /* read Q */
-   if ((err = mp_read_radix(Q->x, (char *)"EA3745501BBC6A70BBFDD8AEEDB18CF5073C6DC9AA7CBB5915170D60", 16)) != CRYPT_OK) { goto done; }
-   if ((err = mp_read_radix(Q->y, (char *)"6C9CB8E68AABFEC989CAC5E2326E0448B7E69C3E56039BA21A44FDAC", 16)) != CRYPT_OK) { goto done; }
+   if ((err = mp_read_radix(Q->x, "EA3745501BBC6A70BBFDD8AEEDB18CF5073C6DC9AA7CBB5915170D60", 16)) != CRYPT_OK) { goto done; }
+   if ((err = mp_read_radix(Q->y, "6C9CB8E68AABFEC989CAC5E2326E0448B7E69C3E56039BA21A44FDAC", 16)) != CRYPT_OK) { goto done; }
    mp_set(Q->z, 1);
    /* calculate nQ */
    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)
    err = CRYPT_OK;
 
    for (i = 0; ltc_ecc_curves[i].prime != NULL; i++) {
-      DO(mp_read_radix(a, (char *)ltc_ecc_curves[i].A,  16));
-      DO(mp_read_radix(modulus, (char *)ltc_ecc_curves[i].prime, 16));
-      DO(mp_read_radix(order, (char *)ltc_ecc_curves[i].order, 16));
+      DO(mp_read_radix(a, ltc_ecc_curves[i].A,  16));
+      DO(mp_read_radix(modulus, ltc_ecc_curves[i].prime, 16));
+      DO(mp_read_radix(order, ltc_ecc_curves[i].order, 16));
 
       /* is prime actually prime? */
       DO(mp_prime_is_prime(modulus, 8, &primality));
@@ -373,8 +373,8 @@ static int s_ecc_test_mp(void)
          printf("Order failed prime check: %s\n", buf);
       }
 
-      DO(mp_read_radix(G->x, (char *)ltc_ecc_curves[i].Gx, 16));
-      DO(mp_read_radix(G->y, (char *)ltc_ecc_curves[i].Gy, 16));
+      DO(mp_read_radix(G->x, ltc_ecc_curves[i].Gx, 16));
+      DO(mp_read_radix(G->y, ltc_ecc_curves[i].Gy, 16));
       mp_set(G->z, 1);
 
       /* then we should have G == (order + 1)G */