For tests, rename ASSERT_COMPARE() to TEST_BUFFERS_EQUAL()

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
This commit is contained in:
Tom Cosgrove 2023-07-20 16:46:01 +01:00
parent ed70fd0c39
commit 65cd8519f7
39 changed files with 418 additions and 416 deletions

View file

@ -166,14 +166,16 @@
* \param size2 Size of the second buffer in bytes.
* This expression may be evaluated multiple times.
*/
#define ASSERT_COMPARE(p1, size1, p2, size2) \
do \
{ \
#define TEST_BUFFERS_EQUAL(p1, size1, p2, size2) \
do { \
TEST_EQUAL((size1), (size2)); \
if ((size1) != 0) \
TEST_ASSERT(memcmp((p1), (p2), (size1)) == 0); \
} \
while (0)
if ((size1) != 0) { \
TEST_ASSERT(memcmp((p1), (p2), (size1)) == 0); \
} \
} while (0)
/* For backwards compatibility */
#define ASSERT_COMPARE(p1, size1, p2, size2) TEST_BUFFERS_EQUAL(p1, size1, p2, size2)
/**
* \brief This macro tests the expression passed to it and skips the

View file

@ -38,13 +38,13 @@ static int test_copy(const data_t *key,
// Encrypt with copied context
TEST_ASSERT(mbedtls_aes_crypt_ecb(enc, MBEDTLS_AES_ENCRYPT,
plaintext, output) == 0);
ASSERT_COMPARE(ciphertext, 16, output, 16);
TEST_BUFFERS_EQUAL(ciphertext, 16, output, 16);
mbedtls_aes_free(enc);
// Decrypt with copied context
TEST_ASSERT(mbedtls_aes_crypt_ecb(dec, MBEDTLS_AES_DECRYPT,
ciphertext, output) == 0);
ASSERT_COMPARE(plaintext, 16, output, 16);
TEST_BUFFERS_EQUAL(plaintext, 16, output, 16);
mbedtls_aes_free(dec);
return 1;

View file

@ -77,7 +77,7 @@ void aria_encrypt_ecb(data_t *key_str, data_t *src_str,
output + i) == 0);
}
ASSERT_COMPARE(output, expected_output->len,
TEST_BUFFERS_EQUAL(output, expected_output->len,
expected_output->x, expected_output->len);
}
@ -105,7 +105,7 @@ void aria_decrypt_ecb(data_t *key_str, data_t *src_str,
output + i) == 0);
}
ASSERT_COMPARE(output, expected_output->len,
TEST_BUFFERS_EQUAL(output, expected_output->len,
expected_output->x, expected_output->len);
}
@ -130,7 +130,7 @@ void aria_encrypt_cbc(data_t *key_str, data_t *iv_str,
src_str->len, iv_str->x, src_str->x,
output) == cbc_result);
if (cbc_result == 0) {
ASSERT_COMPARE(output, expected_output->len,
TEST_BUFFERS_EQUAL(output, expected_output->len,
expected_output->x, expected_output->len);
}
@ -155,7 +155,7 @@ void aria_decrypt_cbc(data_t *key_str, data_t *iv_str,
src_str->len, iv_str->x, src_str->x,
output) == cbc_result);
if (cbc_result == 0) {
ASSERT_COMPARE(output, expected_output->len,
TEST_BUFFERS_EQUAL(output, expected_output->len,
expected_output->x, expected_output->len);
}
@ -182,7 +182,7 @@ void aria_encrypt_cfb128(data_t *key_str, data_t *iv_str,
iv_str->x, src_str->x, output)
== result);
ASSERT_COMPARE(output, expected_output->len,
TEST_BUFFERS_EQUAL(output, expected_output->len,
expected_output->x, expected_output->len);
exit:
@ -208,7 +208,7 @@ void aria_decrypt_cfb128(data_t *key_str, data_t *iv_str,
iv_str->x, src_str->x, output)
== result);
ASSERT_COMPARE(output, expected_output->len,
TEST_BUFFERS_EQUAL(output, expected_output->len,
expected_output->x, expected_output->len);
exit:
@ -234,7 +234,7 @@ void aria_encrypt_ctr(data_t *key_str, data_t *iv_str,
iv_str->x, blk, src_str->x, output)
== result);
ASSERT_COMPARE(output, expected_output->len,
TEST_BUFFERS_EQUAL(output, expected_output->len,
expected_output->x, expected_output->len);
exit:
@ -260,7 +260,7 @@ void aria_decrypt_ctr(data_t *key_str, data_t *iv_str,
iv_str->x, blk, src_str->x, output)
== result);
ASSERT_COMPARE(output, expected_output->len,
TEST_BUFFERS_EQUAL(output, expected_output->len,
expected_output->x, expected_output->len);
exit:

View file

@ -37,7 +37,7 @@ int generic_write_finish_step(generic_write_data_t *data,
TEST_EQUAL(ret, data->end - data->p);
TEST_ASSERT(data->p >= data->start);
TEST_ASSERT(data->p <= data->end);
ASSERT_COMPARE(data->p, (size_t) (data->end - data->p),
TEST_BUFFERS_EQUAL(data->p, (size_t) (data->end - data->p),
expected->x, expected->len);
}
ok = 1;
@ -322,7 +322,7 @@ void mbedtls_asn1_write_algorithm_identifier(data_t *oid,
TEST_EQUAL(mbedtls_asn1_get_alg(&p, end_complete,
&alg, &params), 0);
TEST_EQUAL(alg.tag, MBEDTLS_ASN1_OID);
ASSERT_COMPARE(alg.p, alg.len, oid->x, oid->len);
TEST_BUFFERS_EQUAL(alg.p, alg.len, oid->x, oid->len);
TEST_EQUAL(params.tag, expected_params_tag);
TEST_EQUAL(params.len, expected_params_len);
mbedtls_free(buf_complete);
@ -440,7 +440,7 @@ void test_asn1_write_bitstrings(data_t *bitstring, int bits,
mbedtls_asn1_bitstring read = { 0, 0, NULL };
TEST_EQUAL(mbedtls_asn1_get_bitstring(&data.p, data.end,
&read), 0);
ASSERT_COMPARE(read.p, read.len,
TEST_BUFFERS_EQUAL(read.p, read.len,
masked_bitstring, byte_length);
TEST_EQUAL(read.unused_bits, 8 * byte_length - value_bits);
}
@ -545,7 +545,7 @@ void store_named_data_val_found(int old_len, int new_len)
TEST_ASSERT(found == head);
if (new_val != NULL) {
ASSERT_COMPARE(found->val.p, found->val.len,
TEST_BUFFERS_EQUAL(found->val.p, found->val.len,
new_val, (size_t) new_len);
}
if (new_len == 0) {
@ -580,14 +580,14 @@ void store_named_data_val_new(int new_len, int set_new_val)
TEST_ASSERT(found != NULL);
TEST_ASSERT(found == head);
TEST_ASSERT(found->oid.p != oid);
ASSERT_COMPARE(found->oid.p, found->oid.len, oid, oid_len);
TEST_BUFFERS_EQUAL(found->oid.p, found->oid.len, oid, oid_len);
if (new_len == 0) {
TEST_ASSERT(found->val.p == NULL);
} else if (new_val == NULL) {
TEST_ASSERT(found->val.p != NULL);
} else {
TEST_ASSERT(found->val.p != new_val);
ASSERT_COMPARE(found->val.p, found->val.len,
TEST_BUFFERS_EQUAL(found->val.p, found->val.len,
new_val, (size_t) new_len);
}

View file

@ -34,45 +34,45 @@ static int mpi_core_verify_add(mbedtls_mpi_uint *A,
/* A + B => correct result and carry */
TEST_EQUAL(carry, mbedtls_mpi_core_add(X, A, B, limbs));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* A + B; alias output and first operand => correct result and carry */
memcpy(X, A, bytes);
TEST_EQUAL(carry, mbedtls_mpi_core_add(X, X, B, limbs));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* A + B; alias output and second operand => correct result and carry */
memcpy(X, B, bytes);
TEST_EQUAL(carry, mbedtls_mpi_core_add(X, A, X, limbs));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
if (memcmp(A, B, bytes) == 0) {
/* A == B, so test where A and B are aliased */
/* A + A => correct result and carry */
TEST_EQUAL(carry, mbedtls_mpi_core_add(X, A, A, limbs));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* A + A, output aliased to both operands => correct result and carry */
memcpy(X, A, bytes);
TEST_EQUAL(carry, mbedtls_mpi_core_add(X, X, X, limbs));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
} else {
/* A != B, so test B + A */
/* B + A => correct result and carry */
TEST_EQUAL(carry, mbedtls_mpi_core_add(X, B, A, limbs));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* B + A; alias output and first operand => correct result and carry */
memcpy(X, B, bytes);
TEST_EQUAL(carry, mbedtls_mpi_core_add(X, X, A, limbs));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* B + A; alias output and second operand => correct result and carry */
memcpy(X, A, bytes);
TEST_EQUAL(carry, mbedtls_mpi_core_add(X, B, X, limbs));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
}
ret = 1;
@ -111,11 +111,11 @@ static int mpi_core_verify_add_if(mbedtls_mpi_uint *A,
/* cond = 0 => X unchanged, no carry */
memcpy(X, A, bytes);
TEST_EQUAL(0, mbedtls_mpi_core_add_if(X, B, limbs, 0));
ASSERT_COMPARE(X, bytes, A, bytes);
TEST_BUFFERS_EQUAL(X, bytes, A, bytes);
/* cond = 1 => correct result and carry */
TEST_EQUAL(carry, mbedtls_mpi_core_add_if(X, B, limbs, 1));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
if (memcmp(A, B, bytes) == 0) {
/* A == B, so test where A and B are aliased */
@ -123,22 +123,22 @@ static int mpi_core_verify_add_if(mbedtls_mpi_uint *A,
/* cond = 0 => X unchanged, no carry */
memcpy(X, B, bytes);
TEST_EQUAL(0, mbedtls_mpi_core_add_if(X, X, limbs, 0));
ASSERT_COMPARE(X, bytes, B, bytes);
TEST_BUFFERS_EQUAL(X, bytes, B, bytes);
/* cond = 1 => correct result and carry */
TEST_EQUAL(carry, mbedtls_mpi_core_add_if(X, X, limbs, 1));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
} else {
/* A != B, so test B + A */
/* cond = 0 => d unchanged, no carry */
memcpy(X, B, bytes);
TEST_EQUAL(0, mbedtls_mpi_core_add_if(X, A, limbs, 0));
ASSERT_COMPARE(X, bytes, B, bytes);
TEST_BUFFERS_EQUAL(X, bytes, B, bytes);
/* cond = 1 => correct result and carry */
TEST_EQUAL(carry, mbedtls_mpi_core_add_if(X, A, limbs, 1));
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
}
ret = 1;
@ -458,10 +458,10 @@ void mpi_core_cond_assign(char *input_X,
TEST_CF_PUBLIC(X, bytes);
TEST_CF_PUBLIC(Y, bytes);
ASSERT_COMPARE(X, copy_bytes, Y, copy_bytes);
TEST_BUFFERS_EQUAL(X, copy_bytes, Y, copy_bytes);
TEST_ASSERT(memcmp(X, Y, bytes) != 0);
} else {
ASSERT_COMPARE(X, bytes, Y, bytes);
TEST_BUFFERS_EQUAL(X, bytes, Y, bytes);
}
exit:
@ -508,8 +508,8 @@ void mpi_core_cond_swap(char *input_X,
TEST_CF_PUBLIC(X, bytes);
TEST_CF_PUBLIC(Y, bytes);
ASSERT_COMPARE(X, bytes, tmp_X, bytes);
ASSERT_COMPARE(Y, bytes, tmp_Y, bytes);
TEST_BUFFERS_EQUAL(X, bytes, tmp_X, bytes);
TEST_BUFFERS_EQUAL(Y, bytes, tmp_Y, bytes);
/* condition is true */
TEST_CF_SECRET(X, bytes);
@ -523,15 +523,15 @@ void mpi_core_cond_swap(char *input_X,
/* Check if the given length is copied even it is smaller
than the length of the given MPIs. */
if (copy_limbs < limbs) {
ASSERT_COMPARE(X, copy_bytes, tmp_Y, copy_bytes);
ASSERT_COMPARE(Y, copy_bytes, tmp_X, copy_bytes);
TEST_BUFFERS_EQUAL(X, copy_bytes, tmp_Y, copy_bytes);
TEST_BUFFERS_EQUAL(Y, copy_bytes, tmp_X, copy_bytes);
TEST_ASSERT(memcmp(X, tmp_X, bytes) != 0);
TEST_ASSERT(memcmp(X, tmp_Y, bytes) != 0);
TEST_ASSERT(memcmp(Y, tmp_X, bytes) != 0);
TEST_ASSERT(memcmp(Y, tmp_Y, bytes) != 0);
} else {
ASSERT_COMPARE(X, bytes, tmp_Y, bytes);
ASSERT_COMPARE(Y, bytes, tmp_X, bytes);
TEST_BUFFERS_EQUAL(X, bytes, tmp_Y, bytes);
TEST_BUFFERS_EQUAL(Y, bytes, tmp_X, bytes);
}
exit:
@ -554,7 +554,7 @@ void mpi_core_shift_r(char *input, int count, char *result)
TEST_EQUAL(limbs, n);
mbedtls_mpi_core_shift_r(X, limbs, count);
ASSERT_COMPARE(X, limbs * ciL, Y, limbs * ciL);
TEST_BUFFERS_EQUAL(X, limbs * ciL, Y, limbs * ciL);
exit:
mbedtls_free(X);
@ -574,7 +574,7 @@ void mpi_core_shift_l(char *input, int count, char *result)
TEST_EQUAL(limbs, n);
mbedtls_mpi_core_shift_l(X, limbs, count);
ASSERT_COMPARE(X, limbs * ciL, Y, limbs * ciL);
TEST_BUFFERS_EQUAL(X, limbs * ciL, Y, limbs * ciL);
exit:
mbedtls_free(X);
@ -664,7 +664,7 @@ void mpi_core_sub(char *input_A, char *input_B,
TEST_EQUAL(carry, mbedtls_mpi_core_sub(r, a, b, limbs));
/* 1b) r = a - b => we should get the correct result */
ASSERT_COMPARE(r, bytes, x, bytes);
TEST_BUFFERS_EQUAL(r, bytes, x, bytes);
/* 2 and 3 test "r may be aliased to a or b" */
/* 2a) r = a; r -= b => we should get the correct carry (use r to avoid clobbering a) */
@ -672,20 +672,20 @@ void mpi_core_sub(char *input_A, char *input_B,
TEST_EQUAL(carry, mbedtls_mpi_core_sub(r, r, b, limbs));
/* 2b) r -= b => we should get the correct result */
ASSERT_COMPARE(r, bytes, x, bytes);
TEST_BUFFERS_EQUAL(r, bytes, x, bytes);
/* 3a) r = b; r = a - r => we should get the correct carry (use r to avoid clobbering b) */
memcpy(r, b, bytes);
TEST_EQUAL(carry, mbedtls_mpi_core_sub(r, a, r, limbs));
/* 3b) r = a - b => we should get the correct result */
ASSERT_COMPARE(r, bytes, x, bytes);
TEST_BUFFERS_EQUAL(r, bytes, x, bytes);
/* 4 tests "r may be aliased to [...] both" */
if (A.n == B.n && memcmp(A.p, B.p, bytes) == 0) {
memcpy(r, b, bytes);
TEST_EQUAL(carry, mbedtls_mpi_core_sub(r, r, r, limbs));
ASSERT_COMPARE(r, bytes, x, bytes);
TEST_BUFFERS_EQUAL(r, bytes, x, bytes);
}
exit:
@ -774,13 +774,13 @@ void mpi_core_mla(char *input_A, char *input_B, char *input_S,
TEST_EQUAL(mbedtls_mpi_core_mla(a, limbs, B.p, B.n, *S.p), *cy->p);
/* 1b) A += B * s => we should get the correct result */
ASSERT_COMPARE(a, bytes, x, bytes);
TEST_BUFFERS_EQUAL(a, bytes, x, bytes);
if (A.n == B.n && memcmp(A.p, B.p, bytes) == 0) {
/* Check when A and B are aliased */
memcpy(a, A.p, A.n * sizeof(mbedtls_mpi_uint));
TEST_EQUAL(mbedtls_mpi_core_mla(a, limbs, a, limbs, *S.p), *cy->p);
ASSERT_COMPARE(a, bytes, x, bytes);
TEST_BUFFERS_EQUAL(a, bytes, x, bytes);
}
exit:
@ -890,14 +890,14 @@ void mpi_core_montmul(int limbs_AN4, int limbs_B4,
mbedtls_mpi_core_montmul(R.p, A.p, B.p, B.n, N.p, N.n, mm, T.p);
size_t bytes = N.n * sizeof(mbedtls_mpi_uint);
ASSERT_COMPARE(R.p, bytes, X->p, bytes);
TEST_BUFFERS_EQUAL(R.p, bytes, X->p, bytes);
/* The output (R, above) may be aliased to A - use R to save the value of A */
memcpy(R.p, A.p, bytes);
mbedtls_mpi_core_montmul(A.p, A.p, B.p, B.n, N.p, N.n, mm, T.p);
ASSERT_COMPARE(A.p, bytes, X->p, bytes);
TEST_BUFFERS_EQUAL(A.p, bytes, X->p, bytes);
memcpy(A.p, R.p, bytes); /* restore A */
@ -906,7 +906,7 @@ void mpi_core_montmul(int limbs_AN4, int limbs_B4,
memcpy(R.p, N.p, bytes);
mbedtls_mpi_core_montmul(N.p, A.p, B.p, B.n, N.p, N.n, mm, T.p);
ASSERT_COMPARE(N.p, bytes, X->p, bytes);
TEST_BUFFERS_EQUAL(N.p, bytes, X->p, bytes);
memcpy(N.p, R.p, bytes);
@ -917,7 +917,7 @@ void mpi_core_montmul(int limbs_AN4, int limbs_B4,
* don't bother with yet another test with only A and B aliased */
mbedtls_mpi_core_montmul(B.p, B.p, B.p, B.n, N.p, N.n, mm, T.p);
ASSERT_COMPARE(B.p, bytes, X->p, bytes);
TEST_BUFFERS_EQUAL(B.p, bytes, X->p, bytes);
memcpy(B.p, A.p, bytes); /* restore B from equal value A */
}
@ -925,7 +925,7 @@ void mpi_core_montmul(int limbs_AN4, int limbs_B4,
/* The output may be aliased to B - last test, so we don't save B */
mbedtls_mpi_core_montmul(B.p, A.p, B.p, B.n, N.p, N.n, mm, T.p);
ASSERT_COMPARE(B.p, bytes, X->p, bytes);
TEST_BUFFERS_EQUAL(B.p, bytes, X->p, bytes);
}
exit:
@ -1046,7 +1046,7 @@ void mpi_core_ct_uint_table_lookup(int bitlen, int window_size)
TEST_CF_PUBLIC(dest, limbs * sizeof(*dest));
TEST_CF_PUBLIC(table, count * limbs * sizeof(*table));
ASSERT_COMPARE(dest, limbs * sizeof(*dest),
TEST_BUFFERS_EQUAL(dest, limbs * sizeof(*dest),
current, limbs * sizeof(*current));
TEST_CF_PUBLIC(&i, sizeof(i));
}
@ -1143,24 +1143,24 @@ void mpi_core_mul(char *input_A,
/* 1. X = A * B - result should be correct, A and B unchanged */
mbedtls_mpi_core_mul(X, A, A_limbs, B, B_limbs);
ASSERT_COMPARE(X, X_bytes, R, X_bytes);
ASSERT_COMPARE(A, A_bytes, A_orig, A_bytes);
ASSERT_COMPARE(B, B_bytes, B_orig, B_bytes);
TEST_BUFFERS_EQUAL(X, X_bytes, R, X_bytes);
TEST_BUFFERS_EQUAL(A, A_bytes, A_orig, A_bytes);
TEST_BUFFERS_EQUAL(B, B_bytes, B_orig, B_bytes);
/* 2. A == B: alias A and B - result should be correct, A and B unchanged */
if (A_bytes == B_bytes && memcmp(A, B, A_bytes) == 0) {
memset(X, '!', X_bytes);
mbedtls_mpi_core_mul(X, A, A_limbs, A, A_limbs);
ASSERT_COMPARE(X, X_bytes, R, X_bytes);
ASSERT_COMPARE(A, A_bytes, A_orig, A_bytes);
TEST_BUFFERS_EQUAL(X, X_bytes, R, X_bytes);
TEST_BUFFERS_EQUAL(A, A_bytes, A_orig, A_bytes);
}
/* 3. X = B * A - result should be correct, A and B unchanged */
else {
memset(X, '!', X_bytes);
mbedtls_mpi_core_mul(X, B, B_limbs, A, A_limbs);
ASSERT_COMPARE(X, X_bytes, R, X_bytes);
ASSERT_COMPARE(A, A_bytes, A_orig, A_bytes);
ASSERT_COMPARE(B, B_bytes, B_orig, B_bytes);
TEST_BUFFERS_EQUAL(X, X_bytes, R, X_bytes);
TEST_BUFFERS_EQUAL(A, A_bytes, A_orig, A_bytes);
TEST_BUFFERS_EQUAL(B, B_bytes, B_orig, B_bytes);
}
exit:
@ -1280,7 +1280,7 @@ void mpi_core_sub_int(char *input_A, char *input_B,
ASSERT_ALLOC(R, limbs);
#define TEST_COMPARE_CORE_MPIS(A, B, limbs) \
ASSERT_COMPARE(A, (limbs) * sizeof(mbedtls_mpi_uint), B, (limbs) * sizeof(mbedtls_mpi_uint))
TEST_BUFFERS_EQUAL(A, (limbs) * sizeof(mbedtls_mpi_uint), B, (limbs) * sizeof(mbedtls_mpi_uint))
/* 1. R = A - b. Result and borrow should be correct */
TEST_EQUAL(mbedtls_mpi_core_sub_int(R, A, B[0], limbs), borrow);

View file

@ -7,7 +7,7 @@
#include "test/constant_flow.h"
#define TEST_COMPARE_MPI_RESIDUES(a, b) \
ASSERT_COMPARE((a).p, (a).limbs * sizeof(mbedtls_mpi_uint), \
TEST_BUFFERS_EQUAL((a).p, (a).limbs * sizeof(mbedtls_mpi_uint), \
(b).p, (b).limbs * sizeof(mbedtls_mpi_uint))
static int test_read_residue(mbedtls_mpi_mod_residue *r,
@ -128,42 +128,42 @@ void mpi_mod_mul(char *input_A,
TEST_EQUAL(mbedtls_mpi_mod_residue_setup(&rX, &m, X, limbs), 0);
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rB, &m), 0);
ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
TEST_BUFFERS_EQUAL(rX.p, bytes, rR.p, bytes);
/* alias X to A */
memcpy(rX.p, rA.p, bytes);
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rX, &rB, &m), 0);
ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
TEST_BUFFERS_EQUAL(rX.p, bytes, rR.p, bytes);
/* alias X to B */
memcpy(rX.p, rB.p, bytes);
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rX, &m), 0);
ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
TEST_BUFFERS_EQUAL(rX.p, bytes, rR.p, bytes);
/* A == B: alias A and B */
if (memcmp(rA.p, rB.p, bytes) == 0) {
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rA, &rA, &m), 0);
ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
TEST_BUFFERS_EQUAL(rX.p, bytes, rR.p, bytes);
/* X, A, B all aliased together */
memcpy(rX.p, rA.p, bytes);
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rX, &rX, &m), 0);
ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
TEST_BUFFERS_EQUAL(rX.p, bytes, rR.p, bytes);
}
/* A != B: test B * A */
else {
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rB, &rA, &m), 0);
ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
TEST_BUFFERS_EQUAL(rX.p, bytes, rR.p, bytes);
/* B * A: alias X to A */
memcpy(rX.p, rA.p, bytes);
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rB, &rX, &m), 0);
ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
TEST_BUFFERS_EQUAL(rX.p, bytes, rR.p, bytes);
/* B + A: alias X to B */
memcpy(rX.p, rB.p, bytes);
TEST_EQUAL(mbedtls_mpi_mod_mul(&rX, &rX, &rA, &m), 0);
ASSERT_COMPARE(rX.p, bytes, rR.p, bytes);
TEST_BUFFERS_EQUAL(rX.p, bytes, rR.p, bytes);
}
exit:
@ -702,7 +702,7 @@ void mpi_mod_io(char *input_N, data_t *input_A, int endian)
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 */
ASSERT_COMPARE(r.p, r.limbs, r_copy.p, r_copy.limbs);
TEST_BUFFERS_EQUAL(r.p, r.limbs, r_copy.p, r_copy.limbs);
/* Set up reference output for checking the result */
ASSERT_ALLOC(ref_buf, obuf_sizes[i]);
@ -723,7 +723,7 @@ void mpi_mod_io(char *input_N, data_t *input_A, int endian)
}
/* Check the result */
ASSERT_COMPARE(obuf, obuf_sizes[i], ref_buf, obuf_sizes[i]);
TEST_BUFFERS_EQUAL(obuf, obuf_sizes[i], ref_buf, obuf_sizes[i]);
mbedtls_free(ref_buf);
ref_buf = NULL;

