1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-30 22:43:08 +03:00

For tests, rename TEST_BUFFERS_EQUAL() to TEST_MEMORY_COMPARE()

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
This commit is contained in:
Tom Cosgrove
2023-09-04 11:23:02 +01:00
parent cd5a7c76f2
commit ba3b14dad9
26 changed files with 224 additions and 224 deletions

View File

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

View File

@ -34,7 +34,7 @@ static int test_ctx_alignment(const data_t *key,
// Decrypt
TEST_ASSERT(mbedtls_aes_crypt_ecb(dec, MBEDTLS_AES_DECRYPT,
ciphertext, output) == 0);
TEST_BUFFERS_EQUAL(plaintext, 16, output, 16);
TEST_MEMORY_COMPARE(plaintext, 16, output, 16);
mbedtls_aes_free(dec);

View File

@ -224,7 +224,7 @@ void aria_encrypt_ecb(data_t *key_str, data_t *src_str,
output + i) == 0);
}
TEST_BUFFERS_EQUAL(output, expected_output->len,
TEST_MEMORY_COMPARE(output, expected_output->len,
expected_output->x, expected_output->len);
}
@ -252,7 +252,7 @@ void aria_decrypt_ecb(data_t *key_str, data_t *src_str,
output + i) == 0);
}
TEST_BUFFERS_EQUAL(output, expected_output->len,
TEST_MEMORY_COMPARE(output, expected_output->len,
expected_output->x, expected_output->len);
}
@ -277,7 +277,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) {
TEST_BUFFERS_EQUAL(output, expected_output->len,
TEST_MEMORY_COMPARE(output, expected_output->len,
expected_output->x, expected_output->len);
}
@ -302,7 +302,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) {
TEST_BUFFERS_EQUAL(output, expected_output->len,
TEST_MEMORY_COMPARE(output, expected_output->len,
expected_output->x, expected_output->len);
}
@ -329,7 +329,7 @@ void aria_encrypt_cfb128(data_t *key_str, data_t *iv_str,
iv_str->x, src_str->x, output)
== result);
TEST_BUFFERS_EQUAL(output, expected_output->len,
TEST_MEMORY_COMPARE(output, expected_output->len,
expected_output->x, expected_output->len);
exit:
@ -355,7 +355,7 @@ void aria_decrypt_cfb128(data_t *key_str, data_t *iv_str,
iv_str->x, src_str->x, output)
== result);
TEST_BUFFERS_EQUAL(output, expected_output->len,
TEST_MEMORY_COMPARE(output, expected_output->len,
expected_output->x, expected_output->len);
exit:
@ -381,7 +381,7 @@ void aria_encrypt_ctr(data_t *key_str, data_t *iv_str,
iv_str->x, blk, src_str->x, output)
== result);
TEST_BUFFERS_EQUAL(output, expected_output->len,
TEST_MEMORY_COMPARE(output, expected_output->len,
expected_output->x, expected_output->len);
exit:
@ -407,7 +407,7 @@ void aria_decrypt_ctr(data_t *key_str, data_t *iv_str,
iv_str->x, blk, src_str->x, output)
== result);
TEST_BUFFERS_EQUAL(output, expected_output->len,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(data->p, (size_t) (data->end - data->p),
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(alg.p, alg.len, oid->x, oid->len);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(read.p, read.len,
TEST_MEMORY_COMPARE(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) {
TEST_BUFFERS_EQUAL(found->val.p, found->val.len,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(found->oid.p, found->oid.len, oid, oid_len);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(found->val.p, found->val.len,
TEST_MEMORY_COMPARE(found->val.p, found->val.len,
new_val, (size_t) new_len);
}

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);
TEST_BUFFERS_EQUAL(output, expected_output_str->len,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(output, expected_output_str->len,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(output, expected_output_str->len,
TEST_MEMORY_COMPARE(output, expected_output_str->len,
expected_output_str->x, expected_output_str->len);
mbedtls_chacha20_free(&ctx);

View File

@ -1274,7 +1274,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);
TEST_BUFFERS_EQUAL(decrypt_buf, outlen, clear->x, clear->len);
TEST_MEMORY_COMPARE(decrypt_buf, outlen, clear->x, clear->len);
}
/* Free this, but keep cipher_plus_tag for deprecated function with PSA */
@ -1390,7 +1390,7 @@ void auth_crypt_tv(int cipher_id, data_t *key, data_t *iv,
} else {
/* authentic message: is the plaintext correct? */
TEST_ASSERT(ret == 0);
TEST_BUFFERS_EQUAL(decrypt_buf, outlen, clear->x, clear->len);
TEST_MEMORY_COMPARE(decrypt_buf, outlen, clear->x, clear->len);
}
mbedtls_free(decrypt_buf);

View File

@ -38,7 +38,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);
TEST_BUFFERS_EQUAL(dst, len, src + secret, len);
TEST_MEMORY_COMPARE(dst, len, src + secret, len);
}
exit:

View File

@ -84,7 +84,7 @@ void ssl_cf_hmac(int hash)
TEST_EQUAL(0, mbedtls_md_hmac_reset(&ref_ctx));
/* Compare */
TEST_BUFFERS_EQUAL(out, out_len, ref_out, out_len);
TEST_MEMORY_COMPARE(out, out_len, ref_out, out_len);
}
mbedtls_free(data);

View File

@ -852,7 +852,7 @@ void ecp_muladd(int id,
&len, actual_result, sizeof(actual_result)));
TEST_ASSERT(len <= MBEDTLS_ECP_MAX_PT_LEN);
TEST_BUFFERS_EQUAL(expected_result->x, expected_result->len,
TEST_MEMORY_COMPARE(expected_result->x, expected_result->len,
actual_result, len);
exit:
@ -1356,7 +1356,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);
TEST_BUFFERS_EQUAL(in_key->x, in_key->len,
TEST_MEMORY_COMPARE(in_key->x, in_key->len,
buf, in_key->len);
} else {
unsigned char export1[MBEDTLS_ECP_MAX_BYTES];
@ -1371,7 +1371,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);
TEST_BUFFERS_EQUAL(export1, in_key->len,
TEST_MEMORY_COMPARE(export1, in_key->len,
export2, in_key->len);
}
}
@ -1448,7 +1448,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). */
TEST_BUFFERS_EQUAL(expected->x, expected->len,
TEST_MEMORY_COMPARE(expected->x, expected->len,
actual, expected->len);
}

