For tests, rename TEST_CALLOC_OR_FAIL() to just TEST_CALLOC()

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
This commit is contained in:
Tom Cosgrove 2023-07-21 11:31:13 +01:00
parent 412a813ad4
commit 05b2a87ea0
40 changed files with 339 additions and 339 deletions

View file

@ -123,7 +123,7 @@
* This expression may be evaluated multiple times.
*
*/
#define TEST_CALLOC_OR_FAIL(pointer, length) \
#define TEST_CALLOC(pointer, length) \
do { \
TEST_ASSERT((pointer) == NULL); \
if ((length) != 0) { \
@ -134,11 +134,11 @@
} while (0)
/* For backwards compatibility */
#define ASSERT_ALLOC(pointer, length) TEST_CALLOC_OR_FAIL(pointer, length)
#define ASSERT_ALLOC(pointer, length) TEST_CALLOC(pointer, length)
/** Allocate memory dynamically. If the allocation fails, skip the test case.
*
* This macro behaves like #TEST_CALLOC_OR_FAIL, except that if the allocation
* This macro behaves like #TEST_CALLOC, except that if the allocation
* fails, it marks the test as skipped rather than failed.
*/
#define TEST_CALLOC_OR_SKIP(pointer, length) \

View file

@ -506,7 +506,7 @@ psa_status_t mbedtls_test_psa_key_agreement_with_self(
key_bits = psa_get_key_bits(&attributes);
public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(private_key_type);
public_key_length = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(public_key_type, key_bits);
TEST_CALLOC_OR_FAIL(public_key, public_key_length);
TEST_CALLOC(public_key, public_key_length);
PSA_ASSERT(psa_export_public_key(key, public_key, public_key_length,
&public_key_length));
@ -548,7 +548,7 @@ psa_status_t mbedtls_test_psa_raw_key_agreement_with_self(
key_bits = psa_get_key_bits(&attributes);
public_key_type = PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(private_key_type);
public_key_length = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(public_key_type, key_bits);
TEST_CALLOC_OR_FAIL(public_key, public_key_length);
TEST_CALLOC(public_key, public_key_length);
PSA_ASSERT(psa_export_public_key(key,
public_key, public_key_length,
&public_key_length));
@ -838,7 +838,7 @@ static int exercise_export_key(mbedtls_svc_key_id_t key,
exported_size = PSA_EXPORT_KEY_OUTPUT_SIZE(
psa_get_key_type(&attributes),
psa_get_key_bits(&attributes));
TEST_CALLOC_OR_FAIL(exported, exported_size);
TEST_CALLOC(exported, exported_size);
if ((usage & PSA_KEY_USAGE_EXPORT) == 0 &&
!PSA_KEY_TYPE_IS_PUBLIC_KEY(psa_get_key_type(&attributes))) {
@ -881,7 +881,7 @@ static int exercise_export_public_key(mbedtls_svc_key_id_t key)
exported_size = PSA_EXPORT_KEY_OUTPUT_SIZE(
psa_get_key_type(&attributes),
psa_get_key_bits(&attributes));
TEST_CALLOC_OR_FAIL(exported, exported_size);
TEST_CALLOC(exported, exported_size);
TEST_EQUAL(psa_export_public_key(key, exported,
exported_size, &exported_length),
@ -894,7 +894,7 @@ static int exercise_export_public_key(mbedtls_svc_key_id_t key)
psa_get_key_type(&attributes));
exported_size = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(public_type,
psa_get_key_bits(&attributes));
TEST_CALLOC_OR_FAIL(exported, exported_size);
TEST_CALLOC(exported, exported_size);
PSA_ASSERT(psa_export_public_key(key,
exported, exported_size,

View file

@ -91,7 +91,7 @@ void mbedtls_test_init_handshake_options(
opts->resize_buffers = 1;
#if defined(MBEDTLS_SSL_CACHE_C)
opts->cache = NULL;
TEST_CALLOC_OR_FAIL(opts->cache, 1);
TEST_CALLOC(opts->cache, 1);
mbedtls_ssl_cache_init(opts->cache);
#if defined(MBEDTLS_HAVE_TIME)
TEST_EQUAL(mbedtls_ssl_cache_get_timeout(opts->cache),
@ -627,9 +627,9 @@ int mbedtls_test_ssl_endpoint_certificate_init(mbedtls_test_ssl_endpoint *ep,
}
cert = &(ep->cert);
TEST_CALLOC_OR_FAIL(cert->ca_cert, 1);
TEST_CALLOC_OR_FAIL(cert->cert, 1);
TEST_CALLOC_OR_FAIL(cert->pkey, 1);
TEST_CALLOC(cert->ca_cert, 1);
TEST_CALLOC(cert->cert, 1);
TEST_CALLOC(cert->pkey, 1);
mbedtls_x509_crt_init(cert->ca_cert);
mbedtls_x509_crt_init(cert->cert);

View file

@ -545,9 +545,9 @@ void aes_ecb_copy_context(data_t *key)
struct align1 *dec1 = NULL;
/* All peak alignment */
TEST_CALLOC_OR_FAIL(src0, 1);
TEST_CALLOC_OR_FAIL(enc0, 1);
TEST_CALLOC_OR_FAIL(dec0, 1);
TEST_CALLOC(src0, 1);
TEST_CALLOC(enc0, 1);
TEST_CALLOC(dec0, 1);
if (!test_copy(key, &src0->ctx, &enc0->ctx, &dec0->ctx)) {
goto exit;
}
@ -559,9 +559,9 @@ void aes_ecb_copy_context(data_t *key)
dec0 = NULL;
/* Original shifted */
TEST_CALLOC_OR_FAIL(src1, 1);
TEST_CALLOC_OR_FAIL(enc0, 1);
TEST_CALLOC_OR_FAIL(dec0, 1);
TEST_CALLOC(src1, 1);
TEST_CALLOC(enc0, 1);
TEST_CALLOC(dec0, 1);
if (!test_copy(key, &src1->ctx, &enc0->ctx, &dec0->ctx)) {
goto exit;
}
@ -573,9 +573,9 @@ void aes_ecb_copy_context(data_t *key)
dec0 = NULL;
/* Copies shifted */
TEST_CALLOC_OR_FAIL(src0, 1);
TEST_CALLOC_OR_FAIL(enc1, 1);
TEST_CALLOC_OR_FAIL(dec1, 1);
TEST_CALLOC(src0, 1);
TEST_CALLOC(enc1, 1);
TEST_CALLOC(dec1, 1);
if (!test_copy(key, &src0->ctx, &enc1->ctx, &dec1->ctx)) {
goto exit;
}
@ -587,9 +587,9 @@ void aes_ecb_copy_context(data_t *key)
dec1 = NULL;
/* Source and copies shifted */
TEST_CALLOC_OR_FAIL(src1, 1);
TEST_CALLOC_OR_FAIL(enc1, 1);
TEST_CALLOC_OR_FAIL(dec1, 1);
TEST_CALLOC(src1, 1);
TEST_CALLOC(enc1, 1);
TEST_CALLOC(dec1, 1);
if (!test_copy(key, &src1->ctx, &enc1->ctx, &dec1->ctx)) {
goto exit;
}

View file

@ -135,7 +135,7 @@ int get_len_step(const data_t *input, size_t buffer_size,
/* Allocate a new buffer of exactly the length to parse each time.
* This gives memory sanitizers a chance to catch buffer overreads. */
if (buffer_size == 0) {
TEST_CALLOC_OR_FAIL(buf, 1);
TEST_CALLOC(buf, 1);
end = buf + 1;
p = end;
} else {
@ -247,7 +247,7 @@ void parse_prefixes(const data_t *input,
mbedtls_test_set_step(buffer_size);
/* Allocate a new buffer of exactly the length to parse each time.
* This gives memory sanitizers a chance to catch buffer overreads. */
TEST_CALLOC_OR_FAIL(buf, buffer_size);
TEST_CALLOC(buf, buffer_size);
memcpy(buf, input->x, buffer_size);
p = buf;
ret = nested_parse(&p, buf + buffer_size);
@ -506,7 +506,7 @@ void get_mpi_too_large()
mbedtls_mpi_init(&actual_mpi);
TEST_CALLOC_OR_FAIL(buf, size);
TEST_CALLOC(buf, size);
buf[0] = 0x02; /* tag: INTEGER */
buf[1] = 0x84; /* 4-octet length */
buf[2] = (too_many_octets >> 24) & 0xff;
@ -729,10 +729,10 @@ void free_named_data(int with_oid, int with_val, int with_next)
{ { 0x06, 0, NULL }, { 0, 0, NULL }, NULL, 0 };
if (with_oid) {
TEST_CALLOC_OR_FAIL(head.oid.p, 1);
TEST_CALLOC(head.oid.p, 1);
}
if (with_val) {
TEST_CALLOC_OR_FAIL(head.val.p, 1);
TEST_CALLOC(head.val.p, 1);
}
if (with_next) {
head.next = &next;
@ -758,7 +758,7 @@ void free_named_data_list(int length)
for (i = 0; i < length; i++) {
mbedtls_asn1_named_data *new = NULL;
TEST_CALLOC_OR_FAIL(new, 1);
TEST_CALLOC(new, 1);
new->next = head;
head = new;
}

View file

@ -17,7 +17,7 @@ int generic_write_start_step(generic_write_data_t *data)
mbedtls_test_set_step(data->size);
mbedtls_free(data->output);
data->output = NULL;
TEST_CALLOC_OR_FAIL(data->output, data->size == 0 ? 1 : data->size);
TEST_CALLOC(data->output, data->size == 0 ? 1 : data->size);
data->end = data->output + data->size;
data->p = data->end;
data->start = data->end - data->size;
@ -296,7 +296,7 @@ void mbedtls_asn1_write_algorithm_identifier(data_t *oid,
size_t len_complete = data_len + par_len;
unsigned char expected_params_tag;
size_t expected_params_len;
TEST_CALLOC_OR_FAIL(buf_complete, len_complete);
TEST_CALLOC(buf_complete, len_complete);
unsigned char *end_complete = buf_complete + len_complete;
memcpy(buf_complete, data.p, data_len);
if (par_len == 0) {
@ -404,7 +404,7 @@ void test_asn1_write_bitstrings(data_t *bitstring, int bits,
TEST_ASSERT(bitstring->len >= byte_length);
#if defined(MBEDTLS_ASN1_PARSE_C)
TEST_CALLOC_OR_FAIL(masked_bitstring, byte_length);
TEST_CALLOC(masked_bitstring, byte_length);
if (byte_length != 0) {
memcpy(masked_bitstring, bitstring->x, byte_length);
if (bits % 8 != 0) {
@ -477,7 +477,7 @@ void store_named_data_find(data_t *oid0, data_t *oid1,
}
pointers[ARRAY_LENGTH(nd)] = NULL;
for (i = 0; i < ARRAY_LENGTH(nd); i++) {
TEST_CALLOC_OR_FAIL(nd[i].oid.p, oid[i]->len);
TEST_CALLOC(nd[i].oid.p, oid[i]->len);
memcpy(nd[i].oid.p, oid[i]->x, oid[i]->len);
nd[i].oid.len = oid[i]->len;
nd[i].next = pointers[i+1];
@ -529,7 +529,7 @@ void store_named_data_val_found(int old_len, int new_len)
unsigned char *new_val = (unsigned char *) "new value";
if (old_len != 0) {
TEST_CALLOC_OR_FAIL(nd.val.p, (size_t) old_len);
TEST_CALLOC(nd.val.p, (size_t) old_len);
old_val = nd.val.p;
nd.val.len = old_len;
memset(old_val, 'x', old_len);

View file

@ -493,10 +493,10 @@ void mpi_core_cond_swap(char *input_X,
TEST_EQUAL(limbs_X, limbs_Y);
TEST_ASSERT(copy_limbs <= limbs);
TEST_CALLOC_OR_FAIL(X, limbs);
TEST_CALLOC(X, limbs);
memcpy(X, tmp_X, bytes);
TEST_CALLOC_OR_FAIL(Y, limbs);
TEST_CALLOC(Y, limbs);
memcpy(Y, tmp_Y, bytes);
/* condition is false */
@ -601,7 +601,7 @@ void mpi_core_add_and_add_if(char *input_A, char *input_B,
TEST_EQUAL(A_limbs, S_limbs);
size_t limbs = A_limbs;
TEST_CALLOC_OR_FAIL(X, limbs);
TEST_CALLOC(X, limbs);
TEST_ASSERT(mpi_core_verify_add(A, B, limbs, S, carry, X));
TEST_ASSERT(mpi_core_verify_add_if(A, B, limbs, S, carry, X));
@ -646,15 +646,15 @@ void mpi_core_sub(char *input_A, char *input_B,
/* Now let's get arrays of mbedtls_mpi_uints, rather than MPI structures */
/* TEST_CALLOC_OR_FAIL() uses calloc() under the hood, so these do get zeroed */
TEST_CALLOC_OR_FAIL(a, bytes);
TEST_CALLOC_OR_FAIL(b, bytes);
TEST_CALLOC_OR_FAIL(x, bytes);
TEST_CALLOC_OR_FAIL(r, bytes);
/* TEST_CALLOC() uses calloc() under the hood, so these do get zeroed */
TEST_CALLOC(a, bytes);
TEST_CALLOC(b, bytes);
TEST_CALLOC(x, bytes);
TEST_CALLOC(r, bytes);
/* Populate the arrays. As the mbedtls_mpi_uint[]s in mbedtls_mpis (and as
* processed by mbedtls_mpi_core_sub()) are little endian, we can just
* copy what we have as long as MSBs are 0 (which they are from TEST_CALLOC_OR_FAIL())
* copy what we have as long as MSBs are 0 (which they are from TEST_CALLOC())
*/
memcpy(a, A.p, A.n * sizeof(mbedtls_mpi_uint));
memcpy(b, B.p, B.n * sizeof(mbedtls_mpi_uint));
@ -759,13 +759,13 @@ void mpi_core_mla(char *input_A, char *input_B, char *input_S,
/* Now let's get arrays of mbedtls_mpi_uints, rather than MPI structures */
/* TEST_CALLOC_OR_FAIL() uses calloc() under the hood, so these do get zeroed */
TEST_CALLOC_OR_FAIL(a, bytes);
TEST_CALLOC_OR_FAIL(x, bytes);
/* TEST_CALLOC() uses calloc() under the hood, so these do get zeroed */
TEST_CALLOC(a, bytes);
TEST_CALLOC(x, bytes);
/* Populate the arrays. As the mbedtls_mpi_uint[]s in mbedtls_mpis (and as
* processed by mbedtls_mpi_core_mla()) are little endian, we can just
* copy what we have as long as MSBs are 0 (which they are from TEST_CALLOC_OR_FAIL()).
* copy what we have as long as MSBs are 0 (which they are from TEST_CALLOC()).
*/
memcpy(a, A.p, A.n * sizeof(mbedtls_mpi_uint));
memcpy(x, X->p, X->n * sizeof(mbedtls_mpi_uint));
@ -1017,8 +1017,8 @@ void mpi_core_ct_uint_table_lookup(int bitlen, int window_size)
mbedtls_mpi_uint *table = NULL;
mbedtls_mpi_uint *dest = NULL;
TEST_CALLOC_OR_FAIL(table, limbs * count);
TEST_CALLOC_OR_FAIL(dest, limbs);
TEST_CALLOC(table, limbs * count);
TEST_CALLOC(dest, limbs);
/*
* Fill the table with a unique counter so that differences are easily
@ -1070,7 +1070,7 @@ void mpi_core_fill_random(int wanted_bytes_arg, int extra_rng_bytes,
int ret;
/* Prepare an RNG with known output, limited to rng_bytes. */
TEST_CALLOC_OR_FAIL(rnd_data, rng_bytes);
TEST_CALLOC(rnd_data, rng_bytes);
TEST_EQUAL(0, mbedtls_test_rnd_std_rand(NULL, rnd_data, rng_bytes));
rnd_info.buf = rnd_data;
@ -1078,7 +1078,7 @@ void mpi_core_fill_random(int wanted_bytes_arg, int extra_rng_bytes,
* extra_limbs may be negative but the total limb count must be positive.
* Fill the MPI with the byte value in before. */
TEST_LE_U(1, X_limbs);
TEST_CALLOC_OR_FAIL(X, X_limbs);
TEST_CALLOC(X, X_limbs);
memset(X, before, X_limbs * sizeof(*X));
ret = mbedtls_mpi_core_fill_random(X, X_limbs, wanted_bytes,
@ -1128,14 +1128,14 @@ void mpi_core_mul(char *input_A,
const size_t X_limbs = A_limbs + B_limbs;
const size_t X_bytes = X_limbs * sizeof(mbedtls_mpi_uint);
TEST_CALLOC_OR_FAIL(X, X_limbs);
TEST_CALLOC(X, X_limbs);
const size_t A_bytes = A_limbs * sizeof(mbedtls_mpi_uint);
TEST_CALLOC_OR_FAIL(A_orig, A_limbs);
TEST_CALLOC(A_orig, A_limbs);
memcpy(A_orig, A, A_bytes);
const size_t B_bytes = B_limbs * sizeof(mbedtls_mpi_uint);
TEST_CALLOC_OR_FAIL(B_orig, B_limbs);
TEST_CALLOC(B_orig, B_limbs);
memcpy(B_orig, B, B_bytes);
/* Set result to something that is unlikely to be correct */
@ -1195,7 +1195,7 @@ void mpi_core_exp_mod(char *input_N, char *input_A,
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&E, &E_limbs, input_E));
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &N_limbs, input_N));
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
TEST_CALLOC_OR_FAIL(Y, N_limbs);
TEST_CALLOC(Y, N_limbs);
TEST_EQUAL(A_limbs, N_limbs);
TEST_EQUAL(X_limbs, N_limbs);
@ -1227,7 +1227,7 @@ void mpi_core_exp_mod(char *input_N, char *input_A,
TEST_LE_U(mbedtls_mpi_core_montmul_working_limbs(N_limbs),
working_limbs);
TEST_CALLOC_OR_FAIL(T, working_limbs);
TEST_CALLOC(T, working_limbs);
mbedtls_mpi_core_exp_mod(Y, A, N, N_limbs, E, E_limbs, R2, T);
@ -1277,7 +1277,7 @@ void mpi_core_sub_int(char *input_A, char *input_B,
TEST_EQUAL(A_limbs, X_limbs);
size_t limbs = A_limbs;
TEST_CALLOC_OR_FAIL(R, limbs);
TEST_CALLOC(R, limbs);
#define TEST_COMPARE_CORE_MPIS(A, B, limbs) \
TEST_BUFFERS_EQUAL(A, (limbs) * sizeof(mbedtls_mpi_uint), B, (limbs) * sizeof(mbedtls_mpi_uint))

View file

@ -123,7 +123,7 @@ void mpi_mod_mul(char *input_A,
TEST_EQUAL(rB.limbs, limbs);
TEST_EQUAL(rR.limbs, limbs);
TEST_CALLOC_OR_FAIL(X, limbs);
TEST_CALLOC(X, limbs);
TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&rX, &m, X, limbs), 0);
@ -206,7 +206,7 @@ void mpi_mod_mul_neg(char *input_A,
const size_t limbs = m.limbs;
TEST_CALLOC_OR_FAIL(X, limbs);
TEST_CALLOC(X, limbs);
TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&rX, &m, X, limbs), 0);
rX.limbs = rR.limbs;
@ -259,7 +259,7 @@ void mpi_mod_sub(char *input_N,
if (expected_ret == 0) {
/* Negative test with too many limbs in output */
TEST_CALLOC_OR_FAIL(X_raw, limbs + 1);
TEST_CALLOC(X_raw, limbs + 1);
x.p = X_raw;
x.limbs = limbs + 1;
@ -271,7 +271,7 @@ void mpi_mod_sub(char *input_N,
/* Negative test with too few limbs in output */
if (limbs > 1) {
TEST_CALLOC_OR_FAIL(X_raw, limbs - 1);
TEST_CALLOC(X_raw, limbs - 1);
x.p = X_raw;
x.limbs = limbs - 1;
@ -286,7 +286,7 @@ void mpi_mod_sub(char *input_N,
* manually-written test cases with expected_ret != 0. */
}
TEST_CALLOC_OR_FAIL(X_raw, limbs);
TEST_CALLOC(X_raw, limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&x, &m, X_raw, limbs));
@ -358,7 +358,7 @@ void mpi_mod_inv_mont(char *input_N,
size_t limbs = N.limbs;
size_t bytes = limbs * sizeof(*X_raw);
TEST_CALLOC_OR_FAIL(X_raw, limbs);
TEST_CALLOC(X_raw, limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&x, &N, X_raw, limbs));
@ -408,7 +408,7 @@ void mpi_mod_inv_non_mont(char *input_N,
size_t limbs = N.limbs;
size_t bytes = limbs * sizeof(*X_raw);
TEST_CALLOC_OR_FAIL(X_raw, limbs);
TEST_CALLOC(X_raw, limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&x, &N, X_raw, limbs));
@ -462,7 +462,7 @@ void mpi_mod_add(char *input_N,
if (expected_ret == 0) {
/* Negative test with too many limbs in output */
TEST_CALLOC_OR_FAIL(X_raw, limbs + 1);
TEST_CALLOC(X_raw, limbs + 1);
x.p = X_raw;
x.limbs = limbs + 1;
@ -474,7 +474,7 @@ void mpi_mod_add(char *input_N,
/* Negative test with too few limbs in output */
if (limbs > 1) {
TEST_CALLOC_OR_FAIL(X_raw, limbs - 1);
TEST_CALLOC(X_raw, limbs - 1);
x.p = X_raw;
x.limbs = limbs - 1;
@ -490,7 +490,7 @@ void mpi_mod_add(char *input_N,
}
/* Allocate correct number of limbs for X_raw */
TEST_CALLOC_OR_FAIL(X_raw, limbs);
TEST_CALLOC(X_raw, limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&x, &m, X_raw, limbs));
@ -582,7 +582,7 @@ void mpi_mod_io_neg(char *input_N, data_t *buf, int ret)
size_t n_limbs;
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &n_limbs, input_N));
size_t r_limbs = n_limbs;
TEST_CALLOC_OR_FAIL(R, r_limbs);
TEST_CALLOC(R, r_limbs);
/* modulus->p == NULL || residue->p == NULL ( m has not been set-up ) */
TEST_EQUAL(MBEDTLS_ERR_MPI_BAD_INPUT_DATA,
@ -658,8 +658,8 @@ void mpi_mod_io(char *input_N, data_t *input_A, int endian)
a_bytes = input_A->len;
/* Allocate the memory for intermediate data structures */
TEST_CALLOC_OR_FAIL(R, n_bytes);
TEST_CALLOC_OR_FAIL(R_COPY, n_bytes);
TEST_CALLOC(R, n_bytes);
TEST_CALLOC(R_COPY, n_bytes);
/* Test that input's size is not greater to modulo's */
TEST_LE_U(a_bytes, n_bytes);
@ -698,14 +698,14 @@ void mpi_mod_io(char *input_N, data_t *input_A, int endian)
obuf_sizes[2] = a_bytes + 8;
for (size_t i = 0; i < obuf_sizes_len; i++) {
TEST_CALLOC_OR_FAIL(obuf, obuf_sizes[i]);
TEST_CALLOC(obuf, obuf_sizes[i]);
TEST_EQUAL(0, mbedtls_mpi_mod_write(&r, &m, obuf, obuf_sizes[i], endian));
/* Make sure that writing didn't corrupt the value of r */
TEST_BUFFERS_EQUAL(r.p, r.limbs, r_copy.p, r_copy.limbs);
/* Set up reference output for checking the result */
TEST_CALLOC_OR_FAIL(ref_buf, obuf_sizes[i]);
TEST_CALLOC(ref_buf, obuf_sizes[i]);
switch (endian) {
case MBEDTLS_MPI_MOD_EXT_REP_LE:
memcpy(ref_buf, input_A->x, a_bytes_trimmed);

View file

@ -133,7 +133,7 @@ void mpi_mod_raw_cond_assign(char *input_X,
TEST_EQUAL(limbs_X, limbs_Y);
TEST_ASSERT(copy_limbs <= limbs);
TEST_CALLOC_OR_FAIL(buff_m, copy_limbs);
TEST_CALLOC(buff_m, copy_limbs);
memset(buff_m, 0xFF, copy_limbs);
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
&m, buff_m, copy_limbs), 0);
@ -203,15 +203,15 @@ void mpi_mod_raw_cond_swap(char *input_X,
TEST_EQUAL(limbs_X, limbs_Y);
TEST_ASSERT(copy_limbs <= limbs);
TEST_CALLOC_OR_FAIL(buff_m, copy_limbs);
TEST_CALLOC(buff_m, copy_limbs);
memset(buff_m, 0xFF, copy_limbs);
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
&m, buff_m, copy_limbs), 0);
TEST_CALLOC_OR_FAIL(X, limbs);
TEST_CALLOC(X, limbs);
memcpy(X, tmp_X, bytes);
TEST_CALLOC_OR_FAIL(Y, bytes);
TEST_CALLOC(Y, bytes);
memcpy(Y, tmp_Y, bytes);
/* condition is false */
@ -291,7 +291,7 @@ void mpi_mod_raw_sub(char *input_A,
TEST_EQUAL(limbs_B, limbs);
TEST_EQUAL(limbs_res, limbs);
TEST_CALLOC_OR_FAIL(X, limbs);
TEST_CALLOC(X, limbs);
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
&m, N, limbs), 0);
@ -356,7 +356,7 @@ void mpi_mod_raw_fix_quasi_reduction(char *input_N,
TEST_EQUAL(limbs_X, limbs);
TEST_EQUAL(limbs_res, limbs);
TEST_CALLOC_OR_FAIL(tmp, limbs);
TEST_CALLOC(tmp, limbs);
memcpy(tmp, X, bytes);
/* Check that 0 <= X < 2N */
@ -411,13 +411,13 @@ void mpi_mod_raw_mul(char *input_A,
TEST_EQUAL(limbs_B, limbs);
TEST_EQUAL(limbs_R, limbs);
TEST_CALLOC_OR_FAIL(X, limbs);
TEST_CALLOC(X, limbs);
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
&m, N, limbs), 0);
const size_t limbs_T = limbs * 2 + 1;
TEST_CALLOC_OR_FAIL(T, limbs_T);
TEST_CALLOC(T, limbs_T);
mbedtls_mpi_mod_raw_mul(X, A, B, &m, T);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
@ -489,7 +489,7 @@ void mpi_mod_raw_inv_prime(char *input_N, char *input_A, char *input_X)
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&A, &A_limbs, input_A));
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&N, &N_limbs, input_N));
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
TEST_CALLOC_OR_FAIL(Y, N_limbs);
TEST_CALLOC(Y, N_limbs);
TEST_EQUAL(A_limbs, N_limbs);
TEST_EQUAL(X_limbs, N_limbs);
@ -519,7 +519,7 @@ void mpi_mod_raw_inv_prime(char *input_N, char *input_A, char *input_X)
TEST_LE_U(mbedtls_mpi_core_montmul_working_limbs(N_limbs),
working_limbs);
TEST_CALLOC_OR_FAIL(T, working_limbs);
TEST_CALLOC(T, working_limbs);
mbedtls_mpi_mod_raw_inv_prime(Y, A, N, N_limbs, R2, T);
@ -571,7 +571,7 @@ void mpi_mod_raw_add(char *input_N,
TEST_EQUAL(B_limbs, limbs);
TEST_EQUAL(S_limbs, limbs);
TEST_CALLOC_OR_FAIL(X, limbs);
TEST_CALLOC(X, limbs);
TEST_EQUAL(mbedtls_mpi_mod_modulus_setup(
&m, N, limbs), 0);
@ -718,8 +718,8 @@ void mpi_mod_raw_to_mont_rep(char *input_N, char *input_A, char *input_X)
/* It has separate output, and requires temporary working storage */
size_t temp_limbs = mbedtls_mpi_core_montmul_working_limbs(limbs);
TEST_CALLOC_OR_FAIL(T, temp_limbs);
TEST_CALLOC_OR_FAIL(R, limbs);
TEST_CALLOC(T, temp_limbs);
TEST_CALLOC(R, limbs);
mbedtls_mpi_core_to_mont_rep(R, A, N, n_limbs,
m.rep.mont.mm, m.rep.mont.rr, T);
/* Test that the low-level function gives the required value */
@ -782,8 +782,8 @@ void mpi_mod_raw_from_mont_rep(char *input_N, char *input_A, char *input_X)
/* It has separate output, and requires temporary working storage */
size_t temp_limbs = mbedtls_mpi_core_montmul_working_limbs(limbs);
TEST_CALLOC_OR_FAIL(T, temp_limbs);
TEST_CALLOC_OR_FAIL(R, limbs);
TEST_CALLOC(T, temp_limbs);
TEST_CALLOC(R, limbs);
mbedtls_mpi_core_from_mont_rep(R, A, N, n_limbs,
m.rep.mont.mm, T);
/* Test that the low-level function gives the required value */
@ -834,8 +834,8 @@ void mpi_mod_raw_neg(char *input_N, char *input_A, char *input_X)
TEST_EQUAL(x_limbs, n_limbs);
bytes = n_limbs * sizeof(mbedtls_mpi_uint);
TEST_CALLOC_OR_FAIL(R, n_limbs);
TEST_CALLOC_OR_FAIL(Z, n_limbs);
TEST_CALLOC(R, n_limbs);
TEST_CALLOC(Z, n_limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_modulus_setup(&m, N, n_limbs));

View file

@ -124,9 +124,9 @@ void mpi_core_random_basic(int min, char *bound_bytes, int expected_ret)
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&upper_bound, &limbs,
bound_bytes));
TEST_CALLOC_OR_FAIL(lower_bound, limbs);
TEST_CALLOC(lower_bound, limbs);
lower_bound[0] = min;
TEST_CALLOC_OR_FAIL(result, limbs);
TEST_CALLOC(result, limbs);
TEST_EQUAL(expected_ret,
mbedtls_mpi_core_random(result, min, upper_bound, limbs,
@ -159,7 +159,7 @@ void mpi_legacy_random_values(int min, char *max_hex)
TEST_EQUAL(0, mbedtls_test_read_mpi(&max_legacy, max_hex));
size_t limbs = max_legacy.n;
TEST_CALLOC_OR_FAIL(R_core, limbs);
TEST_CALLOC(R_core, limbs);
/* Call the legacy function and the core function with the same random
* stream. */
@ -209,9 +209,9 @@ void mpi_mod_random_values(int min, char *max_hex, int rep)
mbedtls_mpi_mod_modulus_init(&N);
TEST_EQUAL(mbedtls_test_read_mpi_modulus(&N, max_hex, rep), 0);
TEST_CALLOC_OR_FAIL(R_core, N.limbs);
TEST_CALLOC_OR_FAIL(R_mod_raw, N.limbs);
TEST_CALLOC_OR_FAIL(R_mod_digits, N.limbs);
TEST_CALLOC(R_core, N.limbs);
TEST_CALLOC(R_mod_raw, N.limbs);
TEST_CALLOC(R_mod_digits, N.limbs);
TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&R_mod, &N,
R_mod_digits, N.limbs),
0);
@ -287,7 +287,7 @@ void mpi_random_many(int min, char *bound_hex, int iterations)
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&upper_bound, &limbs,
bound_hex));
TEST_CALLOC_OR_FAIL(result, limbs);
TEST_CALLOC(result, limbs);
n_bits = mbedtls_mpi_core_bitlen(upper_bound, limbs);
/* Consider a bound "small" if it's less than 2^5. This value is chosen
@ -302,7 +302,7 @@ void mpi_random_many(int min, char *bound_hex, int iterations)
full_stats = 0;
stats_len = n_bits;
}
TEST_CALLOC_OR_FAIL(stats, stats_len);
TEST_CALLOC(stats, stats_len);
for (i = 0; i < (size_t) iterations; i++) {
mbedtls_test_set_step(i);
@ -340,7 +340,7 @@ void mpi_random_many(int min, char *bound_hex, int iterations)
}
} else {
bound_bytes.len = limbs * sizeof(mbedtls_mpi_uint);
TEST_CALLOC_OR_FAIL(bound_bytes.x, bound_bytes.len);
TEST_CALLOC(bound_bytes.x, bound_bytes.len);
mbedtls_mpi_core_write_be(upper_bound, limbs,
bound_bytes.x, bound_bytes.len);
int statistically_safe_all_the_way =
@ -416,7 +416,7 @@ void mpi_mod_random_validation(int min, char *bound_hex,
MBEDTLS_MPI_MOD_REP_OPT_RED),
0);
size_t result_limbs = N.limbs + result_limbs_delta;
TEST_CALLOC_OR_FAIL(result_digits, result_limbs);
TEST_CALLOC(result_digits, result_limbs);
/* Build a reside that might not match the modulus, to test that
* the library function rejects that as expected. */
mbedtls_mpi_mod_residue result = { result_digits, result_limbs };

View file

@ -32,7 +32,7 @@ static int check_multipart(mbedtls_ccm_context *ctx,
/* Allocate a tight buffer for each update call. This way, if the function
* tries to write beyond the advertised required buffer size, this will
* count as an overflow for memory sanitizers and static checkers. */
TEST_CALLOC_OR_FAIL(output, n1);
TEST_CALLOC(output, n1);
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_ccm_update(ctx, input->x, n1, output, n1, &olen));
TEST_EQUAL(n1, olen);
@ -40,7 +40,7 @@ static int check_multipart(mbedtls_ccm_context *ctx,
mbedtls_free(output);
output = NULL;
TEST_CALLOC_OR_FAIL(output, n2);
TEST_CALLOC(output, n2);
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_ccm_update(ctx, input->x + n1, n2, output, n2, &olen));
TEST_EQUAL(n2, olen);
@ -48,7 +48,7 @@ static int check_multipart(mbedtls_ccm_context *ctx,
mbedtls_free(output);
output = NULL;
TEST_CALLOC_OR_FAIL(output, tag->len);
TEST_CALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_ccm_finish(ctx, output, tag->len));
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
mbedtls_free(output);
@ -190,13 +190,13 @@ void mbedtls_ccm_encrypt_and_tag(int cipher_id, data_t *key,
const uint8_t *expected_tag = result->x + msg->len;
/* Prepare input/output message buffer */
TEST_CALLOC_OR_FAIL(io_msg_buf, msg->len);
TEST_CALLOC(io_msg_buf, msg->len);
if (msg->len != 0) {
memcpy(io_msg_buf, msg->x, msg->len);
}
/* Prepare tag buffer */
TEST_CALLOC_OR_FAIL(tag_buf, expected_tag_len);
TEST_CALLOC(tag_buf, expected_tag_len);
mbedtls_ccm_init(&ctx);
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
@ -246,7 +246,7 @@ void mbedtls_ccm_star_no_tag(int cipher_id, int mode, data_t *key,
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 0, msg->len, 0));
TEST_CALLOC_OR_FAIL(output, msg->len);
TEST_CALLOC(output, msg->len);
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
TEST_EQUAL(result->len, olen);
TEST_BUFFERS_EQUAL(output, olen, result->x, result->len);
@ -272,7 +272,7 @@ void mbedtls_ccm_auth_decrypt(int cipher_id, data_t *key,
/* Prepare input/output message buffer */
uint8_t *io_msg_buf = NULL;
TEST_CALLOC_OR_FAIL(io_msg_buf, expected_msg_len);
TEST_CALLOC(io_msg_buf, expected_msg_len);
if (expected_msg_len) {
memcpy(io_msg_buf, msg->x, expected_msg_len);
}
@ -344,16 +344,16 @@ void mbedtls_ccm_star_encrypt_and_tag(int cipher_id,
}
/* Prepare input/output message buffer */
TEST_CALLOC_OR_FAIL(io_msg_buf, msg->len);
TEST_CALLOC(io_msg_buf, msg->len);
if (msg->len) {
memcpy(io_msg_buf, msg->x, msg->len);
}
/* Prepare tag buffer */
if (expected_tag_len == 0) {
TEST_CALLOC_OR_FAIL(tag_buf, 16);
TEST_CALLOC(tag_buf, 16);
} else {
TEST_CALLOC_OR_FAIL(tag_buf, expected_tag_len);
TEST_CALLOC(tag_buf, expected_tag_len);
}
/* Calculate iv */
@ -429,7 +429,7 @@ void mbedtls_ccm_star_auth_decrypt(int cipher_id,
/* Prepare input/output message buffer */
uint8_t *io_msg_buf = NULL;
TEST_CALLOC_OR_FAIL(io_msg_buf, expected_msg_len);
TEST_CALLOC(io_msg_buf, expected_msg_len);
if (expected_msg_len) {
memcpy(io_msg_buf, msg->x, expected_msg_len);
}
@ -500,7 +500,7 @@ void mbedtls_ccm_skip_ad(int cipher_id, int mode,
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 0, msg->len, tag->len));
TEST_CALLOC_OR_FAIL(output, result->len);
TEST_CALLOC(output, result->len);
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, result->len, &olen));
TEST_EQUAL(result->len, olen);
@ -508,7 +508,7 @@ void mbedtls_ccm_skip_ad(int cipher_id, int mode,
mbedtls_free(output);
output = NULL;
TEST_CALLOC_OR_FAIL(output, tag->len);
TEST_CALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, output, tag->len));
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
mbedtls_free(output);
@ -536,7 +536,7 @@ void mbedtls_ccm_skip_update(int cipher_id, int mode,
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
TEST_CALLOC_OR_FAIL(output, tag->len);
TEST_CALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, output, tag->len));
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
mbedtls_free(output);
@ -607,7 +607,7 @@ void mbedtls_ccm_unexpected_text(int cipher_id, int mode,
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
TEST_CALLOC_OR_FAIL(output, msg->len);
TEST_CALLOC(output, msg->len);
olen = 0xdeadbeef;
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT,
mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
@ -633,7 +633,7 @@ void mbedtls_ccm_incomplete_ad(int cipher_id, int mode,
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len - 1));
TEST_CALLOC_OR_FAIL(output, 16);
TEST_CALLOC(output, 16);
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
exit:
@ -713,7 +713,7 @@ void mbedtls_ccm_overflow_update(int cipher_id, int mode,
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
TEST_CALLOC_OR_FAIL(output, msg->len);
TEST_CALLOC(output, msg->len);
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, \
mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
exit:
@ -740,13 +740,13 @@ void mbedtls_ccm_incomplete_update(int cipher_id, int mode,
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
TEST_CALLOC_OR_FAIL(output, msg->len);
TEST_CALLOC(output, msg->len);
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len - 1, output, msg->len, &olen));
mbedtls_free(output);
output = NULL;
TEST_CALLOC_OR_FAIL(output, 16);
TEST_CALLOC(output, 16);
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
exit:
@ -774,7 +774,7 @@ void mbedtls_ccm_full_update_and_overflow(int cipher_id, int mode,
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
TEST_CALLOC_OR_FAIL(output, msg->len);
TEST_CALLOC(output, msg->len);
// pass full text
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
// pass 1 extra byte
@ -809,7 +809,7 @@ void mbedtls_ccm_incomplete_update_overflow(int cipher_id, int mode,
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
TEST_CALLOC_OR_FAIL(output, msg->len + 1);
TEST_CALLOC(output, msg->len + 1);
// pass incomplete text
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len - 1, output, msg->len + 1, &olen));
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
@ -836,7 +836,7 @@ void mbedtls_ccm_instant_finish(int cipher_id, int mode,
// They are not a part of this test
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 16, 16, 16));
TEST_CALLOC_OR_FAIL(output, 16);
TEST_CALLOC(output, 16);
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
exit:

View file

@ -583,7 +583,7 @@ void dec_empty_buf(int cipher,
iv_len = 12;
}
TEST_CALLOC_OR_FAIL(iv, iv_len);
TEST_CALLOC(iv, iv_len);
memset(iv, 0, iv_len);
TEST_ASSERT(sizeof(key) * 8 >= mbedtls_cipher_info_get_key_bitlen(cipher_info));
@ -905,7 +905,7 @@ void auth_crypt_tv(int cipher_id, data_t *key, data_t *iv,
* (we need the tag appended to the ciphertext)
*/
cipher_plus_tag_len = cipher->len + tag->len;
TEST_CALLOC_OR_FAIL(cipher_plus_tag, cipher_plus_tag_len);
TEST_CALLOC(cipher_plus_tag, cipher_plus_tag_len);
memcpy(cipher_plus_tag, cipher->x, cipher->len);
memcpy(cipher_plus_tag + cipher->len, tag->x, tag->len);
@ -923,7 +923,7 @@ void auth_crypt_tv(int cipher_id, data_t *key, data_t *iv,
* Try decrypting to a buffer that's 1B too small
*/
if (decrypt_buf_len != 0) {
TEST_CALLOC_OR_FAIL(decrypt_buf, decrypt_buf_len - 1);
TEST_CALLOC(decrypt_buf, decrypt_buf_len - 1);
outlen = 0;
ret = mbedtls_cipher_auth_decrypt_ext(&ctx, iv->x, iv->len,
@ -938,7 +938,7 @@ void auth_crypt_tv(int cipher_id, data_t *key, data_t *iv,
/*
* Authenticate and decrypt, and check result
*/
TEST_CALLOC_OR_FAIL(decrypt_buf, decrypt_buf_len);
TEST_CALLOC(decrypt_buf, decrypt_buf_len);
outlen = 0;
ret = mbedtls_cipher_auth_decrypt_ext(&ctx, iv->x, iv->len,
@ -981,7 +981,7 @@ void auth_crypt_tv(int cipher_id, data_t *key, data_t *iv,
/*
* Try encrypting with an output buffer that's 1B too small
*/
TEST_CALLOC_OR_FAIL(encrypt_buf, encrypt_buf_len - 1);
TEST_CALLOC(encrypt_buf, encrypt_buf_len - 1);
outlen = 0;
ret = mbedtls_cipher_auth_encrypt_ext(&ctx, iv->x, iv->len,
@ -995,7 +995,7 @@ void auth_crypt_tv(int cipher_id, data_t *key, data_t *iv,
/*
* Encrypt and check the result
*/
TEST_CALLOC_OR_FAIL(encrypt_buf, encrypt_buf_len);
TEST_CALLOC(encrypt_buf, encrypt_buf_len);
outlen = 0;
ret = mbedtls_cipher_auth_encrypt_ext(&ctx, iv->x, iv->len,

View file

@ -17,10 +17,10 @@ void mbedtls_xor(int len)
{
size_t n = (size_t) len;
unsigned char *a = NULL, *b = NULL, *r1 = NULL, *r2 = NULL;
TEST_CALLOC_OR_FAIL(a, n + 1);
TEST_CALLOC_OR_FAIL(b, n + 1);
TEST_CALLOC_OR_FAIL(r1, n + 1);
TEST_CALLOC_OR_FAIL(r2, n + 1);
TEST_CALLOC(a, n + 1);
TEST_CALLOC(b, n + 1);
TEST_CALLOC(r1, n + 1);
TEST_CALLOC(r2, n + 1);
/* Test non-overlapping */
fill_arrays(a, b, r1, r2, n);

View file

@ -29,8 +29,8 @@ void mbedtls_ct_memcmp_null()
void mbedtls_ct_memcmp(int same, int size, int offset)
{
uint8_t *a = NULL, *b = NULL;
TEST_CALLOC_OR_FAIL(a, size + offset);
TEST_CALLOC_OR_FAIL(b, size + offset);
TEST_CALLOC(a, size + offset);
TEST_CALLOC(b, size + offset);
TEST_CF_SECRET(a + offset, size);
TEST_CF_SECRET(b + offset, size);
@ -70,9 +70,9 @@ exit:
void mbedtls_ct_memcpy_if_eq(int eq, int size, int offset)
{
uint8_t *src = NULL, *result = NULL, *expected = NULL;
TEST_CALLOC_OR_FAIL(src, size + offset);
TEST_CALLOC_OR_FAIL(result, size + offset);
TEST_CALLOC_OR_FAIL(expected, size + offset);
TEST_CALLOC(src, size + offset);
TEST_CALLOC(result, size + offset);
TEST_CALLOC(expected, size + offset);
for (int i = 0; i < size + offset; i++) {
src[i] = 1;
@ -125,8 +125,8 @@ void ssl_cf_memcpy_offset(int offset_min, int offset_max, int len)
size_t src_len = offset_max + len;
size_t secret;
TEST_CALLOC_OR_FAIL(dst, len);
TEST_CALLOC_OR_FAIL(src, src_len);
TEST_CALLOC(dst, len);
TEST_CALLOC(src, src_len);
/* Fill src in a way that we can detect if we copied the right bytes */
mbedtls_test_rnd_std_rand(NULL, src, src_len);

View file

@ -58,7 +58,7 @@ void ssl_cf_hmac(int hash)
#endif /* MBEDTLS_USE_PSA_CRYPTO */
/* Use allocated out buffer to catch overwrites */
TEST_CALLOC_OR_FAIL(out, out_len);
TEST_CALLOC(out, out_len);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
/* Set up dummy key */
@ -85,7 +85,7 @@ void ssl_cf_hmac(int hash)
mbedtls_test_set_step(max_in_len * 10000);
/* Use allocated in buffer to catch overreads */
TEST_CALLOC_OR_FAIL(data, max_in_len);
TEST_CALLOC(data, max_in_len);
min_in_len = max_in_len > 255 ? max_in_len - 255 : 0;
for (in_len = min_in_len; in_len <= max_in_len; in_len++) {

View file

@ -1101,7 +1101,7 @@ void genkey_mx_known_answer(int bits, data_t *seed, data_t *expected)
rnd_info.fallback_f_rng = NULL;
rnd_info.fallback_p_rng = NULL;
TEST_CALLOC_OR_FAIL(actual, expected->len);
TEST_CALLOC(actual, expected->len);
ret = mbedtls_ecp_gen_privkey_mx(bits, &d,
mbedtls_test_rnd_buffer_rand, &rnd_info);
@ -1456,10 +1456,10 @@ void ecp_mod_mul_inv(char *input_A, int id, int ctype)
/* Test for limb sizes */
TEST_EQUAL(m.limbs, limbs);
TEST_CALLOC_OR_FAIL(A_inverse, limbs);
TEST_CALLOC(A_inverse, limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&rA_inverse, &m, A_inverse, limbs));
TEST_CALLOC_OR_FAIL(rX_raw, limbs);
TEST_CALLOC(rX_raw, limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&rX, &m, rX_raw, limbs));
/* Get inverse of A mode m, and multiply it with itself,
@ -1467,7 +1467,7 @@ void ecp_mod_mul_inv(char *input_A, int id, int ctype)
TEST_EQUAL(0, mbedtls_mpi_mod_inv(&rA_inverse, &rA, &m));
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rA_inverse, &m), 0);
TEST_CALLOC_OR_FAIL(bufx, limbs);
TEST_CALLOC(bufx, limbs);
TEST_EQUAL(mbedtls_mpi_mod_write(&rX, &m, (unsigned char *) bufx,
limbs * ciL,
MBEDTLS_MPI_MOD_EXT_REP_LE), 0);
@ -1515,7 +1515,7 @@ void ecp_mod_add_sub(char *input_A, char *input_B, int id, int ctype)
TEST_EQUAL(m.limbs, p_A_limbs);
bytes = p_A_limbs * ciL;
TEST_CALLOC_OR_FAIL(p_S, p_A_limbs);
TEST_CALLOC(p_S, p_A_limbs);
TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&rA, &m, p_A, p_A_limbs), 0);
TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&rB, &m, p_B, p_B_limbs), 0);
@ -1562,11 +1562,11 @@ void ecp_mod_read_write(char *input_A, int id, int ctype)
/* Test for limb sizes */
TEST_EQUAL(m.limbs, limbs);
TEST_CALLOC_OR_FAIL(rX_raw, limbs);
TEST_CALLOC(rX_raw, limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&rX, &m, rX_raw, limbs));
bytes = limbs * ciL;
TEST_CALLOC_OR_FAIL(bufx, limbs);
TEST_CALLOC(bufx, limbs);
/* Write source mod residue to a buffer, then read it back to
* the destination mod residue, compare the two mod residues.
* Firstly test little endian write and read */
@ -1616,7 +1616,7 @@ void ecp_mod_random(int id, int ctype)
limbs = m.limbs;
TEST_CALLOC_OR_FAIL(rX_raw, limbs);
TEST_CALLOC(rX_raw, limbs);
TEST_EQUAL(0, mbedtls_mpi_mod_residue_setup(&rX, &m, rX_raw, limbs));
TEST_EQUAL(0, mbedtls_mpi_mod_random(&rX, 1, &m,

View file

@ -33,7 +33,7 @@ static int check_multipart(mbedtls_gcm_context *ctx,
/* Allocate a tight buffer for each update call. This way, if the function
* tries to write beyond the advertised required buffer size, this will
* count as an overflow for memory sanitizers and static checkers. */
TEST_CALLOC_OR_FAIL(output, n1);
TEST_CALLOC(output, n1);
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x, n1, output, n1, &olen));
TEST_EQUAL(n1, olen);
@ -41,7 +41,7 @@ static int check_multipart(mbedtls_gcm_context *ctx,
mbedtls_free(output);
output = NULL;
TEST_CALLOC_OR_FAIL(output, n2);
TEST_CALLOC(output, n2);
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x + n1, n2, output, n2, &olen));
TEST_EQUAL(n2, olen);
@ -49,7 +49,7 @@ static int check_multipart(mbedtls_gcm_context *ctx,
mbedtls_free(output);
output = NULL;
TEST_CALLOC_OR_FAIL(output, tag->len);
TEST_CALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
TEST_EQUAL(0, olen);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
@ -87,7 +87,7 @@ static void check_cipher_with_empty_ad(mbedtls_gcm_context *ctx,
/* Allocate a tight buffer for each update call. This way, if the function
* tries to write beyond the advertised required buffer size, this will
* count as an overflow for memory sanitizers and static checkers. */
TEST_CALLOC_OR_FAIL(output, input->len);
TEST_CALLOC(output, input->len);
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x, input->len, output, input->len, &olen));
TEST_EQUAL(input->len, olen);
@ -95,7 +95,7 @@ static void check_cipher_with_empty_ad(mbedtls_gcm_context *ctx,
mbedtls_free(output);
output = NULL;
TEST_CALLOC_OR_FAIL(output, tag->len);
TEST_CALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
TEST_EQUAL(0, olen);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
@ -124,7 +124,7 @@ static void check_empty_cipher_with_ad(mbedtls_gcm_context *ctx,
TEST_EQUAL(0, olen);
}
TEST_CALLOC_OR_FAIL(output_tag, tag->len);
TEST_CALLOC(output_tag, tag->len);
TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen,
output_tag, tag->len));
TEST_EQUAL(0, olen);
@ -144,7 +144,7 @@ static void check_no_cipher_no_ad(mbedtls_gcm_context *ctx,
TEST_EQUAL(0, mbedtls_gcm_starts(ctx, mode,
iv->x, iv->len));
TEST_CALLOC_OR_FAIL(output, tag->len);
TEST_CALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
TEST_EQUAL(0, olen);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
@ -448,7 +448,7 @@ void gcm_update_output_buffer_too_small(int cipher_id, int mode,
TEST_EQUAL(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8), 0);
TEST_EQUAL(0, mbedtls_gcm_starts(&ctx, mode, iv->x, iv->len));
TEST_CALLOC_OR_FAIL(output, output_len);
TEST_CALLOC(output, output_len);
TEST_EQUAL(MBEDTLS_ERR_GCM_BUFFER_TOO_SMALL,
mbedtls_gcm_update(&ctx, input->x, input->len, output, output_len, &olen));

View file

@ -50,7 +50,7 @@ void test_hkdf_extract(int md_alg,
TEST_ASSERT(md != NULL);
output_prk_len = mbedtls_md_get_size(md);
TEST_CALLOC_OR_FAIL(output_prk, output_prk_len);
TEST_CALLOC(output_prk, output_prk_len);
ret = mbedtls_hkdf_extract(md, salt->x, salt->len,
ikm->x, ikm->len, output_prk);
@ -79,7 +79,7 @@ void test_hkdf_expand(int md_alg,
const mbedtls_md_info_t *md = mbedtls_md_info_from_type(md_alg);
TEST_ASSERT(md != NULL);
TEST_CALLOC_OR_FAIL(output_okm, OKM_LEN);
TEST_CALLOC(output_okm, OKM_LEN);
TEST_ASSERT(prk->len == mbedtls_md_get_size(md));
TEST_ASSERT(okm->len < OKM_LEN);
@ -110,7 +110,7 @@ void test_hkdf_extract_ret(int hash_len, int ret)
fake_md_info.type = MBEDTLS_MD_NONE;
fake_md_info.size = hash_len;
TEST_CALLOC_OR_FAIL(prk, MBEDTLS_MD_MAX_SIZE);
TEST_CALLOC(prk, MBEDTLS_MD_MAX_SIZE);
salt_len = 0;
ikm_len = 0;
@ -140,11 +140,11 @@ void test_hkdf_expand_ret(int hash_len, int prk_len, int okm_len, int ret)
info_len = 0;
if (prk_len > 0) {
TEST_CALLOC_OR_FAIL(prk, prk_len);
TEST_CALLOC(prk, prk_len);
}
if (okm_len > 0) {
TEST_CALLOC_OR_FAIL(okm, okm_len);
TEST_CALLOC(okm, okm_len);
}
output_ret = mbedtls_hkdf_expand(&fake_md_info, prk, prk_len,

View file

@ -122,7 +122,7 @@ void lmots_verify_test(data_t *msg, data_t *sig, data_t *pub_key,
continue;
}
TEST_CALLOC_OR_FAIL(tmp_sig, size);
TEST_CALLOC(tmp_sig, size);
if (tmp_sig != NULL) {
memcpy(tmp_sig, sig->x, MIN(size, sig->len));
}
@ -154,7 +154,7 @@ void lmots_import_export_test(data_t *pub_key, int expected_import_rc)
if (expected_import_rc == 0) {
exported_pub_key_buf_size = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8);
TEST_CALLOC_OR_FAIL(exported_pub_key, exported_pub_key_buf_size);
TEST_CALLOC(exported_pub_key, exported_pub_key_buf_size);
TEST_EQUAL(mbedtls_lmots_export_public_key(&ctx, exported_pub_key,
exported_pub_key_buf_size,
@ -169,7 +169,7 @@ void lmots_import_export_test(data_t *pub_key, int expected_import_rc)
/* Export into too-small buffer should fail */
exported_pub_key_buf_size = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8) - 1;
TEST_CALLOC_OR_FAIL(exported_pub_key, exported_pub_key_buf_size);
TEST_CALLOC(exported_pub_key, exported_pub_key_buf_size);
TEST_EQUAL(mbedtls_lmots_export_public_key(&ctx, exported_pub_key,
exported_pub_key_buf_size, NULL),
MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL);
@ -178,7 +178,7 @@ void lmots_import_export_test(data_t *pub_key, int expected_import_rc)
/* Export into too-large buffer should succeed */
exported_pub_key_buf_size = MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8) + 1;
TEST_CALLOC_OR_FAIL(exported_pub_key, exported_pub_key_buf_size);
TEST_CALLOC(exported_pub_key, exported_pub_key_buf_size);
TEST_EQUAL(mbedtls_lmots_export_public_key(&ctx, exported_pub_key,
exported_pub_key_buf_size,
&exported_pub_key_size),

View file

@ -124,7 +124,7 @@ void lms_verify_test(data_t *msg, data_t *sig, data_t *pub_key,
continue;
}
TEST_CALLOC_OR_FAIL(tmp_sig, size);
TEST_CALLOC(tmp_sig, size);
if (tmp_sig != NULL) {
memcpy(tmp_sig, sig->x, MIN(size, sig->len));
}
@ -156,7 +156,7 @@ void lms_import_export_test(data_t *pub_key, int expected_import_rc)
if (expected_import_rc == 0) {
exported_pub_key_buf_size = MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10);
TEST_CALLOC_OR_FAIL(exported_pub_key, exported_pub_key_buf_size);
TEST_CALLOC(exported_pub_key, exported_pub_key_buf_size);
TEST_EQUAL(mbedtls_lms_export_public_key(&ctx, exported_pub_key,
exported_pub_key_buf_size,
@ -171,7 +171,7 @@ void lms_import_export_test(data_t *pub_key, int expected_import_rc)
/* Export into too-small buffer should fail */
exported_pub_key_buf_size = MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10) - 1;
TEST_CALLOC_OR_FAIL(exported_pub_key, exported_pub_key_buf_size);
TEST_CALLOC(exported_pub_key, exported_pub_key_buf_size);
TEST_EQUAL(mbedtls_lms_export_public_key(&ctx, exported_pub_key,
exported_pub_key_buf_size, NULL),
MBEDTLS_ERR_LMS_BUFFER_TOO_SMALL);
@ -180,7 +180,7 @@ void lms_import_export_test(data_t *pub_key, int expected_import_rc)
/* Export into too-large buffer should succeed */
exported_pub_key_buf_size = MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10) + 1;
TEST_CALLOC_OR_FAIL(exported_pub_key, exported_pub_key_buf_size);
TEST_CALLOC(exported_pub_key, exported_pub_key_buf_size);
TEST_EQUAL(mbedtls_lms_export_public_key(&ctx, exported_pub_key,
exported_pub_key_buf_size,
&exported_pub_key_size),

View file

@ -844,15 +844,15 @@ void mbedtls_mps_reader_random_usage(int num_out_chunks,
mbedtls_mps_reader rd;
if (acc_size > 0) {
TEST_CALLOC_OR_FAIL(acc, acc_size);
TEST_CALLOC(acc, acc_size);
}
/* This probably needs to be changed because we want
* our tests to be deterministic. */
// srand( time( NULL ) );
TEST_CALLOC_OR_FAIL(outgoing, num_out_chunks * max_chunk_size);
TEST_CALLOC_OR_FAIL(incoming, num_out_chunks * max_chunk_size);
TEST_CALLOC(outgoing, num_out_chunks * max_chunk_size);
TEST_CALLOC(incoming, num_out_chunks * max_chunk_size);
mbedtls_mps_reader_init(&rd, acc, acc_size);
@ -884,7 +884,7 @@ void mbedtls_mps_reader_random_usage(int num_out_chunks,
}
tmp_size = (rand() % max_chunk_size) + 1;
TEST_CALLOC_OR_FAIL(tmp, tmp_size);
TEST_CALLOC(tmp, tmp_size);
TEST_ASSERT(mbedtls_test_rnd_std_rand(NULL, tmp, tmp_size) == 0);
ret = mbedtls_mps_reader_feed(&rd, tmp, tmp_size);

View file

@ -44,7 +44,7 @@ void pkcs12_derive_key(int md_type, int key_size_arg,
salt_len = salt_arg->len;
TEST_CALLOC_OR_FAIL(output_data, key_size);
TEST_CALLOC(output_data, key_size);
int ret = mbedtls_pkcs12_derivation(output_data,
key_size,

View file

@ -85,8 +85,8 @@ void pkcs7_verify(char *pkcs7_file,
}
}
TEST_CALLOC_OR_FAIL(crts, n_crts);
TEST_CALLOC_OR_FAIL(crt_files_arr, n_crts);
TEST_CALLOC(crts, n_crts);
TEST_CALLOC(crt_files_arr, n_crts);
for (i = 0; i < strlen(crt_files); i++) {
for (k = i; k < strlen(crt_files); k++) {
@ -94,7 +94,7 @@ void pkcs7_verify(char *pkcs7_file,
break;
}
}
TEST_CALLOC_OR_FAIL(crt_files_arr[cnt], (k-i)+1);
TEST_CALLOC(crt_files_arr[cnt], (k-i)+1);
crt_files_arr[cnt][k-i] = '\0';
memcpy(crt_files_arr[cnt++], crt_files + i, k-i);
i = k;
@ -102,7 +102,7 @@ void pkcs7_verify(char *pkcs7_file,
mbedtls_pkcs7_init(&pkcs7);
for (i = 0; i < n_crts; i++) {
TEST_CALLOC_OR_FAIL(crts[i], 1);
TEST_CALLOC(crts[i], 1);
mbedtls_x509_crt_init(crts[i]);
}
@ -127,7 +127,7 @@ void pkcs7_verify(char *pkcs7_file,
datalen = st.st_size;
/* Special-case for zero-length input so that data will be non-NULL */
TEST_CALLOC_OR_FAIL(data, datalen == 0 ? 1 : datalen);
TEST_CALLOC(data, datalen == 0 ? 1 : datalen);
buflen = fread((void *) data, sizeof(unsigned char), datalen, file);
TEST_EQUAL(buflen, datalen);
@ -135,7 +135,7 @@ void pkcs7_verify(char *pkcs7_file,
if (do_hash_alg) {
md_info = mbedtls_md_info_from_type((mbedtls_md_type_t) do_hash_alg);
TEST_CALLOC_OR_FAIL(hash, mbedtls_md_get_size(md_info));
TEST_CALLOC(hash, mbedtls_md_get_size(md_info));
res = mbedtls_md(md_info, data, datalen, hash);
TEST_EQUAL(res, 0);

View file

@ -169,7 +169,7 @@ void pk_parse_fix_montgomery(data_t *input_key, data_t *exp_output)
mbedtls_test_rnd_std_rand, NULL), 0);
output_key_len = input_key->len;
TEST_CALLOC_OR_FAIL(output_key, output_key_len);
TEST_CALLOC(output_key, output_key_len);
/* output_key_len is updated with the real amount of data written to
* output_key buffer. */
output_key_len = mbedtls_pk_write_key_der(&pk, output_key, output_key_len);

View file

@ -99,7 +99,7 @@ static void pk_write_check_common(char *key_file, int is_public_key, int is_der)
}
TEST_ASSERT(check_buf_len > 0);
TEST_CALLOC_OR_FAIL(buf, check_buf_len);
TEST_CALLOC(buf, check_buf_len);
if (is_public_key) {
TEST_EQUAL(mbedtls_pk_parse_public_keyfile(&key, key_file), 0);
@ -185,7 +185,7 @@ void pk_write_public_from_private(char *priv_key_file, char *pub_key_file)
&pub_key_len), 0);
derived_key_len = pub_key_len;
TEST_CALLOC_OR_FAIL(derived_key_raw, derived_key_len);
TEST_CALLOC(derived_key_raw, derived_key_len);
TEST_EQUAL(mbedtls_pk_write_pubkey_der(&priv_key, derived_key_raw,
derived_key_len), pub_key_len);

View file

@ -32,7 +32,7 @@ void printf_int(char *format, /* any format expecting one int argument, e.g. "%d
const size_t n = strlen(result);
/* Nominal case: buffer just large enough */
TEST_CALLOC_OR_FAIL(output, n + 1);
TEST_CALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, x));
TEST_BUFFERS_EQUAL(result, n + 1, output, n + 1);
mbedtls_free(output);
@ -53,11 +53,11 @@ void printf_long_max(const char *format, /* "%lx" or longer type */
const size_t n = sizeof(value) * 2;
/* We assume that long has no padding bits! */
TEST_CALLOC_OR_FAIL(expected, n + 1);
TEST_CALLOC(expected, n + 1);
expected[0] = '7';
memset(expected + 1, 'f', sizeof(value) * 2 - 1);
TEST_CALLOC_OR_FAIL(output, n + 1);
TEST_CALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, value));
TEST_BUFFERS_EQUAL(expected, n + 1, output, n + 1);
mbedtls_free(output);
@ -77,7 +77,7 @@ void printf_char2(char *format, /* "%c%c" */
const size_t n = strlen(result);
/* Nominal case: buffer just large enough */
TEST_CALLOC_OR_FAIL(output, n + 1);
TEST_CALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, arg1, arg2));
TEST_BUFFERS_EQUAL(result, n + 1, output, n + 1);
mbedtls_free(output);

View file

@ -429,7 +429,7 @@ static int aead_multipart_internal_func(int key_type_arg, data_t *key_data,
data_true_size = input_data->len - tag_length;
}
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
if (is_encrypt) {
final_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
@ -439,7 +439,7 @@ static int aead_multipart_internal_func(int key_type_arg, data_t *key_data,
TEST_LE_U(final_output_size, PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE);
}
TEST_CALLOC_OR_FAIL(final_data, final_output_size);
TEST_CALLOC(final_data, final_output_size);
if (is_encrypt) {
status = psa_aead_encrypt_setup(&operation, key, alg);
@ -502,7 +502,7 @@ static int aead_multipart_internal_func(int key_type_arg, data_t *key_data,
part_data_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg,
(size_t) data_part_len);
TEST_CALLOC_OR_FAIL(part_data, part_data_size);
TEST_CALLOC(part_data, part_data_size);
for (part_offset = 0, part_count = 0;
part_offset < data_true_size;
@ -744,8 +744,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
psa_status_t expected_status = PSA_SUCCESS;
psa_status_t status;
TEST_CALLOC_OR_FAIL(buffer0, buffer_length);
TEST_CALLOC_OR_FAIL(buffer1, buffer_length);
TEST_CALLOC(buffer0, buffer_length);
TEST_CALLOC(buffer1, buffer_length);
switch (round) {
case 1:
@ -1472,7 +1472,7 @@ void import_rsa_made_up(int bits_arg, int keypair, int expected_status_arg)
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(buffer, buffer_size);
TEST_CALLOC(buffer, buffer_size);
TEST_ASSERT((ret = construct_fake_rsa_key(buffer, buffer_size, &p,
bits, keypair)) >= 0);
@ -1519,9 +1519,9 @@ void import_export(data_t *data,
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
export_size = (ptrdiff_t) data->len + export_size_delta;
TEST_CALLOC_OR_FAIL(exported, export_size);
TEST_CALLOC(exported, export_size);
if (!canonical_input) {
TEST_CALLOC_OR_FAIL(reexported, export_size);
TEST_CALLOC(reexported, export_size);
}
PSA_ASSERT(psa_crypto_init());
@ -1641,7 +1641,7 @@ void import_export_public_key(data_t *data,
PSA_ASSERT(psa_import_key(&attributes, data->x, data->len, &key));
/* Export the public key */
TEST_CALLOC_OR_FAIL(exported, export_size);
TEST_CALLOC(exported, export_size);
status = psa_export_public_key(key,
exported, export_size,
&exported_length);
@ -1938,8 +1938,8 @@ void cipher_key_policy(int policy_usage_arg,
output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, exercise_alg,
input_buffer_size);
TEST_CALLOC_OR_FAIL(input, input_buffer_size);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(input, input_buffer_size);
TEST_CALLOC(output, output_buffer_size);
PSA_ASSERT(psa_crypto_init());
@ -2128,7 +2128,7 @@ void asymmetric_encryption_key_policy(int policy_usage_arg,
key_bits = psa_get_key_bits(&attributes);
buffer_length = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits,
exercise_alg);
TEST_CALLOC_OR_FAIL(buffer, buffer_length);
TEST_CALLOC(buffer, buffer_length);
status = psa_asymmetric_encrypt(key, exercise_alg,
NULL, 0,
@ -2498,7 +2498,7 @@ void copy_success(int source_usage_arg,
psa_get_key_enrollment_algorithm(&target_attributes));
if (expected_usage & PSA_KEY_USAGE_EXPORT) {
size_t length;
TEST_CALLOC_OR_FAIL(export_buffer, material->len);
TEST_CALLOC(export_buffer, material->len);
PSA_ASSERT(psa_export_key(target_key, export_buffer,
material->len, &length));
TEST_BUFFERS_EQUAL(material->x, material->len,
@ -2626,7 +2626,7 @@ void hash_setup(int alg_arg,
/* Hash Setup, one-shot */
output_size = PSA_HASH_LENGTH(alg);
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
status = psa_hash_compute(alg, NULL, 0,
output, output_size, &output_length);
@ -2669,7 +2669,7 @@ void hash_compute_fail(int alg_arg, data_t *input,
psa_status_t expected_status = expected_status_arg;
psa_status_t status;
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
PSA_ASSERT(psa_crypto_init());
@ -3384,7 +3384,7 @@ void mac_sign(int key_type_arg,
PSA_ERROR_BUFFER_TOO_SMALL);
mbedtls_test_set_step(output_size);
TEST_CALLOC_OR_FAIL(actual_mac, output_size);
TEST_CALLOC(actual_mac, output_size);
/* Calculate the MAC, one-shot case. */
TEST_EQUAL(psa_mac_compute(key, alg,
@ -3480,7 +3480,7 @@ void mac_verify(int key_type_arg,
PSA_ERROR_INVALID_SIGNATURE);
/* Test a MAC that's too long, one-shot case. */
TEST_CALLOC_OR_FAIL(perturbed_mac, expected_mac->len + 1);
TEST_CALLOC(perturbed_mac, expected_mac->len + 1);
memcpy(perturbed_mac, expected_mac->x, expected_mac->len);
TEST_EQUAL(psa_mac_verify(key, alg,
input->x, input->len,
@ -3810,7 +3810,7 @@ void cipher_encrypt_fail(int alg_arg,
output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg,
input->len);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
&key));
@ -3869,7 +3869,7 @@ void cipher_encrypt_validate_iv_length(int alg, int key_type, data_t *key_data,
unsigned char *output = NULL;
output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
PSA_ASSERT(psa_crypto_init());
@ -3927,7 +3927,7 @@ void cipher_alg_without_iv(int alg_arg, int key_type_arg, data_t *key_data,
&key));
output_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg,
plaintext->len);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
/* set_iv() is not allowed */
PSA_ASSERT(psa_cipher_encrypt_setup(&operation, key, alg));
@ -4077,8 +4077,8 @@ void cipher_encrypt_validation(int alg_arg,
output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
output2_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len) +
PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_CALLOC_OR_FAIL(output1, output1_buffer_size);
TEST_CALLOC_OR_FAIL(output2, output2_buffer_size);
TEST_CALLOC(output1, output1_buffer_size);
TEST_CALLOC(output2, output2_buffer_size);
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
&key));
@ -4169,7 +4169,7 @@ void cipher_encrypt_multipart(int alg_arg, int key_type_arg,
output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len) +
PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
TEST_LE_U(first_part_size, input->len);
PSA_ASSERT(psa_cipher_update(&operation, input->x, first_part_size,
@ -4268,7 +4268,7 @@ void cipher_decrypt_multipart(int alg_arg, int key_type_arg,
output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len) +
PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
TEST_LE_U(first_part_size, input->len);
PSA_ASSERT(psa_cipher_update(&operation,
@ -4364,13 +4364,13 @@ void cipher_decrypt_fail(int alg_arg,
/* Allocate input buffer and copy the iv and the plaintext */
input_buffer_size = ((size_t) input_arg->len + (size_t) iv->len);
if (input_buffer_size > 0) {
TEST_CALLOC_OR_FAIL(input, input_buffer_size);
TEST_CALLOC(input, input_buffer_size);
memcpy(input, iv->x, iv->len);
memcpy(input + iv->len, input_arg->x, input_arg->len);
}
output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_buffer_size);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
/* Decrypt, one-short */
status = psa_cipher_decrypt(key, alg, input, input_buffer_size, output,
@ -4383,7 +4383,7 @@ void cipher_decrypt_fail(int alg_arg,
output_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg,
input_arg->len) +
PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_CALLOC_OR_FAIL(output_multi, output_buffer_size);
TEST_CALLOC(output_multi, output_buffer_size);
if (iv->len > 0) {
status = psa_cipher_set_iv(&operation, iv->x, iv->len);
@ -4454,13 +4454,13 @@ void cipher_decrypt(int alg_arg,
/* Allocate input buffer and copy the iv and the plaintext */
input_buffer_size = ((size_t) input_arg->len + (size_t) iv->len);
if (input_buffer_size > 0) {
TEST_CALLOC_OR_FAIL(input, input_buffer_size);
TEST_CALLOC(input, input_buffer_size);
memcpy(input, iv->x, iv->len);
memcpy(input + iv->len, input_arg->x, input_arg->len);
}
output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_buffer_size);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
&key));
@ -4508,7 +4508,7 @@ void cipher_verify_output(int alg_arg,
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
&key));
output1_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
TEST_CALLOC_OR_FAIL(output1, output1_size);
TEST_CALLOC(output1, output1_size);
PSA_ASSERT(psa_cipher_encrypt(key, alg, input->x, input->len,
output1, output1_size,
@ -4519,7 +4519,7 @@ void cipher_verify_output(int alg_arg,
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input->len));
output2_size = output1_length;
TEST_CALLOC_OR_FAIL(output2, output2_size);
TEST_CALLOC(output2, output2_size);
PSA_ASSERT(psa_cipher_decrypt(key, alg, output1, output1_length,
output2, output2_size,
@ -4585,7 +4585,7 @@ void cipher_verify_output_multipart(int alg_arg,
output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
TEST_LE_U(output1_buffer_size,
PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input->len));
TEST_CALLOC_OR_FAIL(output1, output1_buffer_size);
TEST_CALLOC(output1, output1_buffer_size);
TEST_LE_U(first_part_size, input->len);
@ -4628,7 +4628,7 @@ void cipher_verify_output_multipart(int alg_arg,
PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, output1_length));
TEST_LE_U(output2_buffer_size,
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(output1_length));
TEST_CALLOC_OR_FAIL(output2, output2_buffer_size);
TEST_CALLOC(output2, output2_buffer_size);
if (iv_length > 0) {
PSA_ASSERT(psa_cipher_set_iv(&operation2,
@ -4724,7 +4724,7 @@ void aead_encrypt_decrypt(int key_type_arg, data_t *key_data,
TEST_LE_U(output_size,
PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
}
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
status = psa_aead_encrypt(key, alg,
nonce->x, nonce->len,
@ -4745,7 +4745,7 @@ void aead_encrypt_decrypt(int key_type_arg, data_t *key_data,
TEST_EQUAL(status, expected_result);
if (PSA_SUCCESS == expected_result) {
TEST_CALLOC_OR_FAIL(output_data2, output_length);
TEST_CALLOC(output_data2, output_length);
/* For all currently defined algorithms, PSA_AEAD_DECRYPT_OUTPUT_SIZE
* should be exact. */
@ -4813,7 +4813,7 @@ void aead_encrypt(int key_type_arg, data_t *key_data,
PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_data->len));
TEST_LE_U(output_size,
PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
status = psa_aead_encrypt(key, alg,
nonce->x, nonce->len,
@ -4883,7 +4883,7 @@ void aead_decrypt(int key_type_arg, data_t *key_data,
TEST_LE_U(output_size,
PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(input_data->len));
}
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
status = psa_aead_decrypt(key, alg,
nonce->x, nonce->len,
@ -5142,13 +5142,13 @@ void aead_multipart_generate_nonce(int key_type_arg, data_t *key_data,
output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_data->len);
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_LE_U(ciphertext_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(ciphertext, ciphertext_size);
TEST_CALLOC(ciphertext, ciphertext_size);
status = psa_aead_encrypt_setup(&operation, key, alg);
@ -5245,13 +5245,13 @@ void aead_multipart_set_nonce(int key_type_arg, data_t *key_data,
output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_data->len);
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_LE_U(ciphertext_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(ciphertext, ciphertext_size);
TEST_CALLOC(ciphertext, ciphertext_size);
status = psa_aead_encrypt_setup(&operation, key, alg);
@ -5268,12 +5268,12 @@ void aead_multipart_set_nonce(int key_type_arg, data_t *key_data,
/* -1 == zero length and valid buffer, 0 = zero length and NULL buffer. */
if (nonce_length_arg == -1) {
/* Arbitrary size buffer, to test zero length valid buffer. */
TEST_CALLOC_OR_FAIL(nonce_buffer, 4);
TEST_CALLOC(nonce_buffer, 4);
nonce_length = 0;
} else {
/* If length is zero, then this will return NULL. */
nonce_length = (size_t) nonce_length_arg;
TEST_CALLOC_OR_FAIL(nonce_buffer, nonce_length);
TEST_CALLOC(nonce_buffer, nonce_length);
if (nonce_buffer) {
for (index = 0; index < nonce_length - 1; ++index) {
@ -5362,11 +5362,11 @@ void aead_multipart_update_buffer_test(int key_type_arg, data_t *key_data,
PSA_ASSERT(psa_get_key_attributes(key, &attributes));
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
ciphertext_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_CALLOC_OR_FAIL(ciphertext, ciphertext_size);
TEST_CALLOC(ciphertext, ciphertext_size);
status = psa_aead_encrypt_setup(&operation, key, alg);
@ -5449,11 +5449,11 @@ void aead_multipart_finish_buffer_test(int key_type_arg, data_t *key_data,
ciphertext_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_data->len);
TEST_CALLOC_OR_FAIL(ciphertext, ciphertext_size);
TEST_CALLOC(ciphertext, ciphertext_size);
TEST_CALLOC_OR_FAIL(finish_ciphertext, finish_ciphertext_size);
TEST_CALLOC(finish_ciphertext, finish_ciphertext_size);
TEST_CALLOC_OR_FAIL(tag_buffer, tag_size);
TEST_CALLOC(tag_buffer, tag_size);
status = psa_aead_encrypt_setup(&operation, key, alg);
@ -5538,11 +5538,11 @@ void aead_multipart_verify(int key_type_arg, data_t *key_data,
plaintext_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg,
input_data->len);
TEST_CALLOC_OR_FAIL(plaintext, plaintext_size);
TEST_CALLOC(plaintext, plaintext_size);
verify_plaintext_size = PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg);
TEST_CALLOC_OR_FAIL(finish_plaintext, verify_plaintext_size);
TEST_CALLOC(finish_plaintext, verify_plaintext_size);
status = psa_aead_decrypt_setup(&operation, key, alg);
@ -5679,13 +5679,13 @@ void aead_multipart_state_test(int key_type_arg, data_t *key_data,
output_size = PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_data->len);
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
finish_output_size = PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_LE_U(finish_output_size, PSA_AEAD_FINISH_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(final_data, finish_output_size);
TEST_CALLOC(final_data, finish_output_size);
/* Test all operations error without calling setup first. */
@ -6483,7 +6483,7 @@ void sign_hash_deterministic(int key_type_arg, data_t *key_data,
key_bits, alg);
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
/* Perform the signature. */
PSA_ASSERT(psa_sign_hash(key, alg,
@ -6566,7 +6566,7 @@ void sign_hash_interruptible(int key_type_arg, data_t *key_data,
key_bits, alg);
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
psa_interruptible_set_max_ops(max_ops);
@ -6651,7 +6651,7 @@ void sign_hash_fail(int key_type_arg, data_t *key_data,
size_t signature_length = 0xdeadbeef;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
PSA_ASSERT(psa_crypto_init());
@ -6731,7 +6731,7 @@ void sign_hash_fail_interruptible(int key_type_arg, data_t *key_data,
psa_sign_hash_interruptible_operation_t operation =
psa_sign_hash_interruptible_operation_init();
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
PSA_ASSERT(psa_crypto_init());
@ -6859,7 +6859,7 @@ void sign_verify_hash(int key_type_arg, data_t *key_data,
key_bits, alg);
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
/* Perform the signature. */
PSA_ASSERT(psa_sign_hash(key, alg,
@ -6962,7 +6962,7 @@ void sign_verify_hash_interruptible(int key_type_arg, data_t *key_data,
key_bits, alg);
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
psa_interruptible_set_max_ops(max_ops);
@ -7444,7 +7444,7 @@ void interruptible_signverify_hash_state_test(int key_type_arg,
key_bits, alg);
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
psa_interruptible_set_max_ops(PSA_INTERRUPTIBLE_MAX_OPS_UNLIMITED);
@ -7600,7 +7600,7 @@ void interruptible_signverify_hash_edgecase_tests(int key_type_arg,
key_bits, alg);
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
/* --- Change function inputs mid run, to cause an error (sign only,
* verify passes all inputs to start. --- */
@ -7731,7 +7731,7 @@ void interruptible_signverify_hash_ops_tests(int key_type_arg,
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
/* Check that default max ops gets set if we don't set it. */
PSA_ASSERT(psa_sign_hash_start(&sign_operation, key, alg,
@ -7905,7 +7905,7 @@ void sign_message_deterministic(int key_type_arg,
signature_size = PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg);
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
PSA_ASSERT(psa_sign_message(key, alg,
input_data->x, input_data->len,
@ -7943,7 +7943,7 @@ void sign_message_fail(int key_type_arg,
size_t signature_length = 0xdeadbeef;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
PSA_ASSERT(psa_crypto_init());
@ -8003,7 +8003,7 @@ void sign_verify_message(int key_type_arg,
signature_size = PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg);
TEST_ASSERT(signature_size != 0);
TEST_LE_U(signature_size, PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
PSA_ASSERT(psa_sign_message(key, alg,
input_data->x, input_data->len,
@ -8143,7 +8143,7 @@ void asymmetric_encrypt(int key_type_arg,
output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
TEST_LE_U(output_size, PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
/* Encrypt the input */
actual_status = psa_asymmetric_encrypt(key, alg,
@ -8225,13 +8225,13 @@ void asymmetric_encrypt_decrypt(int key_type_arg,
output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
TEST_LE_U(output_size, PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
output2_size = input_data->len;
TEST_LE_U(output2_size,
PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg));
TEST_LE_U(output2_size, PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(output2, output2_size);
TEST_CALLOC(output2, output2_size);
/* We test encryption by checking that encrypt-then-decrypt gives back
* the original plaintext because of the non-optional random
@ -8299,7 +8299,7 @@ void asymmetric_decrypt(int key_type_arg,
/* Determine the maximum ciphertext length */
output_size = PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
TEST_LE_U(output_size, PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
PSA_ASSERT(psa_asymmetric_decrypt(key, alg,
input_data->x, input_data->len,
@ -8354,7 +8354,7 @@ void asymmetric_decrypt_fail(int key_type_arg,
psa_status_t expected_status = expected_status_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
PSA_ASSERT(psa_crypto_init());
@ -8722,7 +8722,7 @@ void derive_output(int alg_arg,
expected_outputs[i] = NULL;
}
}
TEST_CALLOC_OR_FAIL(output_buffer, output_buffer_size);
TEST_CALLOC(output_buffer, output_buffer_size);
PSA_ASSERT(psa_crypto_init());
/* Extraction phase. */
@ -8995,7 +8995,7 @@ void derive_ecjpake_to_pms(data_t *input, int expected_input_status_arg,
psa_status_t expected_capacity_status = (psa_status_t) expected_capacity_status_arg;
psa_status_t expected_output_status = (psa_status_t) expected_output_status_arg;
TEST_CALLOC_OR_FAIL(output_buffer, expected_output->len);
TEST_CALLOC(output_buffer, expected_output->len);
PSA_ASSERT(psa_crypto_init());
PSA_ASSERT(psa_key_derivation_setup(&operation, alg));
@ -9116,8 +9116,8 @@ void derive_key_export(int alg_arg,
psa_key_attributes_t derived_attributes = PSA_KEY_ATTRIBUTES_INIT;
size_t length;
TEST_CALLOC_OR_FAIL(output_buffer, capacity);
TEST_CALLOC_OR_FAIL(export_buffer, capacity);
TEST_CALLOC(output_buffer, capacity);
TEST_CALLOC(export_buffer, capacity);
PSA_ASSERT(psa_crypto_init());
psa_set_key_usage_flags(&base_attributes, PSA_KEY_USAGE_DERIVE);
@ -9201,7 +9201,7 @@ void derive_key_type(int alg_arg,
psa_key_attributes_t derived_attributes = PSA_KEY_ATTRIBUTES_INIT;
size_t export_length;
TEST_CALLOC_OR_FAIL(export_buffer, export_buffer_size);
TEST_CALLOC(export_buffer, export_buffer_size);
PSA_ASSERT(psa_crypto_init());
psa_set_key_usage_flags(&base_attributes, PSA_KEY_USAGE_DERIVE);
@ -9373,7 +9373,7 @@ void raw_key_agreement(int alg_arg,
PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE);
/* Good case with exact output size */
TEST_CALLOC_OR_FAIL(output, expected_output->len);
TEST_CALLOC(output, expected_output->len);
PSA_ASSERT(psa_raw_key_agreement(alg, our_key,
peer_key_data->x, peer_key_data->len,
output, expected_output->len,
@ -9385,7 +9385,7 @@ void raw_key_agreement(int alg_arg,
output_length = ~0;
/* Larger buffer */
TEST_CALLOC_OR_FAIL(output, expected_output->len + 1);
TEST_CALLOC(output, expected_output->len + 1);
PSA_ASSERT(psa_raw_key_agreement(alg, our_key,
peer_key_data->x, peer_key_data->len,
output, expected_output->len + 1,
@ -9397,7 +9397,7 @@ void raw_key_agreement(int alg_arg,
output_length = ~0;
/* Buffer too small */
TEST_CALLOC_OR_FAIL(output, expected_output->len - 1);
TEST_CALLOC(output, expected_output->len - 1);
TEST_EQUAL(psa_raw_key_agreement(alg, our_key,
peer_key_data->x, peer_key_data->len,
output, expected_output->len - 1,
@ -9486,7 +9486,7 @@ void key_agreement_output(int alg_arg,
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *actual_output = NULL;
TEST_CALLOC_OR_FAIL(actual_output, MAX(expected_output1->len,
TEST_CALLOC(actual_output, MAX(expected_output1->len,
expected_output2->len));
PSA_ASSERT(psa_crypto_init());
@ -9542,8 +9542,8 @@ void generate_random(int bytes_arg)
TEST_ASSERT(bytes_arg >= 0);
TEST_CALLOC_OR_FAIL(output, bytes);
TEST_CALLOC_OR_FAIL(changed, bytes);
TEST_CALLOC(output, bytes);
TEST_CALLOC(changed, bytes);
PSA_ASSERT(psa_crypto_init());
@ -9661,8 +9661,8 @@ void generate_key_rsa(int bits_arg,
is_default_public_exponent = 1;
e_read_size = 0;
}
TEST_CALLOC_OR_FAIL(e_read_buffer, e_read_size);
TEST_CALLOC_OR_FAIL(exported, exported_size);
TEST_CALLOC(e_read_buffer, e_read_size);
TEST_CALLOC(exported, exported_size);
PSA_ASSERT(psa_crypto_init());
@ -9764,8 +9764,8 @@ void persistent_key_load_key_from_storage(data_t *data,
size_t second_exported_length;
if (usage_flags & PSA_KEY_USAGE_EXPORT) {
TEST_CALLOC_OR_FAIL(first_export, export_size);
TEST_CALLOC_OR_FAIL(second_export, export_size);
TEST_CALLOC(first_export, export_size);
TEST_CALLOC(second_export, export_size);
}
PSA_ASSERT(psa_crypto_init());
@ -9912,7 +9912,7 @@ void ecjpake_setup(int alg_arg, int key_type_pw_arg, int key_usage_pw_arg,
size_t buf_size = PSA_PAKE_OUTPUT_SIZE(alg, primitive_arg,
PSA_PAKE_STEP_KEY_SHARE);
TEST_CALLOC_OR_FAIL(output_buffer, buf_size);
TEST_CALLOC(output_buffer, buf_size);
if (pw_data->len > 0) {
psa_set_key_usage_flags(&attributes, key_usage_pw);

View file

@ -49,8 +49,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
size_t c_x1_pr_off, c_x2_pr_off, c_x2s_pr_off;
psa_status_t status;
TEST_CALLOC_OR_FAIL(buffer0, buffer_length);
TEST_CALLOC_OR_FAIL(buffer1, buffer_length);
TEST_CALLOC(buffer0, buffer_length);
TEST_CALLOC(buffer1, buffer_length);
switch (round) {
case 1:
@ -538,7 +538,7 @@ void sign_hash(int key_type_arg,
TEST_ASSERT(signature_size != 0);
TEST_ASSERT(signature_size <= PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
actual_status = psa_sign_hash(key, alg,
data_input->x, data_input->len,
@ -665,7 +665,7 @@ void sign_message(int key_type_arg,
TEST_ASSERT(signature_size != 0);
TEST_ASSERT(signature_size <= PSA_SIGNATURE_MAX_SIZE);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(signature, signature_size);
actual_status = psa_sign_message(key, alg,
data_input->x, data_input->len,
@ -997,7 +997,7 @@ void key_agreement(int alg_arg,
mbedtls_test_driver_key_agreement_hooks.hits = 0;
mbedtls_test_driver_key_agreement_hooks.forced_status = force_status;
TEST_CALLOC_OR_FAIL(actual_output, expected_output->len);
TEST_CALLOC(actual_output, expected_output->len);
actual_status = psa_raw_key_agreement(alg, our_key,
peer_key_data->x, peer_key_data->len,
actual_output, expected_output->len,
@ -1053,8 +1053,8 @@ void cipher_encrypt_validation(int alg_arg,
output1_buffer_size = PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input->len);
output2_buffer_size = PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input->len) +
PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg);
TEST_CALLOC_OR_FAIL(output1, output1_buffer_size);
TEST_CALLOC_OR_FAIL(output2, output2_buffer_size);
TEST_CALLOC(output1, output1_buffer_size);
TEST_CALLOC(output2, output2_buffer_size);
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
&key));
@ -1171,7 +1171,7 @@ void cipher_encrypt_multipart(int alg_arg,
output_buffer_size = ((size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type));
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
if (mock_output_arg) {
mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x;
@ -1299,7 +1299,7 @@ void cipher_decrypt_multipart(int alg_arg,
output_buffer_size = ((size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type));
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
if (mock_output_arg) {
mbedtls_test_driver_cipher_hooks.forced_output = expected_output->x;
@ -1398,13 +1398,13 @@ void cipher_decrypt(int alg_arg,
/* Allocate input buffer and copy the iv and the plaintext */
input_buffer_size = ((size_t) input_arg->len + (size_t) iv->len);
if (input_buffer_size > 0) {
TEST_CALLOC_OR_FAIL(input, input_buffer_size);
TEST_CALLOC(input, input_buffer_size);
memcpy(input, iv->x, iv->len);
memcpy(input + iv->len, input_arg->x, input_arg->len);
}
output_buffer_size = PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_buffer_size);
TEST_CALLOC_OR_FAIL(output, output_buffer_size);
TEST_CALLOC(output, output_buffer_size);
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
&key));
@ -1451,7 +1451,7 @@ void cipher_entry_points(int alg_arg, int key_type_arg,
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mbedtls_test_driver_cipher_hooks = mbedtls_test_driver_cipher_hooks_init();
TEST_CALLOC_OR_FAIL(output, input->len + 16);
TEST_CALLOC(output, input->len + 16);
output_buffer_size = input->len + 16;
PSA_ASSERT(psa_crypto_init());
@ -1691,7 +1691,7 @@ void aead_encrypt(int key_type_arg, data_t *key_data,
PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_data->len));
TEST_ASSERT(output_size <=
PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
mbedtls_test_driver_aead_hooks.forced_status = forced_status;
status = psa_aead_encrypt(key, alg,
@ -1753,7 +1753,7 @@ void aead_decrypt(int key_type_arg, data_t *key_data,
output_size = input_data->len - PSA_AEAD_TAG_LENGTH(key_type, key_bits,
alg);
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
mbedtls_test_driver_aead_hooks.forced_status = forced_status;
status = psa_aead_decrypt(key, alg,
@ -1816,7 +1816,7 @@ void mac_sign(int key_type_arg,
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
&key));
TEST_CALLOC_OR_FAIL(actual_mac, mac_buffer_size);
TEST_CALLOC(actual_mac, mac_buffer_size);
mbedtls_test_driver_mac_hooks.forced_status = forced_status;
/*
@ -1891,7 +1891,7 @@ void mac_sign_multipart(int key_type_arg,
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
&key));
TEST_CALLOC_OR_FAIL(actual_mac, mac_buffer_size);
TEST_CALLOC(actual_mac, mac_buffer_size);
mbedtls_test_driver_mac_hooks.forced_status = forced_status;
/*
@ -2152,7 +2152,7 @@ void builtin_key_export(int builtin_key_id_arg,
psa_status_t actual_status;
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(output_buffer, expected_output->len);
TEST_CALLOC(output_buffer, expected_output->len);
actual_status = psa_export_key(key, output_buffer, expected_output->len, &output_size);
@ -2203,7 +2203,7 @@ void builtin_pubkey_export(int builtin_key_id_arg,
psa_status_t actual_status;
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(output_buffer, expected_output->len);
TEST_CALLOC(output_buffer, expected_output->len);
actual_status = psa_export_public_key(key, output_buffer, expected_output->len, &output_size);
@ -2244,7 +2244,7 @@ void hash_compute(int alg_arg,
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(output, PSA_HASH_LENGTH(alg));
TEST_CALLOC(output, PSA_HASH_LENGTH(alg));
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
@ -2282,7 +2282,7 @@ void hash_multipart_setup(int alg_arg,
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(output, PSA_HASH_LENGTH(alg));
TEST_CALLOC(output, PSA_HASH_LENGTH(alg));
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
@ -2329,7 +2329,7 @@ void hash_multipart_update(int alg_arg,
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(output, PSA_HASH_LENGTH(alg));
TEST_CALLOC(output, PSA_HASH_LENGTH(alg));
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
@ -2385,7 +2385,7 @@ void hash_multipart_finish(int alg_arg,
size_t output_length;
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(output, PSA_HASH_LENGTH(alg));
TEST_CALLOC(output, PSA_HASH_LENGTH(alg));
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
@ -2440,7 +2440,7 @@ void hash_clone(int alg_arg,
size_t output_length;
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(output, PSA_HASH_LENGTH(alg));
TEST_CALLOC(output, PSA_HASH_LENGTH(alg));
/* Do this after psa_crypto_init() which may call hash drivers */
mbedtls_test_driver_hash_hooks = mbedtls_test_driver_hash_hooks_init();
@ -2539,11 +2539,11 @@ void asymmetric_encrypt_decrypt(int alg_arg,
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
fake_output_encrypt->len;
output_size = fake_output_encrypt->len;
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
} else {
output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
TEST_ASSERT(output_size <= PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
}
/* We test encryption by checking that encrypt-then-decrypt gives back
@ -2571,13 +2571,13 @@ void asymmetric_encrypt_decrypt(int alg_arg,
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
fake_output_decrypt->len;
output2_size = fake_output_decrypt->len;
TEST_CALLOC_OR_FAIL(output2, output2_size);
TEST_CALLOC(output2, output2_size);
} else {
output2_size = input_data->len;
TEST_ASSERT(output2_size <=
PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg));
TEST_ASSERT(output2_size <= PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE);
TEST_CALLOC_OR_FAIL(output2, output2_size);
TEST_CALLOC(output2, output2_size);
}
TEST_EQUAL(psa_asymmetric_decrypt(key, alg,
@ -2651,10 +2651,10 @@ void asymmetric_decrypt(int alg_arg,
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
fake_output_decrypt->len;
output_size = fake_output_decrypt->len;
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
} else {
output_size = expected_output_data->len;
TEST_CALLOC_OR_FAIL(output, expected_output_data->len);
TEST_CALLOC(output, expected_output_data->len);
}
TEST_EQUAL(psa_asymmetric_decrypt(key, alg,
@ -2724,10 +2724,10 @@ void asymmetric_encrypt(int alg_arg,
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length =
fake_output_encrypt->len;
output_size = fake_output_encrypt->len;
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
} else {
output_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg);
TEST_CALLOC_OR_FAIL(output, output_size);
TEST_CALLOC(output, output_size);
}
TEST_EQUAL(psa_asymmetric_encrypt(key, alg,
@ -2824,7 +2824,7 @@ void aead_encrypt_setup(int key_type_arg, data_t *key_data,
PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_data->len));
TEST_ASSERT(output_size <=
PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(input_data->len));
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
status = psa_aead_encrypt_setup(&operation, key, alg);
@ -2926,7 +2926,7 @@ void aead_decrypt_setup(int key_type_arg, data_t *key_data,
output_size = input_ciphertext->len;
TEST_CALLOC_OR_FAIL(output_data, output_size);
TEST_CALLOC(output_data, output_size);
mbedtls_test_driver_aead_hooks.forced_status = forced_status;
@ -3016,12 +3016,12 @@ void pake_operations(data_t *pw_data, int forced_status_setup_arg, int forced_st
PSA_PAKE_STEP_KEY_SHARE);
int in_driver = (forced_status_setup_arg == PSA_SUCCESS);
TEST_CALLOC_OR_FAIL(input_buffer,
TEST_CALLOC(input_buffer,
PSA_PAKE_INPUT_SIZE(PSA_ALG_JPAKE, primitive,
PSA_PAKE_STEP_KEY_SHARE));
memset(input_buffer, 0xAA, size_key_share);
TEST_CALLOC_OR_FAIL(output_buffer,
TEST_CALLOC(output_buffer,
PSA_PAKE_INPUT_SIZE(PSA_ALG_JPAKE, primitive,
PSA_PAKE_STEP_KEY_SHARE));
memset(output_buffer, 0x55, output_size);

View file

@ -86,8 +86,8 @@ void external_rng_failure_sign(int key_type, data_t *key_data, int alg,
size_t signature_size = PSA_SIGNATURE_MAX_SIZE;
size_t signature_length;
TEST_CALLOC_OR_FAIL(input, input_size);
TEST_CALLOC_OR_FAIL(signature, signature_size);
TEST_CALLOC(input, input_size);
TEST_CALLOC(signature, signature_size);
PSA_ASSERT(psa_crypto_init());
PSA_ASSERT(psa_import_key(&attributes, key_data->x, key_data->len,
@ -135,7 +135,7 @@ void validate_entropy_seed_injection(int seed_length_a,
} else {
seed_size = seed_length_b;
}
TEST_CALLOC_OR_FAIL(seed, seed_size);
TEST_CALLOC(seed, seed_size);
/* fill seed with some data */
for (i = 0; i < seed_size; ++i) {
seed[i] = i;

View file

@ -267,7 +267,7 @@ void entropy_from_nv_seed(int seed_size_arg,
uint8_t *seed = NULL;
size_t seed_size = seed_size_arg;
TEST_CALLOC_OR_FAIL(seed, seed_size);
TEST_CALLOC(seed, seed_size);
TEST_ASSERT(mbedtls_nv_seed_write(seed, seed_size) >= 0);
custom_entropy_sources_mask = ENTROPY_SOURCE_NV_SEED;

View file

@ -137,8 +137,8 @@ static void ecjpake_do_round(psa_algorithm_t alg, unsigned int primitive,
size_t c_x1_pr_off, c_x2_pr_off, c_x2s_pr_off;
psa_status_t status;
TEST_CALLOC_OR_FAIL(buffer0, buffer_length);
TEST_CALLOC_OR_FAIL(buffer1, buffer_length);
TEST_CALLOC(buffer0, buffer_length);
TEST_CALLOC(buffer1, buffer_length);
switch (round) {
case PAKE_ROUND_ONE:
@ -617,7 +617,7 @@ void ecjpake_setup(int alg_arg, int key_type_pw_arg, int key_usage_pw_arg,
size_t buf_size = PSA_PAKE_OUTPUT_SIZE(alg, primitive_arg,
PSA_PAKE_STEP_KEY_SHARE);
TEST_CALLOC_OR_FAIL(output_buffer, buf_size);
TEST_CALLOC(output_buffer, buf_size);
psa_set_key_usage_flags(&attributes, key_usage_pw);
psa_set_key_algorithm(&attributes, alg);

View file

@ -61,7 +61,7 @@ void format_storage_data_check(data_t *key_data,
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_enrollment_algorithm(&attributes, key_alg2);
TEST_CALLOC_OR_FAIL(file_data, file_data_length);
TEST_CALLOC(file_data, file_data_length);
psa_format_key_data_for_storage(key_data->x, key_data->len,
&attributes.core,
file_data);
@ -127,7 +127,7 @@ void save_large_persistent_key(int data_length_arg, int expected_status)
size_t data_length = data_length_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
TEST_CALLOC_OR_FAIL(data, data_length);
TEST_CALLOC(data, data_length);
PSA_ASSERT(psa_crypto_init());
@ -267,7 +267,7 @@ void import_export_persistent_key(data_t *data, int type_arg,
size_t exported_length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
TEST_CALLOC_OR_FAIL(exported, export_size);
TEST_CALLOC(exported, export_size);
PSA_ASSERT(psa_crypto_init());

View file

@ -605,7 +605,7 @@ static int check_persistent_data(psa_key_location_t location,
int ok = 0;
PSA_ASSERT(psa_its_get_info(uid, &info));
TEST_CALLOC_OR_FAIL(loaded, info.size);
TEST_CALLOC(loaded, info.size);
PSA_ASSERT(psa_its_get(uid, 0, info.size, loaded, NULL));
TEST_BUFFERS_EQUAL(expected_data, size, loaded, info.size);
ok = 1;

View file

@ -303,7 +303,7 @@ void persistent_slot_lifecycle(int lifetime_arg, int owner_id_arg, int id_arg,
psa_get_key_type(&read_attributes));
TEST_EQUAL(psa_get_key_bits(&attributes),
psa_get_key_bits(&read_attributes));
TEST_CALLOC_OR_FAIL(reexported, key_data->len);
TEST_CALLOC(reexported, key_data->len);
if (usage_flags & PSA_KEY_USAGE_EXPORT) {
PSA_ASSERT(psa_export_key(id, reexported, key_data->len,
&reexported_length));
@ -575,7 +575,7 @@ void copy_across_lifetimes(int source_lifetime_arg, int source_owner_id_arg,
psa_get_key_enrollment_algorithm(&target_attributes));
if (expected_usage & PSA_KEY_USAGE_EXPORT) {
size_t length;
TEST_CALLOC_OR_FAIL(export_buffer, material->len);
TEST_CALLOC(export_buffer, material->len);
PSA_ASSERT(psa_export_key(returned_target_id, export_buffer,
material->len, &length));
TEST_BUFFERS_EQUAL(material->x, material->len,
@ -689,7 +689,7 @@ void copy_to_occupied(int source_lifetime_arg, int source_id_arg,
psa_get_key_algorithm(&attributes2));
if (target_usage & PSA_KEY_USAGE_EXPORT) {
size_t length;
TEST_CALLOC_OR_FAIL(export_buffer, target_material->len);
TEST_CALLOC(export_buffer, target_material->len);
PSA_ASSERT(psa_export_key(returned_target_id, export_buffer,
target_material->len, &length));
TEST_BUFFERS_EQUAL(target_material->x, target_material->len,
@ -813,7 +813,7 @@ void many_transient_keys(int max_keys_arg)
uint8_t exported[sizeof(size_t)];
size_t exported_length;
TEST_CALLOC_OR_FAIL(keys, max_keys);
TEST_CALLOC(keys, max_keys);
PSA_ASSERT(psa_crypto_init());
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_EXPORT);
@ -942,7 +942,7 @@ void non_reusable_key_slots_integrity_in_case_of_key_slot_starvation()
TEST_ASSERT(MBEDTLS_PSA_KEY_SLOT_COUNT >= 1);
TEST_CALLOC_OR_FAIL(keys, MBEDTLS_PSA_KEY_SLOT_COUNT);
TEST_CALLOC(keys, MBEDTLS_PSA_KEY_SLOT_COUNT);
PSA_ASSERT(psa_crypto_init());
psa_set_key_usage_flags(&attributes,

View file

@ -36,7 +36,7 @@ static int test_written_key(const psa_key_attributes_t *attributes,
/* Check that the key is represented as expected. */
PSA_ASSERT(psa_its_get_info(uid, &storage_info));
TEST_EQUAL(storage_info.size, expected_representation->len);
TEST_CALLOC_OR_FAIL(actual_representation, storage_info.size);
TEST_CALLOC(actual_representation, storage_info.size);
PSA_ASSERT(psa_its_get(uid, 0, storage_info.size,
actual_representation, &length));
TEST_BUFFERS_EQUAL(expected_representation->x, expected_representation->len,
@ -259,7 +259,7 @@ static int test_read_key(const psa_key_attributes_t *expected_attributes,
TEST_EQUAL(psa_get_key_enrollment_algorithm(expected_attributes),
psa_get_key_enrollment_algorithm(&actual_attributes));
if (can_export(expected_attributes)) {
TEST_CALLOC_OR_FAIL(exported_material, expected_material->len);
TEST_CALLOC(exported_material, expected_material->len);
PSA_ASSERT(psa_export_key(key_id,
exported_material, expected_material->len,
&length));

View file

@ -92,7 +92,7 @@ void set_get_remove(int uid_arg, int flags_arg, data_t *data)
unsigned char *buffer = NULL;
size_t ret_len = 0;
TEST_CALLOC_OR_FAIL(buffer, data->len);
TEST_CALLOC(buffer, data->len);
PSA_ASSERT(psa_its_set_wrap(uid, data->len, data->x, flags));
@ -122,7 +122,7 @@ void set_overwrite(int uid_arg,
unsigned char *buffer = NULL;
size_t ret_len = 0;
TEST_CALLOC_OR_FAIL(buffer, MAX(data1->len, data2->len));
TEST_CALLOC(buffer, MAX(data1->len, data2->len));
PSA_ASSERT(psa_its_set_wrap(uid, data1->len, data1->x, flags1));
PSA_ASSERT(psa_its_get_info(uid, &info));
@ -214,7 +214,7 @@ void get_at(int uid_arg, data_t *data,
size_t i;
size_t ret_len = 0;
TEST_CALLOC_OR_FAIL(buffer, length + 16);
TEST_CALLOC(buffer, length + 16);
trailer = buffer + length;
memset(trailer, '-', 16);

View file

@ -169,7 +169,7 @@ void mbedtls_psa_get_random_length(int n)
unsigned char *output = NULL;
PSA_ASSERT(psa_crypto_init());
TEST_CALLOC_OR_FAIL(output, n);
TEST_CALLOC(output, n);
TEST_EQUAL(0, mbedtls_psa_get_random(MBEDTLS_PSA_RANDOM_STATE,
output, n));

View file

@ -155,7 +155,7 @@ void mbedtls_sha3(int family, data_t *in, data_t *hash)
{
unsigned char *output = NULL;
TEST_CALLOC_OR_FAIL(output, hash->len);
TEST_CALLOC(output, hash->len);
TEST_ASSERT(mbedtls_sha3(family, in->x, in->len, output, hash->len) == 0);
@ -193,7 +193,7 @@ void mbedtls_sha3_multi(int family, data_t *in, data_t *hash)
mbedtls_sha3_context ctx;
const unsigned int block_size = 256;
TEST_CALLOC_OR_FAIL(output, hash->len);
TEST_CALLOC(output, hash->len);
mbedtls_sha3_init(&ctx);
mbedtls_sha3_starts(&ctx, family);

View file

@ -152,7 +152,7 @@ void test_callback_buffer(int size, int put1, int put1_ret,
if (input_len == 0) {
input_len = 1;
}
TEST_CALLOC_OR_FAIL(input, input_len);
TEST_CALLOC(input, input_len);
output_len = 0;
for (j = 0; j < ROUNDS; j++) {
@ -166,7 +166,7 @@ void test_callback_buffer(int size, int put1, int put1_ret,
if (output_len == 0) {
output_len = 1;
}
TEST_CALLOC_OR_FAIL(output, output_len);
TEST_CALLOC(output, output_len);
/* Fill up the buffer with structured data so that unwanted changes
* can be detected */
@ -1543,8 +1543,8 @@ void ssl_decrypt_non_etm_cbc(int cipher_type, int hash_id, int trunc_hmac,
+ plaintext_len
+ t0.maclen
+ padlen + 1;
TEST_CALLOC_OR_FAIL(buf, buflen);
TEST_CALLOC_OR_FAIL(buf_save, buflen);
TEST_CALLOC(buf, buflen);
TEST_CALLOC(buf_save, buflen);
/* Prepare a dummy record header */
memset(rec.ctr, 0, sizeof(rec.ctr));
@ -2064,7 +2064,7 @@ void ssl_tls13_record_protection(int ciphersuite,
/* Make sure we have enough space in the buffer even if
* we use more padding than the KAT. */
buf_len = ciphertext->len + MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY;
TEST_CALLOC_OR_FAIL(buf, buf_len);
TEST_CALLOC(buf, buf_len);
rec.type = MBEDTLS_SSL_MSG_APPLICATION_DATA;
/* TLS 1.3 uses the version identifier from TLS 1.2 on the wire. */

View file

@ -944,7 +944,7 @@ void mbedtls_x509_dn_get_next(char *name_str,
c = buf + sizeof(buf);
// Additional size required for trailing space
out_size = strlen(expected_oids) + 2;
TEST_CALLOC_OR_FAIL(out, out_size);
TEST_CALLOC(out, out_size);
TEST_EQUAL(mbedtls_x509_string_to_names(&names, name_str), 0);
@ -979,7 +979,7 @@ void mbedtls_x509_dn_get_next(char *name_str,
out = NULL;
out_size = strlen(exp_dn_gets) + 1;
TEST_CALLOC_OR_FAIL(out, out_size);
TEST_CALLOC(out, out_size);
TEST_LE_S(0, mbedtls_x509_dn_gets((char *) out, out_size, &parsed));
TEST_EQUAL(strcmp((char *) out, exp_dn_gets), 0);