mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-07 06:42:56 +03:00
tests: add PSA_INIT/PSA_DONE to CCM and GCM test suites
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
@@ -367,6 +367,30 @@ uint64_t mbedtls_test_parse_binary_string(data_t *bin_string);
|
|||||||
#define MD_PSA_DONE() ((void) 0)
|
#define MD_PSA_DONE() ((void) 0)
|
||||||
#endif /* MBEDTLS_MD_SOME_PSA */
|
#endif /* MBEDTLS_MD_SOME_PSA */
|
||||||
|
|
||||||
|
/** \def BLOCK_CIPHER_PSA_INIT
|
||||||
|
*
|
||||||
|
* Call this macro to initialize the PSA subsystem if BLOCK_CIPHER uses a driver,
|
||||||
|
* and do nothing otherwise.
|
||||||
|
*
|
||||||
|
* If the initialization fails, mark the test case as failed and jump to the
|
||||||
|
* \p exit label.
|
||||||
|
*/
|
||||||
|
/** \def BLOCK_CIPHER_PSA_DONE
|
||||||
|
*
|
||||||
|
* Call this macro at the end of a test case if you called #BLOCK_CIPHER_PSA_INIT.
|
||||||
|
*
|
||||||
|
* This is like #PSA_DONE except it does nothing under the same conditions as
|
||||||
|
* #BLOCK_CIPHER_PSA_INIT.
|
||||||
|
*/
|
||||||
|
#if defined(MBEDTLS_BLOCK_CIPHER_SOME_PSA)
|
||||||
|
#define BLOCK_CIPHER_PSA_INIT() PSA_INIT()
|
||||||
|
#define BLOCK_CIPHER_PSA_DONE() PSA_DONE()
|
||||||
|
#else /* MBEDTLS_MD_SOME_PSA */
|
||||||
|
#define BLOCK_CIPHER_PSA_INIT() ((void) 0)
|
||||||
|
#define BLOCK_CIPHER_PSA_DONE() ((void) 0)
|
||||||
|
#endif /* MBEDTLS_MD_SOME_PSA */
|
||||||
|
|
||||||
|
|
||||||
/** \def MD_OR_USE_PSA_INIT
|
/** \def MD_OR_USE_PSA_INIT
|
||||||
*
|
*
|
||||||
* Call this macro to initialize the PSA subsystem if MD uses a driver,
|
* Call this macro to initialize the PSA subsystem if MD uses a driver,
|
||||||
|
@@ -69,7 +69,9 @@ exit:
|
|||||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_AES_C */
|
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_AES_C */
|
||||||
void mbedtls_ccm_self_test()
|
void mbedtls_ccm_self_test()
|
||||||
{
|
{
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
TEST_ASSERT(mbedtls_ccm_self_test(1) == 0);
|
TEST_ASSERT(mbedtls_ccm_self_test(1) == 0);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -105,6 +107,7 @@ void ccm_lengths(int msg_len, int iv_len, int add_len, int tag_len, int res)
|
|||||||
unsigned char tag[18];
|
unsigned char tag[18];
|
||||||
int decrypt_ret;
|
int decrypt_ret;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
|
|
||||||
TEST_CALLOC_OR_SKIP(add, add_len);
|
TEST_CALLOC_OR_SKIP(add, add_len);
|
||||||
@@ -132,6 +135,7 @@ void ccm_lengths(int msg_len, int iv_len, int add_len, int tag_len, int res)
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(add);
|
mbedtls_free(add);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -148,6 +152,7 @@ void ccm_star_lengths(int msg_len, int iv_len, int add_len, int tag_len,
|
|||||||
unsigned char tag[18];
|
unsigned char tag[18];
|
||||||
int decrypt_ret;
|
int decrypt_ret;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
|
|
||||||
memset(key, 0, sizeof(key));
|
memset(key, 0, sizeof(key));
|
||||||
@@ -174,6 +179,7 @@ void ccm_star_lengths(int msg_len, int iv_len, int add_len, int tag_len,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -198,6 +204,7 @@ void mbedtls_ccm_encrypt_and_tag(int cipher_id, data_t *key,
|
|||||||
/* Prepare tag buffer */
|
/* Prepare tag buffer */
|
||||||
TEST_CALLOC(tag_buf, expected_tag_len);
|
TEST_CALLOC(tag_buf, expected_tag_len);
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
/* Test with input == output */
|
/* Test with input == output */
|
||||||
@@ -230,6 +237,7 @@ exit:
|
|||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
mbedtls_free(io_msg_buf);
|
mbedtls_free(io_msg_buf);
|
||||||
mbedtls_free(tag_buf);
|
mbedtls_free(tag_buf);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -241,6 +249,7 @@ void mbedtls_ccm_star_no_tag(int cipher_id, int mode, data_t *key,
|
|||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
size_t olen;
|
size_t olen;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -255,6 +264,7 @@ void mbedtls_ccm_star_no_tag(int cipher_id, int mode, data_t *key,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -277,6 +287,7 @@ void mbedtls_ccm_auth_decrypt(int cipher_id, data_t *key,
|
|||||||
memcpy(io_msg_buf, msg->x, expected_msg_len);
|
memcpy(io_msg_buf, msg->x, expected_msg_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
/* Test with input == output */
|
/* Test with input == output */
|
||||||
@@ -317,6 +328,7 @@ void mbedtls_ccm_auth_decrypt(int cipher_id, data_t *key,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(io_msg_buf);
|
mbedtls_free(io_msg_buf);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -364,6 +376,7 @@ void mbedtls_ccm_star_encrypt_and_tag(int cipher_id,
|
|||||||
iv[source_address->len + frame_counter->len] = sec_level;
|
iv[source_address->len + frame_counter->len] = sec_level;
|
||||||
iv_len = sizeof(iv);
|
iv_len = sizeof(iv);
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id,
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id,
|
||||||
key->x, key->len * 8), 0);
|
key->x, key->len * 8), 0);
|
||||||
@@ -402,6 +415,7 @@ exit:
|
|||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
mbedtls_free(io_msg_buf);
|
mbedtls_free(io_msg_buf);
|
||||||
mbedtls_free(tag_buf);
|
mbedtls_free(tag_buf);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -443,6 +457,7 @@ void mbedtls_ccm_star_auth_decrypt(int cipher_id,
|
|||||||
iv[source_address->len + frame_counter->len] = sec_level;
|
iv[source_address->len + frame_counter->len] = sec_level;
|
||||||
iv_len = sizeof(iv);
|
iv_len = sizeof(iv);
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_ASSERT(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8) == 0);
|
TEST_ASSERT(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8) == 0);
|
||||||
/* Test with input == output */
|
/* Test with input == output */
|
||||||
@@ -479,6 +494,7 @@ void mbedtls_ccm_star_auth_decrypt(int cipher_id,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
mbedtls_free(io_msg_buf);
|
mbedtls_free(io_msg_buf);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -495,6 +511,7 @@ void mbedtls_ccm_skip_ad(int cipher_id, int mode,
|
|||||||
/* Sanity checks on the test data */
|
/* Sanity checks on the test data */
|
||||||
TEST_EQUAL(msg->len, result->len);
|
TEST_EQUAL(msg->len, result->len);
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -517,6 +534,7 @@ void mbedtls_ccm_skip_ad(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -529,6 +547,7 @@ void mbedtls_ccm_skip_update(int cipher_id, int mode,
|
|||||||
mbedtls_ccm_context ctx;
|
mbedtls_ccm_context ctx;
|
||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -545,6 +564,7 @@ void mbedtls_ccm_skip_update(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -556,6 +576,7 @@ void mbedtls_ccm_overflow_ad(int cipher_id, int mode,
|
|||||||
{
|
{
|
||||||
mbedtls_ccm_context ctx;
|
mbedtls_ccm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -566,6 +587,7 @@ void mbedtls_ccm_overflow_ad(int cipher_id, int mode,
|
|||||||
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -577,6 +599,7 @@ void mbedtls_ccm_unexpected_ad(int cipher_id, int mode,
|
|||||||
{
|
{
|
||||||
mbedtls_ccm_context ctx;
|
mbedtls_ccm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -586,6 +609,7 @@ void mbedtls_ccm_unexpected_ad(int cipher_id, int mode,
|
|||||||
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -599,6 +623,7 @@ void mbedtls_ccm_unexpected_text(int cipher_id, int mode,
|
|||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
size_t olen;
|
size_t olen;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -614,6 +639,7 @@ void mbedtls_ccm_unexpected_text(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -625,6 +651,7 @@ void mbedtls_ccm_incomplete_ad(int cipher_id, int mode,
|
|||||||
mbedtls_ccm_context ctx;
|
mbedtls_ccm_context ctx;
|
||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -639,6 +666,7 @@ void mbedtls_ccm_incomplete_ad(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -651,6 +679,7 @@ void mbedtls_ccm_full_ad_and_overflow(int cipher_id, int mode,
|
|||||||
{
|
{
|
||||||
mbedtls_ccm_context ctx;
|
mbedtls_ccm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -663,6 +692,7 @@ void mbedtls_ccm_full_ad_and_overflow(int cipher_id, int mode,
|
|||||||
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, 1));
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, 1));
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -679,6 +709,7 @@ void mbedtls_ccm_incomplete_ad_and_overflow(int cipher_id, int mode,
|
|||||||
add_second_buffer[0] = add->x[add->len - 1];
|
add_second_buffer[0] = add->x[add->len - 1];
|
||||||
add_second_buffer[1] = 0xAB; // some magic value
|
add_second_buffer[1] = 0xAB; // some magic value
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -691,6 +722,7 @@ void mbedtls_ccm_incomplete_ad_and_overflow(int cipher_id, int mode,
|
|||||||
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add_second_buffer, 2));
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add_second_buffer, 2));
|
||||||
exit:
|
exit:
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -704,6 +736,7 @@ void mbedtls_ccm_overflow_update(int cipher_id, int mode,
|
|||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
size_t olen;
|
size_t olen;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -719,6 +752,7 @@ void mbedtls_ccm_overflow_update(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -732,6 +766,7 @@ void mbedtls_ccm_incomplete_update(int cipher_id, int mode,
|
|||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
size_t olen;
|
size_t olen;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -752,6 +787,7 @@ void mbedtls_ccm_incomplete_update(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -766,6 +802,7 @@ void mbedtls_ccm_full_update_and_overflow(int cipher_id, int mode,
|
|||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
size_t olen;
|
size_t olen;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -783,6 +820,7 @@ void mbedtls_ccm_full_update_and_overflow(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -801,6 +839,7 @@ void mbedtls_ccm_incomplete_update_overflow(int cipher_id, int mode,
|
|||||||
msg_second_buffer[0] = msg->x[msg->len - 1];
|
msg_second_buffer[0] = msg->x[msg->len - 1];
|
||||||
msg_second_buffer[1] = 0xAB; // some magic value
|
msg_second_buffer[1] = 0xAB; // some magic value
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -818,6 +857,7 @@ void mbedtls_ccm_incomplete_update_overflow(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -829,6 +869,7 @@ void mbedtls_ccm_instant_finish(int cipher_id, int mode,
|
|||||||
mbedtls_ccm_context ctx;
|
mbedtls_ccm_context ctx;
|
||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_ccm_init(&ctx);
|
mbedtls_ccm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_ccm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -842,5 +883,6 @@ void mbedtls_ccm_instant_finish(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_ccm_free(&ctx);
|
mbedtls_ccm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
@@ -171,6 +171,7 @@ void gcm_bad_parameters(int cipher_id, int direction,
|
|||||||
mbedtls_gcm_context ctx;
|
mbedtls_gcm_context ctx;
|
||||||
size_t tag_len = tag_len_bits / 8;
|
size_t tag_len = tag_len_bits / 8;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
memset(output, 0x00, sizeof(output));
|
memset(output, 0x00, sizeof(output));
|
||||||
@@ -183,6 +184,7 @@ void gcm_bad_parameters(int cipher_id, int direction,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -200,6 +202,7 @@ void gcm_encrypt_and_tag(int cipher_id, data_t *key_str,
|
|||||||
size_t n1;
|
size_t n1;
|
||||||
size_t n1_add;
|
size_t n1_add;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
memset(output, 0x00, 128);
|
memset(output, 0x00, 128);
|
||||||
@@ -230,6 +233,7 @@ void gcm_encrypt_and_tag(int cipher_id, data_t *key_str,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -247,6 +251,7 @@ void gcm_decrypt_and_verify(int cipher_id, data_t *key_str,
|
|||||||
size_t n1;
|
size_t n1;
|
||||||
size_t n1_add;
|
size_t n1_add;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
memset(output, 0x00, 128);
|
memset(output, 0x00, 128);
|
||||||
@@ -287,6 +292,7 @@ void gcm_decrypt_and_verify(int cipher_id, data_t *key_str,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -300,6 +306,7 @@ void gcm_decrypt_and_verify_empty_cipher(int cipher_id,
|
|||||||
{
|
{
|
||||||
mbedtls_gcm_context ctx;
|
mbedtls_gcm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
||||||
@@ -308,6 +315,7 @@ void gcm_decrypt_and_verify_empty_cipher(int cipher_id,
|
|||||||
cipher_update_calls);
|
cipher_update_calls);
|
||||||
|
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -322,6 +330,7 @@ void gcm_decrypt_and_verify_empty_ad(int cipher_id,
|
|||||||
{
|
{
|
||||||
mbedtls_gcm_context ctx;
|
mbedtls_gcm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
||||||
@@ -330,6 +339,7 @@ void gcm_decrypt_and_verify_empty_ad(int cipher_id,
|
|||||||
ad_update_calls);
|
ad_update_calls);
|
||||||
|
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -341,6 +351,7 @@ void gcm_decrypt_and_verify_no_ad_no_cipher(int cipher_id,
|
|||||||
{
|
{
|
||||||
mbedtls_gcm_context ctx;
|
mbedtls_gcm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
||||||
@@ -348,6 +359,7 @@ void gcm_decrypt_and_verify_no_ad_no_cipher(int cipher_id,
|
|||||||
iv_str, tag_str);
|
iv_str, tag_str);
|
||||||
|
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -361,6 +373,7 @@ void gcm_encrypt_and_tag_empty_cipher(int cipher_id,
|
|||||||
{
|
{
|
||||||
mbedtls_gcm_context ctx;
|
mbedtls_gcm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
||||||
@@ -370,6 +383,7 @@ void gcm_encrypt_and_tag_empty_cipher(int cipher_id,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -384,6 +398,7 @@ void gcm_encrypt_and_tag_empty_ad(int cipher_id,
|
|||||||
{
|
{
|
||||||
mbedtls_gcm_context ctx;
|
mbedtls_gcm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
||||||
@@ -393,6 +408,7 @@ void gcm_encrypt_and_tag_empty_ad(int cipher_id,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -404,6 +420,7 @@ void gcm_encrypt_and_verify_no_ad_no_cipher(int cipher_id,
|
|||||||
{
|
{
|
||||||
mbedtls_gcm_context ctx;
|
mbedtls_gcm_context ctx;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
|
|
||||||
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
TEST_ASSERT(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8) == 0);
|
||||||
@@ -411,6 +428,7 @@ void gcm_encrypt_and_verify_no_ad_no_cipher(int cipher_id,
|
|||||||
iv_str, tag_str);
|
iv_str, tag_str);
|
||||||
|
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
@@ -444,6 +462,7 @@ void gcm_update_output_buffer_too_small(int cipher_id, int mode,
|
|||||||
size_t olen = 0;
|
size_t olen = 0;
|
||||||
size_t output_len = input->len - 1;
|
size_t output_len = input->len - 1;
|
||||||
|
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
mbedtls_gcm_init(&ctx);
|
mbedtls_gcm_init(&ctx);
|
||||||
TEST_EQUAL(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8), 0);
|
TEST_EQUAL(mbedtls_gcm_setkey(&ctx, cipher_id, key_str->x, key_str->len * 8), 0);
|
||||||
TEST_EQUAL(0, mbedtls_gcm_starts(&ctx, mode, iv->x, iv->len));
|
TEST_EQUAL(0, mbedtls_gcm_starts(&ctx, mode, iv->x, iv->len));
|
||||||
@@ -455,12 +474,15 @@ void gcm_update_output_buffer_too_small(int cipher_id, int mode,
|
|||||||
exit:
|
exit:
|
||||||
mbedtls_free(output);
|
mbedtls_free(output);
|
||||||
mbedtls_gcm_free(&ctx);
|
mbedtls_gcm_free(&ctx);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_AES_C */
|
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_AES_C */
|
||||||
void gcm_selftest()
|
void gcm_selftest()
|
||||||
{
|
{
|
||||||
|
BLOCK_CIPHER_PSA_INIT();
|
||||||
TEST_ASSERT(mbedtls_gcm_self_test(1) == 0);
|
TEST_ASSERT(mbedtls_gcm_self_test(1) == 0);
|
||||||
|
BLOCK_CIPHER_PSA_DONE();
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
Reference in New Issue
Block a user