View File

@ -24,7 +24,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);
TEST_BUFFERS_EQUAL(okm, expected_okm->len,
TEST_MEMORY_COMPARE(okm, expected_okm->len,
expected_okm->x, expected_okm->len);
}
/* END_CASE */
@ -53,7 +53,7 @@ void test_hkdf_extract(int md_alg, char *hex_ikm_string,
ret = mbedtls_hkdf_extract(md, salt, salt_len, ikm, ikm_len, output_prk);
TEST_ASSERT(ret == 0);
TEST_BUFFERS_EQUAL(output_prk, output_prk_len, prk, prk_len);
TEST_MEMORY_COMPARE(output_prk, output_prk_len, prk, prk_len);
exit:
mbedtls_free(ikm);
@ -89,7 +89,7 @@ void test_hkdf_expand(int md_alg, char *hex_info_string,
ret = mbedtls_hkdf_expand(md, prk, prk_len, info, info_len,
output_okm, OKM_LEN);
TEST_ASSERT(ret == 0);
TEST_BUFFERS_EQUAL(output_okm, okm_len, okm, okm_len);
TEST_MEMORY_COMPARE(output_okm, okm_len, okm, okm_len);
exit:
mbedtls_free(info);

View File

@ -139,7 +139,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));
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_MEMORY_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
}
/* END_CASE */
@ -155,7 +155,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));
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_MEMORY_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
}
/* END_CASE */
@ -188,14 +188,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));
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_MEMORY_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -228,14 +228,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));
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_MEMORY_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -258,7 +258,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));
TEST_BUFFERS_EQUAL(output, trunc_size, hash->x, hash->len);
TEST_MEMORY_COMPARE(output, trunc_size, hash->x, hash->len);
}
/* END_CASE */
@ -285,7 +285,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));
TEST_BUFFERS_EQUAL(output, trunc_size, hash->x, hash->len);
TEST_MEMORY_COMPARE(output, trunc_size, hash->x, hash->len);
/* Test again, for reset() */
memset(output, 0x00, sizeof(output));
@ -295,7 +295,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));
TEST_BUFFERS_EQUAL(output, trunc_size, hash->x, hash->len);
TEST_MEMORY_COMPARE(output, trunc_size, hash->x, hash->len);
exit:
mbedtls_md_free(&ctx);
@ -314,6 +314,6 @@ void mbedtls_md_file(int md_type, char *filename,
TEST_EQUAL(0, mbedtls_md_file(md_info, filename, output));
TEST_BUFFERS_EQUAL(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
TEST_MEMORY_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len);
}
/* END_CASE */

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);
TEST_BUFFERS_EQUAL(tmp, 100, bufA, 100);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 100, bufA, 100);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 100, bufB, 100);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, buf, 10);
TEST_MEMORY_COMPARE(tmp, 10, buf, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 70, buf + 10, 70);
TEST_MEMORY_COMPARE(tmp, 70, buf + 10, 70);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, &tmp_len) == 0);
TEST_BUFFERS_EQUAL(tmp, tmp_len, buf + 80, 20);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 70, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 70, bufA + 10, 70);
TEST_MEMORY_COMPARE(tmp, 70, bufA + 10, 70);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 30, &tmp, &tmp_len) == 0);
TEST_BUFFERS_EQUAL(tmp, tmp_len, bufA + 80, 20);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 100, bufB, 100);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 50, buf, 50);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 50, buf, 50);
TEST_MEMORY_COMPARE(tmp, 50, buf, 50);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, buf + 50, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, tmp_len, buf + 50, 50);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 50, buf, 50);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 80, bufA, 80);
TEST_MEMORY_COMPARE(tmp, 80, bufA, 80);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 90, bufB + 10, 90);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 80, bufA, 80);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 20, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp + 20, 50, bufB, 50);
TEST_MEMORY_COMPARE(tmp, 20, bufA + 80, 20);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 100, buf, 100);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, sizeof(buf) / 2, buf, sizeof(buf) / 2);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, sizeof(buf) / 2, buf, sizeof(buf) / 2);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, sizeof(buf) / 2,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 50, buf, 50);
TEST_MEMORY_COMPARE(tmp, 50, buf, 50);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 50, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 50, buf + 50, 50);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 50, buf + 50, 50);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 80, bufA, 80);
TEST_MEMORY_COMPARE(tmp, 80, bufA, 80);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 10, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, tmp_len, bufA + 80, 10);
TEST_MEMORY_COMPARE(tmp, tmp_len, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufB + 10, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufC, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufB + 10, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 20, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp + 20, 20, bufB, 20);
TEST_BUFFERS_EQUAL(tmp + 40, 10, bufC, 10);
TEST_MEMORY_COMPARE(tmp, 20, bufA + 80, 20);
TEST_MEMORY_COMPARE(tmp + 20, 20, bufB, 20);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 80, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 80, 10);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 20, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 10, bufA + 90, 10);
TEST_BUFFERS_EQUAL(tmp + 10, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 10, bufA + 90, 10);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 20, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp + 20, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 20, bufA + 80, 20);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 20, bufA + 80, 20);
TEST_BUFFERS_EQUAL(tmp + 20, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 20, bufA + 80, 20);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_MEMORY_COMPARE(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 5, bufA + 95, 5);
TEST_BUFFERS_EQUAL(tmp + 5, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 5, bufA + 95, 5);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_MEMORY_COMPARE(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 5, bufA + 95, 5);
TEST_BUFFERS_EQUAL(tmp + 5, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 5, bufA + 95, 5);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_MEMORY_COMPARE(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
TEST_BUFFERS_EQUAL(tmp, 5, bufA + 95, 5);
TEST_BUFFERS_EQUAL(tmp + 5, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 5, bufA + 95, 5);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 15, bufA + 80, 15);
TEST_MEMORY_COMPARE(tmp, 15, bufA + 80, 15);
TEST_ASSERT(mbedtls_mps_reader_get(&rd, 15, &tmp, NULL) == 0);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
TEST_BUFFERS_EQUAL(tmp, 5, bufA + 95, 5);
TEST_BUFFERS_EQUAL(tmp + 5, 10, bufB, 10);
TEST_MEMORY_COMPARE(tmp, 5, bufA + 95, 5);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 90, bufB + 10, 90);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(tmp, 100, buf, 100);
TEST_MEMORY_COMPARE(tmp, 100, buf, 100);
TEST_ASSERT(mbedtls_mps_reader_commit(&rd) == 0);
/* Wrapup */

