2017-12-01 15:26:40 +01:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include "mbedtls/aria.h"
|
2018-03-01 10:02:47 +01:00
|
|
|
|
|
|
|
/* Maxium size of data used by test vectors
|
|
|
|
* WARNING: to be adapted if and when adding larger test cases */
|
|
|
|
#define ARIA_MAX_DATASIZE 160
|
|
|
|
|
|
|
|
/* Maximum sizes of hexified things */
|
|
|
|
#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
|
|
|
|
*/
|
|
|
|
|
2018-12-17 15:13:36 +01:00
|
|
|
/* BEGIN_CASE */
|
|
|
|
void aria_valid_param( )
|
|
|
|
{
|
|
|
|
TEST_VALID_PARAM( mbedtls_aria_free( NULL ) );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2018-12-11 22:51:38 +01:00
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */
|
|
|
|
void aria_invalid_param( )
|
|
|
|
{
|
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
unsigned char key[128 / 8] = { 0 };
|
|
|
|
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;
|
|
|
|
|
2018-12-18 19:18:45 +01:00
|
|
|
((void) iv_off);
|
|
|
|
((void) iv);
|
|
|
|
|
2018-12-11 22:51:38 +01:00
|
|
|
TEST_INVALID_PARAM( mbedtls_aria_init( NULL ) );
|
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_setkey_enc( NULL, key,
|
|
|
|
sizeof( key ) ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
2018-12-17 13:07:01 +01:00
|
|
|
mbedtls_aria_setkey_enc( &ctx, NULL,
|
|
|
|
sizeof( key ) ) );
|
2018-12-11 22:51:38 +01:00
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
2018-12-17 13:07:01 +01:00
|
|
|
mbedtls_aria_setkey_dec( NULL, key,
|
|
|
|
sizeof( key ) ) );
|
2018-12-11 22:51:38 +01:00
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
2018-12-17 13:07:01 +01:00
|
|
|
mbedtls_aria_setkey_dec( &ctx, NULL,
|
|
|
|
sizeof( key ) ) );
|
2018-12-11 22:51:38 +01:00
|
|
|
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ecb( NULL, input, output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ecb( &ctx, NULL, output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ecb( &ctx, input, NULL ) );
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cbc( NULL,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cbc( &ctx,
|
|
|
|
42 /* invalid mode */,
|
|
|
|
sizeof( input ),
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cbc( &ctx,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
NULL,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cbc( &ctx,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
iv,
|
|
|
|
NULL,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cbc( &ctx,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
NULL ) );
|
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CFB)
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cfb128( NULL,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cfb128( &ctx,
|
|
|
|
42, /* invalid mode */
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cfb128( &ctx,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
NULL,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cfb128( &ctx,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
NULL,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cfb128( &ctx,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
NULL,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_cfb128( &ctx,
|
|
|
|
MBEDTLS_ARIA_ENCRYPT,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
NULL ) );
|
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_CIPHER_MODE_CTR)
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ctr( NULL,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ctr( &ctx,
|
|
|
|
sizeof( input ),
|
|
|
|
NULL,
|
|
|
|
iv,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ctr( &ctx,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
NULL,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ctr( &ctx,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
NULL,
|
|
|
|
input,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ctr( &ctx,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
iv,
|
|
|
|
NULL,
|
|
|
|
output ) );
|
|
|
|
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
|
|
|
|
mbedtls_aria_crypt_ctr( &ctx,
|
|
|
|
sizeof( input ),
|
|
|
|
&iv_off,
|
|
|
|
iv,
|
|
|
|
iv,
|
|
|
|
input,
|
|
|
|
NULL ) );
|
|
|
|
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
|
|
|
|
|
|
|
exit:
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
2017-12-01 15:26:40 +01:00
|
|
|
/* BEGIN_CASE */
|
|
|
|
void aria_encrypt_ecb( char *hex_key_string, char *hex_src_string,
|
2018-03-01 09:43:21 +01:00
|
|
|
char *hex_dst_string, int setkey_result )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char key_str[ARIA_MAX_KEY_STR];
|
|
|
|
unsigned char src_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
int key_len, data_len, i;
|
|
|
|
|
2018-03-01 10:02:47 +01:00
|
|
|
memset( key_str, 0x00, sizeof( key_str ) );
|
|
|
|
memset( src_str, 0x00, sizeof( src_str ) );
|
|
|
|
memset( dst_str, 0x00, sizeof( dst_str ) );
|
|
|
|
memset( output, 0x00, sizeof( output ) );
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_init( &ctx );
|
|
|
|
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
data_len = unhexify( src_str, hex_src_string );
|
|
|
|
|
2018-02-28 10:54:31 +01:00
|
|
|
TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 )
|
|
|
|
== setkey_result );
|
2017-12-01 15:26:40 +01:00
|
|
|
if( setkey_result == 0 )
|
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-06-05 16:53:06 +02:00
|
|
|
TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i )
|
|
|
|
== 0 );
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
hexify( dst_str, output, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_aria_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void aria_decrypt_ecb( char *hex_key_string, char *hex_src_string,
|
2018-03-01 09:43:21 +01:00
|
|
|
char *hex_dst_string, int setkey_result )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char key_str[ARIA_MAX_KEY_STR];
|
|
|
|
unsigned char src_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
int key_len, data_len, i;
|
|
|
|
|
2018-03-01 10:02:47 +01:00
|
|
|
memset( key_str, 0x00, sizeof( key_str ) );
|
|
|
|
memset( src_str, 0x00, sizeof( src_str ) );
|
|
|
|
memset( dst_str, 0x00, sizeof( dst_str ) );
|
|
|
|
memset( output, 0x00, sizeof( output ) );
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_init( &ctx );
|
|
|
|
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
data_len = unhexify( src_str, hex_src_string );
|
|
|
|
|
2018-02-28 10:54:31 +01:00
|
|
|
TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 )
|
|
|
|
== setkey_result );
|
2017-12-01 15:26:40 +01:00
|
|
|
if( setkey_result == 0 )
|
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-06-05 16:53:06 +02:00
|
|
|
TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i )
|
2018-03-01 13:51:52 +01:00
|
|
|
== 0 );
|
2017-12-01 15:26:40 +01:00
|
|
|
}
|
|
|
|
hexify( dst_str, output, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_aria_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
|
|
|
void aria_encrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
2018-03-01 09:43:21 +01:00
|
|
|
char *hex_src_string, char *hex_dst_string,
|
|
|
|
int cbc_result )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char key_str[ARIA_MAX_KEY_STR];
|
|
|
|
unsigned char iv_str[ARIA_BLOCK_STR];
|
|
|
|
unsigned char src_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
int key_len, data_len;
|
|
|
|
|
2018-03-01 10:02:47 +01:00
|
|
|
memset( key_str, 0x00, sizeof( key_str ) );
|
|
|
|
memset( iv_str, 0x00, sizeof( iv_str ) );
|
|
|
|
memset( src_str, 0x00, sizeof( src_str ) );
|
|
|
|
memset( dst_str, 0x00, sizeof( dst_str ) );
|
|
|
|
memset( output, 0x00, sizeof( output ) );
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_init( &ctx );
|
|
|
|
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
unhexify( iv_str, hex_iv_string );
|
|
|
|
data_len = unhexify( src_str, hex_src_string );
|
|
|
|
|
|
|
|
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
|
2018-02-28 10:54:31 +01:00
|
|
|
TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, data_len,
|
|
|
|
iv_str, src_str, output )
|
|
|
|
== cbc_result );
|
2017-12-01 15:26:40 +01:00
|
|
|
if( cbc_result == 0 )
|
|
|
|
{
|
|
|
|
hexify( dst_str, output, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_aria_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
|
|
|
|
void aria_decrypt_cbc( char *hex_key_string, char *hex_iv_string,
|
2018-03-01 09:43:21 +01:00
|
|
|
char *hex_src_string, char *hex_dst_string,
|
|
|
|
int cbc_result )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char key_str[ARIA_MAX_KEY_STR];
|
|
|
|
unsigned char iv_str[ARIA_BLOCK_STR];
|
|
|
|
unsigned char src_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
int key_len, data_len;
|
|
|
|
|
2018-03-01 10:02:47 +01:00
|
|
|
memset( key_str, 0x00, sizeof( key_str ) );
|
|
|
|
memset( iv_str, 0x00, sizeof( iv_str ) );
|
|
|
|
memset( src_str, 0x00, sizeof( src_str ) );
|
|
|
|
memset( dst_str, 0x00, sizeof( dst_str ) );
|
|
|
|
memset( output, 0x00, sizeof( output ) );
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_init( &ctx );
|
|
|
|
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
unhexify( iv_str, hex_iv_string );
|
|
|
|
data_len = unhexify( src_str, hex_src_string );
|
|
|
|
|
|
|
|
mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 );
|
2018-02-28 10:54:31 +01:00
|
|
|
TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, data_len,
|
|
|
|
iv_str, src_str, output )
|
|
|
|
== cbc_result );
|
2017-12-01 15:26:40 +01:00
|
|
|
if( cbc_result == 0 )
|
|
|
|
{
|
|
|
|
hexify( dst_str, output, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_aria_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
|
|
|
void aria_encrypt_cfb128( char *hex_key_string, char *hex_iv_string,
|
2018-03-01 09:43:21 +01:00
|
|
|
char *hex_src_string, char *hex_dst_string,
|
|
|
|
int result )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char key_str[ARIA_MAX_KEY_STR];
|
|
|
|
unsigned char iv_str[ARIA_BLOCK_STR];
|
|
|
|
unsigned char src_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
size_t iv_offset = 0;
|
|
|
|
int key_len, data_len;
|
|
|
|
|
2018-03-01 10:02:47 +01:00
|
|
|
memset( key_str, 0x00, sizeof( key_str ) );
|
|
|
|
memset( iv_str, 0x00, sizeof( iv_str ) );
|
|
|
|
memset( src_str, 0x00, sizeof( src_str ) );
|
|
|
|
memset( dst_str, 0x00, sizeof( dst_str ) );
|
|
|
|
memset( output, 0x00, sizeof( output ) );
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_init( &ctx );
|
|
|
|
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
unhexify( iv_str, hex_iv_string );
|
|
|
|
data_len = unhexify( src_str, hex_src_string );
|
|
|
|
|
|
|
|
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
|
|
|
|
TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT,
|
2018-02-28 10:54:31 +01:00
|
|
|
data_len, &iv_offset, iv_str,
|
2018-03-01 13:51:52 +01:00
|
|
|
src_str, output )
|
|
|
|
== result );
|
2017-12-01 15:26:40 +01:00
|
|
|
hexify( dst_str, output, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_aria_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
|
|
|
|
void aria_decrypt_cfb128( char *hex_key_string, char *hex_iv_string,
|
2018-03-01 09:43:21 +01:00
|
|
|
char *hex_src_string, char *hex_dst_string,
|
|
|
|
int result )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char key_str[ARIA_MAX_KEY_STR];
|
|
|
|
unsigned char iv_str[ARIA_BLOCK_STR];
|
|
|
|
unsigned char src_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char output[ARIA_MAX_DATASIZE];
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_context ctx;
|
|
|
|
size_t iv_offset = 0;
|
|
|
|
int key_len, data_len;
|
|
|
|
|
2018-03-01 10:02:47 +01:00
|
|
|
memset( key_str, 0x00, sizeof( key_str ) );
|
|
|
|
memset( iv_str, 0x00, sizeof( iv_str ) );
|
|
|
|
memset( src_str, 0x00, sizeof( src_str ) );
|
|
|
|
memset( dst_str, 0x00, sizeof( dst_str ) );
|
|
|
|
memset( output, 0x00, sizeof( output ) );
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_init( &ctx );
|
|
|
|
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
unhexify( iv_str, hex_iv_string );
|
|
|
|
data_len = unhexify( src_str, hex_src_string );
|
|
|
|
|
|
|
|
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
|
|
|
|
TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT,
|
2018-02-28 10:54:31 +01:00
|
|
|
data_len, &iv_offset, iv_str,
|
2018-03-01 13:51:52 +01:00
|
|
|
src_str, output )
|
|
|
|
== result );
|
2017-12-01 15:26:40 +01:00
|
|
|
hexify( dst_str, output, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_aria_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
|
|
|
|
void aria_encrypt_ctr( char *hex_key_string, char *hex_iv_string,
|
2018-03-01 09:43:21 +01:00
|
|
|
char *hex_src_string, char *hex_dst_string,
|
|
|
|
int result )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char key_str[ARIA_MAX_KEY_STR];
|
|
|
|
unsigned char iv_str[ARIA_BLOCK_STR];
|
|
|
|
unsigned char src_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
|
|
|
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;
|
|
|
|
int key_len, data_len;
|
|
|
|
|
2018-03-01 10:02:47 +01:00
|
|
|
memset( key_str, 0x00, sizeof( key_str ) );
|
|
|
|
memset( iv_str, 0x00, sizeof( iv_str ) );
|
|
|
|
memset( src_str, 0x00, sizeof( src_str ) );
|
|
|
|
memset( dst_str, 0x00, sizeof( dst_str ) );
|
|
|
|
memset( output, 0x00, sizeof( output ) );
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_init( &ctx );
|
|
|
|
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
unhexify( iv_str, hex_iv_string );
|
|
|
|
data_len = unhexify( src_str, hex_src_string );
|
|
|
|
|
|
|
|
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
|
2018-02-28 10:54:31 +01:00
|
|
|
TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
|
2018-03-01 13:51:52 +01:00
|
|
|
blk, src_str, output )
|
|
|
|
== result );
|
2017-12-01 15:26:40 +01:00
|
|
|
hexify( dst_str, output, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_aria_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
|
|
|
|
void aria_decrypt_ctr( char *hex_key_string, char *hex_iv_string,
|
2018-03-01 09:43:21 +01:00
|
|
|
char *hex_src_string, char *hex_dst_string,
|
|
|
|
int result )
|
2017-12-01 15:26:40 +01:00
|
|
|
{
|
2018-03-01 10:02:47 +01:00
|
|
|
unsigned char key_str[ARIA_MAX_KEY_STR];
|
|
|
|
unsigned char iv_str[ARIA_BLOCK_STR];
|
|
|
|
unsigned char src_str[ARIA_MAX_DATA_STR];
|
|
|
|
unsigned char dst_str[ARIA_MAX_DATA_STR];
|
|
|
|
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;
|
|
|
|
int key_len, data_len;
|
|
|
|
|
2018-03-01 10:02:47 +01:00
|
|
|
memset( key_str, 0x00, sizeof( key_str ) );
|
|
|
|
memset( iv_str, 0x00, sizeof( iv_str ) );
|
|
|
|
memset( src_str, 0x00, sizeof( src_str ) );
|
|
|
|
memset( dst_str, 0x00, sizeof( dst_str ) );
|
|
|
|
memset( output, 0x00, sizeof( output ) );
|
2017-12-01 15:26:40 +01:00
|
|
|
mbedtls_aria_init( &ctx );
|
|
|
|
|
|
|
|
key_len = unhexify( key_str, hex_key_string );
|
|
|
|
unhexify( iv_str, hex_iv_string );
|
|
|
|
data_len = unhexify( src_str, hex_src_string );
|
|
|
|
|
|
|
|
mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 );
|
2018-02-28 10:54:31 +01:00
|
|
|
TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str,
|
2018-03-01 13:51:52 +01:00
|
|
|
blk, src_str, output )
|
|
|
|
== result );
|
2017-12-01 15:26:40 +01:00
|
|
|
hexify( dst_str, output, data_len );
|
|
|
|
|
|
|
|
TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
|
|
|
|
|
|
|
|
exit:
|
|
|
|
mbedtls_aria_free( &ctx );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
|
|
|
void aria_selftest()
|
|
|
|
{
|
|
|
|
TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|