Преглед изворни кода

Add `LTC_ARRAY_SIZE()` macro

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel пре 4 недеља
родитељ
комит
fe32e7ea9d
77 измењених фајлова са 135 додато и 129 уклоњено
  1. 6 2
      demos/hashsum.c
  2. 2 2
      demos/pem-info.c
  3. 3 3
      demos/timing.c
  4. 1 1
      demos/tv_gen.c
  5. 1 1
      src/ciphers/aes/aes.c
  6. 1 1
      src/ciphers/aes/aes_desc.c
  7. 1 1
      src/ciphers/aes/aesni.c
  8. 1 1
      src/ciphers/anubis.c
  9. 1 1
      src/ciphers/camellia.c
  10. 2 2
      src/ciphers/des.c
  11. 1 1
      src/ciphers/idea.c
  12. 1 1
      src/ciphers/kasumi.c
  13. 1 1
      src/ciphers/khazad.c
  14. 1 1
      src/ciphers/kseed.c
  15. 1 1
      src/ciphers/multi2.c
  16. 1 1
      src/ciphers/noekeon.c
  17. 1 1
      src/ciphers/serpent.c
  18. 1 1
      src/ciphers/tea.c
  19. 1 1
      src/ciphers/twofish/twofish.c
  20. 1 1
      src/ciphers/xtea.c
  21. 1 1
      src/encauth/ccm/ccm_test.c
  22. 1 1
      src/encauth/eax/eax_test.c
  23. 1 1
      src/encauth/gcm/gcm_test.c
  24. 1 1
      src/encauth/ocb/ocb_init.c
  25. 1 1
      src/encauth/ocb/ocb_test.c
  26. 1 1
      src/encauth/ocb3/ocb3_init.c
  27. 1 1
      src/encauth/ocb3/ocb3_test.c
  28. 1 1
      src/encauth/siv/siv.c
  29. 1 1
      src/hashes/chc/chc.c
  30. 1 1
      src/hashes/rmd128.c
  31. 1 1
      src/hashes/rmd160.c
  32. 1 1
      src/hashes/rmd256.c
  33. 1 1
      src/hashes/rmd320.c
  34. 1 1
      src/hashes/whirl/whirl.c
  35. 2 0
      src/headers/tomcrypt_private.h
  36. 1 1
      src/mac/f9/f9_test.c
  37. 1 1
      src/mac/omac/omac_test.c
  38. 1 1
      src/mac/pelican/pelican_test.c
  39. 2 2
      src/mac/pmac/pmac_init.c
  40. 1 1
      src/mac/pmac/pmac_test.c
  41. 1 1
      src/mac/xcbc/xcbc_test.c
  42. 1 1
      src/math/ltm_desc.c
  43. 1 1
      src/math/tfm_desc.c
  44. 1 1
      src/misc/error_to_string.c
  45. 2 2
      src/misc/pbes/pbes2.c
  46. 2 2
      src/misc/pem/pem.c
  47. 2 2
      src/misc/pem/pem_pkcs.c
  48. 6 6
      src/misc/pem/pem_ssh.c
  49. 1 1
      src/modes/ctr/ctr_test.c
  50. 1 1
      src/modes/lrw/lrw_test.c
  51. 5 5
      src/pk/asn1/der/general/der_asn1_maps.c
  52. 1 1
      src/pk/asn1/der/general/der_decode_asn1_identifier.c
  53. 2 2
      src/pk/asn1/der/ia5/der_length_ia5_string.c
  54. 2 2
      src/pk/asn1/der/printable_string/der_length_printable_string.c
  55. 2 2
      src/pk/asn1/der/teletex_string/der_length_teletex_string.c
  56. 2 2
      src/pk/asn1/oid/pk_get.c
  57. 1 1
      src/pk/asn1/x509/x509_decode_subject_public_key_info.c
  58. 2 2
      src/pk/asn1/x509/x509_encode_subject_public_key_info.c
  59. 1 1
      src/pk/dsa/dsa_decrypt_key.c
  60. 1 1
      src/pk/dsa/dsa_generate_pqg.c
  61. 1 1
      src/pk/ec25519/ec25519_export.c
  62. 1 1
      src/pk/ecc/ecc_decrypt_key.c
  63. 1 1
      src/pk/ecc/ecc_export_openssl.c
  64. 3 3
      src/pk/rsa/rsa_key.c
  65. 1 1
      src/pk/rsa/rsa_verify_hash.c
  66. 2 2
      tests/base64_test.c
  67. 15 15
      tests/der_test.c
  68. 4 4
      tests/ecc_test.c
  69. 3 3
      tests/ed25519_test.c
  70. 1 1
      tests/modes_test.c
  71. 2 2
      tests/padding_test.c
  72. 2 2
      tests/pkcs_1_eme_test.c
  73. 2 2
      tests/pkcs_1_emsa_test.c
  74. 2 2
      tests/pkcs_1_oaep_test.c
  75. 2 2
      tests/pkcs_1_pss_test.c
  76. 2 2
      tests/test.c
  77. 3 3
      tests/x25519_test.c

+ 6 - 2
demos/hashsum.c

@@ -30,6 +30,10 @@
             '\255')
 #define HEXOF(x) (x - s_base(x))
 
+#ifndef LTC_ARRAY_SIZE
+#define LTC_ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
+#endif
+
 static char* hashsum;
 
 static void cleanup(void)
@@ -190,7 +194,7 @@ int main(int argc, char **argv)
       die(EXIT_FAILURE);
    }
 
-   for (x = 0; x < sizeof(idxs)/sizeof(idxs[0]); ++x) {
+   for (x = 0; x < LTC_ARRAY_SIZE(idxs); ++x) {
       idxs[x] = -2;
    }
    argn = 1;
@@ -243,7 +247,7 @@ int main(int argc, char **argv)
                die(EXIT_FAILURE);
             }
             idx++;