View file

@ -161,10 +161,10 @@ void mpi_mod_raw_cond_assign(char *input_X,
/* Check if the given length is copied even it is smaller
than the length of the given MPIs. */
if (copy_limbs < limbs) {
ASSERT_COMPARE(X, copy_bytes, Y, copy_bytes);
TEST_BUFFERS_EQUAL(X, copy_bytes, Y, copy_bytes);
TEST_ASSERT(memcmp(X, Y, bytes) != 0);
} else {
ASSERT_COMPARE(X, bytes, Y, bytes);
TEST_BUFFERS_EQUAL(X, bytes, Y, bytes);
}
exit:
@ -223,8 +223,8 @@ void mpi_mod_raw_cond_swap(char *input_X,
TEST_CF_PUBLIC(X, bytes);
TEST_CF_PUBLIC(Y, bytes);
ASSERT_COMPARE(X, bytes, tmp_X, bytes);
ASSERT_COMPARE(Y, bytes, tmp_Y, bytes);
TEST_BUFFERS_EQUAL(X, bytes, tmp_X, bytes);
TEST_BUFFERS_EQUAL(Y, bytes, tmp_Y, bytes);
/* condition is true */
TEST_CF_SECRET(X, bytes);
@ -238,15 +238,15 @@ void mpi_mod_raw_cond_swap(char *input_X,
/* Check if the given length is copied even it is smaller
than the length of the given MPIs. */
if (copy_limbs < limbs) {
ASSERT_COMPARE(X, copy_bytes, tmp_Y, copy_bytes);
ASSERT_COMPARE(Y, copy_bytes, tmp_X, copy_bytes);
TEST_BUFFERS_EQUAL(X, copy_bytes, tmp_Y, copy_bytes);
TEST_BUFFERS_EQUAL(Y, copy_bytes, tmp_X, copy_bytes);
TEST_ASSERT(memcmp(X, tmp_X, bytes) != 0);
TEST_ASSERT(memcmp(X, tmp_Y, bytes) != 0);
TEST_ASSERT(memcmp(Y, tmp_X, bytes) != 0);
TEST_ASSERT(memcmp(Y, tmp_Y, bytes) != 0);
} else {
ASSERT_COMPARE(X, bytes, tmp_Y, bytes);
ASSERT_COMPARE(Y, bytes, tmp_X, bytes);
TEST_BUFFERS_EQUAL(X, bytes, tmp_Y, bytes);
TEST_BUFFERS_EQUAL(Y, bytes, tmp_X, bytes);
}
exit:
@ -297,27 +297,27 @@ void mpi_mod_raw_sub(char *input_A,
&m, N, limbs), 0);
mbedtls_mpi_mod_raw_sub(X, A, B, &m);
ASSERT_COMPARE(X, bytes, res, bytes);
TEST_BUFFERS_EQUAL(X, bytes, res, bytes);
/* alias X to A */
memcpy(X, A, bytes);
mbedtls_mpi_mod_raw_sub(X, X, B, &m);
ASSERT_COMPARE(X, bytes, res, bytes);
TEST_BUFFERS_EQUAL(X, bytes, res, bytes);
/* alias X to B */
memcpy(X, B, bytes);
mbedtls_mpi_mod_raw_sub(X, A, X, &m);
ASSERT_COMPARE(X, bytes, res, bytes);
TEST_BUFFERS_EQUAL(X, bytes, res, bytes);
/* A == B: alias A and B */
if (memcmp(A, B, bytes) == 0) {
mbedtls_mpi_mod_raw_sub(X, A, A, &m);
ASSERT_COMPARE(X, bytes, res, bytes);
TEST_BUFFERS_EQUAL(X, bytes, res, bytes);
/* X, A, B all aliased together */
memcpy(X, A, bytes);
mbedtls_mpi_mod_raw_sub(X, X, X, &m);
ASSERT_COMPARE(X, bytes, res, bytes);
TEST_BUFFERS_EQUAL(X, bytes, res, bytes);
}
exit:
mbedtls_free(A);
@ -367,7 +367,7 @@ void mpi_mod_raw_fix_quasi_reduction(char *input_N,
&m, N, limbs), 0);
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
ASSERT_COMPARE(X, bytes, res, bytes);
TEST_BUFFERS_EQUAL(X, bytes, res, bytes);
exit:
mbedtls_free(X);
@ -420,42 +420,42 @@ void mpi_mod_raw_mul(char *input_A,
ASSERT_ALLOC(T, limbs_T);
mbedtls_mpi_mod_raw_mul(X, A, B, &m, T);
ASSERT_COMPARE(X, bytes, R, bytes);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
/* alias X to A */
memcpy(X, A, bytes);
mbedtls_mpi_mod_raw_mul(X, X, B, &m, T);
ASSERT_COMPARE(X, bytes, R, bytes);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
/* alias X to B */
memcpy(X, B, bytes);
mbedtls_mpi_mod_raw_mul(X, A, X, &m, T);
ASSERT_COMPARE(X, bytes, R, bytes);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
/* A == B: alias A and B */
if (memcmp(A, B, bytes) == 0) {
mbedtls_mpi_mod_raw_mul(X, A, A, &m, T);
ASSERT_COMPARE(X, bytes, R, bytes);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
/* X, A, B all aliased together */
memcpy(X, A, bytes);
mbedtls_mpi_mod_raw_mul(X, X, X, &m, T);
ASSERT_COMPARE(X, bytes, R, bytes);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
}
/* A != B: test B * A */
else {
mbedtls_mpi_mod_raw_mul(X, B, A, &m, T);
ASSERT_COMPARE(X, bytes, R, bytes);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
/* B * A: alias X to A */
memcpy(X, A, bytes);
mbedtls_mpi_mod_raw_mul(X, B, X, &m, T);
ASSERT_COMPARE(X, bytes, R, bytes);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
/* B + A: alias X to B */
memcpy(X, B, bytes);
mbedtls_mpi_mod_raw_mul(X, X, A, &m, T);
ASSERT_COMPARE(X, bytes, R, bytes);
TEST_BUFFERS_EQUAL(X, bytes, R, bytes);
}
exit:
@ -578,45 +578,45 @@ void mpi_mod_raw_add(char *input_N,
/* A + B => Correct result */
mbedtls_mpi_mod_raw_add(X, A, B, &m);
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* A + B: alias X to A => Correct result */
memcpy(X, A, bytes);
mbedtls_mpi_mod_raw_add(X, X, B, &m);
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* A + B: alias X to B => Correct result */
memcpy(X, B, bytes);
mbedtls_mpi_mod_raw_add(X, A, X, &m);
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
if (memcmp(A, B, bytes) == 0) {
/* A == B: alias A and B */
/* A + A => Correct result */
mbedtls_mpi_mod_raw_add(X, A, A, &m);
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* A + A: X, A, B all aliased together => Correct result */
memcpy(X, A, bytes);
mbedtls_mpi_mod_raw_add(X, X, X, &m);
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
} else {
/* A != B: test B + A */
/* B + A => Correct result */
mbedtls_mpi_mod_raw_add(X, B, A, &m);
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* B + A: alias X to A => Correct result */
memcpy(X, A, bytes);
mbedtls_mpi_mod_raw_add(X, B, X, &m);
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
/* B + A: alias X to B => Correct result */
memcpy(X, B, bytes);
mbedtls_mpi_mod_raw_add(X, X, A, &m);
ASSERT_COMPARE(X, bytes, S, bytes);
TEST_BUFFERS_EQUAL(X, bytes, S, bytes);
}
exit:
@ -647,7 +647,7 @@ void mpi_mod_raw_canonical_to_modulus_rep(const char *input_N, int rep,
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
TEST_EQUAL(0, mbedtls_mpi_mod_raw_canonical_to_modulus_rep(A, &N));
ASSERT_COMPARE(A, A_limbs * sizeof(mbedtls_mpi_uint),
TEST_BUFFERS_EQUAL(A, A_limbs * sizeof(mbedtls_mpi_uint),
X, X_limbs * sizeof(mbedtls_mpi_uint));
exit:
@ -674,7 +674,7 @@ void mpi_mod_raw_modulus_to_canonical_rep(const char *input_N, int rep,
TEST_EQUAL(0, mbedtls_test_read_mpi_core(&X, &X_limbs, input_X));
TEST_EQUAL(0, mbedtls_mpi_mod_raw_modulus_to_canonical_rep(A, &N));
ASSERT_COMPARE(A, A_limbs * sizeof(mbedtls_mpi_uint),
TEST_BUFFERS_EQUAL(A, A_limbs * sizeof(mbedtls_mpi_uint),
X, X_limbs * sizeof(mbedtls_mpi_uint));
exit:
@ -723,20 +723,20 @@ void mpi_mod_raw_to_mont_rep(char *input_N, char *input_A, char *input_X)
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 */
ASSERT_COMPARE(R, bytes, X, bytes);
TEST_BUFFERS_EQUAL(R, bytes, X, bytes);
/* Test when output is aliased to input */
memcpy(R, A, bytes);
mbedtls_mpi_core_to_mont_rep(R, R, N, n_limbs,
m.rep.mont.mm, m.rep.mont.rr, T);
ASSERT_COMPARE(R, bytes, X, bytes);
TEST_BUFFERS_EQUAL(R, bytes, X, bytes);
/* 2. Test higher-level cannonical to Montgomery conversion */
TEST_EQUAL(0, mbedtls_mpi_mod_raw_to_mont_rep(A, &m));
/* The result matches expected value */
ASSERT_COMPARE(A, bytes, X, bytes);
TEST_BUFFERS_EQUAL(A, bytes, X, bytes);
exit:
mbedtls_mpi_mod_modulus_free(&m);
@ -787,20 +787,20 @@ void mpi_mod_raw_from_mont_rep(char *input_N, char *input_A, char *input_X)
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 */
ASSERT_COMPARE(R, bytes, X, bytes);
TEST_BUFFERS_EQUAL(R, bytes, X, bytes);
/* Test when output is aliased to input */
memcpy(R, A, bytes);
mbedtls_mpi_core_from_mont_rep(R, R, N, n_limbs,
m.rep.mont.mm, T);
ASSERT_COMPARE(R, bytes, X, bytes);
TEST_BUFFERS_EQUAL(R, bytes, X, bytes);
/* 2. Test higher-level Montgomery to cannonical conversion */
TEST_EQUAL(0, mbedtls_mpi_mod_raw_from_mont_rep(A, &m));
/* The result matches expected value */
ASSERT_COMPARE(A, bytes, X, bytes);
TEST_BUFFERS_EQUAL(A, bytes, X, bytes);
exit:
mbedtls_mpi_mod_modulus_free(&m);
@ -841,19 +841,19 @@ void mpi_mod_raw_neg(char *input_N, char *input_A, char *input_X)
/* Neg( A == 0 ) => Zero result */
mbedtls_mpi_mod_raw_neg(R, Z, &m);
ASSERT_COMPARE(R, bytes, Z, bytes);
TEST_BUFFERS_EQUAL(R, bytes, Z, bytes);
/* Neg( A == N ) => Zero result */
mbedtls_mpi_mod_raw_neg(R, N, &m);
ASSERT_COMPARE(R, bytes, Z, bytes);
TEST_BUFFERS_EQUAL(R, bytes, Z, bytes);
/* Neg( A ) => Correct result */
mbedtls_mpi_mod_raw_neg(R, A, &m);
ASSERT_COMPARE(R, bytes, X, bytes);
TEST_BUFFERS_EQUAL(R, bytes, X, bytes);
/* Neg( A ): alias A to R => Correct result */
mbedtls_mpi_mod_raw_neg(A, A, &m);
ASSERT_COMPARE(A, bytes, X, bytes);
TEST_BUFFERS_EQUAL(A, bytes, X, bytes);
exit:
mbedtls_mpi_mod_modulus_free(&m);
mbedtls_free(N);

View file

@ -174,7 +174,7 @@ void mpi_legacy_random_values(int min, char *max_hex)
* same number, with the same limb count. */
TEST_EQUAL(core_ret, legacy_ret);
if (core_ret == 0) {
ASSERT_COMPARE(R_core, limbs * ciL,
TEST_BUFFERS_EQUAL(R_core, limbs * ciL,
R_legacy.p, R_legacy.n * ciL);
}
@ -182,7 +182,7 @@ void mpi_legacy_random_values(int min, char *max_hex)
/* This may theoretically fail on rare platforms with padding in
* the structure! If this is a problem in practice, change to a
* field-by-field comparison. */
ASSERT_COMPARE(&rnd_core, sizeof(rnd_core),
TEST_BUFFERS_EQUAL(&rnd_core, sizeof(rnd_core),
&rnd_legacy, sizeof(rnd_legacy));
exit:
@ -237,11 +237,11 @@ void mpi_mod_random_values(int min, char *max_hex, int rep)
if (core_ret == 0) {
TEST_EQUAL(mbedtls_mpi_mod_raw_modulus_to_canonical_rep(R_mod_raw, &N),
0);
ASSERT_COMPARE(R_core, N.limbs * ciL,
TEST_BUFFERS_EQUAL(R_core, N.limbs * ciL,
R_mod_raw, N.limbs * ciL);
TEST_EQUAL(mbedtls_mpi_mod_raw_modulus_to_canonical_rep(R_mod_digits, &N),
0);
ASSERT_COMPARE(R_core, N.limbs * ciL,
TEST_BUFFERS_EQUAL(R_core, N.limbs * ciL,
R_mod_digits, N.limbs * ciL);
}
@ -249,9 +249,9 @@ void mpi_mod_random_values(int min, char *max_hex, int rep)
/* This may theoretically fail on rare platforms with padding in
* the structure! If this is a problem in practice, change to a
* field-by-field comparison. */
ASSERT_COMPARE(&rnd_core, sizeof(rnd_core),
TEST_BUFFERS_EQUAL(&rnd_core, sizeof(rnd_core),
&rnd_mod_raw, sizeof(rnd_mod_raw));
ASSERT_COMPARE(&rnd_core, sizeof(rnd_core),
TEST_BUFFERS_EQUAL(&rnd_core, sizeof(rnd_core),
&rnd_mod, sizeof(rnd_mod));
exit:

View file

@ -36,7 +36,7 @@ static int check_multipart(mbedtls_ccm_context *ctx,
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_ccm_update(ctx, input->x, n1, output, n1, &olen));
TEST_EQUAL(n1, olen);
ASSERT_COMPARE(output, olen, expected_output->x, n1);
TEST_BUFFERS_EQUAL(output, olen, expected_output->x, n1);
mbedtls_free(output);
output = NULL;
@ -44,13 +44,13 @@ static int check_multipart(mbedtls_ccm_context *ctx,
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_ccm_update(ctx, input->x + n1, n2, output, n2, &olen));
TEST_EQUAL(n2, olen);
ASSERT_COMPARE(output, olen, expected_output->x + n1, n2);
TEST_BUFFERS_EQUAL(output, olen, expected_output->x + n1, n2);
mbedtls_free(output);
output = NULL;
ASSERT_ALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_ccm_finish(ctx, output, tag->len));
ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
mbedtls_free(output);
output = NULL;
@ -204,8 +204,8 @@ void mbedtls_ccm_encrypt_and_tag(int cipher_id, data_t *key,
TEST_EQUAL(mbedtls_ccm_encrypt_and_tag(&ctx, msg->len, iv->x, iv->len, add->x, add->len,
io_msg_buf, io_msg_buf, tag_buf, expected_tag_len), 0);
ASSERT_COMPARE(io_msg_buf, msg->len, result->x, msg->len);
ASSERT_COMPARE(tag_buf, expected_tag_len, expected_tag, expected_tag_len);
TEST_BUFFERS_EQUAL(io_msg_buf, msg->len, result->x, msg->len);
TEST_BUFFERS_EQUAL(tag_buf, expected_tag_len, expected_tag, expected_tag_len);
/* Prepare data_t structures for multipart testing */
const data_t encrypted_expected = { .x = result->x,
@ -249,7 +249,7 @@ void mbedtls_ccm_star_no_tag(int cipher_id, int mode, data_t *key,
ASSERT_ALLOC(output, msg->len);
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
TEST_EQUAL(result->len, olen);
ASSERT_COMPARE(output, olen, result->x, result->len);
TEST_BUFFERS_EQUAL(output, olen, result->x, result->len);
TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, NULL, 0));
exit:
@ -285,7 +285,7 @@ void mbedtls_ccm_auth_decrypt(int cipher_id, data_t *key,
result);
if (result == 0) {
ASSERT_COMPARE(io_msg_buf, expected_msg_len, expected_msg->x, expected_msg_len);
TEST_BUFFERS_EQUAL(io_msg_buf, expected_msg_len, expected_msg->x, expected_msg_len);
/* Prepare data_t structures for multipart testing */
const data_t encrypted = { .x = msg->x,
@ -372,8 +372,8 @@ void mbedtls_ccm_star_encrypt_and_tag(int cipher_id,
add->x, add->len, io_msg_buf,
io_msg_buf, tag_buf, expected_tag_len), output_ret);
ASSERT_COMPARE(io_msg_buf, msg->len, expected_result->x, msg->len);
ASSERT_COMPARE(tag_buf, expected_tag_len, expected_tag, expected_tag_len);
TEST_BUFFERS_EQUAL(io_msg_buf, msg->len, expected_result->x, msg->len);
TEST_BUFFERS_EQUAL(tag_buf, expected_tag_len, expected_tag, expected_tag_len);
if (output_ret == 0) {
const data_t iv_data = { .x = iv,
@ -450,7 +450,7 @@ void mbedtls_ccm_star_auth_decrypt(int cipher_id,
add->x, add->len, io_msg_buf, io_msg_buf,
expected_tag, expected_tag_len), output_ret);
ASSERT_COMPARE(io_msg_buf, expected_msg_len, expected_result->x, expected_msg_len);
TEST_BUFFERS_EQUAL(io_msg_buf, expected_msg_len, expected_result->x, expected_msg_len);
if (output_ret == 0) {
const data_t iv_data = { .x = iv,
@ -504,13 +504,13 @@ void mbedtls_ccm_skip_ad(int cipher_id, int mode,
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, result->len, &olen));
TEST_EQUAL(result->len, olen);
ASSERT_COMPARE(output, olen, result->x, result->len);
TEST_BUFFERS_EQUAL(output, olen, result->x, result->len);
mbedtls_free(output);
output = NULL;
ASSERT_ALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, output, tag->len));
ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
mbedtls_free(output);
output = NULL;
@ -538,7 +538,7 @@ void mbedtls_ccm_skip_update(int cipher_id, int mode,
ASSERT_ALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, output, tag->len));
ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
mbedtls_free(output);
output = NULL;

View file

@ -29,7 +29,7 @@ void chacha20_crypt(data_t *key_str,
TEST_ASSERT(mbedtls_chacha20_crypt(key_str->x, nonce_str->x, counter, src_str->len, src_str->x,
output) == 0);
ASSERT_COMPARE(output, expected_output_str->len,
TEST_BUFFERS_EQUAL(output, expected_output_str->len,
expected_output_str->x, expected_output_str->len);
/*
@ -44,7 +44,7 @@ void chacha20_crypt(data_t *key_str,
memset(output, 0x00, sizeof(output));
TEST_ASSERT(mbedtls_chacha20_update(&ctx, src_str->len, src_str->x, output) == 0);
ASSERT_COMPARE(output, expected_output_str->len,
TEST_BUFFERS_EQUAL(output, expected_output_str->len,
expected_output_str->x, expected_output_str->len);
/*
@ -60,7 +60,7 @@ void chacha20_crypt(data_t *key_str,
TEST_ASSERT(mbedtls_chacha20_update(&ctx, src_str->len - 1,
src_str->x + 1, output + 1) == 0);
ASSERT_COMPARE(output, expected_output_str->len,
TEST_BUFFERS_EQUAL(output, expected_output_str->len,
expected_output_str->x, expected_output_str->len);
mbedtls_chacha20_free(&ctx);

View file

@ -950,7 +950,7 @@ void auth_crypt_tv(int cipher_id, data_t *key, data_t *iv,
TEST_ASSERT(buffer_is_all_zero(decrypt_buf, decrypt_buf_len));
} else {
TEST_ASSERT(ret == 0);
ASSERT_COMPARE(decrypt_buf, outlen, clear->x, clear->len);
TEST_BUFFERS_EQUAL(decrypt_buf, outlen, clear->x, clear->len);
}
mbedtls_free(decrypt_buf);

View file

@ -28,7 +28,7 @@ void mbedtls_xor(int len)
r1[i] = a[i] ^ b[i];
}
mbedtls_xor(r2, a, b, n);
ASSERT_COMPARE(r1, n, r2, n);
TEST_BUFFERS_EQUAL(r1, n, r2, n);
/* Test r == a */
fill_arrays(a, b, r1, r2, n);
@ -36,7 +36,7 @@ void mbedtls_xor(int len)
r1[i] = r1[i] ^ b[i];
}
mbedtls_xor(r2, r2, b, n);
ASSERT_COMPARE(r1, n, r2, n);
TEST_BUFFERS_EQUAL(r1, n, r2, n);
/* Test r == b */
fill_arrays(a, b, r1, r2, n);
@ -44,7 +44,7 @@ void mbedtls_xor(int len)
r1[i] = a[i] ^ r1[i];
}
mbedtls_xor(r2, a, r2, n);
ASSERT_COMPARE(r1, n, r2, n);
TEST_BUFFERS_EQUAL(r1, n, r2, n);
/* Test a == b */
fill_arrays(a, b, r1, r2, n);
@ -52,7 +52,7 @@ void mbedtls_xor(int len)
r1[i] = a[i] ^ a[i];
}
mbedtls_xor(r2, a, a, n);
ASSERT_COMPARE(r1, n, r2, n);
TEST_BUFFERS_EQUAL(r1, n, r2, n);
/* Test a == b == r */
fill_arrays(a, b, r1, r2, n);
@ -60,7 +60,7 @@ void mbedtls_xor(int len)
r1[i] = r1[i] ^ r1[i];
}
mbedtls_xor(r2, r2, r2, n);
ASSERT_COMPARE(r1, n, r2, n);
TEST_BUFFERS_EQUAL(r1, n, r2, n);
/* Test non-word-aligned buffers, for all combinations of alignedness */
for (int i = 0; i < 7; i++) {
@ -71,7 +71,7 @@ void mbedtls_xor(int len)
r1[j + r_off] = a[j + a_off] ^ b[j + b_off];
}
mbedtls_xor(r2 + r_off, a + a_off, b + b_off, n);
ASSERT_COMPARE(r1 + r_off, n, r2 + r_off, n);
TEST_BUFFERS_EQUAL(r1 + r_off, n, r2 + r_off, n);
}
exit:
mbedtls_free(a);

View file

@ -91,7 +91,7 @@ void mbedtls_ct_memcpy_if_eq(int eq, int size, int offset)
TEST_CF_PUBLIC(&one, sizeof(one));
TEST_CF_PUBLIC(&secret_eq, sizeof(secret_eq));
ASSERT_COMPARE(expected, size, result + offset, size);
TEST_BUFFERS_EQUAL(expected, size, result + offset, size);
for (int i = 0; i < size + offset; i++) {
src[i] = 1;
@ -109,7 +109,7 @@ void mbedtls_ct_memcpy_if_eq(int eq, int size, int offset)
TEST_CF_PUBLIC(&one, sizeof(one));
TEST_CF_PUBLIC(&secret_eq, sizeof(secret_eq));
ASSERT_COMPARE(expected, size, result, size);
TEST_BUFFERS_EQUAL(expected, size, result, size);
exit:
mbedtls_free(src);
mbedtls_free(result);
@ -140,7 +140,7 @@ void ssl_cf_memcpy_offset(int offset_min, int offset_max, int len)
TEST_CF_PUBLIC(&secret, sizeof(secret));
TEST_CF_PUBLIC(dst, len);
ASSERT_COMPARE(dst, len, src + secret, len);
TEST_BUFFERS_EQUAL(dst, len, src + secret, len);
}
exit:

View file

@ -133,7 +133,7 @@ void ssl_cf_hmac(int hash)
TEST_EQUAL(0, mbedtls_md_hmac_reset(&ref_ctx));
/* Compare */
ASSERT_COMPARE(out, out_len, ref_out, out_len);
TEST_BUFFERS_EQUAL(out, out_len, ref_out, out_len);
#endif /* MBEDTLS_USE_PSA_CRYPTO */
}

View file

@ -538,7 +538,7 @@ void ecp_muladd(int id,
&len, actual_result, sizeof(actual_result)));
TEST_ASSERT(len <= MBEDTLS_ECP_MAX_PT_LEN);
ASSERT_COMPARE(expected_result->x, expected_result->len,
TEST_BUFFERS_EQUAL(expected_result->x, expected_result->len,
actual_result, len);
exit:
@ -1061,7 +1061,7 @@ void mbedtls_ecp_read_key(int grp_id, data_t *in_key, int expected, int canonica
ret = mbedtls_ecp_write_key(&key, buf, in_key->len);
TEST_ASSERT(ret == 0);
ASSERT_COMPARE(in_key->x, in_key->len,
TEST_BUFFERS_EQUAL(in_key->x, in_key->len,
buf, in_key->len);
} else {
unsigned char export1[MBEDTLS_ECP_MAX_BYTES];
@ -1076,7 +1076,7 @@ void mbedtls_ecp_read_key(int grp_id, data_t *in_key, int expected, int canonica
ret = mbedtls_ecp_write_key(&key2, export2, in_key->len);
TEST_ASSERT(ret == 0);
ASSERT_COMPARE(export1, in_key->len,
TEST_BUFFERS_EQUAL(export1, in_key->len,
export2, in_key->len);
}
}
@ -1123,7 +1123,7 @@ void genkey_mx_known_answer(int bits, data_t *seed, data_t *expected)
* (can be enforced by checking these bits).
* - Other bits must be random (by testing with different RNG outputs,
* we validate that those bits are indeed influenced by the RNG). */
ASSERT_COMPARE(expected->x, expected->len,
TEST_BUFFERS_EQUAL(expected->x, expected->len,
actual, expected->len);
}
@ -1379,7 +1379,7 @@ void ecp_mod_p_generic_raw(int curve_id,
TEST_LE_U(mbedtls_mpi_core_bitlen(X, limbs_X), curve_bits);
mbedtls_mpi_mod_raw_fix_quasi_reduction(X, &m);
ASSERT_COMPARE(X, bytes, res, bytes);
TEST_BUFFERS_EQUAL(X, bytes, res, bytes);
exit:
mbedtls_free(X);
@ -1420,7 +1420,7 @@ void ecp_mod_setup(char *input_A, int id, int ctype, int iret)
}
/* Compare output byte-by-byte */
ASSERT_COMPARE(p, bytes, m.p, bytes);
TEST_BUFFERS_EQUAL(p, bytes, m.p, bytes);
/* Test for user free-ing allocated memory */
mbedtls_mpi_mod_modulus_free(&m);
@ -1472,10 +1472,10 @@ void ecp_mod_mul_inv(char *input_A, int id, int ctype)
limbs * ciL,
MBEDTLS_MPI_MOD_EXT_REP_LE), 0);
ASSERT_COMPARE(bufx, ciL, one, ciL);
TEST_BUFFERS_EQUAL(bufx, ciL, one, ciL);
/*Borrow the buffer of A to compare the left lims with 0 */
memset(A, 0, limbs * ciL);
ASSERT_COMPARE(&bufx[1], (limbs - 1) * ciL, A, (limbs - 1) * ciL);
TEST_BUFFERS_EQUAL(&bufx[1], (limbs - 1) * ciL, A, (limbs - 1) * ciL);
exit:
mbedtls_mpi_mod_modulus_free(&m);
@ -1527,7 +1527,7 @@ void ecp_mod_add_sub(char *input_A, char *input_B, int id, int ctype)
TEST_EQUAL(0, mbedtls_mpi_mod_sub(&rS, &rS, &rB, &m));
/* Compare difference with rA byte-by-byte */
ASSERT_COMPARE(rA.p, bytes, rS.p, bytes);
TEST_BUFFERS_EQUAL(rA.p, bytes, rS.p, bytes);
exit:
mbedtls_mpi_mod_modulus_free(&m);
@ -1577,7 +1577,7 @@ void ecp_mod_read_write(char *input_A, int id, int ctype)
bytes, MBEDTLS_MPI_MOD_EXT_REP_LE));
TEST_EQUAL(limbs, rX.limbs);
ASSERT_COMPARE(rA.p, bytes, rX.p, bytes);
TEST_BUFFERS_EQUAL(rA.p, bytes, rX.p, bytes);
memset(bufx, 0x00, bytes);
memset(rX_raw, 0x00, bytes);
@ -1591,7 +1591,7 @@ void ecp_mod_read_write(char *input_A, int id, int ctype)
MBEDTLS_MPI_MOD_EXT_REP_BE));
TEST_EQUAL(limbs, rX.limbs);
ASSERT_COMPARE(rA.p, bytes, rX.p, bytes);
TEST_BUFFERS_EQUAL(rA.p, bytes, rX.p, bytes);
exit:
mbedtls_mpi_mod_modulus_free(&m);

View file

@ -37,7 +37,7 @@ static int check_multipart(mbedtls_gcm_context *ctx,
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x, n1, output, n1, &olen));
TEST_EQUAL(n1, olen);
ASSERT_COMPARE(output, olen, expected_output->x, n1);
TEST_BUFFERS_EQUAL(output, olen, expected_output->x, n1);
mbedtls_free(output);
output = NULL;
@ -45,14 +45,14 @@ static int check_multipart(mbedtls_gcm_context *ctx,
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x + n1, n2, output, n2, &olen));
TEST_EQUAL(n2, olen);
ASSERT_COMPARE(output, olen, expected_output->x + n1, n2);
TEST_BUFFERS_EQUAL(output, olen, expected_output->x + n1, n2);
mbedtls_free(output);
output = NULL;
ASSERT_ALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
TEST_EQUAL(0, olen);
ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
mbedtls_free(output);
output = NULL;
@ -91,14 +91,14 @@ static void check_cipher_with_empty_ad(mbedtls_gcm_context *ctx,
olen = 0xdeadbeef;
TEST_EQUAL(0, mbedtls_gcm_update(ctx, input->x, input->len, output, input->len, &olen));
TEST_EQUAL(input->len, olen);
ASSERT_COMPARE(output, olen, expected_output->x, input->len);
TEST_BUFFERS_EQUAL(output, olen, expected_output->x, input->len);
mbedtls_free(output);
output = NULL;
ASSERT_ALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
TEST_EQUAL(0, olen);
ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
exit:
mbedtls_free(output);
@ -128,7 +128,7 @@ static void check_empty_cipher_with_ad(mbedtls_gcm_context *ctx,
TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen,
output_tag, tag->len));
TEST_EQUAL(0, olen);
ASSERT_COMPARE(output_tag, tag->len, tag->x, tag->len);
TEST_BUFFERS_EQUAL(output_tag, tag->len, tag->x, tag->len);
exit:
mbedtls_free(output_tag);
@ -147,7 +147,7 @@ static void check_no_cipher_no_ad(mbedtls_gcm_context *ctx,
ASSERT_ALLOC(output, tag->len);
TEST_EQUAL(0, mbedtls_gcm_finish(ctx, NULL, 0, &olen, output, tag->len));
TEST_EQUAL(0, olen);
ASSERT_COMPARE(output, tag->len, tag->x, tag->len);
TEST_BUFFERS_EQUAL(output, tag->len, tag->x, tag->len);
exit:
mbedtls_free(output);
@ -212,8 +212,8 @@ void gcm_encrypt_and_tag(int cipher_id, data_t *key_str,
iv_str->len, add_str->x, add_str->len, src_str->x,
output, tag_len, tag_output) == 0);
ASSERT_COMPARE(output, src_str->len, dst->x, dst->len);
ASSERT_COMPARE(tag_output, tag_len, tag->x, tag->len);
TEST_BUFFERS_EQUAL(output, src_str->len, dst->x, dst->len);
TEST_BUFFERS_EQUAL(tag_output, tag_len, tag->x, tag->len);
for (n1 = 0; n1 <= src_str->len; n1 += 1) {
for (n1_add = 0; n1_add <= add_str->len; n1_add += 1) {
@ -269,7 +269,7 @@ void gcm_decrypt_and_verify(int cipher_id, data_t *key_str,
TEST_ASSERT(ret == MBEDTLS_ERR_GCM_AUTH_FAILED);
} else {
TEST_ASSERT(ret == 0);
ASSERT_COMPARE(output, src_str->len, pt_result->x, pt_result->len);
TEST_BUFFERS_EQUAL(output, src_str->len, pt_result->x, pt_result->len);
for (n1 = 0; n1 <= src_str->len; n1 += 1) {
for (n1_add = 0; n1_add <= add_str->len; n1_add += 1) {

View file

@ -26,7 +26,7 @@ void test_hkdf(int md_alg, data_t *ikm, data_t *salt, data_t *info,
info->x, info->len, okm, expected_okm->len);
TEST_ASSERT(ret == 0);
ASSERT_COMPARE(okm, expected_okm->len,
TEST_BUFFERS_EQUAL(okm, expected_okm->len,
expected_okm->x, expected_okm->len);
exit:
@ -56,7 +56,7 @@ void test_hkdf_extract(int md_alg,
ikm->x, ikm->len, output_prk);
TEST_ASSERT(ret == 0);
ASSERT_COMPARE(output_prk, output_prk_len, prk->x, prk->len);
TEST_BUFFERS_EQUAL(output_prk, output_prk_len, prk->x, prk->len);
exit:
mbedtls_free(output_prk);
@ -88,7 +88,7 @@ void test_hkdf_expand(int md_alg,
info->x, info->len,
output_okm, OKM_LEN);
TEST_ASSERT(ret == 0);
ASSERT_COMPARE(output_okm, okm->len, okm->x, okm->len);
TEST_BUFFERS_EQUAL(output_okm, okm->len, okm->x, okm->len);
exit:
mbedtls_free(output_okm);

View file

@ -162,7 +162,7 @@ void lmots_import_export_test(data_t *pub_key, int expected_import_rc)
TEST_EQUAL(exported_pub_key_size,
MBEDTLS_LMOTS_PUBLIC_KEY_LEN(MBEDTLS_LMOTS_SHA256_N32_W8));
ASSERT_COMPARE(pub_key->x, pub_key->len,
TEST_BUFFERS_EQUAL(pub_key->x, pub_key->len,
exported_pub_key, exported_pub_key_size);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;
@ -183,7 +183,7 @@ void lmots_import_export_test(data_t *pub_key, int expected_import_rc)
exported_pub_key_buf_size,
&exported_pub_key_size),
0);
ASSERT_COMPARE(pub_key->x, pub_key->len,
TEST_BUFFERS_EQUAL(pub_key->x, pub_key->len,
exported_pub_key, exported_pub_key_size);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;

View file

@ -164,7 +164,7 @@ void lms_import_export_test(data_t *pub_key, int expected_import_rc)
TEST_EQUAL(exported_pub_key_size,
MBEDTLS_LMS_PUBLIC_KEY_LEN(MBEDTLS_LMS_SHA256_M32_H10));
ASSERT_COMPARE(pub_key->x, pub_key->len,
TEST_BUFFERS_EQUAL(pub_key->x, pub_key->len,
exported_pub_key, exported_pub_key_size);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;
@ -185,7 +185,7 @@ void lms_import_export_test(data_t *pub_key, int expected_import_rc)
exported_pub_key_buf_size,
&exported_pub_key_size),
0);
ASSERT_COMPARE(pub_key->x, pub_key->len,
TEST_BUFFERS_EQUAL(pub_key->x, pub_key->len,
exported_pub_key, exported_pub_key_size);
mbedtls_free(exported_pub_key);
exported_pub_key = NULL;

View file

@ -185,7 +185,7 @@ void md_text(int md_type, char *text_src_string, data_t *hash)
TEST_EQUAL(0, mbedtls_md(md_info, src, src_len, output));
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
MD_PSA_DONE();
@ -206,7 +206,7 @@ void md_hex(int md_type, data_t *src_str, data_t *hash)
TEST_EQUAL(0, mbedtls_md(md_info, src_str->x, src_str->len, output));
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
MD_PSA_DONE();
@ -248,14 +248,14 @@ void md_text_multi(int md_type, char *text_src_string,
TEST_EQUAL(0, mbedtls_md_update(&ctx, src + halfway, src_len - halfway));
TEST_EQUAL(0, mbedtls_md_finish(&ctx, output));
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
/* Test clone */
memset(output, 0x00, sizeof(output));
TEST_EQUAL(0, mbedtls_md_update(&ctx_copy, src + halfway, src_len - halfway));
TEST_EQUAL(0, mbedtls_md_finish(&ctx_copy, output));
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -295,14 +295,14 @@ void md_hex_multi(int md_type, data_t *src_str, data_t *hash)
TEST_EQUAL(0, mbedtls_md_update(&ctx, src_str->x + halfway, src_str->len - halfway));
TEST_EQUAL(0, mbedtls_md_finish(&ctx, output));
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
/* Test clone */
memset(output, 0x00, sizeof(output));
TEST_EQUAL(0, mbedtls_md_update(&ctx_copy, src_str->x + halfway, src_str->len - halfway));
TEST_EQUAL(0, mbedtls_md_finish(&ctx_copy, output));
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -328,7 +328,7 @@ void mbedtls_md_hmac(int md_type, int trunc_size,
TEST_EQUAL(0, mbedtls_md_hmac(md_info, key_str->x, key_str->len,
src_str->x, src_str->len, output));
ASSERT_COMPARE(output, trunc_size, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, trunc_size, hash->x, hash->len);
exit:
MD_PSA_DONE();
@ -363,7 +363,7 @@ void md_hmac_multi(int md_type, int trunc_size, data_t *key_str,
TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway));
TEST_EQUAL(0, mbedtls_md_hmac_finish(&ctx, output));
ASSERT_COMPARE(output, trunc_size, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, trunc_size, hash->x, hash->len);
/* Test again, for reset() */
memset(output, 0x00, sizeof(output));
@ -373,7 +373,7 @@ void md_hmac_multi(int md_type, int trunc_size, data_t *key_str,
TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway));
TEST_EQUAL(0, mbedtls_md_hmac_finish(&ctx, output));
ASSERT_COMPARE(output, trunc_size, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, trunc_size, hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -395,7 +395,7 @@ void mbedtls_md_file(int md_type, char *filename,
TEST_EQUAL(0, mbedtls_md_file(md_info, filename, output));
ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
MD_PSA_DONE();

View file

@ -60,7 +60,7 @@ void mbedtls_mps_reader_no_pausing_single_step_single_round(int with_acc)
/* Consumption (upper layer) */
/* Consume exactly what's available */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 100, bufA, 100);
TEST_BUFFERS_EQUAL(tmp, 100, bufA, 100);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup (lower layer) */
TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, &paused) == 0);
@ -108,14 +108,14 @@ void mbedtls_mps_reader_no_pausing_single_step_multiple_rounds(int with_acc)
/* Consumption (upper layer) */
/* Consume exactly what's available */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 100, bufA, 100);
TEST_BUFFERS_EQUAL(tmp, 100, bufA, 100);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Preparation */
TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB, sizeof(bufB)) == 0);
/* Consumption */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 100, bufB, 100);
TEST_BUFFERS_EQUAL(tmp, 100, bufB, 100);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup (lower layer) */
TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
@ -162,11 +162,11 @@ void mbedtls_mps_reader_no_pausing_multiple_steps_single_round(int with_acc)
TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, buf, 10);
TEST_BUFFERS_EQUAL(tmp, 10, buf, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 70, buf + 10, 70);
TEST_BUFFERS_EQUAL(tmp, 70, buf + 10, 70);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, &tmp_len) == 0);
ASSERT_COMPARE(tmp, tmp_len, buf + 80, 20);
TEST_BUFFERS_EQUAL(tmp, tmp_len, buf + 80, 20);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup (lower layer) */
TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
@ -202,18 +202,18 @@ void mbedtls_mps_reader_no_pausing_multiple_steps_multiple_rounds(int with_acc)
TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufA, sizeof(bufA)) == 0);
/* Consumption (upper layer) */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 70, bufA + 10, 70);
TEST_BUFFERS_EQUAL(tmp, 70, bufA + 10, 70);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, &tmp_len) == 0);
ASSERT_COMPARE(tmp, tmp_len, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp, tmp_len, bufA + 80, 20);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Preparation */
TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
TEST_ASSERT(mbedtls_mps_reader_feed(&rd, bufB, sizeof(bufB)) == 0);
/* Consumption */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 100, bufB, 100);
TEST_BUFFERS_EQUAL(tmp, 100, bufB, 100);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
@ -243,7 +243,7 @@ void mbedtls_mps_reader_pausing_needed_disabled()
TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 50, buf, 50);
TEST_BUFFERS_EQUAL(tmp, 50, buf, 50);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
@ -284,10 +284,10 @@ void mbedtls_mps_reader_pausing_needed_buffer_too_small()
TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 50, buf, 50);
TEST_BUFFERS_EQUAL(tmp, 50, buf, 50);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, buf + 50, 10);
TEST_BUFFERS_EQUAL(tmp, 10, buf + 50, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
/* Wrapup (lower layer) */
@ -295,7 +295,7 @@ void mbedtls_mps_reader_pausing_needed_buffer_too_small()
MBEDTLS_ERR_MPS_READER_ACCUMULATOR_TOO_SMALL);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, &tmp_len) == 0);
ASSERT_COMPARE(tmp, tmp_len, buf + 50, 50);
TEST_BUFFERS_EQUAL(tmp, tmp_len, buf + 50, 50);
mbedtls_mps_reader_free(&rd);
}
@ -325,7 +325,7 @@ void mbedtls_mps_reader_reclaim_overflow()
TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 50, buf, 50);
TEST_BUFFERS_EQUAL(tmp, 50, buf, 50);
/* Excess request */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, (mbedtls_mps_size_t) -1, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
@ -376,10 +376,10 @@ void mbedtls_mps_reader_pausing(int option)
/* Consumption (upper layer) */
/* Ask for more than what's available. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 80, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 80, bufA, 80);
TEST_BUFFERS_EQUAL(tmp, 80, bufA, 80);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
switch (option) {
case 0: /* Single uncommitted fetch at pausing */
case 1:
@ -400,50 +400,50 @@ void mbedtls_mps_reader_pausing(int option)
switch (option) {
case 0: /* Single fetch at pausing, re-fetch with commit. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
break;
case 1: /* Single fetch at pausing, re-fetch without commit. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
break;
case 2: /* Multiple fetches at pausing, repeat without commit. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
break;
case 3: /* Multiple fetches at pausing, repeat with commit 1. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
break;
case 4: /* Multiple fetches at pausing, repeat with commit 2. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
break;
case 5: /* Multiple fetches at pausing, repeat with commit 3. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
break;
@ -453,7 +453,7 @@ void mbedtls_mps_reader_pausing(int option)
/* In all cases, fetch the rest of the second buffer. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 90, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 90, bufB + 10, 90);
TEST_BUFFERS_EQUAL(tmp, 90, bufB + 10, 90);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
@ -498,7 +498,7 @@ void mbedtls_mps_reader_pausing_multiple_feeds(int option)
/* Consumption (upper layer) */
/* Ask for more than what's available. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 80, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 80, bufA, 80);
TEST_BUFFERS_EQUAL(tmp, 80, bufA, 80);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* 20 left, ask for 70 -> 50 overhead */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) ==
@ -538,8 +538,8 @@ void mbedtls_mps_reader_pausing_multiple_feeds(int option)
/* Consumption */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 20, bufA + 80, 20);
ASSERT_COMPARE(tmp + 20, 50, bufB, 50);
TEST_BUFFERS_EQUAL(tmp, 20, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp + 20, 50, bufB, 50);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 1000, &tmp, &fetch_len) == 0);
switch (option) {
case 0:
@ -591,14 +591,14 @@ void mbedtls_mps_reader_reclaim_data_left(int option)
/* Fetch (but not commit) the entire buffer. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, sizeof(buf), &tmp, NULL)
== 0);
ASSERT_COMPARE(tmp, 100, buf, 100);
TEST_BUFFERS_EQUAL(tmp, 100, buf, 100);
break;
case 1:
/* Fetch (but not commit) parts of the buffer. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, sizeof(buf) / 2,
&tmp, NULL) == 0);
ASSERT_COMPARE(tmp, sizeof(buf) / 2, buf, sizeof(buf) / 2);
TEST_BUFFERS_EQUAL(tmp, sizeof(buf) / 2, buf, sizeof(buf) / 2);
break;
case 2:
@ -606,11 +606,11 @@ void mbedtls_mps_reader_reclaim_data_left(int option)
* fetch but not commit the rest of the buffer. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, sizeof(buf) / 2,
&tmp, NULL) == 0);
ASSERT_COMPARE(tmp, sizeof(buf) / 2, buf, sizeof(buf) / 2);
TEST_BUFFERS_EQUAL(tmp, sizeof(buf) / 2, buf, sizeof(buf) / 2);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, sizeof(buf) / 2,
&tmp, NULL) == 0);
ASSERT_COMPARE(tmp, sizeof(buf) / 2,
TEST_BUFFERS_EQUAL(tmp, sizeof(buf) / 2,
buf + sizeof(buf) / 2,
sizeof(buf) / 2);
break;
@ -646,16 +646,16 @@ void mbedtls_mps_reader_reclaim_data_left_retry()
TEST_ASSERT(mbedtls_mps_reader_feed(&rd, buf, sizeof(buf)) == 0);
/* Consumption (upper layer) */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 50, buf, 50);
TEST_BUFFERS_EQUAL(tmp, 50, buf, 50);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 50, buf + 50, 50);
TEST_BUFFERS_EQUAL(tmp, 50, buf + 50, 50);
/* Preparation */
TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) ==
MBEDTLS_ERR_MPS_READER_DATA_LEFT);
/* Consumption */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 50, buf + 50, 50);
TEST_BUFFERS_EQUAL(tmp, 50, buf + 50, 50);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
TEST_ASSERT(mbedtls_mps_reader_reclaim(&rd, NULL) == 0);
@ -699,10 +699,10 @@ void mbedtls_mps_reader_multiple_pausing(int option)
/* Consumption (upper layer) */
/* Ask for more than what's available. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 80, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 80, bufA, 80);
TEST_BUFFERS_EQUAL(tmp, 80, bufA, 80);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
@ -717,10 +717,10 @@ void mbedtls_mps_reader_multiple_pausing(int option)
/* Consume */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, &tmp_len) == 0);
ASSERT_COMPARE(tmp, tmp_len, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, tmp_len, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
@ -731,18 +731,18 @@ void mbedtls_mps_reader_multiple_pausing(int option)
/* Consume */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufB + 10, 10);
ASSERT_COMPARE(tmp + 10, 10, bufC, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufB + 10, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufC, 10);
break;
case 1: /* Fetch same chunks, commit afterwards, and
* then exceed bounds of new buffer; accumulator
* not large enough. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 51, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
@ -756,10 +756,10 @@ void mbedtls_mps_reader_multiple_pausing(int option)
* then exceed bounds of new buffer; accumulator
* large enough. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
@ -769,19 +769,19 @@ void mbedtls_mps_reader_multiple_pausing(int option)
/* Consume */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 20, bufA + 80, 20);
ASSERT_COMPARE(tmp + 20, 20, bufB, 20);
ASSERT_COMPARE(tmp + 40, 10, bufC, 10);
TEST_BUFFERS_EQUAL(tmp, 20, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp + 20, 20, bufB, 20);
TEST_BUFFERS_EQUAL(tmp + 40, 10, bufC, 10);
break;
case 3: /* Fetch same chunks, don't commit afterwards, and
* then exceed bounds of new buffer; accumulator
* not large enough. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 80, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 10, bufA + 90, 10);
ASSERT_COMPARE(tmp + 10, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 21, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_OUT_OF_DATA);
@ -1005,16 +1005,16 @@ void mbedtls_reader_inconsistent_usage(int option)
case 0:
/* Ask for buffered data in a single chunk, no commit */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 20, bufA + 80, 20);
ASSERT_COMPARE(tmp + 20, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 20, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp + 20, 10, bufB, 10);
success = 1;
break;
case 1:
/* Ask for buffered data in a single chunk, with commit */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 20, bufA + 80, 20);
ASSERT_COMPARE(tmp + 20, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 20, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp + 20, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
success = 1;
break;
@ -1035,7 +1035,7 @@ void mbedtls_reader_inconsistent_usage(int option)
/* Asking for buffered data in different
* chunks than before CAN fail. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) ==
MBEDTLS_ERR_MPS_READER_INCONSISTENT_REQUESTS);
break;
@ -1044,10 +1044,10 @@ void mbedtls_reader_inconsistent_usage(int option)
/* Asking for buffered data different chunks
* than before NEED NOT fail - no commits */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 5, bufA + 95, 5);
ASSERT_COMPARE(tmp + 5, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 5, bufA + 95, 5);
TEST_BUFFERS_EQUAL(tmp + 5, 10, bufB, 10);
success = 1;
break;
@ -1055,11 +1055,11 @@ void mbedtls_reader_inconsistent_usage(int option)
/* Asking for buffered data different chunks
* than before NEED NOT fail - intermediate commit */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 5, bufA + 95, 5);
ASSERT_COMPARE(tmp + 5, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 5, bufA + 95, 5);
TEST_BUFFERS_EQUAL(tmp + 5, 10, bufB, 10);
success = 1;
break;
@ -1067,10 +1067,10 @@ void mbedtls_reader_inconsistent_usage(int option)
/* Asking for buffered data different chunks
* than before NEED NOT fail - end commit */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 5, bufA + 95, 5);
ASSERT_COMPARE(tmp + 5, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 5, bufA + 95, 5);
TEST_BUFFERS_EQUAL(tmp + 5, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
success = 1;
break;
@ -1079,11 +1079,11 @@ void mbedtls_reader_inconsistent_usage(int option)
/* Asking for buffered data different chunks
* than before NEED NOT fail - intermediate & end commit */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 15, bufA + 80, 15);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
ASSERT_COMPARE(tmp, 5, bufA + 95, 5);
ASSERT_COMPARE(tmp + 5, 10, bufB, 10);
TEST_BUFFERS_EQUAL(tmp, 5, bufA + 95, 5);
TEST_BUFFERS_EQUAL(tmp + 5, 10, bufB, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
success = 1;
break;
@ -1096,7 +1096,7 @@ void mbedtls_reader_inconsistent_usage(int option)
if (success == 1) {
/* In all succeeding cases, fetch the rest of the second buffer. */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 90, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 90, bufB + 10, 90);
TEST_BUFFERS_EQUAL(tmp, 90, bufB + 10, 90);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */
@ -1131,7 +1131,7 @@ void mbedtls_mps_reader_feed_empty()
/* Consumption (upper layer) */
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 100, &tmp, NULL) == 0);
ASSERT_COMPARE(tmp, 100, buf, 100);
TEST_BUFFERS_EQUAL(tmp, 100, buf, 100);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */

