if ((flags & CMS_NO_SIGNER_CERT_VERIFY) == 0 || cadesVerify) {
if (cadesVerify) {
/* Certificate trust chain is required to check CAdES signature */
- si_chains = OPENSSL_zalloc(scount * sizeof(si_chains[0]));
+ si_chains = OPENSSL_calloc(scount, sizeof(si_chains[0]));
if (si_chains == NULL)
goto err;
}
{
void *p;
- p = OPENSSL_zalloc(no * size);
+ p = OPENSSL_calloc(no, size);
return p;
}
}
cnt = sk_CONF_VALUE_num(cmd_lists);
ssl_module_free(md);
- ssl_names = OPENSSL_zalloc(sizeof(*ssl_names) * cnt);
+ ssl_names = OPENSSL_calloc(cnt, sizeof(*ssl_names));
if (ssl_names == NULL)
goto err;
ssl_names_count = cnt;
if (ssl_name->name == NULL)
goto err;
cnt = sk_CONF_VALUE_num(cmds);
- ssl_name->cmds = OPENSSL_zalloc(cnt * sizeof(struct ssl_conf_cmd_st));
+ ssl_name->cmds = OPENSSL_calloc(cnt, sizeof(struct ssl_conf_cmd_st));
if (ssl_name->cmds == NULL)
goto err;
ssl_name->cmd_count = cnt;
namemap = ossl_namemap_stored(libctx);
end = sk_OPENSSL_CSTRING_num(encoder_data.names);
if (end > 0) {
- encoder_data.id_names = OPENSSL_malloc(end * sizeof(int));
+ encoder_data.id_names = OPENSSL_malloc_array(end, sizeof(int));
if (encoder_data.id_names == NULL) {
sk_OPENSSL_CSTRING_free(keymgmt_data.names);
goto err;
if (mx < (int)OSSL_NELEM(stack))
storage = stack;
else
- storage = OPENSSL_malloc(sizeof(*storage) * mx);
+ storage = OPENSSL_malloc_array(mx, sizeof(*storage));
if (storage != NULL)
for (i = 0; i < mx; i++)
storage[i] = sk_EX_CALLBACK_value(ip->meth, i);
if (mx < (int)OSSL_NELEM(stack))
storage = stack;
else
- storage = OPENSSL_malloc(sizeof(*storage) * mx);
+ storage = OPENSSL_malloc_array(mx, sizeof(*storage));
if (storage != NULL)
for (i = 0; i < mx; i++)
storage[i] = sk_EX_CALLBACK_value(ip->meth, i);
if (mx < (int)OSSL_NELEM(stack))
storage = stack;
else
- storage = OPENSSL_malloc(sizeof(*storage) * mx);
+ storage = OPENSSL_malloc_array(mx, sizeof(*storage));
if (storage != NULL)
for (i = 0; i < mx; i++) {
storage[i].excb = sk_EX_CALLBACK_value(ip->meth, i);
{
struct ht_neighborhood_st *ret;
- ret = OPENSSL_aligned_alloc(sizeof(struct ht_neighborhood_st) * len,
- CACHE_LINE_BYTES, freeptr);
+ ret = OPENSSL_aligned_alloc_array(len, sizeof(struct ht_neighborhood_st),
+ CACHE_LINE_BYTES, freeptr);
/* fall back to regular malloc */
if (ret == NULL) {
- ret = *freeptr = OPENSSL_malloc(sizeof(struct ht_neighborhood_st) * len);
+ ret = *freeptr =
+ OPENSSL_malloc_array(len, sizeof(struct ht_neighborhood_st));
if (ret == NULL)
return NULL;
}
(size_t)(ctx->plat.s390x.blk_size * HMAC_S390X_BUF_NUM_BLOCKS)) {
OPENSSL_clear_free(ctx->plat.s390x.buf, ctx->plat.s390x.size);
ctx->plat.s390x.size = 0;
- ctx->plat.s390x.buf = OPENSSL_zalloc(ctx->plat.s390x.blk_size *
- HMAC_S390X_BUF_NUM_BLOCKS);
+ ctx->plat.s390x.buf = OPENSSL_calloc(HMAC_S390X_BUF_NUM_BLOCKS,
+ ctx->plat.s390x.blk_size);
if (ctx->plat.s390x.buf == NULL)
return 0;
ctx->plat.s390x.size = ctx->plat.s390x.blk_size *
if ((ret = OPENSSL_zalloc(sizeof(*ret))) == NULL)
return NULL;
- if ((ret->b = OPENSSL_zalloc(sizeof(*ret->b) * MIN_NODES)) == NULL)
+ if ((ret->b = OPENSSL_calloc(MIN_NODES, sizeof(*ret->b))) == NULL)
goto err;
ret->comp = ((c == NULL) ? (OPENSSL_LH_COMPFUNC)strcmp : c);
ret->hash = ((h == NULL) ? (OPENSSL_LH_HASHFUNC)OPENSSL_LH_strhash : h);
pmax = lh->pmax;
if (p + 1 >= pmax) {
j = nni * 2;
- n = OPENSSL_realloc(lh->b, sizeof(OPENSSL_LH_NODE *) * j);
+ n = OPENSSL_realloc_array(lh->b, j, sizeof(OPENSSL_LH_NODE *));
if (n == NULL) {
lh->error++;
return 0;
np = lh->b[lh->p + lh->pmax - 1];
lh->b[lh->p + lh->pmax - 1] = NULL; /* 24/07-92 - eay - weird but :-( */
if (lh->p == 0) {
- n = OPENSSL_realloc(lh->b,
- (unsigned int)(sizeof(OPENSSL_LH_NODE *) * lh->pmax));
+ n = OPENSSL_realloc_array(lh->b, lh->pmax, sizeof(OPENSSL_LH_NODE *));
if (n == NULL) {
/* fputs("realloc error in lhash", stderr); */
lh->error++;
for (i = sh.bittable_size; i; i >>= 1)
sh.freelist_size++;
- sh.freelist = OPENSSL_zalloc(sh.freelist_size * sizeof(char *));
+ sh.freelist = OPENSSL_calloc(sh.freelist_size, sizeof(char *));
OPENSSL_assert(sh.freelist != NULL);
if (sh.freelist == NULL)
goto err;
VECTOR s1_ntt;
VECTOR t;
- polys = OPENSSL_malloc(sizeof(*polys) * (k + l + k * l));
+ polys = OPENSSL_malloc_array(k + l + k * l, sizeof(*polys));
if (polys == NULL)
return 0;
if (key->pub_encoding == NULL || key->priv_encoding == 0)
return 0;
- polys = OPENSSL_malloc(sizeof(*polys) * (2 * k));
+ polys = OPENSSL_malloc_array(2 * k, sizeof(*polys));
if (polys == NULL)
return 0;
md_ctx = EVP_MD_CTX_new();
static ossl_inline ossl_unused
int vector_alloc(VECTOR *v, size_t num_polys)
{
- v->poly = OPENSSL_malloc(num_polys * sizeof(POLY));
+ v->poly = OPENSSL_malloc_array(num_polys, sizeof(POLY));
if (v->poly == NULL)
return 0;
v->num_poly = num_polys;
static ossl_inline ossl_unused
int vector_secure_alloc(VECTOR *v, size_t num_polys)
{
- v->poly = OPENSSL_secure_malloc(num_polys * sizeof(POLY));
+ v->poly = OPENSSL_secure_malloc_array(num_polys, sizeof(POLY));
if (v->poly == NULL)
return 0;
v->num_poly = num_polys;
* the index.
*/
ctx->max_l_index += (idx - ctx->max_l_index + 4) & ~3;
- tmp_ptr = OPENSSL_realloc(ctx->l, ctx->max_l_index * sizeof(OCB_BLOCK));
+ tmp_ptr = OPENSSL_realloc_array(ctx->l, ctx->max_l_index, sizeof(OCB_BLOCK));
if (tmp_ptr == NULL) /* prevent ctx->l from being clobbered */
return NULL;
ctx->l = tmp_ptr;
memset(ctx, 0, sizeof(*ctx));
ctx->l_index = 0;
ctx->max_l_index = 5;
- if ((ctx->l = OPENSSL_malloc(ctx->max_l_index * 16)) == NULL)
+ if ((ctx->l = OPENSSL_malloc_array(ctx->max_l_index, 16)) == NULL)
return 0;
/*
if (keydec)
dest->keydec = keydec;
if (src->l) {
- if ((dest->l = OPENSSL_malloc(src->max_l_index * 16)) == NULL)
+ if ((dest->l = OPENSSL_malloc_array(src->max_l_index, 16)) == NULL)
return 0;
memcpy(dest->l, src->l, (src->l_index + 1) * 16);
}
d.type = type;
d.names =
- OPENSSL_malloc(sizeof(*d.names) * lh_OBJ_NAME_num_items(names_lh));
+ OPENSSL_malloc_array(lh_OBJ_NAME_num_items(names_lh), sizeof(*d.names));
/* Really should return an error if !d.names...but its a void function! */
if (d.names != NULL) {
d.n = 0;
qsort(list2, list2_sz, sizeof(OSSL_PARAM *), compare_params);
/* Allocate enough space to store the merged parameters */
- params = OPENSSL_zalloc((list1_sz + list2_sz + 1) * sizeof(*p1));
+ params = OPENSSL_calloc(list1_sz + list2_sz + 1, sizeof(*p1));
if (params == NULL)
return NULL;
dst = params;
}
}
- buf = OPENSSL_malloc(PEM_BUFSIZE * 8);
+ buf = OPENSSL_malloc_array(PEM_BUFSIZE, 8);
if (buf == NULL)
goto err;
if (!CRYPTO_THREAD_write_lock(store->lock))
return 0;
if (store->provinfosz == 0) {
- store->provinfo = OPENSSL_zalloc(sizeof(*store->provinfo)
- * BUILTINS_BLOCK_SIZE);
+ store->provinfo = OPENSSL_calloc(BUILTINS_BLOCK_SIZE,
+ sizeof(*store->provinfo));
if (store->provinfo == NULL)
goto err;
store->provinfosz = BUILTINS_BLOCK_SIZE;
OSSL_PROVIDER_INFO *tmpbuiltins;
size_t newsz = store->provinfosz + BUILTINS_BLOCK_SIZE;
- tmpbuiltins = OPENSSL_realloc(store->provinfo,
- sizeof(*store->provinfo) * newsz);
+ tmpbuiltins = OPENSSL_realloc_array(store->provinfo,
+ newsz, sizeof(*store->provinfo));
if (tmpbuiltins == NULL)
goto err;
store->provinfo = tmpbuiltins;
/* Allocate one extra item for the "library" name */
prov->error_strings =
- OPENSSL_zalloc(sizeof(ERR_STRING_DATA) * (cnt + 1));
+ OPENSSL_calloc(cnt + 1, sizeof(ERR_STRING_DATA));
if (prov->error_strings == NULL)
goto end;
* decoded.
*/
plaintxt_len = RSA_size(rsa);
- plaintxt = OPENSSL_zalloc(plaintxt_len * 3);
+ plaintxt = OPENSSL_calloc(plaintxt_len, 3);
if (plaintxt == NULL)
goto err;
ciphertxt = plaintxt + plaintxt_len;
goto done;
}
- x2y2 = OPENSSL_zalloc(2 * field_size);
+ x2y2 = OPENSSL_calloc(2, field_size);
C3 = OPENSSL_zalloc(C3_size);
if (x2y2 == NULL || C3 == NULL)
}
msg_mask = OPENSSL_zalloc(msg_len);
- x2y2 = OPENSSL_zalloc(2 * field_size);
+ x2y2 = OPENSSL_calloc(2, field_size);
computed_C3 = OPENSSL_zalloc(hash_size);
if (msg_mask == NULL || x2y2 == NULL || computed_C3 == NULL)
static ossl_inline void **alloc_node(void)
{
- return OPENSSL_zalloc(SA_BLOCK_MAX * sizeof(void *));
+ return OPENSSL_calloc(SA_BLOCK_MAX, sizeof(void *));
}
int ossl_sa_set(OPENSSL_SA *sa, ossl_uintmax_t posn, void *val)
goto err;
if (y != N && BN_ucmp(y, N) >= 0)
goto err;
- if ((tmp = OPENSSL_malloc(numN * 2)) == NULL)
+ if ((tmp = OPENSSL_malloc_array(numN, 2)) == NULL)
goto err;
if (BN_bn2binpad(x, tmp, numN) < 0
|| BN_bn2binpad(y, tmp + numN, numN) < 0
if (*salt == NULL) {
char *tmp_salt;
- if ((tmp_salt = OPENSSL_malloc(SRP_RANDOM_SALT_LEN * 2)) == NULL) {
+ if ((tmp_salt = OPENSSL_malloc_array(SRP_RANDOM_SALT_LEN, 2)) == NULL)
goto err;
- }
if (!t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN)) {
OPENSSL_free(tmp_salt);
goto err;
}
/* duplicate |sk->data| content */
- ret->data = OPENSSL_malloc(sizeof(*ret->data) * sk->num_alloc);
+ ret->data = OPENSSL_malloc_array(sk->num_alloc, sizeof(*ret->data));
if (ret->data == NULL)
goto err;
memcpy(ret->data, sk->data, sizeof(void *) * sk->num);
}
ret->num_alloc = sk->num > min_nodes ? sk->num : min_nodes;
- ret->data = OPENSSL_zalloc(sizeof(*ret->data) * ret->num_alloc);
+ ret->data = OPENSSL_calloc(ret->num_alloc, sizeof(*ret->data));
if (ret->data == NULL)
goto err;
* At this point, |st->num_alloc| and |st->num| are 0;
* so |num_alloc| value is |n| or |min_nodes| if greater than |n|.
*/
- if ((st->data = OPENSSL_zalloc(sizeof(void *) * num_alloc)) == NULL)
+ if ((st->data = OPENSSL_calloc(num_alloc, sizeof(void *))) == NULL)
return 0;
st->num_alloc = num_alloc;
return 1;
return 1;
}
- tmpdata = OPENSSL_realloc((void *)st->data, sizeof(void *) * num_alloc);
+ tmpdata = OPENSSL_realloc_array((void *)st->data, num_alloc, sizeof(void *));
if (tmpdata == NULL)
return 0;
/*
* we didn't find one, but that's ok, just initialize it now
*/
- mkey = OPENSSL_zalloc(sizeof(MASTER_KEY_ENTRY) * CRYPTO_THREAD_LOCAL_KEY_MAX);
+ mkey = OPENSSL_calloc(CRYPTO_THREAD_LOCAL_KEY_MAX,
+ sizeof(MASTER_KEY_ENTRY));
if (mkey == NULL)
return 0;
/*
uint32_t count)
{
struct rcu_qp *new =
- OPENSSL_zalloc(sizeof(*new) * count);
+ OPENSSL_calloc(count, sizeof(*new));
lock->group_count = count;
return new;
uint32_t count)
{
struct rcu_qp *new =
- OPENSSL_zalloc(sizeof(*new) * count);
+ OPENSSL_calloc(count, sizeof(*new));
lock->group_count = count;
return new;
ret->qual = NULL;
if ((ret->data = sk_OPENSSL_PSTRING_new_null()) == NULL)
goto err;
- if ((ret->index = OPENSSL_malloc(sizeof(*ret->index) * num)) == NULL)
+ if ((ret->index = OPENSSL_malloc_array(num, sizeof(*ret->index))) == NULL)
goto err;
- if ((ret->qual = OPENSSL_malloc(sizeof(*(ret->qual)) * num)) == NULL)
+ if ((ret->qual = OPENSSL_malloc_array(num, sizeof(*(ret->qual)))) == NULL)
goto err;
for (i = 0; i < num; i++) {
ret->index[i] = NULL;
* policies of anyPolicy. (RFC 5280 has the TA at depth 0 and the leaf at
* depth n, we have the leaf at depth 0 and the TA at depth n).
*/
- if ((tree->levels = OPENSSL_zalloc(sizeof(*tree->levels)*(n+1))) == NULL) {
+ if ((tree->levels = OPENSSL_calloc(n + 1, sizeof(*tree->levels))) == NULL) {
OPENSSL_free(tree);
return X509_PCY_TREE_INTERNAL;
}
if (der_len <= 0)
return NULL;
der_spki = OPENSSL_malloc(der_len);
- b64_str = OPENSSL_malloc(der_len * 2);
+ b64_str = OPENSSL_malloc_array(der_len, 2);
if (der_spki == NULL || b64_str == NULL) {
OPENSSL_free(der_spki);
OPENSSL_free(b64_str);