-            if ((size_t)idx >= sizeof(idxs)/sizeof(idxs[0])) {
+            if ((size_t)idx >= LTC_ARRAY_SIZE(idxs)) {
                fprintf(stderr, "%s: Too many '-a' options chosen\n", hashsum);
                die(EXIT_FAILURE);
             }

+ 2 - 2
demos/pem-info.c

@@ -34,7 +34,7 @@ static const struct {
 static const char *s_map_cipher(const char *name)
 {
    unsigned long n;
-   for (n = 0; n < sizeof(cipher_name_map)/sizeof(cipher_name_map[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(cipher_name_map); ++n) {
       if (strcmp(name, cipher_name_map[n].is) == 0)
          return cipher_name_map[n].should;
    }
@@ -61,7 +61,7 @@ static const char *s_map_mode(enum cipher_mode mode)
 {
    size_t n;
    mode &= cm_modes | cm_1bit | cm_8bit;
-   for (n = 0; n < sizeof(cipher_mode_map)/sizeof(cipher_mode_map[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(cipher_mode_map); ++n) {
       if (cipher_mode_map[n].mode == mode)
          return cipher_mode_map[n].name;
    }

+ 3 - 3
demos/timing.c

@@ -658,7 +658,7 @@ static const struct {
 
    if (ltc_mp.name == NULL) return;
 
-   for (x = 0; x < (sizeof(groups)/sizeof(groups[0])); x++) {
+   for (x = 0; x < LTC_ARRAY_SIZE(groups); x++) {
        t2 = 0;
        for (y = 0; y < 4; y++) {
            t_start();
@@ -1408,7 +1408,7 @@ if (argc > 1) {
    if (strstr(argv[1], "-h")) {
       die(EXIT_SUCCESS);
    } else if (strstr(argv[1], "-l")) {
-      for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) {
+      for (i = 0; i < LTC_ARRAY_SIZE(test_functions); ++i) {
          printf("%s\n", test_functions[i].name);
       }
       exit(0);
@@ -1446,7 +1446,7 @@ if ((err = rng_make_prng(128, find_prng("yarrow"), &yarrow_prng, NULL)) != CRYPT
 /* single test name from commandline */
 if (argc > 1) single_test = argv[1];
 
-for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) {
+for (i = 0; i < LTC_ARRAY_SIZE(test_functions); ++i) {
    if (single_test && strstr(test_functions[i].name, single_test) == NULL) {
      continue;
    }

+ 1 - 1
demos/tv_gen.c

@@ -535,7 +535,7 @@ static void ccm_gen(void)
           nonce[z] = z;
       }
 
-      for (t = 0; t < sizeof(taglen)/sizeof(taglen[0]); ++t) {
+      for (t = 0; t < LTC_ARRAY_SIZE(taglen); ++t) {
          for (y1 = 0; y1 <= (int)(cipher_descriptor[x].block_length*2); y1++){
             for (z = 0; z < y1; z++) {
                plaintext[z] = (unsigned char)(z & 255);

+ 1 - 1
src/ciphers/aes/aes.c

@@ -669,7 +669,7 @@ int ECB_TEST(void)
   unsigned char tmp[2][16];
   int i, y;
 
-  for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+  for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
     zeromem(&key, sizeof(key));
     if ((err = rijndael_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
        return err;

+ 1 - 1
src/ciphers/aes/aes_desc.c

@@ -189,7 +189,7 @@ int AES_TEST(void)
   int y;
 #endif
 
-  for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+  for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
     zeromem(&key, sizeof(key));
     if ((err = AES_SETUP(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
        return err;

+ 1 - 1
src/ciphers/aes/aesni.c

@@ -313,7 +313,7 @@ int aesni_test(void)
   unsigned char tmp[2][16];
   int i, y;
 
-  for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+  for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
     zeromem(&key, sizeof(key));
     if ((err = aesni_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
        return err;

+ 1 - 1
src/ciphers/anubis.c

@@ -1498,7 +1498,7 @@ int anubis_test(void)
    unsigned char buf[2][16];
    symmetric_key skey;
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
        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);

+ 1 - 1
src/ciphers/camellia.c

@@ -680,7 +680,7 @@ int camellia_test(void)
    int err;
    unsigned int x;
 
-   for (x = 0; x < sizeof(tests)/sizeof(tests[0]); x++) {
+   for (x = 0; x < LTC_ARRAY_SIZE(tests); x++) {
       zeromem(&skey, sizeof(skey));
       if ((err = camellia_setup(tests[x].key, tests[x].keylen, 0, &skey)) != CRYPT_OK) {
          return err;

+ 2 - 2
src/ciphers/des.c

@@ -2018,7 +2018,7 @@ int des_test(void)
     symmetric_key skey;
     int i, err;
 
-    for (i = 0; i < (int)(sizeof(cases)/sizeof(cases[0])); i++)
+    for (i = 0; i < (int)LTC_ARRAY_SIZE(cases); i++)
     {
         if ((err = des_setup(cases[i].key, 8, 0, &skey)) != CRYPT_OK) {
             return err;
@@ -2125,7 +2125,7 @@ int des3_test(void)
         return err;
     }
 
-    for (i = 0; i < (int)(sizeof(cases)/sizeof(cases[0])); i++)
+    for (i = 0; i < (int)LTC_ARRAY_SIZE(cases); i++)
     {
         if ((err = des3_setup(cases[i].key, 16, 0, &skey)) != CRYPT_OK) {
             return err;

+ 1 - 1
src/ciphers/idea.c

@@ -226,7 +226,7 @@ int idea_test(void)
       return CRYPT_FAIL_TESTVECTOR;
    }
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
       if ((err = idea_setup(tests[x].key, 16, 8, &key)) != CRYPT_OK) {
          return err;
       }

+ 1 - 1
src/ciphers/kasumi.c

@@ -286,7 +286,7 @@ int kasumi_test(void)
    symmetric_key key;
    int err, x;
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
        if ((err = kasumi_setup(tests[x].key, 16, 0, &key)) != CRYPT_OK) {
           return err;
        }

+ 1 - 1
src/ciphers/khazad.c

@@ -794,7 +794,7 @@ int khazad_test(void)
    unsigned char buf[2][8];
    symmetric_key skey;
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
        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);

+ 1 - 1
src/ciphers/kseed.c

@@ -334,7 +334,7 @@ int kseed_test(void)
    unsigned char buf[2][16];
    symmetric_key skey;
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
        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);

+ 1 - 1
src/ciphers/multi2.c

@@ -242,7 +242,7 @@ int multi2_test(void)
    symmetric_key skey;
    int err, x;
 
-   for (x = 1; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 1; x < (int)LTC_ARRAY_SIZE(tests); x++) {
       if ((err = multi2_setup(tests[x].key, 40, tests[x].rounds, &skey)) != CRYPT_OK) {
          return err;
       }

+ 1 - 1
src/ciphers/noekeon.c

@@ -267,7 +267,7 @@ int noekeon_test(void)
  unsigned char tmp[2][16];
  int err, i, y;
 
- for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+ for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
     zeromem(&key, sizeof(key));
     if ((err = noekeon_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
        return err;

+ 1 - 1
src/ciphers/serpent.c

@@ -693,7 +693,7 @@ int serpent_test(void)
    symmetric_key key;
    int err, x;
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
       if ((err = serpent_setup(tests[x].key, tests[x].keylen, 0, &key)) != CRYPT_OK) {
         return err;
       }

+ 1 - 1
src/ciphers/tea.c

@@ -150,7 +150,7 @@ int tea_test(void)
    symmetric_key skey;
    size_t i;
    int err, y;
-   for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
+   for (i = 0; i < LTC_ARRAY_SIZE(tests); i++) {
        zeromem(&skey, sizeof(skey));
 
        l = sizeof(key);

+ 1 - 1
src/ciphers/twofish/twofish.c

@@ -651,7 +651,7 @@ int twofish_test(void)
   unsigned char tmp[2][16];
   int err, i, y;
 
-  for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+  for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
     if ((err = twofish_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
        return err;
     }

+ 1 - 1
src/ciphers/xtea.c

@@ -197,7 +197,7 @@ int xtea_test(void)
    unsigned char tmp[2][8];
    symmetric_key skey;
    int i, err, y;
-   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+   for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
        zeromem(&skey, sizeof(skey));
        if ((err = xtea_setup(tests[i].key, 16, 0, &skey)) != CRYPT_OK)  {
           return err;

+ 1 - 1
src/encauth/ccm/ccm_test.c

@@ -121,7 +121,7 @@ int ccm_test(void)
       }
    }
 
-   for (x = 0; x < (sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < LTC_ARRAY_SIZE(tests); x++) {
       for (y = 0; y < 2; y++) {
          taglen = tests[x].taglen;
          if (y == 0) {

+ 1 - 1
src/encauth/eax/eax_test.c

@@ -216,7 +216,7 @@ int eax_test(void)
        }
     }
 
-    for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+    for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
         len = sizeof(outtag);
         if ((err = eax_encrypt_authenticate_memory(idx, tests[x].key, tests[x].keylen,
             tests[x].nonce, tests[x].noncelen, tests[x].header, tests[x].headerlen,

+ 1 - 1
src/encauth/gcm/gcm_test.c

@@ -338,7 +338,7 @@ int gcm_test(void)
    if ((err = gcm_done(&gcm, T[0], &y)) != CRYPT_OK)                         return err;
    if (compare_testvector(T[0], y, tests[0].T, 16, "GCM Encrypt Tag-special", 0))      return CRYPT_FAIL_TESTVECTOR;
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
        y = sizeof(T[0]);
        if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen,
                              tests[x].IV, tests[x].IVlen,

+ 1 - 1
src/encauth/ocb/ocb_init.c

@@ -53,7 +53,7 @@ int ocb_init(ocb_state *ocb, int cipher,
 
    /* determine which polys to use */
    ocb->block_len = cipher_descriptor[cipher].block_length;
-   x = (int)(sizeof(polys)/sizeof(polys[0]));
+   x = (int)LTC_ARRAY_SIZE(polys);
    for (poly = 0; poly < x; poly++) {
        if (polys[poly].len == ocb->block_len) {
           break;

+ 1 - 1
src/encauth/ocb/ocb_test.c

@@ -167,7 +167,7 @@ int ocb_test(void)
        }
     }
 
-    for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+    for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
         len = sizeof(outtag);
         if ((err = ocb_encrypt_authenticate_memory(idx, tests[x].key, 16,
              tests[x].nonce, tests[x].pt, tests[x].ptlen, outct, outtag, &len)) != CRYPT_OK) {

+ 1 - 1
src/encauth/ocb3/ocb3_init.c

@@ -116,7 +116,7 @@ int ocb3_init(ocb3_state *ocb, int cipher,
 
    /* determine which polys to use */
    ocb->block_len = cipher_descriptor[cipher].block_length;
-   x = (int)(sizeof(polys)/sizeof(polys[0]));
+   x = (int)LTC_ARRAY_SIZE(polys);
    for (poly = 0; poly < x; poly++) {
        if (polys[poly].len == ocb->block_len) {
           break;

+ 1 - 1
src/encauth/ocb3/ocb3_test.c

@@ -209,7 +209,7 @@ int ocb3_test(void)
        }
     }
 
-    for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+    for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
         len = 16; /* must be the same as the required taglen */
         if ((err = ocb3_encrypt_authenticate_memory(idx,
                                                    key, sizeof(key),

+ 1 - 1
src/encauth/siv/siv.c

@@ -608,7 +608,7 @@ int siv_test(void)
 
    cipher = find_cipher("aes");
 
-   for (n = 0; n < sizeof(siv_tests)/sizeof(siv_tests[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(siv_tests); ++n) {
       buflen = sizeof(buf);
       if ((err = siv_encrypt_memory(cipher,
                              siv_tests[n].Key, siv_tests[n].Keylen,

+ 1 - 1
src/hashes/chc/chc.c

@@ -277,7 +277,7 @@ int chc_test(void)
    oldhashidx = cipher_idx;
    chc_register(idx);
 
-   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+   for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
        if ((err = chc_init(&md)) != CRYPT_OK) {
           return err;
        }

+ 1 - 1
src/hashes/rmd128.c

@@ -380,7 +380,7 @@ int rmd128_test(void)
    unsigned char tmp[16];
    hash_state md;
 
-   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+   for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
        rmd128_init(&md);
        rmd128_process(&md, (unsigned char *)tests[i].msg, XSTRLEN(tests[i].msg));
        rmd128_done(&md, tmp);

+ 1 - 1
src/hashes/rmd160.c

@@ -439,7 +439,7 @@ int rmd160_test(void)
    unsigned char tmp[20];
    hash_state md;
 
-   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+   for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
        rmd160_init(&md);
        rmd160_process(&md, (unsigned char *)tests[i].msg, XSTRLEN(tests[i].msg));
        rmd160_done(&md, tmp);

+ 1 - 1
src/hashes/rmd256.c

@@ -405,7 +405,7 @@ int rmd256_test(void)
    unsigned char tmp[32];
    hash_state md;
 
-   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+   for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
        rmd256_init(&md);
        rmd256_process(&md, (unsigned char *)tests[i].msg, XSTRLEN(tests[i].msg));
        rmd256_done(&md, tmp);

+ 1 - 1
src/hashes/rmd320.c

@@ -470,7 +470,7 @@ int rmd320_test(void)
    unsigned char tmp[40];
    hash_state md;
 
-   for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+   for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
        rmd320_init(&md);
        rmd320_process(&md, (unsigned char *)tests[i].msg, XSTRLEN(tests[i].msg));
        rmd320_done(&md, tmp);

+ 1 - 1
src/hashes/whirl/whirl.c

@@ -281,7 +281,7 @@ int  whirlpool_test(void)
   unsigned char tmp[64];
   hash_state md;
 
-  for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
+  for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
       whirlpool_init(&md);
       whirlpool_process(&md, (unsigned char *)tests[i].msg, tests[i].len);
       whirlpool_done(&md, tmp);

+ 2 - 0
src/headers/tomcrypt_private.h

@@ -45,6 +45,8 @@ LTC_STATIC_ASSERT(correct_ltc_uintptr_size, sizeof(ltc_uintptr) == sizeof(void*)
    #define LTC_NULL ((void *)0)
 #endif
 
+#define LTC_ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
+
 /*
  * Internal Enums
  */

+ 1 - 1
src/mac/f9/f9_test.c

@@ -48,7 +48,7 @@ int f9_test(void)
      return CRYPT_NOP;
   }
 
-  for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+  for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
      taglen = 4;
      if ((err = f9_memory(idx, tests[x].K, 16, tests[x].M, tests[x].msglen, T, &taglen)) != CRYPT_OK) {
         return err;

+ 1 - 1
src/mac/omac/omac_test.c

@@ -76,7 +76,7 @@ int omac_test(void)
        }
     }
 
-    for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+    for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
        len = sizeof(out);
        if ((err = omac_memory(idx, tests[x].key, tests[x].keylen, tests[x].msg, tests[x].msglen, out, &len)) != CRYPT_OK) {
           return err;

+ 1 - 1
src/mac/pelican/pelican_test.c

@@ -80,7 +80,7 @@ int pelican_test(void)
    unsigned char out[16];
    pelican_state pel;
 
-   for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
        if ((err = pelican_init(&pel, tests[x].K, tests[x].keylen)) != CRYPT_OK) {
           return err;
        }

+ 2 - 2
src/mac/pmac/pmac_init.c

@@ -51,12 +51,12 @@ int pmac_init(pmac_state *pmac, int cipher, const unsigned char *key, unsigned l
 
    /* determine which polys to use */
    pmac->block_len = cipher_descriptor[cipher].block_length;
-   for (poly = 0; poly < (int)(sizeof(polys)/sizeof(polys[0])); poly++) {
+   for (poly = 0; poly < (int)LTC_ARRAY_SIZE(polys); poly++) {
        if (polys[poly].len == pmac->block_len) {
           break;
        }
    }
-   if (poly >= (int)(sizeof(polys)/sizeof(polys[0]))) {
+   if (poly >= (int)LTC_ARRAY_SIZE(polys)) {
       return CRYPT_INVALID_ARG;
     }
    if (polys[poly].len != pmac->block_len) {

+ 1 - 1
src/mac/pmac/pmac_test.c

@@ -124,7 +124,7 @@ int pmac_test(void)
        }
     }
 
-    for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+    for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
         len = sizeof(outtag);
         if ((err = pmac_memory(idx, tests[x].key, 16, tests[x].msg, tests[x].msglen, outtag, &len)) != CRYPT_OK) {
            return err;

+ 1 - 1
src/mac/xcbc/xcbc_test.c

@@ -98,7 +98,7 @@ int xcbc_test(void)
      }
   }
 
-  for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+  for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
      taglen = 16;
      if ((err = xcbc_memory(idx, tests[x].K, 16, tests[x].M, tests[x].msglen, T, &taglen)) != CRYPT_OK) {
         return err;

+ 1 - 1
src/math/ltm_desc.c

@@ -33,7 +33,7 @@ static int mpi_to_ltc_error(mp_err err)
 {
    size_t x;
 
-   for (x = 0; x < sizeof(mpi_to_ltc_codes)/sizeof(mpi_to_ltc_codes[0]); x++) {
+   for (x = 0; x < LTC_ARRAY_SIZE(mpi_to_ltc_codes); x++) {
        if (err == mpi_to_ltc_codes[x].mpi_code) {
           return mpi_to_ltc_codes[x].ltc_code;
        }

+ 1 - 1
src/math/tfm_desc.c

@@ -39,7 +39,7 @@ static int tfm_to_ltc_error(int err)
 {
    int x;
 
-   for (x = 0; x < (int)(sizeof(tfm_to_ltc_codes)/sizeof(tfm_to_ltc_codes[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(tfm_to_ltc_codes); x++) {
        if (err == tfm_to_ltc_codes[x].tfm_code) {
           return tfm_to_ltc_codes[x].ltc_code;
        }

+ 1 - 1
src/misc/error_to_string.c

@@ -54,7 +54,7 @@ static const char * const err_2_str[CRYPT_ERR_NUM] =
    "The PEM header was not recognized",
 };
 
-LTC_STATIC_ASSERT(correct_err_2_str_size, (sizeof(err_2_str)/sizeof(err_2_str[0])) == CRYPT_ERR_NUM)
+LTC_STATIC_ASSERT(correct_err_2_str_size, LTC_ARRAY_SIZE(err_2_str) == CRYPT_ERR_NUM)
 
 /**
    Convert an LTC error code to ASCII

+ 2 - 2
src/misc/pbes/pbes2.c

@@ -51,7 +51,7 @@ static const oid_to_pbes s_pbes2_list[] = {
 static int s_pbes2_from_oid(const ltc_asn1_list *cipher_oid, const ltc_asn1_list *hmac_oid, pbes_properties *res)
 {
    unsigned int i;
-   for (i = 0; i < sizeof(s_pbes2_list)/sizeof(s_pbes2_list[0]); ++i) {
+   for (i = 0; i < LTC_ARRAY_SIZE(s_pbes2_list); ++i) {
       if (pk_oid_cmp_with_asn1(s_pbes2_list[i].oid, cipher_oid) == CRYPT_OK) {
          *res = *s_pbes2_list[i].data;
          break;
@@ -59,7 +59,7 @@ static int s_pbes2_from_oid(const ltc_asn1_list *cipher_oid, const ltc_asn1_list
    }
    if (res->c == NULL) return CRYPT_INVALID_CIPHER;
    if (hmac_oid != NULL) {
-      for (i = 0; i < sizeof(s_hmac_oid_names)/sizeof(s_hmac_oid_names[0]); ++i) {
+      for (i = 0; i < LTC_ARRAY_SIZE(s_hmac_oid_names); ++i) {
          if (pk_oid_cmp_with_asn1(s_hmac_oid_names[i].oid, hmac_oid) == CRYPT_OK) {
             res->h = s_hmac_oid_names[i].id;
             return CRYPT_OK;

+ 2 - 2
src/misc/pem/pem.c

@@ -65,7 +65,7 @@ const struct pem_header_id pem_std_headers[] = {
      .pka = LTC_PKA_DSA,
    },
 };
-const unsigned long pem_std_headers_num = sizeof(pem_std_headers)/sizeof(pem_std_headers[0]);
+const unsigned long pem_std_headers_num = LTC_ARRAY_SIZE(pem_std_headers);
 
 /* Encrypted PEM files */
 const struct str pem_proc_type_encrypted = { SET_CSTR(, "Proc-Type: 4,ENCRYPTED") };
@@ -147,7 +147,7 @@ const struct blockcipher_info pem_dek_infos[] =
       { .name = "SEED-CFB,",          .algo = "seed",     .keylen = 128 / 8, .mode = cm_cfb,    },
       { .name = "SEED-OFB,",          .algo = "seed",     .keylen = 128 / 8, .mode = cm_ofb,    },
    };
-const unsigned long pem_dek_infos_num = sizeof(pem_dek_infos)/sizeof(pem_dek_infos[0]);
+const unsigned long pem_dek_infos_num = LTC_ARRAY_SIZE(pem_dek_infos);
 
 int pem_decrypt(unsigned char *data, unsigned long *datalen,
                 unsigned char *key,  unsigned long keylen,

+ 2 - 2
src/misc/pem/pem_pkcs.c

@@ -96,7 +96,7 @@ static int s_import_x509(unsigned char *asn1_cert, unsigned long asn1_len, ltc_p
       return err;
    }
    if (pka < 0
-         || pka > sizeof(s_import_x509_fns)/sizeof(s_import_x509_fns[0])
+         || pka > LTC_ARRAY_SIZE(s_import_x509_fns)
          || s_import_x509_fns[pka] == NULL) {
       return CRYPT_PK_INVALID_TYPE;
    }
@@ -251,7 +251,7 @@ retry:
    }
 
    if (pka < 0
-         || pka > sizeof(s_import_openssl_fns)/sizeof(s_import_openssl_fns[0])
+         || pka > LTC_ARRAY_SIZE(s_import_openssl_fns)
          || s_import_openssl_fns[pka] == NULL) {
       err = CRYPT_PK_INVALID_TYPE;
       goto cleanup;

+ 6 - 6
src/misc/pem/pem_ssh.c

@@ -47,7 +47,7 @@ const struct blockcipher_info ssh_ciphers[] =
    { .name = "twofish256-cbc",                .algo = "twofish",  .keylen = 256 / 8, .mode = cm_cbc                 },
    { .name = "twofish256-ctr",                .algo = "twofish",  .keylen = 256 / 8, .mode = cm_ctr                 },
 };
-const unsigned long ssh_ciphers_num = sizeof(ssh_ciphers)/sizeof(ssh_ciphers[0]);
+const unsigned long ssh_ciphers_num = LTC_ARRAY_SIZE(ssh_ciphers);
 
 struct kdf_options {
    const char *name;
@@ -398,7 +398,7 @@ static int s_decode_key(const unsigned char *in, unsigned long *inlen, ltc_pka_k
    remaining -= cur_len;
    cur_len = remaining;
 
-   for (n = 0; n < sizeof(ssh_pkas)/sizeof(ssh_pkas[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(ssh_pkas); ++n) {
       if (ssh_pkas[n].name.p != NULL) {
          if (pkalen != ssh_pkas[n].name.len
                || XMEMCMP(pka, ssh_pkas[n].name.p, ssh_pkas[n].name.len) != 0) continue;
@@ -411,7 +411,7 @@ static int s_decode_key(const unsigned char *in, unsigned long *inlen, ltc_pka_k
       }
       break;
    }
-   if (n == sizeof(ssh_pkas)/sizeof(ssh_pkas[0])) {
+   if (n == LTC_ARRAY_SIZE(ssh_pkas)) {
       return CRYPT_PK_INVALID_TYPE;
    }
 
@@ -486,7 +486,7 @@ static int s_parse_line(char *line, unsigned long *len, ltc_pka_key *key, char *
 
    rlen = *len;
    /* Chop up string into the three authorized_keys_elements */
-   for (n = 0; n < sizeof(elements)/sizeof(elements[0]) && rlen; ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(elements) && rlen; ++n) {
       skip_spaces(&r, &rlen);
       elements[n].p = r;
       if (n != 2)
@@ -498,7 +498,7 @@ static int s_parse_line(char *line, unsigned long *len, ltc_pka_key *key, char *
       r++;
    }
 
-   for (n = 0; n < sizeof(ssh_pkas)/sizeof(ssh_pkas[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(ssh_pkas); ++n) {
       if (ssh_pkas[n].name.p != NULL) {
          if (elements[ake_algo_name].len != ssh_pkas[n].name.len
                || XMEMCMP(elements[ake_algo_name].p, ssh_pkas[n].name.p, ssh_pkas[n].name.len) != 0) continue;
@@ -707,7 +707,7 @@ static const struct pem_header_id pem_openssh[] = {
      .flags = pf_public
    },
 };
-static const unsigned long pem_openssh_num = sizeof(pem_openssh)/sizeof(pem_openssh[0]);
+static const unsigned long pem_openssh_num = LTC_ARRAY_SIZE(pem_openssh);
 
 static int s_decode_openssh(struct get_char *g, ltc_pka_key *k, const password_ctx *pw_ctx)
 {

+ 1 - 1
src/modes/ctr/ctr_test.c

@@ -51,7 +51,7 @@ int ctr_test(void)
      }
   }
 
-  for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+  for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
      if ((err = ctr_start(idx, tests[x].IV, tests[x].key, tests[x].keylen, 0, CTR_COUNTER_BIG_ENDIAN|LTC_CTR_RFC3686, &ctr)) != CRYPT_OK) {
         return err;
      }

+ 1 - 1
src/modes/lrw/lrw_test.c

@@ -73,7 +73,7 @@ int lrw_test(void)
      }
   }
 
-  for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
+  for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
      /* schedule it */
      if ((err = lrw_start(idx, tests[x].IV, tests[x].key, 16, tests[x].tweak, 0, &lrw)) != CRYPT_OK) {
         return err;

+ 5 - 5
src/pk/asn1/der/general/der_asn1_maps.c

@@ -39,7 +39,7 @@ const int der_asn1_type_to_identifier_map[] =
  24, /* LTC_ASN1_GENERALIZEDTIME, */
  -1, /* LTC_ASN1_CUSTOM_TYPE, */
 };
-const unsigned long der_asn1_type_to_identifier_map_sz = sizeof(der_asn1_type_to_identifier_map)/sizeof(der_asn1_type_to_identifier_map[0]);
+const unsigned long der_asn1_type_to_identifier_map_sz = LTC_ARRAY_SIZE(der_asn1_type_to_identifier_map);
 
 /**
   A Map from the ASN.1 Class to its string
@@ -51,7 +51,7 @@ const char* der_asn1_class_to_string_map[] =
   "CONTEXT-SPECIFIC",
   "PRIVATE",
 };
-const unsigned long der_asn1_class_to_string_map_sz = sizeof(der_asn1_class_to_string_map)/sizeof(der_asn1_class_to_string_map[0]);
+const unsigned long der_asn1_class_to_string_map_sz = LTC_ARRAY_SIZE(der_asn1_class_to_string_map);
 
 /**
   A Map from the ASN.1 P/C-bit to its string
@@ -61,7 +61,7 @@ const char* der_asn1_pc_to_string_map[] =
   "PRIMITIVE",
   "CONSTRUCTED",
 };
-const unsigned long der_asn1_pc_to_string_map_sz = sizeof(der_asn1_pc_to_string_map)/sizeof(der_asn1_pc_to_string_map[0]);
+const unsigned long der_asn1_pc_to_string_map_sz = LTC_ARRAY_SIZE(der_asn1_pc_to_string_map);
 
 /**
   A Map from the ASN.1 tag to its string
@@ -106,7 +106,7 @@ const char* der_asn1_tag_to_string_map[] =
   "OID internationalized resource identifier type",
   "Relative OID internationalized resource identifier type",
 };
-const unsigned long der_asn1_tag_to_string_map_sz = sizeof(der_asn1_tag_to_string_map)/sizeof(der_asn1_tag_to_string_map[0]);
+const unsigned long der_asn1_tag_to_string_map_sz = LTC_ARRAY_SIZE(der_asn1_tag_to_string_map);
 
 /**
   A Map from ASN.1 Tags to ltc_asn1_type
@@ -152,6 +152,6 @@ const ltc_asn1_type der_asn1_tag_to_type_map[] =
   /* 30 */
   LTC_ASN1_CUSTOM_TYPE,      /* BMPString types */
 };
-const unsigned long der_asn1_tag_to_type_map_sz = sizeof(der_asn1_tag_to_type_map)/sizeof(der_asn1_tag_to_type_map[0]);
+const unsigned long der_asn1_tag_to_type_map_sz = LTC_ARRAY_SIZE(der_asn1_tag_to_type_map);
 
 #endif

+ 1 - 1
src/pk/asn1/der/general/der_decode_asn1_identifier.c

@@ -47,7 +47,7 @@ static const unsigned char tag_constructed_map[] =
  LTC_ASN1_PC_PRIMITIVE,
  LTC_ASN1_PC_PRIMITIVE,
 };
- static const unsigned long tag_constructed_map_sz = sizeof(tag_constructed_map)/sizeof(tag_constructed_map[0]);
+ static const unsigned long tag_constructed_map_sz = LTC_ARRAY_SIZE(tag_constructed_map);
 
 /**
   Decode the ASN.1 Identifier

+ 2 - 2
src/pk/asn1/der/ia5/der_length_ia5_string.c

@@ -119,7 +119,7 @@ static const struct {
 int der_ia5_char_encode(int c)
 {
    int x;
-   for (x = 0; x < (int)(sizeof(ia5_table)/sizeof(ia5_table[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(ia5_table); x++) {
        if (ia5_table[x].code == c) {
           return ia5_table[x].value;
        }
@@ -130,7 +130,7 @@ int der_ia5_char_encode(int c)
 int der_ia5_value_decode(int v)
 {
    int x;
-   for (x = 0; x < (int)(sizeof(ia5_table)/sizeof(ia5_table[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(ia5_table); x++) {
        if (ia5_table[x].value == v) {
           return ia5_table[x].code;
        }

+ 2 - 2
src/pk/asn1/der/printable_string/der_length_printable_string.c

@@ -91,7 +91,7 @@ static const struct {
 int der_printable_char_encode(int c)
 {
    int x;
-   for (x = 0; x < (int)(sizeof(printable_table)/sizeof(printable_table[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(printable_table); x++) {
        if (printable_table[x].code == c) {
           return printable_table[x].value;
        }
@@ -102,7 +102,7 @@ int der_printable_char_encode(int c)
 int der_printable_value_decode(int v)
 {
    int x;
-   for (x = 0; x < (int)(sizeof(printable_table)/sizeof(printable_table[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(printable_table); x++) {
        if (printable_table[x].value == v) {
           return printable_table[x].code;
        }

+ 2 - 2
src/pk/asn1/der/teletex_string/der_length_teletex_string.c

@@ -135,7 +135,7 @@ static const struct {
 int der_teletex_char_encode(int c)
 {
    int x;
-   for (x = 0; x < (int)(sizeof(teletex_table)/sizeof(teletex_table[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(teletex_table); x++) {
        if (teletex_table[x].code == c) {
           return teletex_table[x].value;
        }
@@ -146,7 +146,7 @@ int der_teletex_char_encode(int c)
 int der_teletex_value_decode(int v)
 {
    int x;
-   for (x = 0; x < (int)(sizeof(teletex_table)/sizeof(teletex_table[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(teletex_table); x++) {
        if (teletex_table[x].value == v) {
           return teletex_table[x].code;
        }

+ 2 - 2
src/pk/asn1/oid/pk_get.c

@@ -66,7 +66,7 @@ int pk_get_oid_id(enum ltc_pka_id pka, enum ltc_oid_id *oid)
 {
    unsigned int i;
    LTC_ARGCHK(oid != NULL);
-   for (i = 1; i < sizeof(pka_oids)/sizeof(pka_oids[0]); ++i) {
+   for (i = 1; i < LTC_ARRAY_SIZE(pka_oids); ++i) {
       if (pka_oids[i].pka == pka) {
          *oid = pka_oids[i].id;
          return CRYPT_OK;
@@ -95,7 +95,7 @@ int pk_get_oid_from_asn1(const ltc_asn1_list *oid, enum ltc_oid_id *id)
       return err;
    }
 
-   for (i = 1; i < sizeof(pka_oids)/sizeof(pka_oids[0]); ++i) {
+   for (i = 1; i < LTC_ARRAY_SIZE(pka_oids); ++i) {
       if (XSTRCMP(pka_oids[i].oid, tmp) == 0) {
          *id = pka_oids[i].id;
          return CRYPT_OK;

+ 1 - 1
src/pk/asn1/x509/x509_decode_subject_public_key_info.c

@@ -70,7 +70,7 @@ int x509_decode_subject_public_key_info(const unsigned char *in, unsigned long i
    }
 
    /* this includes the internal hash ID and optional params (NULL in this case) */
-   LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, tmpoid, sizeof(tmpoid)/sizeof(tmpoid[0]));
+   LTC_SET_ASN1(alg_id, 0, LTC_ASN1_OBJECT_IDENTIFIER, tmpoid, LTC_ARRAY_SIZE(tmpoid));
    if (parameters_type == LTC_ASN1_EOL) {
       alg_id_num = 1;
    } else {

+ 2 - 2
src/pk/asn1/x509/x509_encode_subject_public_key_info.c

@@ -47,7 +47,7 @@ int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outle
         return err;
    }
 
-   oidlen = sizeof(oid)/sizeof(oid[0]);
+   oidlen = LTC_ARRAY_SIZE(oid);
    if ((err = pk_oid_str_to_num(OID, oid, &oidlen)) != CRYPT_OK) {
       return err;
    }
@@ -56,7 +56,7 @@ int x509_encode_subject_public_key_info(unsigned char *out, unsigned long *outle
    LTC_SET_ASN1(alg_id, 1, parameters_type,            parameters, parameters_len);
 
    return der_encode_sequence_multi(out, outlen,
-        LTC_ASN1_SEQUENCE, (unsigned long)sizeof(alg_id)/sizeof(alg_id[0]), alg_id,
+        LTC_ASN1_SEQUENCE, (unsigned long)LTC_ARRAY_SIZE(alg_id), alg_id,
         LTC_ASN1_RAW_BIT_STRING, public_key_len*8U, public_key,
         LTC_ASN1_EOL,     0UL, NULL);
 

+ 1 - 1
src/pk/dsa/dsa_decrypt_key.c

@@ -40,7 +40,7 @@ int dsa_decrypt_key(const unsigned char *in,  unsigned long  inlen,
    }
 
    /* decode to find out hash */
-   LTC_SET_ASN1(decode, 0, LTC_ASN1_OBJECT_IDENTIFIER, hashOID, sizeof(hashOID)/sizeof(hashOID[0]));
+   LTC_SET_ASN1(decode, 0, LTC_ASN1_OBJECT_IDENTIFIER, hashOID, LTC_ARRAY_SIZE(hashOID));
    err = der_decode_sequence(in, inlen, decode, 1);
    if (err != CRYPT_OK && err != CRYPT_INPUT_TOO_LONG) {
       return err;

+ 1 - 1
src/pk/dsa/dsa_generate_pqg.c

@@ -89,7 +89,7 @@ static int s_dsa_make_params(prng_state *prng, int wprng, int group_size, int mo
 #endif
 
   hash = -1;
-  for (i = 0; i < sizeof(accepted_hashes)/sizeof(accepted_hashes[0]); ++i) {
+  for (i = 0; i < LTC_ARRAY_SIZE(accepted_hashes); ++i) {
     hash = find_hash(accepted_hashes[i]);
     if (hash != -1) break;
   }

+ 1 - 1
src/pk/ec25519/ec25519_export.c

@@ -46,7 +46,7 @@ int ec25519_export(       unsigned char *out, unsigned long *outlen,
          if ((err = pk_get_oid(oid_id, &OID)) != CRYPT_OK) {
             return err;
          }
-         oidlen = sizeof(oid)/sizeof(oid[0]);
+         oidlen = LTC_ARRAY_SIZE(oid);
          if ((err = pk_oid_str_to_num(OID, oid, &oidlen)) != CRYPT_OK) {
             return err;
          }

+ 1 - 1
src/pk/ecc/ecc_decrypt_key.c

@@ -41,7 +41,7 @@ int ecc_decrypt_key(const unsigned char *in,  unsigned long  inlen,
    }
 
    /* decode to find out hash */
-   LTC_SET_ASN1(decode, 0, LTC_ASN1_OBJECT_IDENTIFIER, hashOID, sizeof(hashOID)/sizeof(hashOID[0]));
+   LTC_SET_ASN1(decode, 0, LTC_ASN1_OBJECT_IDENTIFIER, hashOID, LTC_ARRAY_SIZE(hashOID));
    err = der_decode_sequence(in, inlen, decode, 1);
    if (err != CRYPT_OK && err != CRYPT_INPUT_TOO_LONG) {
       return err;

+ 1 - 1
src/pk/ecc/ecc_export_openssl.c

@@ -90,7 +90,7 @@ int ecc_export_openssl(unsigned char *out, unsigned long *outlen, int type, cons
          }
       */
 
-      oidlen = sizeof(oid)/sizeof(oid[0]);
+      oidlen = LTC_ARRAY_SIZE(oid);
       if ((err = pk_oid_str_to_num(OID, oid, &oidlen)) != CRYPT_OK) {
          goto error;
       }

+ 3 - 3
src/pk/rsa/rsa_key.c

@@ -24,7 +24,7 @@ static void s_mpi_shrink_multi(void **a, ...)
    cur = a;
    va_start(args, a);
    while (cur != NULL) {
-      if (n >= sizeof(tmp)/sizeof(tmp[0])) {
+      if (n >= LTC_ARRAY_SIZE(tmp)) {
          goto out;
       }
       if (*cur != NULL) {
@@ -49,8 +49,8 @@ out:
     * or after this was called with too many args
     */
    if ((err != CRYPT_OK) ||
-         (n >= sizeof(tmp)/sizeof(tmp[0]))) {
-      for (n = 0; n < sizeof(tmp)/sizeof(tmp[0]); ++n) {
+         (n >= LTC_ARRAY_SIZE(tmp))) {
+      for (n = 0; n < LTC_ARRAY_SIZE(tmp); ++n) {
          if (tmp[n] != NULL) {
             ltc_mp_clear(tmp[n]);
          }

+ 1 - 1
src/pk/rsa/rsa_verify_hash.c

@@ -131,7 +131,7 @@ int rsa_verify_hash_ex(const unsigned char *sig,            unsigned long  sigle
            hash    OCTET STRING
         }
      */
-      LTC_SET_ASN1(digestinfo, 0, LTC_ASN1_OBJECT_IDENTIFIER, loid, sizeof(loid)/sizeof(loid[0]));
+      LTC_SET_ASN1(digestinfo, 0, LTC_ASN1_OBJECT_IDENTIFIER, loid, LTC_ARRAY_SIZE(loid));
       LTC_SET_ASN1(digestinfo, 1, LTC_ASN1_NULL,              NULL,                          0);
       LTC_SET_ASN1(siginfo,    0, LTC_ASN1_SEQUENCE,          digestinfo,                    2);
       LTC_SET_ASN1(siginfo,    1, LTC_ASN1_OCTET_STRING,      tmpbuf,                        siglen);

+ 2 - 2
tests/base64_test.c

@@ -71,7 +71,7 @@ int base64_test(void)
          {"vuiSPKIl8PiR5O-rC4z9_xTQK", invalid},
    };
 
-   for (x = 0; x < sizeof(url_cases)/sizeof(url_cases[0]); ++x) {
+   for (x = 0; x < LTC_ARRAY_SIZE(url_cases); ++x) {
        slen1 = XSTRLEN(url_cases[x].s);
        l1 = sizeof(tmp);
        if(url_cases[x].flag == strict) {
@@ -113,7 +113,7 @@ int base64_test(void)
 #endif
 
 #if defined(LTC_BASE64)
-   for (x = 0; x < sizeof(cases)/sizeof(cases[0]); ++x) {
+   for (x = 0; x < LTC_ARRAY_SIZE(cases); ++x) {
        memset(out, 0, sizeof(out));
        memset(tmp, 0, sizeof(tmp));
        slen1 = XSTRLEN(cases[x].s);

+ 15 - 15
tests/der_test.c

@@ -1014,7 +1014,7 @@ static void der_flexi_test(void)
          exit(EXIT_FAILURE);
       }
 
-      if (l->size != sizeof(oid_str)/sizeof(oid_str[0]) || memcmp(oid_str, l->data, l->size*sizeof(oid_str[0]))) {
+      if (l->size != LTC_ARRAY_SIZE(oid_str) || memcmp(oid_str, l->data, l->size*sizeof(oid_str[0]))) {
          fprintf(stderr, "(%d), %d, %lu, next=%p, prev=%p, parent=%p, child=%p\n", __LINE__, l->type, l->size, l->next, l->prev, l->parent, l->child);
          exit(EXIT_FAILURE);
       }
@@ -1097,13 +1097,13 @@ static int der_choice_n_custom_test(void)
    for (x = 0; x < sizeof(octetbuf); x++) { octetbuf[x] = x;     }
    for (x = 0; x < sizeof(ia5buf); x++)   { ia5buf[x]   = 'a';   }
    for (x = 0; x < sizeof(printbuf); x++) { printbuf[x] = 'a';   }
-   for (x = 0; x < sizeof(utf8buf)/sizeof(utf8buf[0]); x++) { utf8buf[x] = L'a';   }
+   for (x = 0; x < LTC_ARRAY_SIZE(utf8buf); x++) { utf8buf[x] = L'a';   }
    integer = 1;
    boolean[0] = 1;
-   for (x = 0; x < sizeof(oidbuf)/sizeof(oidbuf[0]); x++)   { oidbuf[x] = x + 1;   }
+   for (x = 0; x < LTC_ARRAY_SIZE(oidbuf); x++)   { oidbuf[x] = x + 1;   }
    DO(ltc_mp_init(&mpinteger));
 
-   n = sizeof(types)/sizeof(types[0]);
+   n = LTC_ARRAY_SIZE(types);
    for (x = 0; x < n * 2; x++) {
        /* setup list */
        y = 0;
@@ -1115,13 +1115,13 @@ static int der_choice_n_custom_test(void)
        }
        LTC_SET_ASN1(types, y++, LTC_ASN1_OCTET_STRING, octetbuf, sizeof(octetbuf));
        LTC_SET_ASN1(types, y++, LTC_ASN1_IA5_STRING, ia5buf, sizeof(ia5buf));
-       LTC_SET_ASN1(types, y++, LTC_ASN1_BOOLEAN, boolean, sizeof(boolean)/sizeof(boolean[0]));
+       LTC_SET_ASN1(types, y++, LTC_ASN1_BOOLEAN, boolean, LTC_ARRAY_SIZE(boolean));
        if (x > n) {
           LTC_SET_ASN1(types, y++, LTC_ASN1_SHORT_INTEGER, &integer, 1);
        } else {
           LTC_SET_ASN1(types, y++, LTC_ASN1_INTEGER, mpinteger, 1);
        }
-       LTC_SET_ASN1(types, y++, LTC_ASN1_OBJECT_IDENTIFIER, oidbuf, sizeof(oidbuf)/sizeof(oidbuf[0]));
+       LTC_SET_ASN1(types, y++, LTC_ASN1_OBJECT_IDENTIFIER, oidbuf, LTC_ARRAY_SIZE(oidbuf));
        if (x > n) {
           LTC_SET_ASN1(types, y++, LTC_ASN1_UTCTIME, &utctime, 1);
        } else {
@@ -1131,7 +1131,7 @@ static int der_choice_n_custom_test(void)
        LTC_SET_ASN1(custom, 0, LTC_ASN1_NULL, NULL, 0);
        LTC_SET_ASN1_CUSTOM_CONSTRUCTED(types, y++, LTC_ASN1_CL_CONTEXT_SPECIFIC, 0, custom);
 
-       LTC_SET_ASN1(types, y++, LTC_ASN1_UTF8_STRING, utf8buf, sizeof(utf8buf)/sizeof(utf8buf[0]));
+       LTC_SET_ASN1(types, y++, LTC_ASN1_UTF8_STRING, utf8buf, LTC_ARRAY_SIZE(utf8buf));
 
        LTC_SET_ASN1(host, 0, LTC_ASN1_CHOICE, types, n);
 
@@ -1344,7 +1344,7 @@ static void der_Xcode_test(void)
     DER_XCODE(utf8_string, wchar_string),
    };
 
-   for (i = 0; i < sizeof(xcode_tests)/sizeof(xcode_tests[0]); ++i) {
+   for (i = 0; i < LTC_ARRAY_SIZE(xcode_tests); ++i) {
       der_Xcode_run(&xcode_tests[i]);
    }
 
@@ -1425,7 +1425,7 @@ static void s_der_regression_test(void)
    SHOULD_FAIL(der_decode_sequence_flexi(issue_507, &len, &l));
 
    len = sizeof(utf8_length);
-   outlen = sizeof(wtmp)/sizeof(wtmp[0]);
+   outlen = LTC_ARRAY_SIZE(wtmp);
    DO(der_decode_utf8_string(utf8_length, len, wtmp, &outlen));
    ENSURE(outlen == 2);
 }
@@ -1544,7 +1544,7 @@ static void der_toolong_test(void)
 
    ltc_mp_deinit_multi(int1, int2, LTC_NULL);
 
-   LTC_SET_ASN1(seqoid,  0, LTC_ASN1_OBJECT_IDENTIFIER, oid, sizeof(oid)/sizeof(oid[0]));
+   LTC_SET_ASN1(seqoid,  0, LTC_ASN1_OBJECT_IDENTIFIER, oid, LTC_ARRAY_SIZE(oid));
    LTC_SET_ASN1(seqoid,  1, LTC_ASN1_NULL,              NULL,   0);
    LTC_SET_ASN1(seqmain, 0, LTC_ASN1_SEQUENCE,          seqoid, 2);
    LTC_SET_ASN1(seqmain, 1, LTC_ASN1_OCTET_STRING,      buf32,  32);
@@ -1805,7 +1805,7 @@ int der_test(void)
 
 /* test OID */
    x = sizeof(buf[0]);
-   DO(der_encode_object_identifier((unsigned long*)rsa_oid, sizeof(rsa_oid)/sizeof(rsa_oid[0]), buf[0], &x));
+   DO(der_encode_object_identifier((unsigned long*)rsa_oid, LTC_ARRAY_SIZE(rsa_oid), buf[0], &x));
    if (x != sizeof(rsa_oid_der) || memcmp(rsa_oid_der, buf[0], x)) {
       fprintf(stderr, "rsa_oid_der encode failed to match, %lu, ", x);
       for (y = 0; y < x; y++) fprintf(stderr, "%02x ", buf[0][y]);
@@ -1813,9 +1813,9 @@ int der_test(void)
       return 1;
    }
 
-   y = sizeof(oid[0])/sizeof(oid[0][0]);
+   y = LTC_ARRAY_SIZE(oid[0]);
    DO(der_decode_object_identifier(buf[0], x, oid[0], &y));
-   if (y != sizeof(rsa_oid)/sizeof(rsa_oid[0]) || memcmp(rsa_oid, oid[0], sizeof(rsa_oid))) {
+   if (y != LTC_ARRAY_SIZE(rsa_oid) || memcmp(rsa_oid, oid[0], sizeof(rsa_oid))) {
       fprintf(stderr, "rsa_oid_der decode failed to match, %lu, ", y);
       for (z = 0; z < y; z++) fprintf(stderr, "%lu ", oid[0][z]);
       fprintf(stderr, "\n");
@@ -1827,7 +1827,7 @@ int der_test(void)
        /* pick a random number of words */
        ENSURE(yarrow_read(buf[0], 4, &yarrow_prng) == 4);
        LOAD32L(z, buf[0]);
-       z = 2 + (z % ((sizeof(oid[0])/sizeof(oid[0][0])) - 2));
+       z = 2 + (z % (LTC_ARRAY_SIZE(oid[0]) - 2));
 
        /* fill them in */
        oid[0][0] = buf[0][0] % 3;
@@ -1849,7 +1849,7 @@ int der_test(void)
        }
 
        /* decode it */
-       y = sizeof(oid[0])/sizeof(oid[0][0]);
+       y = LTC_ARRAY_SIZE(oid[0]);
        DO(der_decode_object_identifier(buf[0], x, oid[1], &y));
        if (y != z) {
           fprintf(stderr, "Random OID %lu test failed, decode length mismatch: %lu, %lu\n", z, x, y);

+ 4 - 4
tests/ecc_test.c

@@ -156,7 +156,7 @@ static int s_ecc_test_shamir(void)
    LTC_ARGCHK((C1 = ltc_ecc_new_point()) != NULL);
    LTC_ARGCHK((C2 = ltc_ecc_new_point()) != NULL);
 
-   for (x = 0; x < (int)(sizeof(sizes)/sizeof(sizes[0])); x++) {
+   for (x = 0; x < (int)LTC_ARRAY_SIZE(sizes); x++) {
        /* get the base point */
        for (z = 0; ltc_ecc_curves[z].prime != NULL; z++) {
            DO(ltc_mp_read_radix(modulus, ltc_ecc_curves[z].prime, 16));
@@ -406,7 +406,7 @@ static int s_ecc_old_api(void)
    ecc_sizes(&low, &high);
    if (low < 14 || high < 14 || low > 100 || high > 100 || high < low) return CRYPT_FAIL_TESTVECTOR;
 
-   for (s = 0; s < (sizeof(sizes)/sizeof(sizes[0])); s++) {
+   for (s = 0; s < LTC_ARRAY_SIZE(sizes); s++) {
       /* make up two keys */
       DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &usera));
       DO(ecc_make_key (&yarrow_prng, find_prng ("yarrow"), sizes[s], &userb));
@@ -557,7 +557,7 @@ static int s_ecc_new_api(void)
    unsigned char data16[16] = { 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1 };
    unsigned long len16;
 
-   for (i = 0; i < (int)(sizeof(curvenames)/sizeof(curvenames[0])); i++) {
+   for (i = 0; i < (int)LTC_ARRAY_SIZE(curvenames); i++) {
       DO(ecc_find_curve(curvenames[i], &dp));
       /* make new key */
       DO(ecc_make_key_ex(&yarrow_prng, find_prng ("yarrow"), &key, dp));
@@ -1985,7 +1985,7 @@ static int s_ecc_test_recovery(void)
    ecc_free(&pubkey);
 #endif
 
-   for (i = 0; i < (int)(sizeof(curvenames)/sizeof(curvenames[0])); i++) {
+   for (i = 0; i < (int)LTC_ARRAY_SIZE(curvenames); i++) {
       DO(ecc_find_curve(curvenames[i], &dp));
 
       /* generate new key */

+ 3 - 3
tests/ed25519_test.c

@@ -66,7 +66,7 @@ static int s_rfc_8410_10_test(void)
    char tmp[512];
    unsigned long buflen, tmplen;
    password_ctx pw_ctx = { .callback = password_get };
-   for (n = 0; n < sizeof(rfc_8410_10)/sizeof(rfc_8410_10[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(rfc_8410_10); ++n) {
       buflen = sizeof(buf);
       DO(base64_decode(rfc_8410_10[n].b64, XSTRLEN(rfc_8410_10[n].b64), buf, &buflen));
       switch (n) {
@@ -213,7 +213,7 @@ static int s_rfc_8032_7_1_test(void)
    curve25519_key key, key2;
    int ret;
    const int should = 1;
-   for (n = 0; n < sizeof(rfc_8032_7_1)/sizeof(rfc_8032_7_1[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(rfc_8032_7_1); ++n) {
       slen = sizeof(sec);
       DO(base16_decode(rfc_8032_7_1[n].secret_key, XSTRLEN(rfc_8032_7_1[n].secret_key), sec, &slen));
       plen = sizeof(pub);
@@ -316,7 +316,7 @@ static int s_rfc_8032_7_2_test(void)
    int ret;
    const int should = 1;
 
-   for (n = 0; n < sizeof(rfc_8032_7_2)/sizeof(rfc_8032_7_2[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(rfc_8032_7_2); ++n) {
       slen = sizeof(sec);
       DO(base16_decode(rfc_8032_7_2[n].secret_key, XSTRLEN(rfc_8032_7_2[n].secret_key), sec, &slen));
       plen = sizeof(pub);

+ 1 - 1
tests/modes_test.c

@@ -108,7 +108,7 @@ int modes_test(void)
    l = sizeof(w); \
    DO(base16_decode(e . w, XSTRLEN(e . w), w, &l)); \
 } while(0)
-   for (n = 0; n < sizeof(cfb_testvectors)/sizeof(cfb_testvectors[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(cfb_testvectors); ++n) {
       b16(cfb_testvectors[n], key);
       b16(cfb_testvectors[n], iv);
       b16(cfb_testvectors[n], pt);

+ 2 - 2
tests/padding_test.c

@@ -188,11 +188,11 @@ int padding_test(void)
    unsigned char buf[256 + 16];
    unsigned long l;
 
-   for (i = 0; i < sizeof(cases)/sizeof(cases[0]); ++i) {
+   for (i = 0; i < LTC_ARRAY_SIZE(cases); ++i) {
       DOX(s_padding_testrun(&cases[i]), cases[i].name);
    }
 
-   for (i = 0; i < sizeof(tv)/sizeof(tv[0]); ++i) {
+   for (i = 0; i < LTC_ARRAY_SIZE(tv); ++i) {
       XMEMCPY(buf, tv[i].data, sizeof(tv[i].data));
       l = sizeof(tv[i].data);
       DO(padding_depad(buf, &l, tv[i].mode));

+ 2 - 2
tests/pkcs_1_eme_test.c

@@ -21,7 +21,7 @@ int pkcs_1_eme_test(void)
   DO(prng_is_valid(prng_idx));
   DO(hash_is_valid(hash_idx));
 
-  for (i = 0; i < sizeof(testcases_eme)/sizeof(testcases_eme[0]); ++i) {
+  for (i = 0; i < LTC_ARRAY_SIZE(testcases_eme); ++i) {
     testcase_t* t = &testcases_eme[i];
     rsa_key k, *key = &k;
     DOX(ltc_mp_init_multi(&key->e, &key->d, &key->N, &key->dQ,
@@ -37,7 +37,7 @@ int pkcs_1_eme_test(void)
     DOX(ltc_mp_read_unsigned_bin(key->p, t->rsa.p, t->rsa.p_l), t->name);
     key->type = PK_PRIVATE;
 
-    for (j = 0; j < sizeof(t->data)/sizeof(t->data[0]); ++j) {
+    for (j = 0; j < LTC_ARRAY_SIZE(t->data); ++j) {
         rsaData_t* s = &t->data[j];
         unsigned char buf[256], obuf[256];
         unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf);

+ 2 - 2
tests/pkcs_1_emsa_test.c

@@ -18,7 +18,7 @@ int pkcs_1_emsa_test(void)
 
   DO(hash_is_valid(hash_idx));
 
-  for (i = 0; i < sizeof(testcases_emsa)/sizeof(testcases_emsa[0]); ++i) {
+  for (i = 0; i < LTC_ARRAY_SIZE(testcases_emsa); ++i) {
     testcase_t* t = &testcases_emsa[i];
     rsa_key k, *key = &k;
     DOX(ltc_mp_init_multi(&key->e, &key->d, &key->N, &key->dQ,
@@ -34,7 +34,7 @@ int pkcs_1_emsa_test(void)
     DOX(ltc_mp_read_unsigned_bin(key->p, t->rsa.p, t->rsa.p_l), t->name);
     key->type = PK_PRIVATE;
 
-    for (j = 0; j < sizeof(t->data)/sizeof(t->data[0]); ++j) {
+    for (j = 0; j < LTC_ARRAY_SIZE(t->data); ++j) {
         rsaData_t* s = &t->data[j];
         unsigned char buf[20], obuf[256];
         unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf);

+ 2 - 2
tests/pkcs_1_oaep_test.c

@@ -21,7 +21,7 @@ int pkcs_1_oaep_test(void)
   DO(prng_is_valid(prng_idx));
   DO(hash_is_valid(hash_idx));
 
-  for (i = 0; i < sizeof(testcases_oaep)/sizeof(testcases_oaep[0]); ++i) {
+  for (i = 0; i < LTC_ARRAY_SIZE(testcases_oaep); ++i) {
     testcase_t* t = &testcases_oaep[i];
     rsa_key k, *key = &k;
     DOX(ltc_mp_init_multi(&key->e, &key->d, &key->N, &key->dQ,
@@ -37,7 +37,7 @@ int pkcs_1_oaep_test(void)
     DOX(ltc_mp_read_unsigned_bin(key->p, t->rsa.p, t->rsa.p_l), t->name);
     key->type = PK_PRIVATE;
 
-    for (j = 0; j < sizeof(t->data)/sizeof(t->data[0]); ++j) {
+    for (j = 0; j < LTC_ARRAY_SIZE(t->data); ++j) {
         rsaData_t* s = &t->data[j];
         unsigned char buf[256], obuf[256];
         unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf);

+ 2 - 2
tests/pkcs_1_pss_test.c

@@ -21,7 +21,7 @@ int pkcs_1_pss_test(void)
   DO(prng_is_valid(prng_idx));
   DO(hash_is_valid(hash_idx));
 
-  for (i = 0; i < sizeof(testcases_pss)/sizeof(testcases_pss[0]); ++i) {
+  for (i = 0; i < LTC_ARRAY_SIZE(testcases_pss); ++i) {
     testcase_t* t = &testcases_pss[i];
     rsa_key k, *key = &k;
     DOX(ltc_mp_init_multi(&key->e, &key->d, &key->N, &key->dQ,
@@ -37,7 +37,7 @@ int pkcs_1_pss_test(void)
     DOX(ltc_mp_read_unsigned_bin(key->p, t->rsa.p, t->rsa.p_l), t->name);
     key->type = PK_PRIVATE;
 
-    for (j = 0; j < sizeof(t->data)/sizeof(t->data[0]); ++j) {
+    for (j = 0; j < LTC_ARRAY_SIZE(t->data); ++j) {
         rsaData_t* s = &t->data[j];
         unsigned char buf[20], obuf[256];
         unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf);

+ 2 - 2
tests/test.c

@@ -356,7 +356,7 @@ int main(int argc, char **argv)
    }
 
 #ifdef LTC_PTHREAD
-   tinfo = XCALLOC(sizeof(test_functions)/sizeof(test_functions[0]), sizeof(thread_info));
+   tinfo = XCALLOC(LTC_ARRAY_SIZE(test_functions), sizeof(thread_info));
    if (tinfo == NULL) {
       printf("\n\nFAILURE: XCALLOC\n");
       return EXIT_FAILURE;
@@ -385,7 +385,7 @@ int main(int argc, char **argv)
    if (argc > 1) single_test = argv[1];
 
    dur = epoch_usec();
-   for (i = 0; i < sizeof(test_functions)/sizeof(test_functions[0]); ++i) {
+   for (i = 0; i < LTC_ARRAY_SIZE(test_functions); ++i) {
       if (single_test && strstr(test_functions[i].name, single_test) == NULL) {
         continue;
       }

+ 3 - 3
tests/x25519_test.c

@@ -49,7 +49,7 @@ static int s_rfc_7748_5_2_test(void)
    unsigned char out[32];
    unsigned long n;
 
-   for (n = 0; n < sizeof(rfc_7748_5_2)/sizeof(rfc_7748_5_2[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(rfc_7748_5_2); ++n) {
       tweetnacl_crypto_scalarmult(out, rfc_7748_5_2[n].scalar, rfc_7748_5_2[n].u_in);
       if (compare_testvector(out, sizeof(out), rfc_7748_5_2[n].u_out, sizeof(rfc_7748_5_2[n].u_out), "x25519 RFC 7748 Ch. 5.2", n) != 0) {
          return CRYPT_FAIL_TESTVECTOR;
@@ -130,7 +130,7 @@ static int s_rfc_8410_10_test(void)
    curve25519_key key;
    unsigned char buf[1024];
    unsigned long buflen;
-   for (n = 0; n < sizeof(rfc_8410_10)/sizeof(rfc_8410_10[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(rfc_8410_10); ++n) {
       buflen = sizeof(buf);
       DO(base64_decode(rfc_8410_10[n].b64, XSTRLEN(rfc_8410_10[n].b64), buf, &buflen));
       DO(x25519_import_x509(buf, buflen, &key));
@@ -170,7 +170,7 @@ static int s_x25519_pkcs8_test(void)
    unsigned char buf[1024];
    unsigned long buflen;
    password_ctx *p_pw_ctx, pw_ctx = { .callback = password_get };
-   for (n = 0; n < sizeof(s_x25519_pkcs8)/sizeof(s_x25519_pkcs8[0]); ++n) {
+   for (n = 0; n < LTC_ARRAY_SIZE(s_x25519_pkcs8); ++n) {
       buflen = sizeof(buf);
       DO(base64_decode(s_x25519_pkcs8[n].b64, XSTRLEN(s_x25519_pkcs8[n].b64), buf, &buflen));
       pw_ctx.userdata = (void*)s_x25519_pkcs8[n].pass;