View file

@ -59,7 +59,7 @@ void pkcs12_derive_key(int md_type, int key_size_arg,
TEST_EQUAL(ret, expected_status);
if (expected_status == 0) {
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
output_data, key_size);
}

View file

@ -48,7 +48,7 @@ void pkcs1_rsaes_oaep_encrypt(int mod, data_t *input_N, data_t *input_E,
message_str->x,
output) == result);
if (result == 0) {
ASSERT_COMPARE(output, ctx.len, result_str->x, result_str->len);
TEST_BUFFERS_EQUAL(output, ctx.len, result_str->x, result_str->len);
}
exit:
@ -110,7 +110,7 @@ void pkcs1_rsaes_oaep_decrypt(int mod, data_t *input_P, data_t *input_Q,
output,
sizeof(output)) == result);
if (result == 0) {
ASSERT_COMPARE(output, output_len, result_str->x, result_str->len);
TEST_BUFFERS_EQUAL(output, output_len, result_str->x, result_str->len);
}
}
@ -167,7 +167,7 @@ void pkcs1_rsassa_pss_sign(int mod, data_t *input_P, data_t *input_Q,
&ctx, &mbedtls_test_rnd_buffer_rand, &info,
digest, hash_digest->len, hash_digest->x, output) == result);
if (result == 0) {
ASSERT_COMPARE(output, ctx.len, result_str->x, result_str->len);
TEST_BUFFERS_EQUAL(output, ctx.len, result_str->x, result_str->len);
}
info.buf = rnd_buf->x;
@ -179,7 +179,7 @@ void pkcs1_rsassa_pss_sign(int mod, data_t *input_P, data_t *input_Q,
digest, hash_digest->len, hash_digest->x,
fixed_salt_length, output) == result);
if (result == 0) {
ASSERT_COMPARE(output, ctx.len, result_str->x, result_str->len);
TEST_BUFFERS_EQUAL(output, ctx.len, result_str->x, result_str->len);
}
exit:

View file

@ -175,7 +175,7 @@ void pk_parse_fix_montgomery(data_t *input_key, data_t *exp_output)
output_key_len = mbedtls_pk_write_key_der(&pk, output_key, output_key_len);
TEST_ASSERT(output_key_len > 0);
ASSERT_COMPARE(exp_output->x, exp_output->len, output_key, output_key_len);
TEST_BUFFERS_EQUAL(exp_output->x, exp_output->len, output_key, output_key_len);
exit:
if (output_key != NULL) {

View file

@ -113,7 +113,7 @@ static void pk_write_check_common(char *key_file, int is_public_key, int is_der)
TEST_EQUAL(pk_write_any_key(&key, &start_buf, &buf_len, is_public_key,
is_der), 0);
ASSERT_COMPARE(start_buf, buf_len, check_buf, check_buf_len);
TEST_BUFFERS_EQUAL(start_buf, buf_len, check_buf, check_buf_len);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
/* Verify that pk_write works also for opaque private keys */
@ -128,7 +128,7 @@ static void pk_write_check_common(char *key_file, int is_public_key, int is_der)
TEST_EQUAL(pk_write_any_key(&key, &start_buf, &buf_len, is_public_key,
is_der), 0);
ASSERT_COMPARE(start_buf, buf_len, check_buf, check_buf_len);
TEST_BUFFERS_EQUAL(start_buf, buf_len, check_buf, check_buf_len);
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
@ -190,7 +190,7 @@ void pk_write_public_from_private(char *priv_key_file, char *pub_key_file)
TEST_EQUAL(mbedtls_pk_write_pubkey_der(&priv_key, derived_key_raw,
derived_key_len), pub_key_len);
ASSERT_COMPARE(derived_key_raw, derived_key_len,
TEST_BUFFERS_EQUAL(derived_key_raw, derived_key_len,
pub_key_raw, pub_key_len);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
@ -203,7 +203,7 @@ void pk_write_public_from_private(char *priv_key_file, char *pub_key_file)
TEST_EQUAL(mbedtls_pk_write_pubkey_der(&priv_key, derived_key_raw,
derived_key_len), pub_key_len);
ASSERT_COMPARE(derived_key_raw, derived_key_len,
TEST_BUFFERS_EQUAL(derived_key_raw, derived_key_len,
pub_key_raw, pub_key_len);
#endif /* MBEDTLS_USE_PSA_CRYPTO */

View file

@ -34,7 +34,7 @@ void printf_int(char *format, /* any format expecting one int argument, e.g. "%d
/* Nominal case: buffer just large enough */
ASSERT_ALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, x));
ASSERT_COMPARE(result, n + 1, output, n + 1);
TEST_BUFFERS_EQUAL(result, n + 1, output, n + 1);
mbedtls_free(output);
output = NULL;
@ -59,7 +59,7 @@ void printf_long_max(const char *format, /* "%lx" or longer type */
ASSERT_ALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, value));
ASSERT_COMPARE(expected, n + 1, output, n + 1);
TEST_BUFFERS_EQUAL(expected, n + 1, output, n + 1);
mbedtls_free(output);
output = NULL;
@ -79,7 +79,7 @@ void printf_char2(char *format, /* "%c%c" */
/* Nominal case: buffer just large enough */
ASSERT_ALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, arg1, arg2));
ASSERT_COMPARE(result, n + 1, output, n + 1);
TEST_BUFFERS_EQUAL(result, n + 1, output, n + 1);
mbedtls_free(output);
output = NULL;

