if (idx >= 0)
return sk_ASN1_STRING_TABLE_value(stable, idx);
}
- return OBJ_bsearch_table(&fnd, tbl_standard,
- sizeof(tbl_standard) /
- sizeof(ASN1_STRING_TABLE));
+ return OBJ_bsearch_table(&fnd, tbl_standard, OSSL_NELEM(tbl_standard));
}
/*
ASN1_STRING_TABLE *tmp;
int i, last_nid = -1;
- for (tmp = tbl_standard, i = 0;
- i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) {
+ for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++) {
if (tmp->nid < last_nid) {
last_nid = 0;
break;
exit(0);
}
- for (tmp = tbl_standard, i = 0;
- i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++)
+ for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++)
printf("Index %d, NID %d, Name=%s\n", i, tmp->nid,
OBJ_nid2ln(tmp->nid));
void main()
{
int i;
- for (i = 0;
- i < sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *); i++)
+ for (i = 0; i < OSSL_NELEM(standard_methods); i++)
fprintf(stderr, "Number %d id=%d (%s)\n", i,
standard_methods[i]->pkey_id,
OBJ_nid2sn(standard_methods[i]->pkey_id));
int EVP_PKEY_asn1_get_count(void)
{
- int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *);
+ int num = OSSL_NELEM(standard_methods);
if (app_methods)
num += sk_EVP_PKEY_ASN1_METHOD_num(app_methods);
return num;
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx)
{
- int num = sizeof(standard_methods) / sizeof(EVP_PKEY_ASN1_METHOD *);
+ int num = OSSL_NELEM(standard_methods);
if (idx < 0)
return NULL;
if (idx < num)
if (idx >= 0)
return sk_EVP_PKEY_ASN1_METHOD_value(app_methods, idx);
}
- ret = OBJ_bsearch_ameth(&t, standard_methods, sizeof(standard_methods)
- / sizeof(EVP_PKEY_ASN1_METHOD *));
+ ret = OBJ_bsearch_ameth(&t, standard_methods, OSSL_NELEM(standard_methods));
if (!ret || !*ret)
return NULL;
return *ret;
len = strlen(tagstr);
tntmp = tnst;
- for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) {
+ for (i = 0; i < OSSL_NELEM(tnst); i++, tntmp++) {
if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len))
return tntmp->tag;
}
if (MultiByteToWideChar(CP_UTF8, flags,
filename, len_0, wfilename, sz) &&
MultiByteToWideChar(CP_UTF8, 0, mode, strlen(mode) + 1,
- wmode, sizeof(wmode) / sizeof(wmode[0])) &&
+ wmode, OSSL_NELEM(wmode)) &&
(file = _wfopen(wfilename, wmode)) == NULL &&
(errno == ENOENT || errno == EBADF)
) {
*/
#include "bn_lcl.h"
+#include "e_os.h"
#ifndef OPENSSL_NO_DH
/* DH parameters from RFC5114 */
/* Macro to make a BIGNUM from static data */
# define make_dh_bn(x) const BIGNUM _bignum_##x = { (BN_ULONG *) x, \
- sizeof(x)/sizeof(BN_ULONG),\
- sizeof(x)/sizeof(BN_ULONG),\
+ OSSL_NELEM(x),\
+ OSSL_NELEM(x),\
0, BN_FLG_STATIC_DATA };
int arr[6];
bn_check_top(a);
bn_check_top(p);
- ret = BN_GF2m_poly2arr(p, arr, sizeof(arr) / sizeof(arr[0]));
- if (!ret || ret > (int)(sizeof(arr) / sizeof(arr[0]))) {
+ ret = BN_GF2m_poly2arr(p, arr, OSSL_NELEM(arr));
+ if (!ret || ret > (int)OSSL_NELEM(arr)) {
BNerr(BN_F_BN_GF2M_MOD, BN_R_INVALID_LENGTH);
return 0;
}
PTR_SIZE_INT mask;
static const BIGNUM _bignum_nist_p_192_sqr = {
(BN_ULONG *)_nist_p_192_sqr,
- sizeof(_nist_p_192_sqr) / sizeof(_nist_p_192_sqr[0]),
- sizeof(_nist_p_192_sqr) / sizeof(_nist_p_192_sqr[0]),
+ OSSL_NELEM(_nist_p_192_sqr),
+ OSSL_NELEM(_nist_p_192_sqr),
0, BN_FLG_STATIC_DATA
};
} u;
static const BIGNUM _bignum_nist_p_224_sqr = {
(BN_ULONG *)_nist_p_224_sqr,
- sizeof(_nist_p_224_sqr) / sizeof(_nist_p_224_sqr[0]),
- sizeof(_nist_p_224_sqr) / sizeof(_nist_p_224_sqr[0]),
+ OSSL_NELEM(_nist_p_224_sqr),
+ OSSL_NELEM(_nist_p_224_sqr),
0, BN_FLG_STATIC_DATA
};
} u;
static const BIGNUM _bignum_nist_p_256_sqr = {
(BN_ULONG *)_nist_p_256_sqr,
- sizeof(_nist_p_256_sqr) / sizeof(_nist_p_256_sqr[0]),
- sizeof(_nist_p_256_sqr) / sizeof(_nist_p_256_sqr[0]),
+ OSSL_NELEM(_nist_p_256_sqr),
+ OSSL_NELEM(_nist_p_256_sqr),
0, BN_FLG_STATIC_DATA
};
} u;
static const BIGNUM _bignum_nist_p_384_sqr = {
(BN_ULONG *)_nist_p_384_sqr,
- sizeof(_nist_p_384_sqr) / sizeof(_nist_p_384_sqr[0]),
- sizeof(_nist_p_384_sqr) / sizeof(_nist_p_384_sqr[0]),
+ OSSL_NELEM(_nist_p_384_sqr),
+ OSSL_NELEM(_nist_p_384_sqr),
0, BN_FLG_STATIC_DATA
};
PTR_SIZE_INT mask;
static const BIGNUM _bignum_nist_p_521_sqr = {
(BN_ULONG *)_nist_p_521_sqr,
- sizeof(_nist_p_521_sqr) / sizeof(_nist_p_521_sqr[0]),
- sizeof(_nist_p_521_sqr) / sizeof(_nist_p_521_sqr[0]),
+ OSSL_NELEM(_nist_p_521_sqr),
+ OSSL_NELEM(_nist_p_521_sqr),
0, BN_FLG_STATIC_DATA
};
#include "bn_lcl.h"
+#include "e_os.h"
#ifndef OPENSSL_NO_SRP
const BIGNUM bn_group_1024 = {
(BN_ULONG *)bn_group_1024_value,
- (sizeof bn_group_1024_value) / sizeof(BN_ULONG),
- (sizeof bn_group_1024_value) / sizeof(BN_ULONG),
+ OSSL_NELEM(bn_group_1024_value),
+ OSSL_NELEM(bn_group_1024_value),
0,
BN_FLG_STATIC_DATA
};
const BIGNUM bn_group_1536 = {
(BN_ULONG *)bn_group_1536_value,
- (sizeof bn_group_1536_value) / sizeof(BN_ULONG),
- (sizeof bn_group_1536_value) / sizeof(BN_ULONG),
+ OSSL_NELEM(bn_group_1536_value),
+ OSSL_NELEM(bn_group_1536_value),
0,
BN_FLG_STATIC_DATA
};
const BIGNUM bn_group_2048 = {
(BN_ULONG *)bn_group_2048_value,
- (sizeof bn_group_2048_value) / sizeof(BN_ULONG),
- (sizeof bn_group_2048_value) / sizeof(BN_ULONG),
+ OSSL_NELEM(bn_group_2048_value),
+ OSSL_NELEM(bn_group_2048_value),
0,
BN_FLG_STATIC_DATA
};
const BIGNUM bn_group_3072 = {
(BN_ULONG *)bn_group_3072_value,
- (sizeof bn_group_3072_value) / sizeof(BN_ULONG),
- (sizeof bn_group_3072_value) / sizeof(BN_ULONG),
+ OSSL_NELEM(bn_group_3072_value),
+ OSSL_NELEM(bn_group_3072_value),
0,
BN_FLG_STATIC_DATA
};
const BIGNUM bn_group_4096 = {
(BN_ULONG *)bn_group_4096_value,
- (sizeof bn_group_4096_value) / sizeof(BN_ULONG),
- (sizeof bn_group_4096_value) / sizeof(BN_ULONG),
+ OSSL_NELEM(bn_group_4096_value),
+ OSSL_NELEM(bn_group_4096_value),
0,
BN_FLG_STATIC_DATA
};
const BIGNUM bn_group_6144 = {
(BN_ULONG *)bn_group_6144_value,
- (sizeof bn_group_6144_value) / sizeof(BN_ULONG),
- (sizeof bn_group_6144_value) / sizeof(BN_ULONG),
+ OSSL_NELEM(bn_group_6144_value),
+ OSSL_NELEM(bn_group_6144_value),
0,
BN_FLG_STATIC_DATA
};
const BIGNUM bn_group_8192 = {
(BN_ULONG *)bn_group_8192_value,
- (sizeof bn_group_8192_value) / sizeof(BN_ULONG),
- (sizeof bn_group_8192_value) / sizeof(BN_ULONG),
+ OSSL_NELEM(bn_group_8192_value),
+ OSSL_NELEM(bn_group_8192_value),
0,
BN_FLG_STATIC_DATA
};
#include <openssl/err.h>
#include <openssl/obj_mac.h>
#include <openssl/opensslconf.h>
+#include "e_os.h"
typedef struct {
int field_type, /* either NID_X9_62_prime_field or
"RFC 5639 curve over a 512 bit prime field"},
};
-#define curve_list_length (sizeof(curve_list)/sizeof(ec_list_element))
+#define curve_list_length OSSL_NELEM(curve_list)
static EC_GROUP *ec_group_new_from_data(const ec_list_element curve)
{
const char *EC_curve_nid2nist(int nid)
{
size_t i;
- for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) {
+ for (i = 0; i < OSSL_NELEM(nist_curves); i++) {
if (nist_curves[i].nid == nid)
return nist_curves[i].name;
}
int EC_curve_nist2nid(const char *name)
{
size_t i;
- for (i = 0; i < sizeof(nist_curves) / sizeof(EC_NIST_NAME); i++) {
+ for (i = 0; i < OSSL_NELEM(nist_curves); i++) {
if (!strcmp(nist_curves[i].name, name))
return nist_curves[i].nid;
}
* OpenSSL_add_all_algorithms();
*/
- for (i = 0; i < sizeof(builtin_pbe) / sizeof(EVP_PBE_CTL); i++) {
+ for (i = 0; i < OSSL_NELEM(builtin_pbe); i++) {
tpbe = builtin_pbe + i;
fprintf(stderr, "%d %d %s ", tpbe->pbe_type, tpbe->pbe_nid,
OBJ_nid2sn(tpbe->pbe_nid));
pbetmp = sk_EVP_PBE_CTL_value(pbe_algs, i);
}
if (pbetmp == NULL) {
- pbetmp = OBJ_bsearch_pbe2(&pbelu, builtin_pbe,
- sizeof(builtin_pbe) / sizeof(EVP_PBE_CTL));
+ pbetmp = OBJ_bsearch_pbe2(&pbelu, builtin_pbe, OSSL_NELEM(builtin_pbe));
}
if (pbetmp == NULL)
return 0;
#include <openssl/objects.h>
#include "obj_xref.h"
+#include "e_os.h"
DECLARE_STACK_OF(nid_triple)
STACK_OF(nid_triple) *sig_app, *sigx_app;
}
#ifndef OBJ_XREF_TEST2
if (rv == NULL) {
- rv = OBJ_bsearch_sig(&tmp, sigoid_srt,
- sizeof(sigoid_srt) / sizeof(nid_triple));
+ rv = OBJ_bsearch_sig(&tmp, sigoid_srt, OSSL_NELEM(sigoid_srt));
}
#endif
if (rv == NULL)
}
#ifndef OBJ_XREF_TEST2
if (rv == NULL) {
- rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref,
- sizeof(sigoid_srt_xref) / sizeof(nid_triple *)
- );
+ rv = OBJ_bsearch_sigx(&t, sigoid_srt_xref, OSSL_NELEM(sigoid_srt_xref));
}
#endif
if (rv == NULL)
int i, rv;
# ifdef OBJ_XREF_TEST2
- for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) {
+ for (i = 0; i < OSSL_NELEM(sigoid_srt); i++) {
OBJ_add_sigid(sigoid_srt[i][0], sigoid_srt[i][1], sigoid_srt[i][2]);
}
# endif
- for (i = 0; i < sizeof(sigoid_srt) / sizeof(nid_triple); i++) {
+ for (i = 0; i < OSSL_NELEM(sigoid_srt); i++) {
n1 = sigoid_srt[i][0];
rv = OBJ_find_sigid_algs(n1, &n2, &n3);
printf("Forward: %d, %s %s %s\n", rv,
# endif
# ifdef DEVRANDOM
static const char *randomfiles[] = { DEVRANDOM };
- struct stat randomstats[sizeof(randomfiles) / sizeof(randomfiles[0])];
+ struct stat randomstats[OSSL_NELEM(randomfiles)];
int fd;
unsigned int i;
# endif
* out of random entries.
*/
- for (i = 0; (i < sizeof(randomfiles) / sizeof(randomfiles[0])) &&
- (n < ENTROPY_NEEDED); i++) {
+ for (i = 0; (i < OSSL_NELEM(randomfiles)) && (n < ENTROPY_NEEDED); i++) {
if ((fd = open(randomfiles[i], O_RDONLY
# ifdef O_NONBLOCK
| O_NONBLOCK
/* Printing status code. */
BIO_printf(bio, "Status: ");
status = ASN1_INTEGER_get(a->status);
- if (0 <= status
- && status < (long)(sizeof(status_map) / sizeof(status_map[0])))
+ if (0 <= status && status < (long)OSSL_NELEM(status_map))
BIO_printf(bio, "%s\n", status_map[status]);
else
BIO_printf(bio, "out of bounds\n");
"revocationNotification"
};
-#define TS_STATUS_TEXT_SIZE (sizeof(TS_status_text)/sizeof(*TS_status_text))
+#define TS_STATUS_TEXT_SIZE OSSL_NELEM(TS_status_text)
/*
* This must be greater or equal to the sum of the strings in TS_status_text
{X509_TRUST_TSA, 0, trust_1oidany, "TSA server", NID_time_stamp, NULL}
};
-#define X509_TRUST_COUNT (sizeof(trstandard)/sizeof(X509_TRUST))
+#define X509_TRUST_COUNT OSSL_NELEM(trstandard)
static STACK_OF(X509_TRUST) *trtable = NULL;
int X509_VERIFY_PARAM_get_count(void)
{
- int num = sizeof(default_table) / sizeof(X509_VERIFY_PARAM);
+ int num = OSSL_NELEM(default_table);
if (param_table)
num += sk_X509_VERIFY_PARAM_num(param_table);
return num;
const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id)
{
- int num = sizeof(default_table) / sizeof(X509_VERIFY_PARAM);
+ int num = OSSL_NELEM(default_table);
if (id < num)
return default_table + id;
return sk_X509_VERIFY_PARAM_value(param_table, id - num);
if (idx != -1)
return sk_X509_VERIFY_PARAM_value(param_table, idx);
}
- return OBJ_bsearch_table(&pm, default_table,
- sizeof(default_table) /
- sizeof(X509_VERIFY_PARAM));
+ return OBJ_bsearch_table(&pm, default_table, OSSL_NELEM(default_table));
}
void X509_VERIFY_PARAM_table_cleanup(void)
{
int i, prev = -1, bad = 0;
X509V3_EXT_METHOD **tmp;
- i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *);
+ i = OSSL_NELEM(standard_exts);
if (i != STANDARD_EXTENSION_COUNT)
fprintf(stderr, "Extension number invalid expecting %d\n", i);
tmp = standard_exts;
NULL},
};
-#define X509_PURPOSE_COUNT (sizeof(xstandard)/sizeof(X509_PURPOSE))
+#define X509_PURPOSE_COUNT OSSL_NELEM(xstandard)
static STACK_OF(X509_PURPOSE) *xptable = NULL;
if (ex_nid == NID_undef)
return 0;
- if (OBJ_bsearch_nid(&ex_nid, supported_nids,
- sizeof(supported_nids) / sizeof(int)))
+ if (OBJ_bsearch_nid(&ex_nid, supported_nids, OSSL_NELEM(supported_nids)))
return 1;
return 0;
}
# endif
# endif
+#define OSSL_NELEM(x) (sizeof(x)/sizeof(x[0]))
+
#ifdef __cplusplus
}
#endif
const char ssl3_version_str[] = "SSLv3" OPENSSL_VERSION_PTEXT;
-#define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers)/sizeof(SSL_CIPHER))
+#define SSL3_NUM_CIPHERS OSSL_NELEM(ssl3_ciphers)
/* list of available SSLv3 ciphers (sorted by id) */
OPENSSL_GLOBAL const SSL_CIPHER ssl3_ciphers[] = {
}
#define ssl_cipher_info_lookup(table, x) \
- ssl_cipher_info_find(table, sizeof(table)/sizeof(*table), x)
+ ssl_cipher_info_find(table, OSSL_NELEM(table), x)
/*
* PKEY_TYPE for GOST89MAC is known in advance, but, because implementation
* groups of cipher_aliases added together in one list (otherwise
* we would be happy with just the cipher_aliases table).
*/
- num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
+ num_of_group_aliases = OSSL_NELEM(cipher_aliases);
num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
ca_list = OPENSSL_malloc(sizeof(SSL_CIPHER *) * num_of_alias_max);
if (ca_list == NULL) {
#endif
};
cctx->tbl = ssl_option_single;
- cctx->ntbl = sizeof(ssl_option_single) / sizeof(ssl_flag_tbl);
+ cctx->ntbl = OSSL_NELEM(ssl_option_single);
return ssl_set_option_list(cmd, -1, cctx);
}
if (!(cctx->flags & SSL_CONF_FLAG_FILE))
return -2;
cctx->tbl = ssl_protocol_list;
- cctx->ntbl = sizeof(ssl_protocol_list) / sizeof(ssl_flag_tbl);
+ cctx->ntbl = OSSL_NELEM(ssl_protocol_list);
return CONF_parse_list(value, ',', 1, ssl_set_option_list, cctx);
}
if (value == NULL)
return -3;
cctx->tbl = ssl_option_list;
- cctx->ntbl = sizeof(ssl_option_list) / sizeof(ssl_flag_tbl);
+ cctx->ntbl = OSSL_NELEM(ssl_option_list);
return CONF_parse_list(value, ',', 1, ssl_set_option_list, cctx);
}
return NULL;
/* Look for matching parameter name in table */
- for (i = 0, t = ssl_conf_cmds;
- i < sizeof(ssl_conf_cmds) / sizeof(ssl_conf_cmd_tbl); i++, t++) {
+ for (i = 0, t = ssl_conf_cmds; i < OSSL_NELEM(ssl_conf_cmds); i++, t++) {
if (cctx->flags & SSL_CONF_FLAG_CMDLINE) {
if (t->str_cmdline && !strcmp(t->str_cmdline, cmd))
return t;
int tls1_ec_curve_id2nid(int curve_id)
{
/* ECC curves from RFC 4492 and RFC 7027 */
- if ((curve_id < 1) || ((unsigned int)curve_id >
- sizeof(nid_list) / sizeof(nid_list[0])))
+ if ((curve_id < 1) || ((unsigned int)curve_id > OSSL_NELEM(nid_list)))
return 0;
return nid_list[curve_id - 1].nid;
}
const tls_curve_info *cinfo;
if (curve[0])
return 1;
- if ((curve[1] < 1) || ((size_t)curve[1] >
- sizeof(nid_list) / sizeof(nid_list[0])))
+ if ((curve[1] < 1) || ((size_t)curve[1] > OSSL_NELEM(nid_list)))
return 0;
cinfo = &nid_list[curve[1] - 1];
# ifdef OPENSSL_NO_EC2M
int sig_id, md_id;
if (!md)
return 0;
- md_id = tls12_find_id(EVP_MD_type(md), tls12_md,
- sizeof(tls12_md) / sizeof(tls12_lookup));
+ md_id = tls12_find_id(EVP_MD_type(md), tls12_md, OSSL_NELEM(tls12_md));
if (md_id == -1)
return 0;
sig_id = tls12_get_sigid(pk);
int tls12_get_sigid(const EVP_PKEY *pk)
{
- return tls12_find_id(pk->type, tls12_sig,
- sizeof(tls12_sig) / sizeof(tls12_lookup));
+ return tls12_find_id(pk->type, tls12_sig, OSSL_NELEM(tls12_sig));
}
typedef struct {
{
if (hash_alg == 0)
return NULL;
- if (hash_alg > sizeof(tls12_md_info) / sizeof(tls12_md_info[0]))
+ if (hash_alg > OSSL_NELEM(tls12_md_info))
return NULL;
return tls12_md_info + hash_alg - 1;
}
if (!phash_nid && !psign_nid && !psignhash_nid)
return;
if (phash_nid || psignhash_nid) {
- hash_nid = tls12_find_nid(data[0], tls12_md,
- sizeof(tls12_md) / sizeof(tls12_lookup));
+ hash_nid = tls12_find_nid(data[0], tls12_md, OSSL_NELEM(tls12_md));
if (phash_nid)
*phash_nid = hash_nid;
}
if (psign_nid || psignhash_nid) {
- sign_nid = tls12_find_nid(data[1], tls12_sig,
- sizeof(tls12_sig) / sizeof(tls12_lookup));
+ sign_nid = tls12_find_nid(data[1], tls12_sig, OSSL_NELEM(tls12_sig));
if (psign_nid)
*psign_nid = sign_nid;
}
if (sigalgs == NULL)
return 0;
for (i = 0, sptr = sigalgs; i < salglen; i += 2) {
- rhash = tls12_find_id(*psig_nids++, tls12_md,
- sizeof(tls12_md) / sizeof(tls12_lookup));
- rsign = tls12_find_id(*psig_nids++, tls12_sig,
- sizeof(tls12_sig) / sizeof(tls12_lookup));
+ rhash = tls12_find_id(*psig_nids++, tls12_md, OSSL_NELEM(tls12_md));
+ rsign = tls12_find_id(*psig_nids++, tls12_sig, OSSL_NELEM(tls12_sig));
if (rhash == -1 || rsign == -1)
goto err;
} ssl_trace_tbl;
# define ssl_trace_str(val, tbl) \
- do_ssl_trace_str(val, tbl, sizeof(tbl)/sizeof(ssl_trace_tbl))
+ do_ssl_trace_str(val, tbl, OSSL_NELEM(tbl))
# define ssl_trace_list(bio, indent, msg, msglen, value, table) \
do_ssl_trace_list(bio, indent, msg, msglen, value, \
- table, sizeof(table)/sizeof(ssl_trace_tbl))
+ table, OSSL_NELEM(table))
static const char *do_ssl_trace_str(int val, ssl_trace_tbl *tbl, size_t ntbl)
{