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; |
| 30 | unsigned char key[128 / 8] = { 0 }; |
| 31 | unsigned char input[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 32 | unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 33 | unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 34 | size_t iv_off = 0; |
| 35 | |
| 36 | ((void) iv_off); |
| 37 | ((void) iv); |
| 38 | |
| 39 | TEST_INVALID_PARAM( mbedtls_aria_init( NULL ) ); |
| 40 | |
| 41 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 42 | mbedtls_aria_setkey_enc( NULL, key, |
| 43 | sizeof( key ) ) ); |
| 44 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 45 | mbedtls_aria_setkey_enc( &ctx, NULL, |
| 46 | sizeof( key ) ) ); |
| 47 | |
| 48 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 49 | mbedtls_aria_setkey_dec( NULL, key, |
| 50 | sizeof( key ) ) ); |
| 51 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 52 | mbedtls_aria_setkey_dec( &ctx, NULL, |
| 53 | sizeof( key ) ) ); |
| 54 | |
| 55 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 56 | mbedtls_aria_crypt_ecb( NULL, input, output ) ); |
| 57 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 58 | mbedtls_aria_crypt_ecb( &ctx, NULL, output ) ); |
| 59 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 60 | mbedtls_aria_crypt_ecb( &ctx, input, NULL ) ); |
| 61 | |
| 62 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 63 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 64 | mbedtls_aria_crypt_cbc( NULL, |
| 65 | MBEDTLS_ARIA_ENCRYPT, |
| 66 | sizeof( input ), |
| 67 | iv, |
| 68 | input, |
| 69 | output ) ); |
| 70 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 71 | mbedtls_aria_crypt_cbc( &ctx, |
| 72 | 42 /* invalid mode */, |
| 73 | sizeof( input ), |
| 74 | iv, |
| 75 | input, |
| 76 | output ) ); |
| 77 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 78 | mbedtls_aria_crypt_cbc( &ctx, |
| 79 | MBEDTLS_ARIA_ENCRYPT, |
| 80 | sizeof( input ), |
| 81 | NULL, |
| 82 | input, |
| 83 | output ) ); |
| 84 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 85 | mbedtls_aria_crypt_cbc( &ctx, |
| 86 | MBEDTLS_ARIA_ENCRYPT, |
| 87 | sizeof( input ), |
| 88 | iv, |
| 89 | NULL, |
| 90 | output ) ); |
| 91 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 92 | mbedtls_aria_crypt_cbc( &ctx, |
| 93 | MBEDTLS_ARIA_ENCRYPT, |
| 94 | sizeof( input ), |
| 95 | iv, |
| 96 | input, |
| 97 | NULL ) ); |
| 98 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 99 | |
| 100 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 101 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 102 | mbedtls_aria_crypt_cfb128( NULL, |
| 103 | MBEDTLS_ARIA_ENCRYPT, |
| 104 | sizeof( input ), |
| 105 | &iv_off, |
| 106 | iv, |
| 107 | input, |
| 108 | output ) ); |
| 109 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 110 | mbedtls_aria_crypt_cfb128( &ctx, |
| 111 | 42, /* invalid mode */ |
| 112 | sizeof( input ), |
| 113 | &iv_off, |
| 114 | iv, |
| 115 | input, |
| 116 | output ) ); |
| 117 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 118 | mbedtls_aria_crypt_cfb128( &ctx, |
| 119 | MBEDTLS_ARIA_ENCRYPT, |
| 120 | sizeof( input ), |
| 121 | NULL, |
| 122 | iv, |
| 123 | input, |
| 124 | output ) ); |
| 125 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 126 | mbedtls_aria_crypt_cfb128( &ctx, |
| 127 | MBEDTLS_ARIA_ENCRYPT, |
| 128 | sizeof( input ), |
| 129 | &iv_off, |
| 130 | NULL, |
| 131 | input, |
| 132 | output ) ); |
| 133 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 134 | mbedtls_aria_crypt_cfb128( &ctx, |
| 135 | MBEDTLS_ARIA_ENCRYPT, |
| 136 | sizeof( input ), |
| 137 | &iv_off, |
| 138 | iv, |
| 139 | NULL, |
| 140 | output ) ); |
| 141 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 142 | mbedtls_aria_crypt_cfb128( &ctx, |
| 143 | MBEDTLS_ARIA_ENCRYPT, |
| 144 | sizeof( input ), |
| 145 | &iv_off, |
| 146 | iv, |
| 147 | input, |
| 148 | NULL ) ); |
| 149 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
| 150 | |
| 151 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 152 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 153 | mbedtls_aria_crypt_ctr( NULL, |
| 154 | sizeof( input ), |
| 155 | &iv_off, |
| 156 | iv, |
| 157 | iv, |
| 158 | input, |
| 159 | output ) ); |
| 160 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 161 | mbedtls_aria_crypt_ctr( &ctx, |
| 162 | sizeof( input ), |
| 163 | NULL, |
| 164 | iv, |
| 165 | iv, |
| 166 | input, |
| 167 | output ) ); |
| 168 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 169 | mbedtls_aria_crypt_ctr( &ctx, |
| 170 | sizeof( input ), |
| 171 | &iv_off, |
| 172 | NULL, |
| 173 | iv, |
| 174 | input, |
| 175 | output ) ); |
| 176 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 177 | mbedtls_aria_crypt_ctr( &ctx, |
| 178 | sizeof( input ), |
| 179 | &iv_off, |
| 180 | iv, |
| 181 | NULL, |
| 182 | input, |
| 183 | output ) ); |
| 184 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 185 | mbedtls_aria_crypt_ctr( &ctx, |
| 186 | sizeof( input ), |
| 187 | &iv_off, |
| 188 | iv, |
| 189 | iv, |
| 190 | NULL, |
| 191 | output ) ); |
| 192 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 193 | mbedtls_aria_crypt_ctr( &ctx, |
| 194 | sizeof( input ), |
| 195 | &iv_off, |
| 196 | iv, |
| 197 | iv, |
| 198 | input, |
| 199 | NULL ) ); |
| 200 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
| 201 | |
| 202 | exit: |
| 203 | return; |
| 204 | |
| 205 | } |
| 206 | /* END_CASE */ |
| 207 | |
| 208 | /* BEGIN_CASE */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 209 | void aria_encrypt_ecb( data_t *key_str, data_t *src_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 210 | data_t *expected_output, int setkey_result ) |
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 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 213 | mbedtls_aria_context ctx; |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 214 | size_t i; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 215 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 216 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 217 | mbedtls_aria_init( &ctx ); |
| 218 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 219 | 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] | 220 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 221 | if( setkey_result == 0 ) |
| 222 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 223 | 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] | 224 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 225 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i, |
| 226 | output + i ) == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 227 | } |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 228 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame^] | 229 | ASSERT_COMPARE( output, expected_output->len, |
| 230 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | exit: |
| 234 | mbedtls_aria_free( &ctx ); |
| 235 | } |
| 236 | /* END_CASE */ |
| 237 | |
| 238 | /* BEGIN_CASE */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 239 | void aria_decrypt_ecb( data_t *key_str, data_t *src_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 240 | data_t *expected_output, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 241 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 242 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 243 | mbedtls_aria_context ctx; |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 244 | size_t i; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 245 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 246 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 247 | mbedtls_aria_init( &ctx ); |
| 248 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 249 | 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] | 250 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 251 | if( setkey_result == 0 ) |
| 252 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 253 | 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] | 254 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 255 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i, |
| 256 | output + i ) == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 257 | } |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 258 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame^] | 259 | ASSERT_COMPARE( output, expected_output->len, |
| 260 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | exit: |
| 264 | mbedtls_aria_free( &ctx ); |
| 265 | } |
| 266 | /* END_CASE */ |
| 267 | |
| 268 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 269 | void aria_encrypt_cbc( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 270 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 271 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 272 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 273 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 274 | mbedtls_aria_context ctx; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 275 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 276 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 277 | mbedtls_aria_init( &ctx ); |
| 278 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 279 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 280 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, |
| 281 | src_str->len, iv_str->x, src_str->x, |
| 282 | output ) == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 283 | if( cbc_result == 0 ) |
| 284 | { |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame^] | 285 | ASSERT_COMPARE( output, expected_output->len, |
| 286 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | exit: |
| 290 | mbedtls_aria_free( &ctx ); |
| 291 | } |
| 292 | /* END_CASE */ |
| 293 | |
| 294 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 295 | void aria_decrypt_cbc( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 296 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 297 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 298 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 299 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 300 | mbedtls_aria_context ctx; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 301 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 302 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 303 | mbedtls_aria_init( &ctx ); |
| 304 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 305 | mbedtls_aria_setkey_dec( &ctx, key_str->x, key_str->len * 8 ); |
| 306 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, |
| 307 | src_str->len, iv_str->x, src_str->x, |
| 308 | output ) == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 309 | if( cbc_result == 0 ) |
| 310 | { |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame^] | 311 | ASSERT_COMPARE( output, expected_output->len, |
| 312 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | exit: |
| 316 | mbedtls_aria_free( &ctx ); |
| 317 | } |
| 318 | /* END_CASE */ |
| 319 | |
| 320 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 321 | void aria_encrypt_cfb128( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 322 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 323 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 324 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 325 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 326 | mbedtls_aria_context ctx; |
| 327 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 328 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 329 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 330 | mbedtls_aria_init( &ctx ); |
| 331 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 332 | 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] | 333 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT, |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 334 | src_str->len, &iv_offset, |
| 335 | iv_str->x, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 336 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 337 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame^] | 338 | ASSERT_COMPARE( output, expected_output->len, |
| 339 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 340 | |
| 341 | exit: |
| 342 | mbedtls_aria_free( &ctx ); |
| 343 | } |
| 344 | /* END_CASE */ |
| 345 | |
| 346 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 347 | void aria_decrypt_cfb128( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 348 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 349 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 350 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 351 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 352 | mbedtls_aria_context ctx; |
| 353 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 354 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 355 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 356 | mbedtls_aria_init( &ctx ); |
| 357 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 358 | 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] | 359 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT, |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 360 | src_str->len, &iv_offset, |
| 361 | iv_str->x, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 362 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 363 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame^] | 364 | ASSERT_COMPARE( output, expected_output->len, |
| 365 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 366 | |
| 367 | exit: |
| 368 | mbedtls_aria_free( &ctx ); |
| 369 | } |
| 370 | /* END_CASE */ |
| 371 | |
| 372 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 373 | void aria_encrypt_ctr( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 374 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 375 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 376 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 377 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 378 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 379 | mbedtls_aria_context ctx; |
| 380 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 381 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 382 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 383 | mbedtls_aria_init( &ctx ); |
| 384 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 385 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 386 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset, |
| 387 | iv_str->x, blk, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 388 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 389 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame^] | 390 | ASSERT_COMPARE( output, expected_output->len, |
| 391 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 392 | |
| 393 | exit: |
| 394 | mbedtls_aria_free( &ctx ); |
| 395 | } |
| 396 | /* END_CASE */ |
| 397 | |
| 398 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 399 | void aria_decrypt_ctr( data_t *key_str, data_t *iv_str, |
Ronald Cron | 55d97f2 | 2020-06-26 17:00:30 +0200 | [diff] [blame] | 400 | data_t *src_str, data_t *expected_output, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 401 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 402 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 403 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 404 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 405 | mbedtls_aria_context ctx; |
| 406 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 407 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 408 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 409 | mbedtls_aria_init( &ctx ); |
| 410 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 411 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 412 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset, |
| 413 | iv_str->x, blk, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 414 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 415 | |
Ronald Cron | d8902b6 | 2020-07-30 14:18:02 +0200 | [diff] [blame^] | 416 | ASSERT_COMPARE( output, expected_output->len, |
| 417 | expected_output->x, expected_output->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 418 | |
| 419 | exit: |
| 420 | mbedtls_aria_free( &ctx ); |
| 421 | } |
| 422 | /* END_CASE */ |
| 423 | |
| 424 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
| 425 | void aria_selftest() |
| 426 | { |
| 427 | TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 ); |
| 428 | } |
| 429 | /* END_CASE */ |