View file

@ -22,7 +22,7 @@ void mbedtls_poly1305(data_t *key, data_t *expected_mac, data_t *src_str)
TEST_ASSERT(mbedtls_poly1305_mac(key->x, src_str->x,
src_str->len, mac) == 0);
ASSERT_COMPARE(mac, expected_mac->len,
TEST_BUFFERS_EQUAL(mac, expected_mac->len,
expected_mac->x, expected_mac->len);
/*
@ -36,7 +36,7 @@ void mbedtls_poly1305(data_t *key, data_t *expected_mac, data_t *src_str)
TEST_ASSERT(mbedtls_poly1305_finish(&ctx, mac) == 0);
ASSERT_COMPARE(mac, expected_mac->len,
TEST_BUFFERS_EQUAL(mac, expected_mac->len,
expected_mac->x, expected_mac->len);
/*
@ -53,7 +53,7 @@ void mbedtls_poly1305(data_t *key, data_t *expected_mac, data_t *src_str)
TEST_ASSERT(mbedtls_poly1305_finish(&ctx, mac) == 0);
ASSERT_COMPARE(mac, expected_mac->len,
TEST_BUFFERS_EQUAL(mac, expected_mac->len,
expected_mac->x, expected_mac->len);
}
@ -69,7 +69,7 @@ void mbedtls_poly1305(data_t *key, data_t *expected_mac, data_t *src_str)
TEST_ASSERT(mbedtls_poly1305_finish(&ctx, mac) == 0);
ASSERT_COMPARE(mac, expected_mac->len,
TEST_BUFFERS_EQUAL(mac, expected_mac->len,
expected_mac->x, expected_mac->len);
}

View file

@ -583,7 +583,7 @@ static int aead_multipart_internal_func(int key_type_arg, data_t *key_data,
}
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
output_data, output_length);
@ -692,7 +692,7 @@ static int mac_multipart_internal_func(int key_type_arg, data_t *key_data,
PSA_ASSERT(psa_mac_sign_finish(&operation, mac,
PSA_MAC_MAX_SIZE, &mac_len));
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
mac, mac_len);
}
@ -1574,7 +1574,7 @@ void import_export(data_t *data,
}
if (canonical_input) {
ASSERT_COMPARE(data->x, data->len, exported, exported_length);
TEST_BUFFERS_EQUAL(data->x, data->len, exported, exported_length);
} else {
mbedtls_svc_key_id_t key2 = MBEDTLS_SVC_KEY_ID_INIT;
PSA_ASSERT(psa_import_key(&attributes, exported, exported_length,
@ -1583,7 +1583,7 @@ void import_export(data_t *data,
reexported,
export_size,
&reexported_length));
ASSERT_COMPARE(exported, exported_length,
TEST_BUFFERS_EQUAL(exported, exported_length,
reexported, reexported_length);
PSA_ASSERT(psa_destroy_key(key2));
}
@ -1657,7 +1657,7 @@ void import_export_public_key(data_t *data,
PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(public_type, bits));
TEST_LE_U(expected_public_key->len,
PSA_EXPORT_PUBLIC_KEY_MAX_SIZE);
ASSERT_COMPARE(expected_public_key->x, expected_public_key->len,
TEST_BUFFERS_EQUAL(expected_public_key->x, expected_public_key->len,
exported, exported_length);
}
exit:
@ -2501,7 +2501,7 @@ void copy_success(int source_usage_arg,
ASSERT_ALLOC(export_buffer, material->len);
PSA_ASSERT(psa_export_key(target_key, export_buffer,
material->len, &length));
ASSERT_COMPARE(material->x, material->len,
TEST_BUFFERS_EQUAL(material->x, material->len,
export_buffer, length);
}
@ -2760,7 +2760,7 @@ void hash_compute_compare(int alg_arg, data_t *input,
output, PSA_HASH_LENGTH(alg),
&output_length));
TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
ASSERT_COMPARE(output, output_length,
TEST_BUFFERS_EQUAL(output, output_length,
expected_output->x, expected_output->len);
/* Compute with tight buffer, multi-part */
@ -2770,7 +2770,7 @@ void hash_compute_compare(int alg_arg, data_t *input,
PSA_HASH_LENGTH(alg),
&output_length));
TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
ASSERT_COMPARE(output, output_length,
TEST_BUFFERS_EQUAL(output, output_length,
expected_output->x, expected_output->len);
/* Compute with larger buffer, one-shot */
@ -2778,7 +2778,7 @@ void hash_compute_compare(int alg_arg, data_t *input,
output, sizeof(output),
&output_length));
TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
ASSERT_COMPARE(output, output_length,
TEST_BUFFERS_EQUAL(output, output_length,
expected_output->x, expected_output->len);
/* Compute with larger buffer, multi-part */
@ -2787,7 +2787,7 @@ void hash_compute_compare(int alg_arg, data_t *input,
PSA_ASSERT(psa_hash_finish(&operation, output,
sizeof(output), &output_length));
TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
ASSERT_COMPARE(output, output_length,
TEST_BUFFERS_EQUAL(output, output_length,
expected_output->x, expected_output->len);
/* Compare with correct hash, one-shot */
@ -3392,7 +3392,7 @@ void mac_sign(int key_type_arg,
actual_mac, output_size, &mac_length),
expected_status);
if (expected_status == PSA_SUCCESS) {
ASSERT_COMPARE(expected_mac->x, expected_mac->len,
TEST_BUFFERS_EQUAL(expected_mac->x, expected_mac->len,
actual_mac, mac_length);
}
@ -3411,7 +3411,7 @@ void mac_sign(int key_type_arg,
PSA_ASSERT(psa_mac_abort(&operation));
if (expected_status == PSA_SUCCESS) {
ASSERT_COMPARE(expected_mac->x, expected_mac->len,
TEST_BUFFERS_EQUAL(expected_mac->x, expected_mac->len,
actual_mac, mac_length);
}
mbedtls_free(actual_mac);
@ -3962,7 +3962,7 @@ void cipher_alg_without_iv(int alg_arg, int key_type_arg, data_t *key_data,
output_buffer_size - output_length,
&length));
output_length += length;
ASSERT_COMPARE(ciphertext->x, ciphertext->len,
TEST_BUFFERS_EQUAL(ciphertext->x, ciphertext->len,
output, output_length);
/* Multipart encryption */
@ -3980,7 +3980,7 @@ void cipher_alg_without_iv(int alg_arg, int key_type_arg, data_t *key_data,
output_buffer_size - output_length,
&length));
output_length += length;
ASSERT_COMPARE(plaintext->x, plaintext->len,
TEST_BUFFERS_EQUAL(plaintext->x, plaintext->len,
output, output_length);
/* One-shot encryption */
@ -3988,7 +3988,7 @@ void cipher_alg_without_iv(int alg_arg, int key_type_arg, data_t *key_data,
PSA_ASSERT(psa_cipher_encrypt(key, alg, plaintext->x, plaintext->len,
output, output_buffer_size,
&output_length));
ASSERT_COMPARE(ciphertext->x, ciphertext->len,
TEST_BUFFERS_EQUAL(ciphertext->x, ciphertext->len,
output, output_length);
/* One-shot decryption */
@ -3996,7 +3996,7 @@ void cipher_alg_without_iv(int alg_arg, int key_type_arg, data_t *key_data,
PSA_ASSERT(psa_cipher_decrypt(key, alg, ciphertext->x, ciphertext->len,
output, output_buffer_size,
&output_length));
ASSERT_COMPARE(plaintext->x, plaintext->len,
TEST_BUFFERS_EQUAL(plaintext->x, plaintext->len,
output, output_length);
exit:
@ -4116,7 +4116,7 @@ void cipher_encrypt_validation(int alg_arg,
output2_length += function_output_length;
PSA_ASSERT(psa_cipher_abort(&operation));
ASSERT_COMPARE(output1 + iv_size, output1_length - iv_size,
TEST_BUFFERS_EQUAL(output1 + iv_size, output1_length - iv_size,
output2, output2_length);
exit:
@ -4215,7 +4215,7 @@ void cipher_encrypt_multipart(int alg_arg, int key_type_arg,
if (expected_status == PSA_SUCCESS) {
PSA_ASSERT(psa_cipher_abort(&operation));
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
output, total_output_length);
}
@ -4315,7 +4315,7 @@ void cipher_decrypt_multipart(int alg_arg, int key_type_arg,
if (expected_status == PSA_SUCCESS) {
PSA_ASSERT(psa_cipher_abort(&operation));
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
output, total_output_length);
}
@ -4472,7 +4472,7 @@ void cipher_decrypt(int alg_arg,
TEST_LE_U(output_length,
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_buffer_size));
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
output, output_length);
exit:
mbedtls_free(input);
@ -4529,7 +4529,7 @@ void cipher_verify_output(int alg_arg,
TEST_LE_U(output2_length,
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(output1_length));
ASSERT_COMPARE(input->x, input->len, output2, output2_length);
TEST_BUFFERS_EQUAL(input->x, input->len, output2, output2_length);
exit:
mbedtls_free(output1);
@ -4669,7 +4669,7 @@ void cipher_verify_output_multipart(int alg_arg,
PSA_ASSERT(psa_cipher_abort(&operation2));
ASSERT_COMPARE(input->x, input->len, output2, output2_length);
TEST_BUFFERS_EQUAL(input->x, input->len, output2, output2_length);
exit:
psa_cipher_abort(&operation1);
@ -4764,7 +4764,7 @@ void aead_encrypt_decrypt(int key_type_arg, data_t *key_data,
&output_length2),
expected_result);
ASSERT_COMPARE(input_data->x, input_data->len,
TEST_BUFFERS_EQUAL(input_data->x, input_data->len,
output_data2, output_length2);
}
@ -4831,7 +4831,7 @@ void aead_encrypt(int key_type_arg, data_t *key_data,
}
PSA_ASSERT(status);
ASSERT_COMPARE(expected_result->x, expected_result->len,
TEST_BUFFERS_EQUAL(expected_result->x, expected_result->len,
output_data, output_length);
exit:
@ -4904,7 +4904,7 @@ void aead_decrypt(int key_type_arg, data_t *key_data,
TEST_EQUAL(status, expected_result);
if (expected_result == PSA_SUCCESS) {
ASSERT_COMPARE(expected_data->x, expected_data->len,
TEST_BUFFERS_EQUAL(expected_data->x, expected_data->len,
output_data, output_length);
}
@ -6491,7 +6491,7 @@ void sign_hash_deterministic(int key_type_arg, data_t *key_data,
signature, signature_size,
&signature_length));
/* Verify that the signature is what is expected. */
ASSERT_COMPARE(output_data->x, output_data->len,
TEST_BUFFERS_EQUAL(output_data->x, output_data->len,
signature, signature_length);
exit:
@ -6614,7 +6614,7 @@ void sign_hash_interruptible(int key_type_arg, data_t *key_data,
TEST_LE_U(num_completes, max_completes);
/* Verify that the signature is what is expected. */
ASSERT_COMPARE(output_data->x, output_data->len,
TEST_BUFFERS_EQUAL(output_data->x, output_data->len,
signature, signature_length);
PSA_ASSERT(psa_sign_hash_abort(&operation));
@ -7912,7 +7912,7 @@ void sign_message_deterministic(int key_type_arg,
signature, signature_size,
&signature_length));
ASSERT_COMPARE(output_data->x, output_data->len,
TEST_BUFFERS_EQUAL(output_data->x, output_data->len,
signature, signature_length);
exit:
@ -8250,7 +8250,7 @@ void asymmetric_encrypt_decrypt(int key_type_arg,
label->x, label->len,
output2, output2_size,
&output2_length));
ASSERT_COMPARE(input_data->x, input_data->len,
TEST_BUFFERS_EQUAL(input_data->x, input_data->len,
output2, output2_length);
exit:
@ -8307,7 +8307,7 @@ void asymmetric_decrypt(int key_type_arg,
output,
output_size,
&output_length));
ASSERT_COMPARE(expected_data->x, expected_data->len,
TEST_BUFFERS_EQUAL(expected_data->x, expected_data->len,
output, output_length);
/* If the label is empty, the test framework puts a non-null pointer
@ -8323,7 +8323,7 @@ void asymmetric_decrypt(int key_type_arg,
output,
output_size,
&output_length));
ASSERT_COMPARE(expected_data->x, expected_data->len,
TEST_BUFFERS_EQUAL(expected_data->x, expected_data->len,
output, output_length);
}
@ -8892,7 +8892,7 @@ void derive_output(int alg_arg,
/* Success. Check the read data. */
PSA_ASSERT(status);
if (output_sizes[i] != 0) {
ASSERT_COMPARE(output_buffer, output_sizes[i],
TEST_BUFFERS_EQUAL(output_buffer, output_sizes[i],
expected_outputs[i], output_sizes[i]);
}
/* Check the operation status. */
@ -9015,7 +9015,7 @@ void derive_ecjpake_to_pms(data_t *input, int expected_input_status_arg,
TEST_EQUAL(status, expected_output_status);
if (expected_output->len != 0 && expected_output_status == PSA_SUCCESS) {
ASSERT_COMPARE(output_buffer, expected_output->len, expected_output->x,
TEST_BUFFERS_EQUAL(output_buffer, expected_output->len, expected_output->x,
expected_output->len);
}
@ -9167,7 +9167,7 @@ void derive_key_export(int alg_arg,
TEST_EQUAL(length, bytes2);
/* Compare the outputs from the two runs. */
ASSERT_COMPARE(output_buffer, bytes1 + bytes2,
TEST_BUFFERS_EQUAL(output_buffer, bytes1 + bytes2,
export_buffer, capacity);
exit:
@ -9228,7 +9228,7 @@ void derive_key_type(int alg_arg,
PSA_ASSERT(psa_export_key(derived_key,
export_buffer, export_buffer_size,
&export_length));
ASSERT_COMPARE(export_buffer, export_length,
TEST_BUFFERS_EQUAL(export_buffer, export_length,
expected_export->x, expected_export->len);
exit:
@ -9378,7 +9378,7 @@ void raw_key_agreement(int alg_arg,
peer_key_data->x, peer_key_data->len,
output, expected_output->len,
&output_length));
ASSERT_COMPARE(output, output_length,
TEST_BUFFERS_EQUAL(output, output_length,
expected_output->x, expected_output->len);
mbedtls_free(output);
output = NULL;
@ -9390,7 +9390,7 @@ void raw_key_agreement(int alg_arg,
peer_key_data->x, peer_key_data->len,
output, expected_output->len + 1,
&output_length));
ASSERT_COMPARE(output, output_length,
TEST_BUFFERS_EQUAL(output, output_length,
expected_output->x, expected_output->len);
mbedtls_free(output);
output = NULL;
@ -9513,13 +9513,13 @@ void key_agreement_output(int alg_arg,
PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
actual_output,
expected_output1->len));
ASSERT_COMPARE(actual_output, expected_output1->len,
TEST_BUFFERS_EQUAL(actual_output, expected_output1->len,
expected_output1->x, expected_output1->len);
if (expected_output2->len != 0) {
PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
actual_output,
expected_output2->len));
ASSERT_COMPARE(actual_output, expected_output2->len,
TEST_BUFFERS_EQUAL(actual_output, expected_output2->len,
expected_output2->x, expected_output2->len);
}
@ -9688,7 +9688,7 @@ void generate_key_rsa(int bits_arg,
if (is_default_public_exponent) {
TEST_EQUAL(e_read_length, 0);
} else {
ASSERT_COMPARE(e_read_buffer, e_read_length, e_arg->x, e_arg->len);
TEST_BUFFERS_EQUAL(e_read_buffer, e_read_length, e_arg->x, e_arg->len);
}
/* Do something with the key according to its type and permitted usage. */
@ -9724,7 +9724,7 @@ void generate_key_rsa(int bits_arg,
TEST_EQUAL(p[1], 0);
TEST_EQUAL(p[2], 1);
} else {
ASSERT_COMPARE(p, len, e_arg->x, e_arg->len);
TEST_BUFFERS_EQUAL(p, len, e_arg->x, e_arg->len);
}
}
@ -9833,7 +9833,7 @@ void persistent_key_load_key_from_storage(data_t *data,
first_export, export_size,
&first_exported_length));
if (generation_method == IMPORT_KEY) {
ASSERT_COMPARE(data->x, data->len,
TEST_BUFFERS_EQUAL(data->x, data->len,
first_export, first_exported_length);
}
}
@ -9860,7 +9860,7 @@ void persistent_key_load_key_from_storage(data_t *data,
PSA_ASSERT(psa_export_key(key,
second_export, export_size,
&second_exported_length));
ASSERT_COMPARE(first_export, first_exported_length,
TEST_BUFFERS_EQUAL(first_export, first_exported_length,
second_export, second_exported_length);
}

View file

@ -460,7 +460,7 @@ static int sanity_check_rsa_encryption_result(
TEST_EQUAL(buf[0], 0x00);
TEST_EQUAL(buf[1], 0x02);
TEST_EQUAL(buf[length - input_data->len - 1], 0x00);
ASSERT_COMPARE(buf + length - input_data->len, input_data->len,
TEST_BUFFERS_EQUAL(buf + length - input_data->len, input_data->len,
input_data->x, input_data->len);
} else if (PSA_ALG_IS_RSA_OAEP(alg)) {
TEST_EQUAL(buf[0], 0x00);
@ -546,7 +546,7 @@ void sign_hash(int key_type_arg,
&signature_length);
TEST_EQUAL(actual_status, expected_status);
if (expected_status == PSA_SUCCESS) {
ASSERT_COMPARE(signature, signature_length,
TEST_BUFFERS_EQUAL(signature, signature_length,
expected_output->x, expected_output->len);
}
TEST_EQUAL(mbedtls_test_driver_signature_sign_hooks.hits, 1);
@ -673,7 +673,7 @@ void sign_message(int key_type_arg,
&signature_length);
TEST_EQUAL(actual_status, expected_status);
if (expected_status == PSA_SUCCESS) {
ASSERT_COMPARE(signature, signature_length,
TEST_BUFFERS_EQUAL(signature, signature_length,
expected_output->x, expected_output->len);
}
/* In the builtin algorithm the driver is called twice. */
@ -795,7 +795,7 @@ void generate_ec_key(int force_status_arg,
psa_export_key(key, actual_output, sizeof(actual_output), &actual_output_length);
if (fake_output->len > 0) {
ASSERT_COMPARE(actual_output, actual_output_length,
TEST_BUFFERS_EQUAL(actual_output, actual_output_length,
expected_output, expected_output_length);
} else {
size_t zeroes = 0;
@ -927,7 +927,7 @@ void export_key(int force_status_arg,
}
if (actual_status == PSA_SUCCESS) {
ASSERT_COMPARE(actual_output, actual_output_length,
TEST_BUFFERS_EQUAL(actual_output, actual_output_length,
expected_output_ptr, expected_output_length);
}
exit:
@ -1006,7 +1006,7 @@ void key_agreement(int alg_arg,
TEST_EQUAL(mbedtls_test_driver_key_agreement_hooks.hits, 1);
if (actual_status == PSA_SUCCESS) {
ASSERT_COMPARE(actual_output, actual_output_length,
TEST_BUFFERS_EQUAL(actual_output, actual_output_length,
expected_output_ptr, expected_output_length);
}
mbedtls_free(actual_output);
@ -1093,7 +1093,7 @@ void cipher_encrypt_validation(int alg_arg,
PSA_ASSERT(psa_cipher_abort(&operation));
// driver function should've been called as part of the finish() core routine
TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
ASSERT_COMPARE(output1 + iv_size, output1_length - iv_size,
TEST_BUFFERS_EQUAL(output1 + iv_size, output1_length - iv_size,
output2, output2_length);
exit:
@ -1221,7 +1221,7 @@ void cipher_encrypt_multipart(int alg_arg,
PSA_ASSERT(psa_cipher_abort(&operation));
TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
output, total_output_length);
}
@ -1350,7 +1350,7 @@ void cipher_decrypt_multipart(int alg_arg,
PSA_ASSERT(psa_cipher_abort(&operation));
TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
output, total_output_length);
}
@ -1422,7 +1422,7 @@ void cipher_decrypt(int alg_arg,
TEST_EQUAL(status, expected_status);
if (expected_status == PSA_SUCCESS) {
ASSERT_COMPARE(expected_output->x, expected_output->len,
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
output, output_length);
}
@ -1707,7 +1707,7 @@ void aead_encrypt(int key_type_arg, data_t *key_data,
PSA_SUCCESS : forced_status);
if (status == PSA_SUCCESS) {
ASSERT_COMPARE(expected_result->x, expected_result->len,
TEST_BUFFERS_EQUAL(expected_result->x, expected_result->len,
output_data, output_length);
}
@ -1770,7 +1770,7 @@ void aead_decrypt(int key_type_arg, data_t *key_data,
PSA_SUCCESS : forced_status);
if (status == PSA_SUCCESS) {
ASSERT_COMPARE(expected_data->x, expected_data->len,
TEST_BUFFERS_EQUAL(expected_data->x, expected_data->len,
output_data, output_length);
}
@ -1839,7 +1839,7 @@ void mac_sign(int key_type_arg,
TEST_EQUAL(mbedtls_test_driver_mac_hooks.hits, 1);
if (forced_status == PSA_SUCCESS) {
ASSERT_COMPARE(expected_mac->x, expected_mac->len,
TEST_BUFFERS_EQUAL(expected_mac->x, expected_mac->len,
actual_mac, mac_length);
}
@ -1957,7 +1957,7 @@ void mac_sign_multipart(int key_type_arg,
}
if (forced_status == PSA_SUCCESS) {
ASSERT_COMPARE(expected_mac->x, expected_mac->len,
TEST_BUFFERS_EQUAL(expected_mac->x, expected_mac->len,
actual_mac, mac_length);
}
@ -2159,7 +2159,7 @@ void builtin_key_export(int builtin_key_id_arg,
if (expected_status == PSA_SUCCESS) {
PSA_ASSERT(actual_status);
TEST_EQUAL(output_size, expected_output->len);
ASSERT_COMPARE(output_buffer, output_size,
TEST_BUFFERS_EQUAL(output_buffer, output_size,
expected_output->x, expected_output->len);
PSA_ASSERT(psa_get_key_attributes(key, &attributes));
@ -2210,7 +2210,7 @@ void builtin_pubkey_export(int builtin_key_id_arg,
if (expected_status == PSA_SUCCESS) {
PSA_ASSERT(actual_status);
TEST_EQUAL(output_size, expected_output->len);
ASSERT_COMPARE(output_buffer, output_size,
TEST_BUFFERS_EQUAL(output_buffer, output_size,
expected_output->x, expected_output->len);
PSA_ASSERT(psa_get_key_attributes(key, &attributes));
@ -2257,7 +2257,7 @@ void hash_compute(int alg_arg,
TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
if (expected_status == PSA_SUCCESS) {
ASSERT_COMPARE(output, output_length, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
}
exit:
@ -2305,7 +2305,7 @@ void hash_multipart_setup(int alg_arg,
forced_status == PSA_ERROR_NOT_SUPPORTED ? 1 : 4);
TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
ASSERT_COMPARE(output, output_length, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
}
exit:
@ -2362,7 +2362,7 @@ void hash_multipart_update(int alg_arg,
TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 2);
TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
ASSERT_COMPARE(output, output_length, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
}
exit:
@ -2416,7 +2416,7 @@ void hash_multipart_finish(int alg_arg,
TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
if (forced_status == PSA_SUCCESS) {
ASSERT_COMPARE(output, output_length, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
}
exit:
@ -2476,7 +2476,7 @@ void hash_clone(int alg_arg,
TEST_EQUAL(mbedtls_test_driver_hash_hooks.hits, 3);
TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, PSA_SUCCESS);
ASSERT_COMPARE(output, output_length, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
}
exit:
@ -2560,7 +2560,7 @@ void asymmetric_encrypt_decrypt(int alg_arg,
if (expected_status_encrypt == PSA_SUCCESS) {
if (fake_output_encrypt->len > 0) {
ASSERT_COMPARE(fake_output_encrypt->x, fake_output_encrypt->len,
TEST_BUFFERS_EQUAL(fake_output_encrypt->x, fake_output_encrypt->len,
output, output_length);
} else {
mbedtls_test_driver_asymmetric_encryption_hooks.forced_status =
@ -2587,10 +2587,10 @@ void asymmetric_encrypt_decrypt(int alg_arg,
&output2_length), expected_status_decrypt);
if (expected_status_decrypt == PSA_SUCCESS) {
if (fake_output_decrypt->len > 0) {
ASSERT_COMPARE(fake_output_decrypt->x, fake_output_decrypt->len,
TEST_BUFFERS_EQUAL(fake_output_decrypt->x, fake_output_decrypt->len,
output2, output2_length);
} else {
ASSERT_COMPARE(input_data->x, input_data->len,
TEST_BUFFERS_EQUAL(input_data->x, input_data->len,
output2, output2_length);
}
}
@ -2664,7 +2664,7 @@ void asymmetric_decrypt(int alg_arg,
&output_length), expected_status_decrypt);
if (expected_status_decrypt == PSA_SUCCESS) {
TEST_EQUAL(output_length, expected_output_data->len);
ASSERT_COMPARE(expected_output_data->x, expected_output_data->len,
TEST_BUFFERS_EQUAL(expected_output_data->x, expected_output_data->len,
output, output_length);
}
exit:
@ -2738,7 +2738,7 @@ void asymmetric_encrypt(int alg_arg,
if (expected_status_encrypt == PSA_SUCCESS) {
if (fake_output_encrypt->len > 0) {
TEST_EQUAL(fake_output_encrypt->len, output_length);
ASSERT_COMPARE(fake_output_encrypt->x, fake_output_encrypt->len,
TEST_BUFFERS_EQUAL(fake_output_encrypt->x, fake_output_encrypt->len,
output, output_length);
} else {
/* Perform sanity checks on the output */
@ -2873,11 +2873,11 @@ void aead_encrypt_setup(int key_type_arg, data_t *key_data,
forced_status == PSA_SUCCESS ? 1 : 0);
/* Compare output_data and expected_ciphertext */
ASSERT_COMPARE(expected_ciphertext->x, expected_ciphertext->len,
TEST_BUFFERS_EQUAL(expected_ciphertext->x, expected_ciphertext->len,
output_data, output_length + finish_output_length);
/* Compare tag and expected_tag */
ASSERT_COMPARE(expected_tag->x, expected_tag->len, tag_buffer, tag_length);
TEST_BUFFERS_EQUAL(expected_tag->x, expected_tag->len, tag_buffer, tag_length);
}
exit:
@ -2979,7 +2979,7 @@ void aead_decrypt_setup(int key_type_arg, data_t *key_data,
TEST_EQUAL(mbedtls_test_driver_aead_hooks.hits_abort,
forced_status == PSA_SUCCESS ? 1 : 0);
ASSERT_COMPARE(expected_result->x, expected_result->len,
TEST_BUFFERS_EQUAL(expected_result->x, expected_result->len,
output_data, output_length + verify_output_length);
}

View file

@ -25,7 +25,7 @@ void hash_finish(int alg_arg, data_t *input, data_t *expected_hash)
PSA_ASSERT(psa_hash_finish(&operation,
actual_hash, sizeof(actual_hash),
&actual_hash_length));
ASSERT_COMPARE(expected_hash->x, expected_hash->len,
TEST_BUFFERS_EQUAL(expected_hash->x, expected_hash->len,
actual_hash, actual_hash_length);
exit:
@ -83,13 +83,13 @@ void hash_multi_part(int alg_arg, data_t *input, data_t *expected_hash)
PSA_ASSERT(psa_hash_finish(&operation,
actual_hash, sizeof(actual_hash),
&actual_hash_length));
ASSERT_COMPARE(expected_hash->x, expected_hash->len,
TEST_BUFFERS_EQUAL(expected_hash->x, expected_hash->len,
actual_hash, actual_hash_length);
PSA_ASSERT(psa_hash_finish(&operation2,
actual_hash, sizeof(actual_hash),
&actual_hash_length));
ASSERT_COMPARE(expected_hash->x, expected_hash->len,
TEST_BUFFERS_EQUAL(expected_hash->x, expected_hash->len,
actual_hash, actual_hash_length);
} while (len++ != input->len);

View file

@ -1031,7 +1031,7 @@ void pake_input_getters_password()
&buffer_len_ret),
PSA_SUCCESS);
ASSERT_COMPARE(password_ret, buffer_len_ret, password, strlen(password));
TEST_BUFFERS_EQUAL(password_ret, buffer_len_ret, password, strlen(password));
exit:
PSA_ASSERT(psa_destroy_key(key));
PSA_ASSERT(psa_pake_abort(&operation));
@ -1064,7 +1064,7 @@ void pake_input_getters_cipher_suite()
TEST_EQUAL(psa_crypto_driver_pake_get_cipher_suite(&operation.data.inputs, &cipher_suite_ret),
PSA_SUCCESS);
ASSERT_COMPARE(&cipher_suite_ret, sizeof(cipher_suite_ret),
TEST_BUFFERS_EQUAL(&cipher_suite_ret, sizeof(cipher_suite_ret),
&cipher_suite, sizeof(cipher_suite));
exit:
@ -1128,7 +1128,7 @@ void pake_input_getters_user()
&buffer_len_ret),
PSA_SUCCESS);
ASSERT_COMPARE(user_ret, buffer_len_ret, user, user_len);
TEST_BUFFERS_EQUAL(user_ret, buffer_len_ret, user, user_len);
}
exit:
PSA_ASSERT(psa_pake_abort(&operation));
@ -1191,7 +1191,7 @@ void pake_input_getters_peer()
&buffer_len_ret),
PSA_SUCCESS);
ASSERT_COMPARE(peer_ret, buffer_len_ret, peer, peer_len);
TEST_BUFFERS_EQUAL(peer_ret, buffer_len_ret, peer, peer_len);
}
exit:
PSA_ASSERT(psa_pake_abort(&operation));

View file

@ -66,7 +66,7 @@ void format_storage_data_check(data_t *key_data,
&attributes.core,
file_data);
ASSERT_COMPARE(expected_file_data->x, expected_file_data->len,
TEST_BUFFERS_EQUAL(expected_file_data->x, expected_file_data->len,
file_data, file_data_length);
exit:
@ -111,7 +111,7 @@ void parse_storage_data_check(data_t *file_data,
(uint32_t) expected_key_alg);
TEST_EQUAL(psa_get_key_enrollment_algorithm(&attributes),
(uint32_t) expected_key_alg2);
ASSERT_COMPARE(expected_key_data->x, expected_key_data->len,
TEST_BUFFERS_EQUAL(expected_key_data->x, expected_key_data->len,
key_data, key_data_length);
exit:
@ -307,7 +307,7 @@ void import_export_persistent_key(data_t *data, int type_arg,
PSA_ASSERT(psa_export_key(key_id, exported, export_size,
&exported_length));
ASSERT_COMPARE(data->x, data->len, exported, exported_length);
TEST_BUFFERS_EQUAL(data->x, data->len, exported, exported_length);
/* Destroy the key */
PSA_ASSERT(psa_destroy_key(key_id));

View file

@ -607,7 +607,7 @@ static int check_persistent_data(psa_key_location_t location,
PSA_ASSERT(psa_its_get_info(uid, &info));
ASSERT_ALLOC(loaded, info.size);
PSA_ASSERT(psa_its_get(uid, 0, info.size, loaded, NULL));
ASSERT_COMPARE(expected_data, size, loaded, info.size);
TEST_BUFFERS_EQUAL(expected_data, size, loaded, info.size);
ok = 1;
exit:
@ -965,7 +965,7 @@ void key_creation_import_export(int lifetime_arg, int min_slot, int restart)
PSA_ASSERT(psa_export_key(returned_id,
exported, sizeof(exported),
&exported_length));
ASSERT_COMPARE(key_material, sizeof(key_material),
TEST_BUFFERS_EQUAL(key_material, sizeof(key_material),
exported, exported_length);
PSA_ASSERT(psa_destroy_key(returned_id));

View file

@ -307,7 +307,7 @@ void persistent_slot_lifecycle(int lifetime_arg, int owner_id_arg, int id_arg,
if (usage_flags & PSA_KEY_USAGE_EXPORT) {
PSA_ASSERT(psa_export_key(id, reexported, key_data->len,
&reexported_length));
ASSERT_COMPARE(key_data->x, key_data->len,
TEST_BUFFERS_EQUAL(key_data->x, key_data->len,
reexported, reexported_length);
} else {
TEST_EQUAL(psa_export_key(id, reexported,
@ -402,7 +402,7 @@ void create_existent(int lifetime_arg, int owner_id_arg, int id_arg,
PSA_ASSERT(psa_export_key(id,
reexported, sizeof(reexported),
&reexported_length));
ASSERT_COMPARE(material1, sizeof(material1),
TEST_BUFFERS_EQUAL(material1, sizeof(material1),
reexported, reexported_length);
PSA_ASSERT(psa_close_key(id));
@ -578,7 +578,7 @@ void copy_across_lifetimes(int source_lifetime_arg, int source_owner_id_arg,
ASSERT_ALLOC(export_buffer, material->len);
PSA_ASSERT(psa_export_key(returned_target_id, export_buffer,
material->len, &length));
ASSERT_COMPARE(material->x, material->len,
TEST_BUFFERS_EQUAL(material->x, material->len,
export_buffer, length);
} else {
size_t length;
@ -692,7 +692,7 @@ void copy_to_occupied(int source_lifetime_arg, int source_id_arg,
ASSERT_ALLOC(export_buffer, target_material->len);
PSA_ASSERT(psa_export_key(returned_target_id, export_buffer,
target_material->len, &length));
ASSERT_COMPARE(target_material->x, target_material->len,
TEST_BUFFERS_EQUAL(target_material->x, target_material->len,
export_buffer, length);
}
@ -840,7 +840,7 @@ void many_transient_keys(int max_keys_arg)
PSA_ASSERT(psa_export_key(keys[i],
exported, sizeof(exported),
&exported_length));
ASSERT_COMPARE(exported, exported_length,
TEST_BUFFERS_EQUAL(exported, exported_length,
(uint8_t *) &i, sizeof(i));
}
PSA_ASSERT(psa_close_key(keys[i - 1]));
@ -917,7 +917,7 @@ void key_slot_eviction_to_import_new_key(int lifetime_arg)
PSA_ASSERT(psa_export_key(key,
exported, sizeof(exported),
&exported_length));
ASSERT_COMPARE(exported, exported_length,
TEST_BUFFERS_EQUAL(exported, exported_length,
(uint8_t *) &i, sizeof(i));
PSA_ASSERT(psa_destroy_key(key));
}
@ -988,7 +988,7 @@ void non_reusable_key_slots_integrity_in_case_of_key_slot_starvation()
exported, sizeof(exported),
&exported_length));
i = MBEDTLS_PSA_KEY_SLOT_COUNT - 1;
ASSERT_COMPARE(exported, exported_length, (uint8_t *) &i, sizeof(i));
TEST_BUFFERS_EQUAL(exported, exported_length, (uint8_t *) &i, sizeof(i));
PSA_ASSERT(psa_destroy_key(keys[MBEDTLS_PSA_KEY_SLOT_COUNT - 1]));
/*
@ -1016,7 +1016,7 @@ void non_reusable_key_slots_integrity_in_case_of_key_slot_starvation()
PSA_ASSERT(psa_export_key(keys[i],
exported, sizeof(exported),
&exported_length));
ASSERT_COMPARE(exported, exported_length,
TEST_BUFFERS_EQUAL(exported, exported_length,
(uint8_t *) &i, sizeof(i));
PSA_ASSERT(psa_destroy_key(keys[i]));
}
@ -1028,7 +1028,7 @@ void non_reusable_key_slots_integrity_in_case_of_key_slot_starvation()
PSA_ASSERT(psa_export_key(persistent_key, exported, sizeof(exported),
&exported_length));
ASSERT_COMPARE(exported, exported_length,
TEST_BUFFERS_EQUAL(exported, exported_length,
(uint8_t *) &persistent_key, sizeof(persistent_key));
exit:
/*

View file

@ -39,7 +39,7 @@ static int test_written_key(const psa_key_attributes_t *attributes,
ASSERT_ALLOC(actual_representation, storage_info.size);
PSA_ASSERT(psa_its_get(uid, 0, storage_info.size,
actual_representation, &length));
ASSERT_COMPARE(expected_representation->x, expected_representation->len,
TEST_BUFFERS_EQUAL(expected_representation->x, expected_representation->len,
actual_representation, length);
ok = 1;
@ -263,7 +263,7 @@ static int test_read_key(const psa_key_attributes_t *expected_attributes,
PSA_ASSERT(psa_export_key(key_id,
exported_material, expected_material->len,
&length));
ASSERT_COMPARE(expected_material->x, expected_material->len,
TEST_BUFFERS_EQUAL(expected_material->x, expected_material->len,
exported_material, length);
}

View file

@ -100,7 +100,7 @@ void set_get_remove(int uid_arg, int flags_arg, data_t *data)
TEST_ASSERT(info.size == data->len);
TEST_ASSERT(info.flags == flags);
PSA_ASSERT(psa_its_get(uid, 0, data->len, buffer, &ret_len));
ASSERT_COMPARE(data->x, data->len, buffer, ret_len);
TEST_BUFFERS_EQUAL(data->x, data->len, buffer, ret_len);
PSA_ASSERT(psa_its_remove(uid));
@ -129,7 +129,7 @@ void set_overwrite(int uid_arg,
TEST_ASSERT(info.size == data1->len);
TEST_ASSERT(info.flags == flags1);
PSA_ASSERT(psa_its_get(uid, 0, data1->len, buffer, &ret_len));
ASSERT_COMPARE(data1->x, data1->len, buffer, ret_len);
TEST_BUFFERS_EQUAL(data1->x, data1->len, buffer, ret_len);
PSA_ASSERT(psa_its_set_wrap(uid, data2->len, data2->x, flags2));
PSA_ASSERT(psa_its_get_info(uid, &info));
@ -137,7 +137,7 @@ void set_overwrite(int uid_arg,
TEST_ASSERT(info.flags == flags2);
ret_len = 0;
PSA_ASSERT(psa_its_get(uid, 0, data2->len, buffer, &ret_len));
ASSERT_COMPARE(data2->x, data2->len, buffer, ret_len);
TEST_BUFFERS_EQUAL(data2->x, data2->len, buffer, ret_len);
PSA_ASSERT(psa_its_remove(uid));
@ -167,7 +167,7 @@ void set_multiple(int first_id, int count)
mbedtls_snprintf(stored, sizeof(stored),
"Content of file 0x%08lx", (unsigned long) uid);
PSA_ASSERT(psa_its_get(uid, 0, sizeof(stored), retrieved, &ret_len));
ASSERT_COMPARE(retrieved, ret_len,
TEST_BUFFERS_EQUAL(retrieved, ret_len,
stored, sizeof(stored));
PSA_ASSERT(psa_its_remove(uid));
TEST_ASSERT(psa_its_get(uid, 0, 0, NULL, NULL) ==
@ -223,7 +223,7 @@ void get_at(int uid_arg, data_t *data,
status = psa_its_get(uid, offset, length_arg, buffer, &ret_len);
TEST_ASSERT(status == (psa_status_t) expected_status);
if (status == PSA_SUCCESS) {
ASSERT_COMPARE(data->x + offset, (size_t) length_arg,
TEST_BUFFERS_EQUAL(data->x + offset, (size_t) length_arg,
buffer, ret_len);
}
for (i = 0; i < 16; i++) {

View file

@ -159,7 +159,7 @@ void mbedtls_sha3(int family, data_t *in, data_t *hash)
TEST_ASSERT(mbedtls_sha3(family, in->x, in->len, output, hash->len) == 0);
ASSERT_COMPARE(output, hash->len, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, hash->len, hash->x, hash->len);
exit:
mbedtls_free(output);
@ -204,7 +204,7 @@ void mbedtls_sha3_multi(int family, data_t *in, data_t *hash)
TEST_ASSERT(mbedtls_sha3_finish(&ctx, output, hash->len) == 0);
ASSERT_COMPARE(output, hash->len, hash->x, hash->len);
TEST_BUFFERS_EQUAL(output, hash->len, hash->x, hash->len);
exit:
mbedtls_free(output);
@ -253,7 +253,7 @@ void sha3_streaming(int type, data_t *input)
mbedtls_sha3_finish(&ctx, hash, hash_length);
mbedtls_sha3_free(&ctx);
ASSERT_COMPARE(hash, hash_length, reference_hash, hash_length);
TEST_BUFFERS_EQUAL(hash, hash_length, reference_hash, hash_length);
}
exit:
@ -289,13 +289,13 @@ void sha3_reuse(data_t *input1, data_t *hash1,
TEST_ASSERT(mbedtls_sha3_starts(&ctx, type1) == 0);
TEST_ASSERT(mbedtls_sha3_update(&ctx, input1->x, input1->len) == 0);
TEST_ASSERT(mbedtls_sha3_finish(&ctx, output, sizeof(output)) == 0);
ASSERT_COMPARE(output, hash1->len, hash1->x, hash1->len);
TEST_BUFFERS_EQUAL(output, hash1->len, hash1->x, hash1->len);
/* Round 2 */
TEST_ASSERT(mbedtls_sha3_starts(&ctx, type2) == 0);
TEST_ASSERT(mbedtls_sha3_update(&ctx, input2->x, input2->len) == 0);
TEST_ASSERT(mbedtls_sha3_finish(&ctx, output, sizeof(output)) == 0);
ASSERT_COMPARE(output, hash2->len, hash2->x, hash2->len);
TEST_BUFFERS_EQUAL(output, hash2->len, hash2->x, hash2->len);
exit:
mbedtls_sha3_free(&ctx);

View file

@ -1728,7 +1728,7 @@ void ssl_tls13_hkdf_expand_label(int hash_alg,
ctx->x, ctx->len,
dst, desired_length) == 0);
ASSERT_COMPARE(dst, (size_t) desired_length,
TEST_BUFFERS_EQUAL(dst, (size_t) desired_length,
expected->x, (size_t) expected->len);
exit:
@ -1768,19 +1768,19 @@ void ssl_tls13_traffic_key_generation(int hash_alg,
desired_key_len, desired_iv_len,
&keys) == 0);
ASSERT_COMPARE(keys.client_write_key,
TEST_BUFFERS_EQUAL(keys.client_write_key,
keys.key_len,
expected_client_write_key->x,
(size_t) desired_key_len);
ASSERT_COMPARE(keys.server_write_key,
TEST_BUFFERS_EQUAL(keys.server_write_key,
keys.key_len,
expected_server_write_key->x,
(size_t) desired_key_len);
ASSERT_COMPARE(keys.client_write_iv,
TEST_BUFFERS_EQUAL(keys.client_write_iv,
keys.iv_len,
expected_client_write_iv->x,
(size_t) desired_iv_len);
ASSERT_COMPARE(keys.server_write_iv,
TEST_BUFFERS_EQUAL(keys.server_write_iv,
keys.iv_len,
expected_server_write_iv->x,
(size_t) desired_iv_len);
@ -1827,7 +1827,7 @@ void ssl_tls13_derive_secret(int hash_alg,
already_hashed,
dst, desired_length) == 0);
ASSERT_COMPARE(dst, desired_length,
TEST_BUFFERS_EQUAL(dst, desired_length,
expected->x, desired_length);
exit:
@ -1859,9 +1859,9 @@ void ssl_tls13_derive_early_secrets(int hash_alg,
alg, secret->x, transcript->x, transcript->len,
&secrets) == 0);
ASSERT_COMPARE(secrets.client_early_traffic_secret, hash_len,
TEST_BUFFERS_EQUAL(secrets.client_early_traffic_secret, hash_len,
traffic_expected->x, traffic_expected->len);
ASSERT_COMPARE(secrets.early_exporter_master_secret, hash_len,
TEST_BUFFERS_EQUAL(secrets.early_exporter_master_secret, hash_len,
exporter_expected->x, exporter_expected->len);
exit:
@ -1893,9 +1893,9 @@ void ssl_tls13_derive_handshake_secrets(int hash_alg,
alg, secret->x, transcript->x, transcript->len,
&secrets) == 0);
ASSERT_COMPARE(secrets.client_handshake_traffic_secret, hash_len,
TEST_BUFFERS_EQUAL(secrets.client_handshake_traffic_secret, hash_len,
client_expected->x, client_expected->len);
ASSERT_COMPARE(secrets.server_handshake_traffic_secret, hash_len,
TEST_BUFFERS_EQUAL(secrets.server_handshake_traffic_secret, hash_len,
server_expected->x, server_expected->len);
exit:
@ -1929,11 +1929,11 @@ void ssl_tls13_derive_application_secrets(int hash_alg,
alg, secret->x, transcript->x, transcript->len,
&secrets) == 0);
ASSERT_COMPARE(secrets.client_application_traffic_secret_N, hash_len,
TEST_BUFFERS_EQUAL(secrets.client_application_traffic_secret_N, hash_len,
client_expected->x, client_expected->len);
ASSERT_COMPARE(secrets.server_application_traffic_secret_N, hash_len,
TEST_BUFFERS_EQUAL(secrets.server_application_traffic_secret_N, hash_len,
server_expected->x, server_expected->len);
ASSERT_COMPARE(secrets.exporter_master_secret, hash_len,
TEST_BUFFERS_EQUAL(secrets.exporter_master_secret, hash_len,
exporter_expected->x, exporter_expected->len);
exit:
@ -1963,7 +1963,7 @@ void ssl_tls13_derive_resumption_secrets(int hash_alg,
alg, secret->x, transcript->x, transcript->len,
&secrets) == 0);
ASSERT_COMPARE(secrets.resumption_master_secret, hash_len,
TEST_BUFFERS_EQUAL(secrets.resumption_master_secret, hash_len,
resumption_expected->x, resumption_expected->len);
exit:
@ -1997,7 +1997,7 @@ void ssl_tls13_create_psk_binder(int hash_alg,
transcript->x,
binder) == 0);
ASSERT_COMPARE(binder, hash_len,
TEST_BUFFERS_EQUAL(binder, hash_len,
binder_expected->x, binder_expected->len);
exit:
@ -2090,12 +2090,12 @@ void ssl_tls13_record_protection(int ciphersuite,
NULL, NULL) == 0);
if (padding_used == MBEDTLS_SSL_CID_TLS1_3_PADDING_GRANULARITY) {
ASSERT_COMPARE(rec.buf + rec.data_offset, rec.data_len,
TEST_BUFFERS_EQUAL(rec.buf + rec.data_offset, rec.data_len,
ciphertext->x, ciphertext->len);
}
TEST_ASSERT(mbedtls_ssl_decrypt_buf(NULL, &transform_recv, &rec) == 0);
ASSERT_COMPARE(rec.buf + rec.data_offset, rec.data_len,
TEST_BUFFERS_EQUAL(rec.buf + rec.data_offset, rec.data_len,
plaintext->x, plaintext->len);
exit:
@ -2122,7 +2122,7 @@ void ssl_tls13_key_evolution(int hash_alg,
input->len ? input->x : NULL, input->len,
secret_new) == 0);
ASSERT_COMPARE(secret_new, (size_t) expected->len,
TEST_BUFFERS_EQUAL(secret_new, (size_t) expected->len,
expected->x, (size_t) expected->len);
exit:
@ -3326,7 +3326,7 @@ void cid_sanity()
== 0);
TEST_EQUAL(cid_enabled, MBEDTLS_SSL_CID_ENABLED);
ASSERT_COMPARE(own_cid, own_cid_len, test_cid, own_cid_len);
TEST_BUFFERS_EQUAL(own_cid, own_cid_len, test_cid, own_cid_len);
/* Test disabling works. */
TEST_ASSERT(mbedtls_ssl_set_cid(&ssl, MBEDTLS_SSL_CID_DISABLED, NULL,

View file

@ -447,7 +447,7 @@ void x509_crt_parse_cn_inet_pton(const char *cn, data_t *exp, int ref_ret)
TEST_EQUAL(addrlen, (size_t) ref_ret);
if (addrlen) {
ASSERT_COMPARE(exp->x, exp->len, addr, addrlen);
TEST_BUFFERS_EQUAL(exp->x, exp->len, addr, addrlen);
}
}
/* END_CASE */