2014-05-02 15:17:29 +02:00
|
|
|
/* BEGIN_HEADER */
|
2015-03-09 18:05:11 +01:00
|
|
|
#include "mbedtls/ccm.h"
|
2021-07-12 14:53:45 +02:00
|
|
|
|
|
|
|
/* Use the multipart interface to process the encrypted data in two parts
|
|
|
|
* and check that the output matches the expected output.
|
|
|
|
* The context must have been set up with the key. */
|
2023-01-11 14:50:10 +01:00
|
|
|
static int check_multipart(mbedtls_ccm_context *ctx,
|
|
|
|
int mode,
|
|
|
|
const data_t *iv,
|
|
|
|
const data_t *add,
|
|
|
|
const data_t *input,
|
|
|
|
const data_t *expected_output,
|
|
|
|
const data_t *tag,
|
|
|
|
size_t n1,
|
|
|
|
size_t n1_add)
|
2021-07-12 14:53:45 +02:00
|
|
|
{
|
|
|
|
int ok = 0;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
size_t n2 = input->len - n1;
|
|
|
|
size_t n2_add = add->len - n1_add;
|
|
|
|
size_t olen;
|
|
|
|
|
|
|
|
/* Sanity checks on the test data */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(n1 <= input->len);
|
|
|
|
TEST_ASSERT(n1_add <= add->len);
|
|
|
|
TEST_EQUAL(input->len, expected_output->len);
|
|
|
|
TEST_EQUAL(0, mbedtls_ccm_starts(ctx, mode, iv->x, iv->len));
|
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(ctx, add->len, input->len, tag->len));
|
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(ctx, add->x, n1_add));
|
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(ctx, add->x + n1_add, n2_add));
|
2021-07-12 14:53:45 +02:00
|
|
|
|
|
|
|
/* Allocate a tight buffer for each update call. This way, if the function
|
|
|
|
* tries to write beyond the advertised required buffer size, this will
|
|
|
|
* count as an overflow for memory sanitizers and static checkers. */
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, n1);
|
2021-07-12 14:53:45 +02:00
|
|
|
olen = 0xdeadbeef;
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update(ctx, input->x, n1, output, n1, &olen));
|
|
|
|
TEST_EQUAL(n1, olen);
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, olen, expected_output->x, n1);
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
2021-07-12 14:53:45 +02:00
|
|
|
output = NULL;
|
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, n2);
|
2021-07-12 14:53:45 +02:00
|
|
|
olen = 0xdeadbeef;
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update(ctx, input->x + n1, n2, output, n2, &olen));
|
|
|
|
TEST_EQUAL(n2, olen);
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, olen, expected_output->x + n1, n2);
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
2021-07-12 14:53:45 +02:00
|
|
|
output = NULL;
|
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, tag->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_finish(ctx, output, tag->len));
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, tag->len, tag->x, tag->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
2021-07-12 14:53:45 +02:00
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
ok = 1;
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
return ok;
|
2021-07-12 14:53:45 +02:00
|
|
|
}
|
2014-05-02 15:17:29 +02:00
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
2015-04-08 12:49:31 +02:00
|
|
|
* depends_on:MBEDTLS_CCM_C
|
2014-05-02 15:17:29 +02:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
2023-12-20 09:53:39 +01:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST:MBEDTLS_CCM_GCM_CAN_AES */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_self_test()
|
2014-05-02 15:17:29 +02:00
|
|
|
{
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ccm_self_test(1) == 0);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2014-05-02 15:17:29 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2014-05-06 12:12:45 +02:00
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_setkey(int cipher_id, int key_size, int result)
|
2014-05-06 12:12:45 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ccm_context ctx;
|
2014-05-06 12:12:45 +02:00
|
|
|
unsigned char key[32];
|
|
|
|
int ret;
|
|
|
|
|
2023-12-20 09:54:39 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
2015-04-28 18:02:54 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(key, 0x2A, sizeof(key));
|
|
|
|
TEST_ASSERT((unsigned) key_size <= 8 * sizeof(key));
|
2014-05-06 12:12:45 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
ret = mbedtls_ccm_setkey(&ctx, cipher_id, key, key_size);
|
|
|
|
TEST_ASSERT(ret == result);
|
2014-05-06 12:12:45 +02:00
|
|
|
|
2014-07-10 15:26:12 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-20 09:54:39 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2014-05-06 12:12:45 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2014-05-06 12:13:09 +02:00
|
|
|
|
2023-12-20 09:53:39 +01:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CCM_GCM_CAN_AES */
|
2023-01-11 14:50:10 +01:00
|
|
|
void ccm_lengths(int msg_len, int iv_len, int add_len, int tag_len, int res)
|
2014-05-06 18:07:24 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ccm_context ctx;
|
2014-05-06 18:07:24 +02:00
|
|
|
unsigned char key[16];
|
|
|
|
unsigned char msg[10];
|
|
|
|
unsigned char iv[14];
|
2020-10-15 15:00:40 +02:00
|
|
|
unsigned char *add = NULL;
|
2014-05-06 18:07:24 +02:00
|
|
|
unsigned char out[10];
|
|
|
|
unsigned char tag[18];
|
|
|
|
int decrypt_ret;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
2015-04-28 18:02:54 +02:00
|
|
|
|
2023-07-20 17:55:14 +02:00
|
|
|
TEST_CALLOC_OR_SKIP(add, add_len);
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(key, 0, sizeof(key));
|
|
|
|
memset(msg, 0, sizeof(msg));
|
|
|
|
memset(iv, 0, sizeof(iv));
|
|
|
|
memset(out, 0, sizeof(out));
|
|
|
|
memset(tag, 0, sizeof(tag));
|
2014-05-06 18:07:24 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ccm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES,
|
|
|
|
key, 8 * sizeof(key)) == 0);
|
2014-05-06 18:07:24 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ccm_encrypt_and_tag(&ctx, msg_len, iv, iv_len, add, add_len,
|
|
|
|
msg, out, tag, tag_len) == res);
|
2014-05-06 18:07:24 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
decrypt_ret = mbedtls_ccm_auth_decrypt(&ctx, msg_len, iv, iv_len, add, add_len,
|
|
|
|
msg, out, tag, tag_len);
|
2014-05-06 18:07:24 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (res == 0) {
|
|
|
|
TEST_ASSERT(decrypt_ret == MBEDTLS_ERR_CCM_AUTH_FAILED);
|
|
|
|
} else {
|
|
|
|
TEST_ASSERT(decrypt_ret == res);
|
|
|
|
}
|
2014-05-06 18:07:24 +02:00
|
|
|
|
2014-07-10 15:26:12 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(add);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2014-05-06 18:07:24 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2023-12-20 09:54:39 +01:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CCM_GCM_CAN_AES */
|
2023-01-11 14:50:10 +01:00
|
|
|
void ccm_star_lengths(int msg_len, int iv_len, int add_len, int tag_len,
|
|
|
|
int res)
|
2018-05-14 15:32:41 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
unsigned char key[16];
|
|
|
|
unsigned char msg[10];
|
|
|
|
unsigned char iv[14];
|
|
|
|
unsigned char add[10];
|
|
|
|
unsigned char out[10];
|
|
|
|
unsigned char tag[18];
|
|
|
|
int decrypt_ret;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
2018-05-14 15:32:41 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(key, 0, sizeof(key));
|
|
|
|
memset(msg, 0, sizeof(msg));
|
|
|
|
memset(iv, 0, sizeof(iv));
|
|
|
|
memset(add, 0, sizeof(add));
|
|
|
|
memset(out, 0, sizeof(out));
|
|
|
|
memset(tag, 0, sizeof(tag));
|
2018-05-14 15:32:41 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ccm_setkey(&ctx, MBEDTLS_CIPHER_ID_AES,
|
|
|
|
key, 8 * sizeof(key)) == 0);
|
2018-05-14 15:32:41 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_ccm_star_encrypt_and_tag(&ctx, msg_len, iv, iv_len,
|
|
|
|
add, add_len, msg, out, tag, tag_len) == res);
|
2018-05-14 15:32:41 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
decrypt_ret = mbedtls_ccm_star_auth_decrypt(&ctx, msg_len, iv, iv_len, add,
|
|
|
|
add_len, msg, out, tag, tag_len);
|
2018-05-14 15:32:41 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (res == 0 && tag_len != 0) {
|
|
|
|
TEST_ASSERT(decrypt_ret == MBEDTLS_ERR_CCM_AUTH_FAILED);
|
|
|
|
} else {
|
|
|
|
TEST_ASSERT(decrypt_ret == res);
|
|
|
|
}
|
2018-05-14 15:32:41 +02:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2018-05-14 15:32:41 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2014-05-06 12:13:09 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_encrypt_and_tag(int cipher_id, data_t *key,
|
|
|
|
data_t *msg, data_t *iv,
|
|
|
|
data_t *add, data_t *result)
|
2014-05-06 12:13:09 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ccm_context ctx;
|
2021-07-12 14:53:45 +02:00
|
|
|
size_t n1, n1_add;
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *io_msg_buf = NULL;
|
|
|
|
uint8_t *tag_buf = NULL;
|
2021-07-13 15:33:19 +02:00
|
|
|
const size_t expected_tag_len = result->len - msg->len;
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint8_t *expected_tag = result->x + msg->len;
|
2015-04-28 18:02:54 +02:00
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Prepare input/output message buffer */
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(io_msg_buf, msg->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
if (msg->len != 0) {
|
|
|
|
memcpy(io_msg_buf, msg->x, msg->len);
|
|
|
|
}
|
2017-05-30 15:23:15 +02:00
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Prepare tag buffer */
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(tag_buf, expected_tag_len);
|
2014-05-06 12:13:09 +02:00
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
2014-05-07 14:43:46 +02:00
|
|
|
/* Test with input == output */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(mbedtls_ccm_encrypt_and_tag(&ctx, msg->len, iv->x, iv->len, add->x, add->len,
|
|
|
|
io_msg_buf, io_msg_buf, tag_buf, expected_tag_len), 0);
|
2014-05-06 12:13:09 +02:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(io_msg_buf, msg->len, result->x, msg->len);
|
|
|
|
TEST_MEMORY_COMPARE(tag_buf, expected_tag_len, expected_tag, expected_tag_len);
|
2014-05-06 12:13:09 +02:00
|
|
|
|
2021-07-30 14:36:22 +02:00
|
|
|
/* Prepare data_t structures for multipart testing */
|
2021-07-12 14:53:45 +02:00
|
|
|
const data_t encrypted_expected = { .x = result->x,
|
|
|
|
.len = msg->len };
|
2023-01-11 14:50:10 +01:00
|
|
|
const data_t tag_expected = { .x = (uint8_t *) expected_tag, /* cast to conform with data_t x type */
|
2021-07-13 15:33:19 +02:00
|
|
|
.len = expected_tag_len };
|
2021-07-12 14:53:45 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (n1 = 0; n1 <= msg->len; n1 += 1) {
|
|
|
|
for (n1_add = 0; n1_add <= add->len; n1_add += 1) {
|
|
|
|
mbedtls_test_set_step(n1 * 10000 + n1_add);
|
|
|
|
if (!check_multipart(&ctx, MBEDTLS_CCM_ENCRYPT,
|
|
|
|
iv, add, msg,
|
|
|
|
&encrypted_expected,
|
|
|
|
&tag_expected,
|
|
|
|
n1, n1_add)) {
|
2021-07-12 14:53:45 +02:00
|
|
|
goto exit;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-07-12 14:53:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-10 15:26:12 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
|
|
|
mbedtls_free(io_msg_buf);
|
|
|
|
mbedtls_free(tag_buf);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2014-05-06 12:13:09 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2014-05-06 18:06:52 +02:00
|
|
|
|
2021-10-21 10:04:57 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_star_no_tag(int cipher_id, int mode, data_t *key,
|
|
|
|
data_t *msg, data_t *iv, data_t *result)
|
2021-10-21 10:04:57 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
size_t olen;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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_set_lengths(&ctx, 0, msg->len, 0));
|
2021-10-21 10:04:57 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, msg->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
|
|
|
|
TEST_EQUAL(result->len, olen);
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, olen, result->x, result->len);
|
2021-10-21 10:04:57 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, NULL, 0));
|
2021-10-21 10:04:57 +02:00
|
|
|
exit:
|
|
|
|
mbedtls_free(output);
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-10-21 10:04:57 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2014-05-06 18:06:52 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_auth_decrypt(int cipher_id, data_t *key,
|
|
|
|
data_t *msg, data_t *iv,
|
|
|
|
data_t *add, int expected_tag_len, int result,
|
|
|
|
data_t *expected_msg)
|
2014-05-06 18:06:52 +02:00
|
|
|
{
|
2015-04-08 12:49:31 +02:00
|
|
|
mbedtls_ccm_context ctx;
|
2021-07-12 14:53:45 +02:00
|
|
|
size_t n1, n1_add;
|
2014-05-06 18:06:52 +02:00
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
const size_t expected_msg_len = msg->len - expected_tag_len;
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint8_t *expected_tag = msg->x + expected_msg_len;
|
2021-07-12 14:53:45 +02:00
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Prepare input/output message buffer */
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *io_msg_buf = NULL;
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(io_msg_buf, expected_msg_len);
|
2023-01-11 14:50:10 +01:00
|
|
|
if (expected_msg_len) {
|
|
|
|
memcpy(io_msg_buf, msg->x, expected_msg_len);
|
|
|
|
}
|
2014-05-06 18:06:52 +02:00
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8), 0);
|
2014-05-07 14:43:46 +02:00
|
|
|
/* Test with input == output */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(mbedtls_ccm_auth_decrypt(&ctx, expected_msg_len, iv->x, iv->len, add->x, add->len,
|
|
|
|
io_msg_buf, io_msg_buf, expected_tag, expected_tag_len),
|
|
|
|
result);
|
2014-05-06 18:06:52 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (result == 0) {
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(io_msg_buf, expected_msg_len, expected_msg->x, expected_msg_len);
|
2021-07-12 14:53:45 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
/* Prepare data_t structures for multipart testing */
|
2021-07-13 15:33:19 +02:00
|
|
|
const data_t encrypted = { .x = msg->x,
|
|
|
|
.len = expected_msg_len };
|
2021-07-12 14:53:45 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
const data_t tag_expected = { .x = (uint8_t *) expected_tag,
|
2021-07-13 15:33:19 +02:00
|
|
|
.len = expected_tag_len };
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (n1 = 0; n1 <= expected_msg_len; n1 += 1) {
|
|
|
|
for (n1_add = 0; n1_add <= add->len; n1_add += 1) {
|
|
|
|
mbedtls_test_set_step(n1 * 10000 + n1_add);
|
|
|
|
if (!check_multipart(&ctx, MBEDTLS_CCM_DECRYPT,
|
|
|
|
iv, add, &encrypted,
|
|
|
|
expected_msg,
|
|
|
|
&tag_expected,
|
|
|
|
n1, n1_add)) {
|
2021-07-12 14:53:45 +02:00
|
|
|
goto exit;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
}
|
2021-07-12 14:53:45 +02:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
2014-05-06 18:06:52 +02:00
|
|
|
size_t i;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (i = 0; i < expected_msg_len; i++) {
|
|
|
|
TEST_EQUAL(io_msg_buf[i], 0);
|
|
|
|
}
|
2014-05-06 18:06:52 +02:00
|
|
|
}
|
|
|
|
|
2014-07-10 15:26:12 +02:00
|
|
|
exit:
|
2021-07-13 15:33:19 +02:00
|
|
|
mbedtls_free(io_msg_buf);
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2014-05-06 18:06:52 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2018-05-29 15:12:26 +02:00
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_star_encrypt_and_tag(int cipher_id,
|
|
|
|
data_t *key, data_t *msg,
|
|
|
|
data_t *source_address, data_t *frame_counter,
|
|
|
|
int sec_level, data_t *add,
|
|
|
|
data_t *expected_result, int output_ret)
|
2018-05-29 15:12:26 +02:00
|
|
|
{
|
|
|
|
unsigned char iv[13];
|
|
|
|
mbedtls_ccm_context ctx;
|
2021-07-13 15:33:19 +02:00
|
|
|
size_t iv_len, expected_tag_len;
|
2021-07-13 12:26:17 +02:00
|
|
|
size_t n1, n1_add;
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *io_msg_buf = NULL;
|
|
|
|
uint8_t *tag_buf = NULL;
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint8_t *expected_tag = expected_result->x + msg->len;
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Calculate tag length */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (sec_level % 4 == 0) {
|
2021-07-13 15:33:19 +02:00
|
|
|
expected_tag_len = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
|
|
|
expected_tag_len = 1 << (sec_level % 4 + 1);
|
|
|
|
}
|
2021-07-13 15:33:19 +02:00
|
|
|
|
|
|
|
/* Prepare input/output message buffer */
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(io_msg_buf, msg->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
if (msg->len) {
|
|
|
|
memcpy(io_msg_buf, msg->x, msg->len);
|
|
|
|
}
|
2021-07-13 15:33:19 +02:00
|
|
|
|
|
|
|
/* Prepare tag buffer */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (expected_tag_len == 0) {
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(tag_buf, 16);
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(tag_buf, expected_tag_len);
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Calculate iv */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(source_address->len == 8);
|
|
|
|
TEST_ASSERT(frame_counter->len == 4);
|
|
|
|
memcpy(iv, source_address->x, source_address->len);
|
|
|
|
memcpy(iv + source_address->len, frame_counter->x, frame_counter->len);
|
2020-06-25 09:03:34 +02:00
|
|
|
iv[source_address->len + frame_counter->len] = sec_level;
|
2023-01-11 14:50:10 +01:00
|
|
|
iv_len = sizeof(iv);
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
TEST_EQUAL(mbedtls_ccm_setkey(&ctx, cipher_id,
|
|
|
|
key->x, key->len * 8), 0);
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Test with input == output */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(mbedtls_ccm_star_encrypt_and_tag(&ctx, msg->len, iv, iv_len,
|
|
|
|
add->x, add->len, io_msg_buf,
|
|
|
|
io_msg_buf, tag_buf, expected_tag_len), output_ret);
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(io_msg_buf, msg->len, expected_result->x, msg->len);
|
|
|
|
TEST_MEMORY_COMPARE(tag_buf, expected_tag_len, expected_tag, expected_tag_len);
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (output_ret == 0) {
|
2021-07-13 12:26:17 +02:00
|
|
|
const data_t iv_data = { .x = iv,
|
|
|
|
.len = iv_len };
|
|
|
|
|
|
|
|
const data_t encrypted_expected = { .x = expected_result->x,
|
|
|
|
.len = msg->len };
|
2023-01-11 14:50:10 +01:00
|
|
|
const data_t tag_expected = { .x = (uint8_t *) expected_tag,
|
2021-07-13 15:33:19 +02:00
|
|
|
.len = expected_tag_len };
|
2021-07-13 12:26:17 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (n1 = 0; n1 <= msg->len; n1 += 1) {
|
|
|
|
for (n1_add = 0; n1_add <= add->len; n1_add += 1) {
|
|
|
|
mbedtls_test_set_step(n1 * 10000 + n1_add);
|
|
|
|
if (!check_multipart(&ctx, MBEDTLS_CCM_STAR_ENCRYPT,
|
|
|
|
&iv_data, add, msg,
|
|
|
|
&encrypted_expected,
|
|
|
|
&tag_expected,
|
|
|
|
n1, n1_add)) {
|
2021-07-13 12:26:17 +02:00
|
|
|
goto exit;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2021-07-13 12:26:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-29 15:12:26 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
|
|
|
mbedtls_free(io_msg_buf);
|
|
|
|
mbedtls_free(tag_buf);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2018-05-29 15:12:26 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_star_auth_decrypt(int cipher_id,
|
|
|
|
data_t *key, data_t *msg,
|
|
|
|
data_t *source_address, data_t *frame_counter,
|
|
|
|
int sec_level, data_t *add,
|
|
|
|
data_t *expected_result, int output_ret)
|
2018-05-29 15:12:26 +02:00
|
|
|
{
|
|
|
|
unsigned char iv[13];
|
|
|
|
mbedtls_ccm_context ctx;
|
2021-07-13 15:33:19 +02:00
|
|
|
size_t iv_len, expected_tag_len;
|
2021-07-13 12:26:17 +02:00
|
|
|
size_t n1, n1_add;
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Calculate tag length */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (sec_level % 4 == 0) {
|
2021-07-13 15:33:19 +02:00
|
|
|
expected_tag_len = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
|
|
|
expected_tag_len = 1 << (sec_level % 4 + 1);
|
|
|
|
}
|
2021-07-13 15:33:19 +02:00
|
|
|
|
|
|
|
const size_t expected_msg_len = msg->len - expected_tag_len;
|
2023-01-11 14:50:10 +01:00
|
|
|
const uint8_t *expected_tag = msg->x + expected_msg_len;
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Prepare input/output message buffer */
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *io_msg_buf = NULL;
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(io_msg_buf, expected_msg_len);
|
2023-01-11 14:50:10 +01:00
|
|
|
if (expected_msg_len) {
|
|
|
|
memcpy(io_msg_buf, msg->x, expected_msg_len);
|
|
|
|
}
|
2021-07-13 15:33:19 +02:00
|
|
|
|
|
|
|
/* Calculate iv */
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(iv, 0x00, sizeof(iv));
|
|
|
|
TEST_ASSERT(source_address->len == 8);
|
|
|
|
TEST_ASSERT(frame_counter->len == 4);
|
|
|
|
memcpy(iv, source_address->x, source_address->len);
|
|
|
|
memcpy(iv + source_address->len, frame_counter->x, frame_counter->len);
|
2020-06-25 09:03:34 +02:00
|
|
|
iv[source_address->len + frame_counter->len] = sec_level;
|
2023-01-11 14:50:10 +01:00
|
|
|
iv_len = sizeof(iv);
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
TEST_ASSERT(mbedtls_ccm_setkey(&ctx, cipher_id, key->x, key->len * 8) == 0);
|
2021-07-13 15:33:19 +02:00
|
|
|
/* Test with input == output */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(mbedtls_ccm_star_auth_decrypt(&ctx, expected_msg_len, iv, iv_len,
|
|
|
|
add->x, add->len, io_msg_buf, io_msg_buf,
|
|
|
|
expected_tag, expected_tag_len), output_ret);
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(io_msg_buf, expected_msg_len, expected_result->x, expected_msg_len);
|
2018-05-29 15:12:26 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (output_ret == 0) {
|
2021-07-13 12:26:17 +02:00
|
|
|
const data_t iv_data = { .x = iv,
|
|
|
|
.len = iv_len };
|
|
|
|
|
2021-07-13 15:33:19 +02:00
|
|
|
const data_t encrypted = { .x = msg->x,
|
2023-01-11 14:50:10 +01:00
|
|
|
.len = expected_msg_len };
|
2021-07-13 12:26:17 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
const data_t tag_expected = { .x = (uint8_t *) expected_tag,
|
2021-07-13 15:33:19 +02:00
|
|
|
.len = expected_tag_len };
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (n1 = 0; n1 <= expected_msg_len; n1 += 1) {
|
|
|
|
for (n1_add = 0; n1_add <= add->len; n1_add += 1) {
|
|
|
|
mbedtls_test_set_step(n1 * 10000 + n1_add);
|
|
|
|
if (!check_multipart(&ctx, MBEDTLS_CCM_STAR_DECRYPT,
|
|
|
|
&iv_data, add, &encrypted,
|
|
|
|
expected_result,
|
|
|
|
&tag_expected,
|
|
|
|
n1, n1_add)) {
|
2021-07-13 12:26:17 +02:00
|
|
|
goto exit;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
|
|
|
}
|
2021-07-13 12:26:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-29 15:12:26 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
|
|
|
mbedtls_free(io_msg_buf);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2018-05-29 15:12:26 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2021-07-29 14:08:18 +02:00
|
|
|
|
2021-08-10 13:45:19 +02:00
|
|
|
/* Skip auth data, provide full text */
|
2021-07-29 14:08:18 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_skip_ad(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *msg, data_t *iv,
|
|
|
|
data_t *result, data_t *tag)
|
2021-07-29 14:08:18 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
size_t olen;
|
|
|
|
|
|
|
|
/* Sanity checks on the test data */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(msg->len, result->len);
|
2021-07-29 14:08:18 +02:00
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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_set_lengths(&ctx, 0, msg->len, tag->len));
|
2021-07-29 14:08:18 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, result->len);
|
2021-07-29 14:08:18 +02:00
|
|
|
olen = 0xdeadbeef;
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, result->len, &olen));
|
|
|
|
TEST_EQUAL(result->len, olen);
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, olen, result->x, result->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
2021-07-29 14:08:18 +02:00
|
|
|
output = NULL;
|
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, tag->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, output, tag->len));
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, tag->len, tag->x, tag->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
2021-07-29 14:08:18 +02:00
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-07-29 14:08:18 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-08-10 13:45:19 +02:00
|
|
|
/* Provide auth data, skip full text */
|
2021-07-29 14:08:18 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_skip_update(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *iv, data_t *add,
|
|
|
|
data_t *tag)
|
2021-07-29 14:08:18 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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_set_lengths(&ctx, add->len, 0, tag->len));
|
2021-07-29 14:08:18 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-07-29 14:08:18 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, tag->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_finish(&ctx, output, tag->len));
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, tag->len, tag->x, tag->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
2021-07-29 14:08:18 +02:00
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-07-29 14:08:18 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-08-10 13:45:19 +02:00
|
|
|
/* Provide too much auth data */
|
2021-07-29 14:08:18 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_overflow_ad(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *iv,
|
|
|
|
data_t *add)
|
2021-07-29 14:08:18 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-07-29 14:08:18 +02:00
|
|
|
// use hardcoded values for msg length and tag length. They are not a part of this test
|
2021-09-02 12:38:51 +02:00
|
|
|
// subtract 1 from configured auth data length to provoke an overflow
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len - 1, 16, 16));
|
2021-07-29 14:08:18 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-07-29 14:08:18 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-07-29 14:08:18 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-09-03 14:07:21 +02:00
|
|
|
/* Provide unexpected auth data */
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_unexpected_ad(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *iv,
|
|
|
|
data_t *add)
|
2021-09-03 14:07:21 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-09-03 14:07:21 +02:00
|
|
|
// use hardcoded values for msg length and tag length. They are not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 0, 16, 16));
|
2021-09-03 14:07:21 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-09-03 14:07:21 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-09-03 14:07:21 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* Provide unexpected plaintext/ciphertext data */
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_unexpected_text(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *msg, data_t *iv,
|
|
|
|
data_t *add)
|
2021-09-03 14:07:21 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
size_t olen;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-09-03 14:07:21 +02:00
|
|
|
// use hardcoded value for tag length. It is not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 0, 16));
|
2021-09-03 14:07:21 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-09-03 14:07:21 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, msg->len);
|
2021-09-03 14:07:21 +02:00
|
|
|
olen = 0xdeadbeef;
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT,
|
|
|
|
mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
|
2021-09-03 14:07:21 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-09-03 14:07:21 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-08-10 13:45:19 +02:00
|
|
|
/* Provide incomplete auth data and finish */
|
2021-08-10 13:36:43 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_incomplete_ad(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *iv, data_t *add)
|
2021-08-10 13:36:43 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-08-10 13:36:43 +02:00
|
|
|
// use hardcoded values for msg length and tag length. They are not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 0, 16));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len - 1));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, 16);
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-08-10 13:36:43 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-08-10 13:45:19 +02:00
|
|
|
/* Provide complete auth data on first update_ad.
|
|
|
|
* Provide unexpected auth data on second update_ad */
|
2021-08-10 13:36:43 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_full_ad_and_overflow(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *iv,
|
|
|
|
data_t *add)
|
2021-08-10 13:36:43 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-08-10 13:36:43 +02:00
|
|
|
// use hardcoded values for msg length and tag length. They are not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 16, 16));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
|
|
|
// pass full auth data
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-08-10 13:36:43 +02:00
|
|
|
// pass 1 extra byte
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add->x, 1));
|
2021-08-10 13:36:43 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-08-10 13:36:43 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-09-02 13:25:19 +02:00
|
|
|
/* Provide incomplete auth data on first update_ad.
|
|
|
|
* Provide too much auth data on second update_ad */
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_incomplete_ad_and_overflow(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *iv,
|
|
|
|
data_t *add)
|
2021-09-02 13:25:19 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
2021-09-17 09:38:07 +02:00
|
|
|
uint8_t add_second_buffer[2];
|
2021-09-02 13:25:19 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
add_second_buffer[0] = add->x[add->len - 1];
|
2021-09-17 09:38:07 +02:00
|
|
|
add_second_buffer[1] = 0xAB; // some magic value
|
2021-09-02 13:25:19 +02:00
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-09-02 13:25:19 +02:00
|
|
|
// use hardcoded values for msg length and tag length. They are not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, 16, 16));
|
2021-09-02 13:25:19 +02:00
|
|
|
|
|
|
|
// pass incomplete auth data
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len - 1));
|
2021-09-02 13:25:19 +02:00
|
|
|
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad(&ctx, add_second_buffer, 2));
|
2021-09-02 13:25:19 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-09-02 13:25:19 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-08-10 13:45:19 +02:00
|
|
|
/* Provide too much plaintext/ciphertext */
|
2021-07-29 14:08:18 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_overflow_update(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *msg, data_t *iv,
|
|
|
|
data_t *add)
|
2021-07-29 14:08:18 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
size_t olen;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-07-29 14:08:18 +02:00
|
|
|
// use hardcoded value for tag length. It is a not a part of this test
|
2021-09-02 12:38:51 +02:00
|
|
|
// subtract 1 from configured msg length to provoke an overflow
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, msg->len - 1, 16));
|
2021-07-29 14:08:18 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-07-29 14:08:18 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, msg->len);
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, \
|
|
|
|
mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
|
2021-07-29 14:08:18 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-07-29 14:08:18 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2021-08-10 13:36:43 +02:00
|
|
|
|
2021-08-10 13:45:19 +02:00
|
|
|
/* Provide incomplete plaintext/ciphertext and finish */
|
2021-08-10 13:36:43 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_incomplete_update(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *msg, data_t *iv,
|
|
|
|
data_t *add)
|
2021-08-10 13:36:43 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
size_t olen;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-08-10 13:36:43 +02:00
|
|
|
// use hardcoded value for tag length. It is not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, msg->len, 16));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, msg->len);
|
2021-08-10 13:36:43 +02:00
|
|
|
olen = 0xdeadbeef;
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len - 1, output, msg->len, &olen));
|
|
|
|
mbedtls_free(output);
|
2021-08-10 13:36:43 +02:00
|
|
|
output = NULL;
|
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, 16);
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-08-10 13:36:43 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-08-10 13:45:19 +02:00
|
|
|
/* Provide full plaintext/ciphertext of first update
|
|
|
|
* Provide unexpected plaintext/ciphertext on second update */
|
2021-08-10 13:36:43 +02:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_full_update_and_overflow(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *msg, data_t *iv,
|
|
|
|
data_t *add)
|
2021-08-10 13:36:43 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
size_t olen;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-08-10 13:36:43 +02:00
|
|
|
// use hardcoded value for tag length. It is a not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, msg->len, 16));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-08-10 13:36:43 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, msg->len);
|
2021-08-10 13:36:43 +02:00
|
|
|
// pass full text
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len, output, msg->len, &olen));
|
2021-08-10 13:36:43 +02:00
|
|
|
// pass 1 extra byte
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, \
|
|
|
|
mbedtls_ccm_update(&ctx, msg->x, 1, output, 1, &olen));
|
2021-08-10 13:36:43 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-08-10 13:36:43 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
2021-08-10 13:55:47 +02:00
|
|
|
|
2021-09-02 13:25:19 +02:00
|
|
|
/* Provide incomplete plaintext/ciphertext of first update
|
|
|
|
* Provide too much plaintext/ciphertext on second update */
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_incomplete_update_overflow(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *msg, data_t *iv,
|
|
|
|
data_t *add)
|
2021-09-02 13:25:19 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
size_t olen;
|
2021-09-17 09:38:07 +02:00
|
|
|
uint8_t msg_second_buffer[2];
|
2021-09-02 13:25:19 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
msg_second_buffer[0] = msg->x[msg->len - 1];
|
2021-09-17 09:38:07 +02:00
|
|
|
msg_second_buffer[1] = 0xAB; // some magic value
|
2021-09-02 13:25:19 +02:00
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-09-02 13:25:19 +02:00
|
|
|
// use hardcoded value for tag length. It is a not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, add->len, msg->len, 16));
|
2021-09-02 13:25:19 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update_ad(&ctx, add->x, add->len));
|
2021-09-02 13:25:19 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, msg->len + 1);
|
2021-09-02 13:25:19 +02:00
|
|
|
// pass incomplete text
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_update(&ctx, msg->x, msg->len - 1, output, msg->len + 1, &olen));
|
2021-09-02 13:25:19 +02:00
|
|
|
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, \
|
|
|
|
mbedtls_ccm_update(&ctx, msg_second_buffer, 2, output + msg->len - 1, 2, &olen));
|
2021-09-02 13:25:19 +02:00
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-09-02 13:25:19 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2021-08-10 13:55:47 +02:00
|
|
|
/* Finish without passing any auth data or plaintext/ciphertext input */
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_ccm_instant_finish(int cipher_id, int mode,
|
|
|
|
data_t *key, data_t *iv)
|
2021-08-10 13:55:47 +02:00
|
|
|
{
|
|
|
|
mbedtls_ccm_context ctx;
|
|
|
|
uint8_t *output = NULL;
|
|
|
|
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_INIT();
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_ccm_init(&ctx);
|
|
|
|
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));
|
2021-08-10 13:55:47 +02:00
|
|
|
// use hardcoded values for add length, msg length and tag length.
|
|
|
|
// They are not a part of this test
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(0, mbedtls_ccm_set_lengths(&ctx, 16, 16, 16));
|
2021-08-10 13:55:47 +02:00
|
|
|
|
2023-07-21 12:31:13 +02:00
|
|
|
TEST_CALLOC(output, 16);
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_finish(&ctx, output, 16));
|
2021-08-10 13:55:47 +02:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_free(output);
|
|
|
|
mbedtls_ccm_free(&ctx);
|
2023-12-12 11:54:20 +01:00
|
|
|
BLOCK_CIPHER_PSA_DONE();
|
2021-08-10 13:55:47 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|