In OpenSSL, it's actually OSSL_NELEM() in "internal/nelem.h".
Found by running the checkpatch.pl Linux script to enforce coding style.
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22097)
*/
#include "internal/cryptlib.h"
+#include "internal/nelem.h"
#include "bn_local.h"
int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
if (bn_wexpand(r, mtop) == NULL)
return 0;
- if (mtop > sizeof(storage) / sizeof(storage[0])) {
+ if (mtop > OSSL_NELEM(storage)) {
tp = OPENSSL_malloc(mtop * sizeof(BN_ULONG));
if (tp == NULL)
return 0;
#include <string.h>
#include <assert.h>
+#include "internal/nelem.h"
+
size_t SHA3_absorb(uint64_t A[5][5], const unsigned char *inp, size_t len,
size_t r);
void SHA3_squeeze(uint64_t A[5][5], unsigned char *out, size_t len, size_t r, int next);
static void Iota(uint64_t A[5][5], size_t i)
{
- assert(i < (sizeof(iotas) / sizeof(iotas[0])));
+ assert(i < OSSL_NELEM(iotas));
A[0][0] ^= iotas[i];
}
uint64_t C[5], E[2]; /* registers */
uint64_t D[5], T[2][5]; /* memory */
- assert(i < (sizeof(iotas) / sizeof(iotas[0])));
+ assert(i < OSSL_NELEM(iotas));
C[0] = A[0][0] ^ A[1][0] ^ A[2][0] ^ A[3][0] ^ A[4][0];
C[1] = A[0][1] ^ A[1][1] ^ A[2][1] ^ A[3][1] ^ A[4][1];
{
uint64_t C[5], D[5];
- assert(i < (sizeof(iotas) / sizeof(iotas[0])));
+ assert(i < OSSL_NELEM(iotas));
C[0] = A[0][0] ^ A[1][0] ^ A[2][0] ^ A[3][0] ^ A[4][0];
C[1] = A[0][1] ^ A[1][1] ^ A[2][1] ^ A[3][1] ^ A[4][1];
{
uint64_t C[5], D[5];
- assert(i < (sizeof(iotas) / sizeof(iotas[0])));
+ assert(i < OSSL_NELEM(iotas));
C[0] = A[0][0] ^ A[1][0] ^ A[2][0] ^ A[3][0] ^ A[4][0];
C[1] = A[0][1] ^ A[1][1] ^ A[2][1] ^ A[3][1] ^ A[4][1];
{
uint64_t B[5], C[5], D[5];
- assert(i <= (sizeof(iotas) / sizeof(iotas[0]) - 4));
+ assert(i <= OSSL_NELEM(iotas) - 4);
/* Round 4*n */
C[0] = A[0][0] ^ A[1][0] ^ A[2][0] ^ A[3][0] ^ A[4][0];
#include <openssl/store.h>
+#include "internal/nelem.h"
+
static char *type_strings[] = {
"Name", /* OSSL_STORE_INFO_NAME */
"Parameters", /* OSSL_STORE_INFO_PARAMS */
const char *OSSL_STORE_INFO_type_string(int type)
{
- int types = sizeof(type_strings) / sizeof(type_strings[0]);
+ int types = OSSL_NELEM(type_strings);
if (type < 1 || type > types)
return NULL;
if (cipher == NULL) {
*nids = afalg_cipher_nids;
- return (sizeof(afalg_cipher_nids) / sizeof(afalg_cipher_nids[0]));
+ return OSSL_NELEM(afalg_cipher_nids);
}
switch (nid) {
/* Do decode_custom checks */
nelems = package->encode_expectations_size
/ package->encode_expectations_elem_size;
- OPENSSL_assert(nelems ==
- sizeof(test_custom_data) / sizeof(test_custom_data[0]));
+ OPENSSL_assert(nelems == OSSL_NELEM(test_custom_data));
for (i = 0; i < nelems; i++) {
size_t pos = i * package->encode_expectations_elem_size;
EXPECTED *expected
#include <stdio.h>
#include <string.h>
#include <openssl/bio.h>
+#include "internal/nelem.h"
#include "internal/numbers.h"
#include "testutil.h"
#include "testutil/output.h"
-#define nelem(x) (int)(sizeof(x) / sizeof((x)[0]))
-
static int justprint = 0;
static char *fpexpected[][10][5] = {
char format[80], result[80];
int ret = 1, i;
- for (i = 0; i < nelem(fspecs); i++) {
+ for (i = 0; i < (int)OSSL_NELEM(fspecs); i++) {
const char *fspec = fspecs[i];
if (prec >= 0)
}
ADD_TEST(test_big);
- ADD_ALL_TESTS(test_fp, nelem(pw_params));
- ADD_ALL_TESTS(test_zu, nelem(zu_data));
- ADD_ALL_TESTS(test_j, nelem(jf_data));
+ ADD_ALL_TESTS(test_fp, OSSL_NELEM(pw_params));
+ ADD_ALL_TESTS(test_zu, OSSL_NELEM(zu_data));
+ ADD_ALL_TESTS(test_j, OSSL_NELEM(jf_data));
return 1;
}
# endif
};
-#define NUM_KTLS_TEST_CIPHERS \
- (sizeof(ktls_test_ciphers) / sizeof(ktls_test_ciphers[0]))
+#define NUM_KTLS_TEST_CIPHERS OSSL_NELEM(ktls_test_ciphers)
static int test_ktls(int test)
{