param_len = len;
/* Allocate space to store the padded data for (p, a, b, x, y, order) */
- param_bytes = OPENSSL_malloc(param_len * NUM_BN_FIELDS);
+ param_bytes = OPENSSL_malloc_array(NUM_BN_FIELDS, param_len);
if (param_bytes == NULL)
goto end;
totalnum = num + numblocks;
- wsize = OPENSSL_malloc(totalnum * sizeof(wsize[0]));
- wNAF_len = OPENSSL_malloc(totalnum * sizeof(wNAF_len[0]));
+ wsize = OPENSSL_malloc_array(totalnum, sizeof(wsize[0]));
+ wNAF_len = OPENSSL_malloc_array(totalnum, sizeof(wNAF_len[0]));
/* include space for pivot */
- wNAF = OPENSSL_malloc((totalnum + 1) * sizeof(wNAF[0]));
- val_sub = OPENSSL_malloc(totalnum * sizeof(val_sub[0]));
+ wNAF = OPENSSL_malloc_array(totalnum + 1, sizeof(wNAF[0]));
+ val_sub = OPENSSL_malloc_array(totalnum, sizeof(val_sub[0]));
/* Ensure wNAF is initialised in case we end up going to err */
if (wNAF != NULL)
* 'val_sub[i]' is a pointer to the subarray for the i-th point, or to a
* subarray of 'pre_comp->points' if we already have precomputation.
*/
- val = OPENSSL_malloc((num_val + 1) * sizeof(val[0]));
+ val = OPENSSL_malloc_array(num_val + 1, sizeof(val[0]));
if (val == NULL)
goto err;
val[num_val] = NULL; /* pivot element */
num = pre_points_per_block * numblocks; /* number of points to compute
* and store */
- points = OPENSSL_malloc(sizeof(*points) * (num + 1));
+ points = OPENSSL_malloc_array(num + 1, sizeof(*points));
if (points == NULL)
goto err;
*/
mixed = 1;
}
- secrets = OPENSSL_zalloc(sizeof(*secrets) * num_points);
- pre_comp = OPENSSL_zalloc(sizeof(*pre_comp) * num_points);
+ secrets = OPENSSL_calloc(num_points, sizeof(*secrets));
+ pre_comp = OPENSSL_calloc(num_points, sizeof(*pre_comp));
if (mixed)
tmp_felems =
- OPENSSL_malloc(sizeof(felem) * (num_points * 17 + 1));
+ OPENSSL_malloc_array(num_points * 17 + 1, sizeof(felem));
if ((secrets == NULL) || (pre_comp == NULL)
|| (mixed && (tmp_felems == NULL)))
goto err;
*/
mixed = 1;
}
- secrets = OPENSSL_zalloc(sizeof(*secrets) * num_points);
- pre_comp = OPENSSL_zalloc(sizeof(*pre_comp) * num_points);
+ secrets = OPENSSL_calloc(num_points, sizeof(*secrets));
+ pre_comp = OPENSSL_calloc(num_points, sizeof(*pre_comp));
if (mixed)
- tmp_smallfelems =
- OPENSSL_malloc(sizeof(*tmp_smallfelems) * (num_points * 17 + 1));
+ tmp_smallfelems = OPENSSL_malloc_array(num_points * 17 + 1,
+ sizeof(*tmp_smallfelems));
if ((secrets == NULL) || (pre_comp == NULL)
|| (mixed && (tmp_smallfelems == NULL)))
goto err;
*/
mixed = 1;
}
- secrets = OPENSSL_zalloc(sizeof(*secrets) * num_points);
- pre_comp = OPENSSL_zalloc(sizeof(*pre_comp) * num_points);
+ secrets = OPENSSL_calloc(num_points, sizeof(*secrets));
+ pre_comp = OPENSSL_calloc(num_points, sizeof(*pre_comp));
if (mixed)
tmp_felems =
- OPENSSL_malloc(sizeof(*tmp_felems) * (num_points * 17 + 1));
+ OPENSSL_malloc_array(num_points * 17 + 1, sizeof(*tmp_felems));
if ((secrets == NULL) || (pre_comp == NULL)
|| (mixed && (tmp_felems == NULL)))
goto err;
*/
mixed = 1;
}
- secrets = OPENSSL_zalloc(sizeof(*secrets) * num_points);
- pre_comp = OPENSSL_zalloc(sizeof(*pre_comp) * num_points);
+ secrets = OPENSSL_calloc(num_points, sizeof(*secrets));
+ pre_comp = OPENSSL_calloc(num_points, sizeof(*pre_comp));
if (mixed)
tmp_felems =
- OPENSSL_malloc(sizeof(*tmp_felems) * (num_points * 17 + 1));
+ OPENSSL_malloc_array(num_points * 17 + 1, sizeof(*tmp_felems));
if ((secrets == NULL) || (pre_comp == NULL)
|| (mixed && (tmp_felems == NULL)))
goto err;
if ((num * 16 + 6) > OPENSSL_MALLOC_MAX_NELEMS(P256_POINT)
|| (table_storage =
OPENSSL_malloc((num * 16 + 5) * sizeof(P256_POINT) + 64)) == NULL
- || (p_str =
- OPENSSL_malloc(num * 33 * sizeof(unsigned char))) == NULL
- || (scalars = OPENSSL_malloc(num * sizeof(BIGNUM *))) == NULL)
+ || (p_str = OPENSSL_malloc_array(num, 33)) == NULL
+ || (scalars = OPENSSL_malloc_array(num, sizeof(BIGNUM *))) == NULL)
goto err;
table = (void *)ALIGNPTR(table_storage, 64);
* Without a precomputed table for the generator, it has to be
* handled like a normal point.
*/
- new_scalars = OPENSSL_malloc((num + 1) * sizeof(BIGNUM *));
+ new_scalars = OPENSSL_malloc_array(num + 1, sizeof(BIGNUM *));
if (new_scalars == NULL)
goto err;
- new_points = OPENSSL_malloc((num + 1) * sizeof(EC_POINT *));
+ new_points = OPENSSL_malloc_array(num + 1, sizeof(EC_POINT *));
if (new_points == NULL)
goto err;
} t, p;
if (num > OPENSSL_MALLOC_MAX_NELEMS(P256_POINT)
- || (scalars = OPENSSL_malloc(num * sizeof(BIGNUM *))) == NULL) {
+ || (scalars = OPENSSL_malloc_array(num, sizeof(BIGNUM *))) == NULL) {
ECerr(ERR_LIB_EC, ERR_R_MALLOC_FAILURE);
goto err;
}
if (tmp_Z == NULL)
goto err;
- prod_Z = OPENSSL_malloc(num * sizeof(prod_Z[0]));
+ prod_Z = OPENSSL_malloc_array(num, sizeof(prod_Z[0]));
if (prod_Z == NULL)
goto err;
for (i = 0; i < num; i++) {