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, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 210 | char *hex_dst_string, 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 dst_str[ARIA_MAX_DATA_STR]; |
| 213 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 214 | mbedtls_aria_context ctx; |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 215 | size_t i; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 216 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 217 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 218 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 219 | mbedtls_aria_init( &ctx ); |
| 220 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 221 | 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] | 222 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 223 | if( setkey_result == 0 ) |
| 224 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 225 | 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] | 226 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 227 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i, |
| 228 | output + i ) == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 229 | } |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 230 | mbedtls_test_hexify( dst_str, output, src_str->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 231 | |
| 232 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 233 | } |
| 234 | |
| 235 | exit: |
| 236 | mbedtls_aria_free( &ctx ); |
| 237 | } |
| 238 | /* END_CASE */ |
| 239 | |
| 240 | /* BEGIN_CASE */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 241 | void aria_decrypt_ecb( data_t *key_str, data_t *src_str, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 242 | char *hex_dst_string, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 243 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 244 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 245 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 246 | mbedtls_aria_context ctx; |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 247 | size_t i; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 248 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 249 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 250 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 251 | mbedtls_aria_init( &ctx ); |
| 252 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 253 | 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] | 254 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 255 | if( setkey_result == 0 ) |
| 256 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 257 | 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] | 258 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 259 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str->x + i, |
| 260 | output + i ) == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 261 | } |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 262 | mbedtls_test_hexify( dst_str, output, src_str->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 263 | |
| 264 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 265 | } |
| 266 | |
| 267 | exit: |
| 268 | mbedtls_aria_free( &ctx ); |
| 269 | } |
| 270 | /* END_CASE */ |
| 271 | |
| 272 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 273 | void aria_encrypt_cbc( data_t *key_str, data_t *iv_str, |
| 274 | data_t *src_str, char *hex_dst_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 275 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 276 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 277 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 278 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 279 | mbedtls_aria_context ctx; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 280 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 281 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 282 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 283 | mbedtls_aria_init( &ctx ); |
| 284 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 285 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 286 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, |
| 287 | src_str->len, iv_str->x, src_str->x, |
| 288 | output ) == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 289 | if( cbc_result == 0 ) |
| 290 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 291 | mbedtls_test_hexify( dst_str, output, src_str->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 292 | |
| 293 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 294 | } |
| 295 | |
| 296 | exit: |
| 297 | mbedtls_aria_free( &ctx ); |
| 298 | } |
| 299 | /* END_CASE */ |
| 300 | |
| 301 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 302 | void aria_decrypt_cbc( data_t *key_str, data_t *iv_str, |
| 303 | data_t *src_str, char *hex_dst_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 304 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 305 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 306 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 307 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 308 | mbedtls_aria_context ctx; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 309 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 310 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 311 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 312 | mbedtls_aria_init( &ctx ); |
| 313 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 314 | mbedtls_aria_setkey_dec( &ctx, key_str->x, key_str->len * 8 ); |
| 315 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, |
| 316 | src_str->len, iv_str->x, src_str->x, |
| 317 | output ) == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 318 | if( cbc_result == 0 ) |
| 319 | { |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 320 | mbedtls_test_hexify( dst_str, output, src_str->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 321 | |
| 322 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 323 | } |
| 324 | |
| 325 | exit: |
| 326 | mbedtls_aria_free( &ctx ); |
| 327 | } |
| 328 | /* END_CASE */ |
| 329 | |
| 330 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 331 | void aria_encrypt_cfb128( data_t *key_str, data_t *iv_str, |
| 332 | data_t *src_str, char *hex_dst_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 333 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 334 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 335 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 336 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 337 | mbedtls_aria_context ctx; |
| 338 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 339 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 340 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 341 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 342 | mbedtls_aria_init( &ctx ); |
| 343 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 344 | 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] | 345 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT, |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 346 | src_str->len, &iv_offset, |
| 347 | iv_str->x, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 348 | == result ); |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 349 | mbedtls_test_hexify( dst_str, output, src_str->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 350 | |
| 351 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 352 | |
| 353 | exit: |
| 354 | mbedtls_aria_free( &ctx ); |
| 355 | } |
| 356 | /* END_CASE */ |
| 357 | |
| 358 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 359 | void aria_decrypt_cfb128( data_t *key_str, data_t *iv_str, |
| 360 | data_t *src_str, char *hex_dst_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 361 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 362 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 363 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 364 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 365 | mbedtls_aria_context ctx; |
| 366 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 367 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 368 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 369 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 370 | mbedtls_aria_init( &ctx ); |
| 371 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 372 | 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] | 373 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT, |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 374 | src_str->len, &iv_offset, |
| 375 | iv_str->x, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 376 | == result ); |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 377 | mbedtls_test_hexify( dst_str, output, src_str->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 378 | |
| 379 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 380 | |
| 381 | exit: |
| 382 | mbedtls_aria_free( &ctx ); |
| 383 | } |
| 384 | /* END_CASE */ |
| 385 | |
| 386 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 387 | void aria_encrypt_ctr( data_t *key_str, data_t *iv_str, |
| 388 | data_t *src_str, char *hex_dst_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 389 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 390 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 391 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 392 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 393 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 394 | mbedtls_aria_context ctx; |
| 395 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 396 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 397 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 398 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 399 | mbedtls_aria_init( &ctx ); |
| 400 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 401 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 402 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset, |
| 403 | iv_str->x, blk, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 404 | == result ); |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 405 | mbedtls_test_hexify( dst_str, output, src_str->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 406 | |
| 407 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 408 | |
| 409 | exit: |
| 410 | mbedtls_aria_free( &ctx ); |
| 411 | } |
| 412 | /* END_CASE */ |
| 413 | |
| 414 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 415 | void aria_decrypt_ctr( data_t *key_str, data_t *iv_str, |
| 416 | data_t *src_str, char *hex_dst_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 417 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 418 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 419 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 420 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 421 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 422 | mbedtls_aria_context ctx; |
| 423 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 424 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 425 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 426 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 427 | mbedtls_aria_init( &ctx ); |
| 428 | |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 429 | mbedtls_aria_setkey_enc( &ctx, key_str->x, key_str->len * 8 ); |
| 430 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, src_str->len, &iv_offset, |
| 431 | iv_str->x, blk, src_str->x, output ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 432 | == result ); |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 433 | mbedtls_test_hexify( dst_str, output, src_str->len ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 434 | |
| 435 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 436 | |
| 437 | exit: |
| 438 | mbedtls_aria_free( &ctx ); |
| 439 | } |
| 440 | /* END_CASE */ |
| 441 | |
| 442 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
| 443 | void aria_selftest() |
| 444 | { |
| 445 | TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 ); |
| 446 | } |
| 447 | /* END_CASE */ |