123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429 |
- /* BEGIN_HEADER */
- #include "mbedtls/aria.h"
- /* 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 )
- /* END_HEADER */
- /* BEGIN_DEPENDENCIES
- * depends_on:MBEDTLS_ARIA_C
- * END_DEPENDENCIES
- */
- /* BEGIN_CASE */
- void aria_valid_param( )
- {
- TEST_VALID_PARAM( mbedtls_aria_free( NULL ) );
- }
- /* END_CASE */
- /* 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;
- ((void) iv_off);
- ((void) iv);
- 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,
- mbedtls_aria_setkey_enc( &ctx, NULL,
- sizeof( key ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_setkey_dec( NULL, key,
- sizeof( key ) ) );
- TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA,
- mbedtls_aria_setkey_dec( &ctx, NULL,
- sizeof( key ) ) );
- 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 */
- /* BEGIN_CASE */
- void aria_encrypt_ecb( data_t *key_str, data_t *src_str,
- data_t *expected_output, int setkey_result )
- {
- unsigned char output[ARIA_MAX_DATASIZE];
- mbedtls_aria_context ctx;
- size_t i;
- 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 );
- }
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
- }
- exit:
- mbedtls_aria_free( &ctx );
- }
- /* END_CASE */
- /* BEGIN_CASE */
- void aria_decrypt_ecb( data_t *key_str, data_t *src_str,
- data_t *expected_output, int setkey_result )
- {
- unsigned char output[ARIA_MAX_DATASIZE];
- mbedtls_aria_context ctx;
- size_t i;
- 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 );
- }
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
- }
- exit:
- mbedtls_aria_free( &ctx );
- }
- /* END_CASE */
- /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
- void aria_encrypt_cbc( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int cbc_result )
- {
- unsigned char output[ARIA_MAX_DATASIZE];
- mbedtls_aria_context ctx;
- 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 )
- {
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
- }
- exit:
- mbedtls_aria_free( &ctx );
- }
- /* END_CASE */
- /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
- void aria_decrypt_cbc( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int cbc_result )
- {
- unsigned char output[ARIA_MAX_DATASIZE];
- mbedtls_aria_context ctx;
- 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 )
- {
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
- }
- exit:
- mbedtls_aria_free( &ctx );
- }
- /* END_CASE */
- /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
- void aria_encrypt_cfb128( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int result )
- {
- unsigned char output[ARIA_MAX_DATASIZE];
- mbedtls_aria_context ctx;
- size_t iv_offset = 0;
- 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_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT,
- src_str->len, &iv_offset,
- iv_str->x, src_str->x, output )
- == result );
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
- exit:
- mbedtls_aria_free( &ctx );
- }
- /* END_CASE */
- /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */
- void aria_decrypt_cfb128( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int result )
- {
- unsigned char output[ARIA_MAX_DATASIZE];
- mbedtls_aria_context ctx;
- size_t iv_offset = 0;
- 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_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT,
- src_str->len, &iv_offset,
- iv_str->x, src_str->x, output )
- == result );
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
- exit:
- mbedtls_aria_free( &ctx );
- }
- /* END_CASE */
- /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
- void aria_encrypt_ctr( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int result )
- {
- unsigned char output[ARIA_MAX_DATASIZE];
- unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
- mbedtls_aria_context ctx;
- size_t iv_offset = 0;
- 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_ctr( &ctx, src_str->len, &iv_offset,
- iv_str->x, blk, src_str->x, output )
- == result );
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
- exit:
- mbedtls_aria_free( &ctx );
- }
- /* END_CASE */
- /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */
- void aria_decrypt_ctr( data_t *key_str, data_t *iv_str,
- data_t *src_str, data_t *expected_output,
- int result )
- {
- unsigned char output[ARIA_MAX_DATASIZE];
- unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE];
- mbedtls_aria_context ctx;
- size_t iv_offset = 0;
- 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_ctr( &ctx, src_str->len, &iv_offset,
- iv_str->x, blk, src_str->x, output )
- == result );
- ASSERT_COMPARE( output, expected_output->len,
- expected_output->x, expected_output->len );
- 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 */
|