Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
| 2 | #include "mbedtls/aria.h" |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 3 | |
| 4 | /* Maxium size of data used by test vectors |
| 5 | * WARNING: to be adapted if and when adding larger test cases */ |
| 6 | #define ARIA_MAX_DATASIZE 160 |
| 7 | |
| 8 | /* Maximum sizes of hexified things */ |
| 9 | #define ARIA_MAX_KEY_STR ( 2 * MBEDTLS_ARIA_MAX_KEYSIZE + 1 ) |
| 10 | #define ARIA_BLOCK_STR ( 2 * MBEDTLS_ARIA_BLOCKSIZE + 1 ) |
| 11 | #define ARIA_MAX_DATA_STR ( 2 * ARIA_MAX_DATASIZE + 1 ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 12 | /* END_HEADER */ |
| 13 | |
| 14 | /* BEGIN_DEPENDENCIES |
| 15 | * depends_on:MBEDTLS_ARIA_C |
| 16 | * END_DEPENDENCIES |
| 17 | */ |
| 18 | |
| 19 | /* BEGIN_CASE */ |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 20 | void aria_valid_param( ) |
| 21 | { |
| 22 | TEST_VALID_PARAM( mbedtls_aria_free( NULL ) ); |
| 23 | } |
| 24 | /* END_CASE */ |
| 25 | |
| 26 | /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */ |
| 27 | void aria_invalid_param( ) |
| 28 | { |
| 29 | mbedtls_aria_context ctx; |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 30 | unsigned char input[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 31 | unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 32 | unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 33 | size_t iv_off = 0; |
| 34 | |
| 35 | ((void) iv_off); |
| 36 | ((void) iv); |
| 37 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 38 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Ronald Cron | 875b5fb | 2021-05-21 08:50:00 +0200 | [diff] [blame^] | 39 | TEST_EQUAL( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 40 | mbedtls_aria_crypt_cbc( &ctx, |
| 41 | 42 /* invalid mode */, |
| 42 | sizeof( input ), |
| 43 | iv, |
| 44 | input, |
| 45 | output ) ); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 46 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 47 | |
| 48 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Ronald Cron | 875b5fb | 2021-05-21 08:50:00 +0200 | [diff] [blame^] | 49 | TEST_EQUAL( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 50 | mbedtls_aria_crypt_cfb128( &ctx, |
| 51 | 42, /* invalid mode */ |
| 52 | sizeof( input ), |
| 53 | &iv_off, |
| 54 | iv, |
| 55 | input, |
| 56 | output ) ); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 57 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
| 58 | |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 59 | exit: |
| 60 | return; |
| 61 | |
| 62 | } |
| 63 | /* END_CASE */ |
| 64 | |
| 65 | /* BEGIN_CASE */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 66 | void aria_encrypt_ecb( data_t *key_str, data_t *src_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 67 | data_t *expected_output, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 68 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 69 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 70 | mbedtls_aria_context ctx; |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 71 | size_t i; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 72 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 73 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 74 | mbedtls_aria_init( &ctx ); |
| 75 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 76 | TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 77 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 78 | if( setkey_result == 0 ) |
| 79 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 80 | for( i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 81 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 82 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i, |
| 83 | output + i ) == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 84 | } |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 85 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame] | 86 | ASSERT_COMPARE( output, expected_output->len, |
| 87 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | exit: |
| 91 | mbedtls_aria_free( &ctx ); |
| 92 | } |
| 93 | /* END_CASE */ |
| 94 | |
| 95 | /* BEGIN_CASE */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 96 | void aria_decrypt_ecb( data_t *key_str, data_t *src_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 97 | data_t *expected_output, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 98 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 99 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 100 | mbedtls_aria_context ctx; |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 101 | size_t i; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 102 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 103 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 104 | mbedtls_aria_init( &ctx ); |
| 105 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 106 | TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 107 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 108 | if( setkey_result == 0 ) |
| 109 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 110 | for( i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 111 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 112 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i, |
| 113 | output + i ) == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 114 | } |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 115 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame] | 116 | ASSERT_COMPARE( output, expected_output->len, |
| 117 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | exit: |
| 121 | mbedtls_aria_free( &ctx ); |
| 122 | } |
| 123 | /* END_CASE */ |
| 124 | |
| 125 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 126 | void aria_encrypt_cbc( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 127 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 128 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 129 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 130 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 131 | mbedtls_aria_context ctx; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 132 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 133 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 134 | mbedtls_aria_init( &ctx ); |
| 135 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 136 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 137 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, |
| 138 | src_str->len, iv_str->x, src_str->x, |
| 139 | output ) == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 140 | if( cbc_result == 0 ) |
| 141 | { |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame] | 142 | ASSERT_COMPARE( output, expected_output->len, |
| 143 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | exit: |
| 147 | mbedtls_aria_free( &ctx ); |
| 148 | } |
| 149 | /* END_CASE */ |
| 150 | |
| 151 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 152 | void aria_decrypt_cbc( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 153 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 154 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 155 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 156 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 157 | mbedtls_aria_context ctx; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 158 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 159 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 160 | mbedtls_aria_init( &ctx ); |
| 161 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 162 | mbedtls_aria_setkey_dec( &ctx, key_str->x, key_str->len * 8 ); |
| 163 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, |
| 164 | src_str->len, iv_str->x, src_str->x, |
| 165 | output ) == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 166 | if( cbc_result == 0 ) |
| 167 | { |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame] | 168 | ASSERT_COMPARE( output, expected_output->len, |
| 169 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | exit: |
| 173 | mbedtls_aria_free( &ctx ); |
| 174 | } |
| 175 | /* END_CASE */ |
| 176 | |
| 177 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 178 | void aria_encrypt_cfb128( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 179 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 180 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 181 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 182 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 183 | mbedtls_aria_context ctx; |
| 184 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 185 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 186 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 187 | mbedtls_aria_init( &ctx ); |
| 188 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 189 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 190 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT, |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 191 | src_str->len, &iv_offset, |
| 192 | iv_str->x, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 193 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 194 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame] | 195 | ASSERT_COMPARE( output, expected_output->len, |
| 196 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 197 | |
| 198 | exit: |
| 199 | mbedtls_aria_free( &ctx ); |
| 200 | } |
| 201 | /* END_CASE */ |
| 202 | |
| 203 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 204 | void aria_decrypt_cfb128( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 205 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 206 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 207 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 208 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 209 | mbedtls_aria_context ctx; |
| 210 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 211 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 212 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 213 | mbedtls_aria_init( &ctx ); |
| 214 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 215 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 216 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT, |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 217 | src_str->len, &iv_offset, |
| 218 | iv_str->x, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 219 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 220 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame] | 221 | ASSERT_COMPARE( output, expected_output->len, |
| 222 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 223 | |
| 224 | exit: |
| 225 | mbedtls_aria_free( &ctx ); |
| 226 | } |
| 227 | /* END_CASE */ |
| 228 | |
| 229 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 230 | void aria_encrypt_ctr( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 231 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 232 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 233 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 234 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 235 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 236 | mbedtls_aria_context ctx; |
| 237 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 238 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 239 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 240 | mbedtls_aria_init( &ctx ); |
| 241 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 242 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 243 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset, |
| 244 | iv_str->x, blk, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 245 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 246 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame] | 247 | ASSERT_COMPARE( output, expected_output->len, |
| 248 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 249 | |
| 250 | exit: |
| 251 | mbedtls_aria_free( &ctx ); |
| 252 | } |
| 253 | /* END_CASE */ |
| 254 | |
| 255 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 256 | void aria_decrypt_ctr( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 257 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 258 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 259 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 260 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 261 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 262 | mbedtls_aria_context ctx; |
| 263 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 264 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 265 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 266 | mbedtls_aria_init( &ctx ); |
| 267 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 268 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 269 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset, |
| 270 | iv_str->x, blk, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 271 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 272 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame] | 273 | ASSERT_COMPARE( output, expected_output->len, |
| 274 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 275 | |
| 276 | exit: |
| 277 | mbedtls_aria_free( &ctx ); |
| 278 | } |
| 279 | /* END_CASE */ |
| 280 | |
| 281 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
| 282 | void aria_selftest() |
| 283 | { |
| 284 | TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 ); |
| 285 | } |
| 286 | /* END_CASE */ |