View File

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

View File

@ -42,7 +42,7 @@ void pkcs1_rsaes_oaep_encrypt(int mod, data_t *input_N, data_t *input_E,
message_str->len, message_str->x,
output) == result);
if (result == 0) {
TEST_BUFFERS_EQUAL(output, ctx.len, result_str->x, result_str->len);
TEST_MEMORY_COMPARE(output, ctx.len, result_str->x, result_str->len);
}
exit:
@ -98,7 +98,7 @@ void pkcs1_rsaes_oaep_decrypt(int mod, data_t *input_P, data_t *input_Q,
output,
sizeof(output)) == result);
if (result == 0) {
TEST_BUFFERS_EQUAL(output, output_len, result_str->x, result_str->len);
TEST_MEMORY_COMPARE(output, output_len, result_str->x, result_str->len);
}
}
@ -154,7 +154,7 @@ void pkcs1_rsassa_pss_sign(int mod, data_t *input_P, data_t *input_Q,
&info, MBEDTLS_RSA_PRIVATE, digest, 0,
hash_result, output) == result);
if (result == 0) {
TEST_BUFFERS_EQUAL(output, ctx.len, result_str->x, result_str->len);
TEST_MEMORY_COMPARE(output, ctx.len, result_str->x, result_str->len);
}
info.buf = rnd_buf->x;
@ -165,7 +165,7 @@ void pkcs1_rsassa_pss_sign(int mod, data_t *input_P, data_t *input_Q,
&info, digest, 0, hash_result,
fixed_salt_length, output) == result);
if (result == 0) {
TEST_BUFFERS_EQUAL(output, ctx.len, result_str->x, result_str->len);
TEST_MEMORY_COMPARE(output, ctx.len, result_str->x, result_str->len);
}
exit:

View File

