2017-12-01 15:26:40 +01:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include "mbedtls/aria.h"
|
2018-03-01 10:02:47 +01:00
|
|
|
|
2021-12-21 06:14:10 +01:00
|
|
|
/* Maximum size of data used by test vectors
|
2018-03-01 10:02:47 +01:00
|
|
|
* WARNING: to be adapted if and when adding larger test cases */
|
|
|
|
#define ARIA_MAX_DATASIZE 160
|
|
|
|
|
|
|
|
/* Maximum sizes of hexified things */
|
2023-01-11 14:50:10 +01:00
|
|
|
#define ARIA_MAX_KEY_STR (2 * MBEDTLS_ARIA_MAX_KEYSIZE + 1)
|
|
|
|
#define ARIA_BLOCK_STR (2 * MBEDTLS_ARIA_BLOCKSIZE + 1)
|
|
|
|
#define ARIA_MAX_DATA_STR (2 * ARIA_MAX_DATASIZE + 1)
|
2017-12-01 15:26:40 +01:00
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
* depends_on:MBEDTLS_ARIA_C
|
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
2021-05-25 15:15:57 +02:00
|
|
|
/* BEGIN_CASE depends_on:NOT_DEFINED */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_invalid_param()
|
2019-01-31 14:20:20 +01:00
|
|
|
{
|
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
unsigned char input[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
|
|
|
|
unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
|
|
|
|
unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE] = { 0 };
|
|
|
|
size_t iv_off = 0;
|
|
|
|
|
|
|
|
((void) iv_off);
|
|
|
|
((void) iv);
|
2021-05-28 12:56:57 +02:00
|
|
|
((void) ctx);
|
|
|
|
((void) input);
|
|
|
|
((void) output);
|
2019-01-31 14:20:20 +01:00
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cbc(&ctx,
|
|
|
|
42 /* invalid mode */,
|
|
|
|
sizeof(input),
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output));
|
2019-01-31 14:20:20 +01:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cfb128(&ctx,
|
|
|
|
42, /* invalid mode */
|
|
|
|
sizeof(input),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output));
|
2019-01-31 14:20:20 +01:00
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2017-12-01 15:26:40 +01:00
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_encrypt_ecb(data_t *key_str, data_t *src_str,
|
|
|
|
data_t *expected_output, int setkey_result)
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
2020-06-25 09:03:34 +02:00
|
|
|
size_t i;
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(output, 0x00, sizeof(output));
|
|
|
|
mbedtls_aria_init(&ctx);
|
|
|
|
|
|
|
|
TEST_ASSERT(mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8)
|
|
|
|
== setkey_result);
|
|
|
|
if (setkey_result == 0) {
|
|
|
|
for (i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE) {
|
|
|
|
TEST_ASSERT(mbedtls_aria_crypt_ecb(&ctx, src_str->x + i,
|
|
|
|
output + i) == 0);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, expected_output->len,
|
2023-07-27 15:17:27 +02:00
|
|
|
expected_output->x, expected_output->len);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_free(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2023-10-31 10:10:32 +01:00
|
|
|
/* BEGIN_CASE depends_on:!MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_decrypt_ecb(data_t *key_str, data_t *src_str,
|
|
|
|
data_t *expected_output, int setkey_result)
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
2020-06-25 09:03:34 +02:00
|
|
|
size_t i;
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(output, 0x00, sizeof(output));
|
|
|
|
mbedtls_aria_init(&ctx);
|
|
|
|
|
|
|
|
TEST_ASSERT(mbedtls_aria_setkey_dec(&ctx, key_str->x, key_str->len * 8)
|
|
|
|
== setkey_result);
|
|
|
|
if (setkey_result == 0) {
|
|
|
|
for (i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE) {
|
|
|
|
TEST_ASSERT(mbedtls_aria_crypt_ecb(&ctx, src_str->x + i,
|
|
|
|
output + i) == 0);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, expected_output->len,
|
2023-07-27 15:17:27 +02:00
|
|
|
expected_output->x, expected_output->len);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_free(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_encrypt_cbc(data_t *key_str, data_t *iv_str,
|
|
|
|
data_t *src_str, data_t *expected_output,
|
|
|
|
int cbc_result)
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(output, 0x00, sizeof(output));
|
|
|
|
mbedtls_aria_init(&ctx);
|
|
|
|
|
|
|
|
mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
|
|
|
|
TEST_ASSERT(mbedtls_aria_crypt_cbc(&ctx, MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
src_str->len, iv_str->x, src_str->x,
|
|
|
|
output) == cbc_result);
|
|
|
|
if (cbc_result == 0) {
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, expected_output->len,
|
2023-07-27 15:17:27 +02:00
|
|
|
expected_output->x, expected_output->len);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_free(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_decrypt_cbc(data_t *key_str, data_t *iv_str,
|
|
|
|
data_t *src_str, data_t *expected_output,
|
|
|
|
int cbc_result)
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(output, 0x00, sizeof(output));
|
|
|
|
mbedtls_aria_init(&ctx);
|
|
|
|
|
|
|
|
mbedtls_aria_setkey_dec(&ctx, key_str->x, key_str->len * 8);
|
|
|
|
TEST_ASSERT(mbedtls_aria_crypt_cbc(&ctx, MBEDTLS_ARIA_DECRYPT,
|
|
|
|
src_str->len, iv_str->x, src_str->x,
|
|
|
|
output) == cbc_result);
|
|
|
|
if (cbc_result == 0) {
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, expected_output->len,
|
2023-07-27 15:17:27 +02:00
|
|
|
expected_output->x, expected_output->len);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_free(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_encrypt_cfb128(data_t *key_str, data_t *iv_str,
|
|
|
|
data_t *src_str, data_t *expected_output,
|
|
|
|
int result)
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
size_t iv_offset = 0;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(output, 0x00, sizeof(output));
|
|
|
|
mbedtls_aria_init(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
|
|
|
|
TEST_ASSERT(mbedtls_aria_crypt_cfb128(&ctx, MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
src_str->len, &iv_offset,
|
|
|
|
iv_str->x, src_str->x, output)
|
|
|
|
== result);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, expected_output->len,
|
2023-07-27 15:17:27 +02:00
|
|
|
expected_output->x, expected_output->len);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_free(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_decrypt_cfb128(data_t *key_str, data_t *iv_str,
|
|
|
|
data_t *src_str, data_t *expected_output,
|
|
|
|
int result)
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
size_t iv_offset = 0;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(output, 0x00, sizeof(output));
|
|
|
|
mbedtls_aria_init(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
|
|
|
|
TEST_ASSERT(mbedtls_aria_crypt_cfb128(&ctx, MBEDTLS_ARIA_DECRYPT,
|
|
|
|
src_str->len, &iv_offset,
|
|
|
|
iv_str->x, src_str->x, output)
|
|
|
|
== result);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, expected_output->len,
|
2023-07-27 15:17:27 +02:00
|
|
|
expected_output->x, expected_output->len);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_free(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_encrypt_ctr(data_t *key_str, data_t *iv_str,
|
|
|
|
data_t *src_str, data_t *expected_output,
|
|
|
|
int result)
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
|
|
|
unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
size_t iv_offset = 0;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(output, 0x00, sizeof(output));
|
|
|
|
mbedtls_aria_init(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
|
|
|
|
TEST_ASSERT(mbedtls_aria_crypt_ctr(&ctx, src_str->len, &iv_offset,
|
|
|
|
iv_str->x, blk, src_str->x, output)
|
|
|
|
== result);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, expected_output->len,
|
2023-07-27 15:17:27 +02:00
|
|
|
expected_output->x, expected_output->len);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_free(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
|
2023-01-11 14:50:10 +01:00
|
|
|
void aria_decrypt_ctr(data_t *key_str, data_t *iv_str,
|
|
|
|
data_t *src_str, data_t *expected_output,
|
|
|
|
int result)
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
|
|
|
unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
size_t iv_offset = 0;
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
memset(output, 0x00, sizeof(output));
|
|
|
|
mbedtls_aria_init(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8);
|
|
|
|
TEST_ASSERT(mbedtls_aria_crypt_ctr(&ctx, src_str->len, &iv_offset,
|
|
|
|
iv_str->x, blk, src_str->x, output)
|
|
|
|
== result);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
2023-07-21 12:40:20 +02:00
|
|
|
TEST_MEMORY_COMPARE(output, expected_output->len,
|
2023-07-27 15:17:27 +02:00
|
|
|
expected_output->x, expected_output->len);
|
2017-12-01 15:26:40 +01:00
|
|
|
|
|
|
|
exit:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_aria_free(&ctx);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
|
|
|
void aria_selftest()
|
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(mbedtls_aria_self_test(1) == 0);
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|