@ -94,7 +94,7 @@ static void pk_write_check_common(char *key_file, int is_public_key, int is_der)
start_buf = buf;
}
TEST_BUFFERS_EQUAL(start_buf, buf_len, check_buf, check_buf_len);
TEST_MEMORY_COMPARE(start_buf, buf_len, check_buf, check_buf_len);
exit:
mbedtls_free(buf);
@ -150,7 +150,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);
TEST_BUFFERS_EQUAL(derived_key_raw, derived_key_len,
TEST_MEMORY_COMPARE(derived_key_raw, derived_key_len,
pub_key_raw, pub_key_len);
#if defined(MBEDTLS_USE_PSA_CRYPTO)
@ -162,7 +162,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);
TEST_BUFFERS_EQUAL(derived_key_raw, derived_key_len,
TEST_MEMORY_COMPARE(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 */
TEST_CALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, x));
TEST_BUFFERS_EQUAL(result, n + 1, output, n + 1);
TEST_MEMORY_COMPARE(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 */
TEST_CALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, value));
TEST_BUFFERS_EQUAL(expected, n + 1, output, n + 1);
TEST_MEMORY_COMPARE(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 */
TEST_CALLOC(output, n + 1);
TEST_EQUAL(n, mbedtls_snprintf(output, n + 1, format, arg1, arg2));
TEST_BUFFERS_EQUAL(result, n + 1, output, n + 1);
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(mac, expected_mac->len,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(mac, expected_mac->len,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(mac, expected_mac->len,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(mac, expected_mac->len,
TEST_MEMORY_COMPARE(mac, expected_mac->len,
expected_mac->x, expected_mac->len);
}

View File

@ -623,7 +623,7 @@ void import_export(data_t *data,
}
if (canonical_input) {
TEST_BUFFERS_EQUAL(data->x, data->len, exported, exported_length);
TEST_MEMORY_COMPARE(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,
@ -632,7 +632,7 @@ void import_export(data_t *data,
reexported,
export_size,
&reexported_length));
TEST_BUFFERS_EQUAL(exported, exported_length,
TEST_MEMORY_COMPARE(exported, exported_length,
reexported, reexported_length);
PSA_ASSERT(psa_destroy_key(key2));
}
@ -703,7 +703,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);
TEST_BUFFERS_EQUAL(expected_public_key->x, expected_public_key->len,
TEST_MEMORY_COMPARE(expected_public_key->x, expected_public_key->len,
exported, exported_length);
}
@ -1449,7 +1449,7 @@ void copy_success(int source_usage_arg,
TEST_CALLOC(export_buffer, material->len);
PSA_ASSERT(psa_export_key(target_key, export_buffer,
material->len, &length));
TEST_BUFFERS_EQUAL(material->x, material->len,
TEST_MEMORY_COMPARE(material->x, material->len,
export_buffer, length);
}
@ -1650,7 +1650,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));
TEST_BUFFERS_EQUAL(output, output_length,
TEST_MEMORY_COMPARE(output, output_length,
expected_output->x, expected_output->len);
/* Compute with larger buffer */
@ -1658,7 +1658,7 @@ void hash_compute_compare(int alg_arg, data_t *input,
output, sizeof(output),
&output_length));
TEST_EQUAL(output_length, PSA_HASH_LENGTH(alg));
TEST_BUFFERS_EQUAL(output, output_length,
TEST_MEMORY_COMPARE(output, output_length,
expected_output->x, expected_output->len);
/* Compare with correct hash */
@ -2195,7 +2195,7 @@ void mac_sign(int key_type_arg,
actual_mac, output_size, &mac_length),
expected_status);
if (expected_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(expected_mac->x, expected_mac->len,
TEST_MEMORY_COMPARE(expected_mac->x, expected_mac->len,
actual_mac, mac_length);
}
@ -2214,7 +2214,7 @@ void mac_sign(int key_type_arg,
PSA_ASSERT(psa_mac_abort(&operation));
if (expected_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(expected_mac->x, expected_mac->len,
TEST_MEMORY_COMPARE(expected_mac->x, expected_mac->len,
actual_mac, mac_length);
}
mbedtls_free(actual_mac);
@ -2697,7 +2697,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;
TEST_BUFFERS_EQUAL(ciphertext->x, ciphertext->len,
TEST_MEMORY_COMPARE(ciphertext->x, ciphertext->len,
output, output_length);
/* Multipart encryption */
@ -2715,7 +2715,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;
TEST_BUFFERS_EQUAL(plaintext->x, plaintext->len,
TEST_MEMORY_COMPARE(plaintext->x, plaintext->len,
output, output_length);
/* One-shot encryption */
@ -2723,7 +2723,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));
TEST_BUFFERS_EQUAL(ciphertext->x, ciphertext->len,
TEST_MEMORY_COMPARE(ciphertext->x, ciphertext->len,
output, output_length);
/* One-shot decryption */
@ -2731,7 +2731,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));
TEST_BUFFERS_EQUAL(plaintext->x, plaintext->len,
TEST_MEMORY_COMPARE(plaintext->x, plaintext->len,
output, output_length);
exit:
@ -2850,7 +2850,7 @@ void cipher_encrypt_validation(int alg_arg,
output2_length += function_output_length;
PSA_ASSERT(psa_cipher_abort(&operation));
TEST_BUFFERS_EQUAL(output1 + iv_size, output1_length - iv_size,
TEST_MEMORY_COMPARE(output1 + iv_size, output1_length - iv_size,
output2, output2_length);
exit:
@ -2949,7 +2949,7 @@ void cipher_encrypt_multipart(int alg_arg, int key_type_arg,
if (expected_status == PSA_SUCCESS) {
PSA_ASSERT(psa_cipher_abort(&operation));
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
TEST_MEMORY_COMPARE(expected_output->x, expected_output->len,
output, total_output_length);
}
@ -3049,7 +3049,7 @@ void cipher_decrypt_multipart(int alg_arg, int key_type_arg,
if (expected_status == PSA_SUCCESS) {
PSA_ASSERT(psa_cipher_abort(&operation));
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
TEST_MEMORY_COMPARE(expected_output->x, expected_output->len,
output, total_output_length);
}
@ -3160,7 +3160,7 @@ void cipher_decrypt(int alg_arg,
TEST_LE_U(output_length,
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_buffer_size));
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
TEST_MEMORY_COMPARE(expected_output->x, expected_output->len,
output, output_length);
exit:
mbedtls_free(input);
@ -3217,7 +3217,7 @@ void cipher_verify_output(int alg_arg,
TEST_LE_U(output2_length,
PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(output1_length));
TEST_BUFFERS_EQUAL(input->x, input->len, output2, output2_length);
TEST_MEMORY_COMPARE(input->x, input->len, output2, output2_length);
exit:
mbedtls_free(output1);
@ -3357,7 +3357,7 @@ void cipher_verify_output_multipart(int alg_arg,
PSA_ASSERT(psa_cipher_abort(&operation2));
TEST_BUFFERS_EQUAL(input->x, input->len, output2, output2_length);
TEST_MEMORY_COMPARE(input->x, input->len, output2, output2_length);
exit:
psa_cipher_abort(&operation1);
@ -3452,7 +3452,7 @@ void aead_encrypt_decrypt(int key_type_arg, data_t *key_data,
&output_length2),
expected_result);
TEST_BUFFERS_EQUAL(input_data->x, input_data->len,
TEST_MEMORY_COMPARE(input_data->x, input_data->len,
output_data2, output_length2);
}
@ -3519,7 +3519,7 @@ void aead_encrypt(int key_type_arg, data_t *key_data,
}
PSA_ASSERT(status);
TEST_BUFFERS_EQUAL(expected_result->x, expected_result->len,
TEST_MEMORY_COMPARE(expected_result->x, expected_result->len,
output_data, output_length);
exit:
@ -3592,7 +3592,7 @@ void aead_decrypt(int key_type_arg, data_t *key_data,
TEST_EQUAL(status, expected_result);
if (expected_result == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(expected_data->x, expected_data->len,
TEST_MEMORY_COMPARE(expected_data->x, expected_data->len,
output_data, output_length);
}
@ -3663,7 +3663,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. */
TEST_BUFFERS_EQUAL(output_data->x, output_data->len,
TEST_MEMORY_COMPARE(output_data->x, output_data->len,
signature, signature_length);
#if defined(MBEDTLS_TEST_DEPRECATED)
@ -3673,7 +3673,7 @@ void sign_hash_deterministic(int key_type_arg, data_t *key_data,
input_data->x, input_data->len,
signature, signature_size,
&signature_length));
TEST_BUFFERS_EQUAL(output_data->x, output_data->len,
TEST_MEMORY_COMPARE(output_data->x, output_data->len,
signature, signature_length);
#endif /* MBEDTLS_TEST_DEPRECATED */
@ -3933,7 +3933,7 @@ void sign_message_deterministic(int key_type_arg,
signature, signature_size,
&signature_length));
TEST_BUFFERS_EQUAL(output_data->x, output_data->len,
TEST_MEMORY_COMPARE(output_data->x, output_data->len,
signature, signature_length);
exit:
@ -4271,7 +4271,7 @@ void asymmetric_encrypt_decrypt(int key_type_arg,
label->x, label->len,
output2, output2_size,
&output2_length));
TEST_BUFFERS_EQUAL(input_data->x, input_data->len,
TEST_MEMORY_COMPARE(input_data->x, input_data->len,
output2, output2_length);
exit:
@ -4328,7 +4328,7 @@ void asymmetric_decrypt(int key_type_arg,
output,
output_size,
&output_length));
TEST_BUFFERS_EQUAL(expected_data->x, expected_data->len,
TEST_MEMORY_COMPARE(expected_data->x, expected_data->len,
output, output_length);
/* If the label is empty, the test framework puts a non-null pointer
@ -4344,7 +4344,7 @@ void asymmetric_decrypt(int key_type_arg,
output,
output_size,
&output_length));
TEST_BUFFERS_EQUAL(expected_data->x, expected_data->len,
TEST_MEMORY_COMPARE(expected_data->x, expected_data->len,
output, output_length);
}
@ -4756,7 +4756,7 @@ void derive_output(int alg_arg,
/* Success. Check the read data. */
PSA_ASSERT(status);
if (output_sizes[i] != 0) {
TEST_BUFFERS_EQUAL(output_buffer, output_sizes[i],
TEST_MEMORY_COMPARE(output_buffer, output_sizes[i],
expected_outputs[i], output_sizes[i]);
}
/* Check the operation status. */
@ -4982,7 +4982,7 @@ void derive_key_export(int alg_arg,
TEST_EQUAL(length, bytes2);
/* Compare the outputs from the two runs. */
TEST_BUFFERS_EQUAL(output_buffer, bytes1 + bytes2,
TEST_MEMORY_COMPARE(output_buffer, bytes1 + bytes2,
export_buffer, capacity);
exit:
@ -5133,7 +5133,7 @@ void raw_key_agreement(int alg_arg,
peer_key_data->x, peer_key_data->len,
output, expected_output->len,
&output_length));
TEST_BUFFERS_EQUAL(output, output_length,
TEST_MEMORY_COMPARE(output, output_length,
expected_output->x, expected_output->len);
mbedtls_free(output);
output = NULL;
@ -5145,7 +5145,7 @@ void raw_key_agreement(int alg_arg,
peer_key_data->x, peer_key_data->len,
output, expected_output->len + 1,
&output_length));
TEST_BUFFERS_EQUAL(output, output_length,
TEST_MEMORY_COMPARE(output, output_length,
expected_output->x, expected_output->len);
mbedtls_free(output);
output = NULL;
@ -5268,13 +5268,13 @@ void key_agreement_output(int alg_arg,
PSA_ASSERT(psa_key_derivation_output_bytes(&operation,
actual_output,
expected_output1->len));
TEST_BUFFERS_EQUAL(actual_output, expected_output1->len,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(actual_output, expected_output2->len,
TEST_MEMORY_COMPARE(actual_output, expected_output2->len,
expected_output2->x, expected_output2->len);
}
@ -5443,7 +5443,7 @@ void generate_key_rsa(int bits_arg,
if (is_default_public_exponent) {
TEST_EQUAL(e_read_length, 0);
} else {
TEST_BUFFERS_EQUAL(e_read_buffer, e_read_length, e_arg->x, e_arg->len);
TEST_MEMORY_COMPARE(e_read_buffer, e_read_length, e_arg->x, e_arg->len);
}
/* Do something with the key according to its type and permitted usage. */
@ -5479,7 +5479,7 @@ void generate_key_rsa(int bits_arg,
TEST_EQUAL(p[1], 0);
TEST_EQUAL(p[2], 1);
} else {
TEST_BUFFERS_EQUAL(p, len, e_arg->x, e_arg->len);
TEST_MEMORY_COMPARE(p, len, e_arg->x, e_arg->len);
}
}
@ -5588,7 +5588,7 @@ void persistent_key_load_key_from_storage(data_t *data,
first_export, export_size,
&first_exported_length));
if (generation_method == IMPORT_KEY) {
TEST_BUFFERS_EQUAL(data->x, data->len,
TEST_MEMORY_COMPARE(data->x, data->len,
first_export, first_exported_length);
}
}
@ -5615,7 +5615,7 @@ void persistent_key_load_key_from_storage(data_t *data,
PSA_ASSERT(psa_export_key(key,
second_export, export_size,
&second_exported_length));
TEST_BUFFERS_EQUAL(first_export, first_exported_length,
TEST_MEMORY_COMPARE(first_export, first_exported_length,
second_export, second_exported_length);
}

View File

@ -64,7 +64,7 @@ void sign_hash(int key_type_arg,
&signature_length);
TEST_EQUAL(actual_status, expected_status);
if (expected_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(signature, signature_length,
TEST_MEMORY_COMPARE(signature, signature_length,
expected_output->x, expected_output->len);
}
TEST_EQUAL(mbedtls_test_driver_signature_sign_hooks.hits, 1);
@ -191,7 +191,7 @@ void sign_message(int key_type_arg,
&signature_length);
TEST_EQUAL(actual_status, expected_status);
if (expected_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(signature, signature_length,
TEST_MEMORY_COMPARE(signature, signature_length,
expected_output->x, expected_output->len);
}
/* In the builtin algorithm the driver is called twice. */
@ -313,7 +313,7 @@ void generate_key(int force_status_arg,
psa_export_key(key, actual_output, sizeof(actual_output), &actual_output_length);
if (fake_output->len > 0) {
TEST_BUFFERS_EQUAL(actual_output, actual_output_length,
TEST_MEMORY_COMPARE(actual_output, actual_output_length,
expected_output, expected_output_length);
} else {
size_t zeroes = 0;
@ -445,7 +445,7 @@ void export_key(int force_status_arg,
}
if (actual_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(actual_output, actual_output_length,
TEST_MEMORY_COMPARE(actual_output, actual_output_length,
expected_output_ptr, expected_output_length);
}
exit:
@ -527,7 +527,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);
TEST_BUFFERS_EQUAL(output1 + iv_size, output1_length - iv_size,
TEST_MEMORY_COMPARE(output1 + iv_size, output1_length - iv_size,
output2, output2_length);
exit:
@ -655,7 +655,7 @@ void cipher_encrypt_multipart(int alg_arg,
PSA_ASSERT(psa_cipher_abort(&operation));
TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
TEST_MEMORY_COMPARE(expected_output->x, expected_output->len,
output, total_output_length);
}
@ -784,7 +784,7 @@ void cipher_decrypt_multipart(int alg_arg,
PSA_ASSERT(psa_cipher_abort(&operation));
TEST_EQUAL(mbedtls_test_driver_cipher_hooks.hits, 0);
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
TEST_MEMORY_COMPARE(expected_output->x, expected_output->len,
output, total_output_length);
}
@ -856,7 +856,7 @@ void cipher_decrypt(int alg_arg,
TEST_EQUAL(status, expected_status);
if (expected_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(expected_output->x, expected_output->len,
TEST_MEMORY_COMPARE(expected_output->x, expected_output->len,
output, output_length);
}
@ -1141,7 +1141,7 @@ void aead_encrypt(int key_type_arg, data_t *key_data,
PSA_SUCCESS : forced_status);
if (status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(expected_result->x, expected_result->len,
TEST_MEMORY_COMPARE(expected_result->x, expected_result->len,
output_data, output_length);
}
@ -1204,7 +1204,7 @@ void aead_decrypt(int key_type_arg, data_t *key_data,
PSA_SUCCESS : forced_status);
if (status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(expected_data->x, expected_data->len,
TEST_MEMORY_COMPARE(expected_data->x, expected_data->len,
output_data, output_length);
}
@ -1326,7 +1326,7 @@ void mac_sign(int key_type_arg,
}
if (forced_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(expected_mac->x, expected_mac->len,
TEST_MEMORY_COMPARE(expected_mac->x, expected_mac->len,
actual_mac, mac_length);
}
@ -1477,7 +1477,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);
TEST_BUFFERS_EQUAL(output_buffer, output_size,
TEST_MEMORY_COMPARE(output_buffer, output_size,
expected_output->x, expected_output->len);
PSA_ASSERT(psa_get_key_attributes(key, &attributes));
@ -1528,7 +1528,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);
TEST_BUFFERS_EQUAL(output_buffer, output_size,
TEST_MEMORY_COMPARE(output_buffer, output_size,
expected_output->x, expected_output->len);
PSA_ASSERT(psa_get_key_attributes(key, &attributes));
@ -1573,7 +1573,7 @@ void hash_compute(int alg_arg,
TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
if (expected_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
TEST_MEMORY_COMPARE(output, output_length, hash->x, hash->len);
}
exit:
@ -1619,7 +1619,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);
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
TEST_MEMORY_COMPARE(output, output_length, hash->x, hash->len);
}
exit:
@ -1674,7 +1674,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);
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
TEST_MEMORY_COMPARE(output, output_length, hash->x, hash->len);
}
exit:
@ -1727,7 +1727,7 @@ void hash_multipart_finish(int alg_arg,
TEST_EQUAL(mbedtls_test_driver_hash_hooks.driver_status, forced_status);
if (forced_status == PSA_SUCCESS) {
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
TEST_MEMORY_COMPARE(output, output_length, hash->x, hash->len);
}
exit:
@ -1786,7 +1786,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);
TEST_BUFFERS_EQUAL(output, output_length, hash->x, hash->len);
TEST_MEMORY_COMPARE(output, output_length, hash->x, hash->len);
}
exit:

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));
TEST_BUFFERS_EQUAL(expected_hash->x, expected_hash->len,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(expected_hash->x, expected_hash->len,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(expected_hash->x, expected_hash->len,
TEST_MEMORY_COMPARE(expected_hash->x, expected_hash->len,
actual_hash, actual_hash_length);
} while (len++ != input->len);

View File

@ -66,7 +66,7 @@ void format_storage_data_check(data_t *key_data,
&attributes.core,
file_data);
TEST_BUFFERS_EQUAL(expected_file_data->x, expected_file_data->len,
TEST_MEMORY_COMPARE(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);
TEST_BUFFERS_EQUAL(expected_key_data->x, expected_key_data->len,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(data->x, data->len, exported, exported_length);
TEST_MEMORY_COMPARE(data->x, data->len, exported, exported_length);
/* Destroy the key */
PSA_ASSERT(psa_destroy_key(key_id));

View File

@ -603,7 +603,7 @@ static int check_persistent_data(psa_key_location_t location,
PSA_ASSERT(psa_its_get_info(uid, &info));
TEST_CALLOC(loaded, info.size);
PSA_ASSERT(psa_its_get(uid, 0, info.size, loaded, NULL));
TEST_BUFFERS_EQUAL(expected_data, size, loaded, info.size);
TEST_MEMORY_COMPARE(expected_data, size, loaded, info.size);
ok = 1;
exit:
@ -958,7 +958,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));
TEST_BUFFERS_EQUAL(key_material, sizeof(key_material),
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(key_data->x, key_data->len,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(material1, sizeof(material1),
TEST_MEMORY_COMPARE(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,
TEST_CALLOC(export_buffer, material->len);
PSA_ASSERT(psa_export_key(returned_target_id, export_buffer,
material->len, &length));
TEST_BUFFERS_EQUAL(material->x, material->len,
TEST_MEMORY_COMPARE(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,
TEST_CALLOC(export_buffer, target_material->len);
PSA_ASSERT(psa_export_key(returned_target_id, export_buffer,
target_material->len, &length));
TEST_BUFFERS_EQUAL(target_material->x, target_material->len,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(exported, exported_length,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(exported, exported_length,
TEST_MEMORY_COMPARE(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;
TEST_BUFFERS_EQUAL(exported, exported_length, (uint8_t *) &i, sizeof(i));
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(exported, exported_length,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(exported, exported_length,
TEST_MEMORY_COMPARE(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,
TEST_CALLOC(actual_representation, storage_info.size);
PSA_ASSERT(psa_its_get(uid, 0, storage_info.size,
actual_representation, &length));
TEST_BUFFERS_EQUAL(expected_representation->x, expected_representation->len,
TEST_MEMORY_COMPARE(expected_representation->x, expected_representation->len,
actual_representation, length);
ok = 1;
@ -272,7 +272,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));
TEST_BUFFERS_EQUAL(expected_material->x, expected_material->len,
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(data->x, data->len, buffer, ret_len);
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(data1->x, data1->len, buffer, ret_len);
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(data2->x, data2->len, buffer, ret_len);
TEST_MEMORY_COMPARE(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));
TEST_BUFFERS_EQUAL(retrieved, ret_len,
TEST_MEMORY_COMPARE(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) {
TEST_BUFFERS_EQUAL(data->x + offset, (size_t) length_arg,
TEST_MEMORY_COMPARE(data->x + offset, (size_t) length_arg,
buffer, ret_len);
}
for (i = 0; i < 16; i++) {

View File

@ -1689,7 +1689,7 @@ void ssl_tls1_3_hkdf_expand_label(int hash_alg,
ctx->x, ctx->len,
dst, desired_length) == 0);
TEST_BUFFERS_EQUAL(dst, (size_t) desired_length,
TEST_MEMORY_COMPARE(dst, (size_t) desired_length,
expected->x, (size_t) expected->len);
}
/* END_CASE */
@ -1724,19 +1724,19 @@ void ssl_tls1_3_traffic_key_generation(int hash_alg,
desired_key_len, desired_iv_len,
&keys) == 0);
TEST_BUFFERS_EQUAL(keys.client_write_key,
TEST_MEMORY_COMPARE(keys.client_write_key,
keys.key_len,
expected_client_write_key->x,
(size_t) desired_key_len);
TEST_BUFFERS_EQUAL(keys.server_write_key,
TEST_MEMORY_COMPARE(keys.server_write_key,
keys.key_len,
expected_server_write_key->x,
(size_t) desired_key_len);
TEST_BUFFERS_EQUAL(keys.client_write_iv,
TEST_MEMORY_COMPARE(keys.client_write_iv,
keys.iv_len,
expected_client_write_iv->x,
(size_t) desired_iv_len);
TEST_BUFFERS_EQUAL(keys.server_write_iv,
TEST_MEMORY_COMPARE(keys.server_write_iv,
keys.iv_len,
expected_server_write_iv->x,
(size_t) desired_iv_len);
@ -1778,7 +1778,7 @@ void ssl_tls1_3_derive_secret(int hash_alg,
already_hashed,
dst, desired_length) == 0);
TEST_BUFFERS_EQUAL(dst, desired_length,
TEST_MEMORY_COMPARE(dst, desired_length,
expected->x, desired_length);
}
/* END_CASE */
@ -1797,7 +1797,7 @@ void ssl_tls1_3_key_evolution(int hash_alg,
input->len ? input->x : NULL, input->len,
secret_new) == 0);
TEST_BUFFERS_EQUAL(secret_new, (size_t) expected->len,
TEST_MEMORY_COMPARE(secret_new, (size_t) expected->len,
expected->x, (size_t) expected->len);
}
/* END_CASE */