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 | |
Hanno Becker | 9e45c16 | 2018-12-11 21:51:38 +0000 | [diff] [blame^] | 19 | /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */ |
| 20 | void aria_invalid_param( ) |
| 21 | { |
| 22 | mbedtls_aria_context ctx; |
| 23 | unsigned char key[128 / 8] = { 0 }; |
| 24 | unsigned char input[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 25 | unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 26 | unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 27 | size_t iv_off = 0; |
| 28 | |
| 29 | TEST_INVALID_PARAM( mbedtls_aria_init( NULL ) ); |
| 30 | |
| 31 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 32 | mbedtls_aria_setkey_enc( NULL, key, |
| 33 | sizeof( key ) ) ); |
| 34 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 35 | mbedtls_aria_setkey_enc( &ctx, NULL, |
| 36 | sizeof( key ) ) ); |
| 37 | |
| 38 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 39 | mbedtls_aria_setkey_dec( NULL, key, |
| 40 | sizeof( key ) ) ); |
| 41 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 42 | mbedtls_aria_setkey_dec( &ctx, NULL, |
| 43 | sizeof( key ) ) ); |
| 44 | |
| 45 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 46 | mbedtls_aria_crypt_ecb( NULL, input, output ) ); |
| 47 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 48 | mbedtls_aria_crypt_ecb( &ctx, NULL, output ) ); |
| 49 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 50 | mbedtls_aria_crypt_ecb( &ctx, input, NULL ) ); |
| 51 | |
| 52 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
| 53 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 54 | mbedtls_aria_crypt_cbc( NULL, |
| 55 | MBEDTLS_ARIA_ENCRYPT, |
| 56 | sizeof( input ), |
| 57 | iv, |
| 58 | input, |
| 59 | output ) ); |
| 60 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 61 | mbedtls_aria_crypt_cbc( &ctx, |
| 62 | 42 /* invalid mode */, |
| 63 | sizeof( input ), |
| 64 | iv, |
| 65 | input, |
| 66 | output ) ); |
| 67 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 68 | mbedtls_aria_crypt_cbc( &ctx, |
| 69 | MBEDTLS_ARIA_ENCRYPT, |
| 70 | sizeof( input ), |
| 71 | NULL, |
| 72 | input, |
| 73 | output ) ); |
| 74 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 75 | mbedtls_aria_crypt_cbc( &ctx, |
| 76 | MBEDTLS_ARIA_ENCRYPT, |
| 77 | sizeof( input ), |
| 78 | iv, |
| 79 | NULL, |
| 80 | output ) ); |
| 81 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 82 | mbedtls_aria_crypt_cbc( &ctx, |
| 83 | MBEDTLS_ARIA_ENCRYPT, |
| 84 | sizeof( input ), |
| 85 | iv, |
| 86 | input, |
| 87 | NULL ) ); |
| 88 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 89 | |
| 90 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
| 91 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 92 | mbedtls_aria_crypt_cfb128( NULL, |
| 93 | MBEDTLS_ARIA_ENCRYPT, |
| 94 | sizeof( input ), |
| 95 | &iv_off, |
| 96 | iv, |
| 97 | input, |
| 98 | output ) ); |
| 99 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 100 | mbedtls_aria_crypt_cfb128( &ctx, |
| 101 | 42, /* invalid mode */ |
| 102 | sizeof( input ), |
| 103 | &iv_off, |
| 104 | iv, |
| 105 | input, |
| 106 | output ) ); |
| 107 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 108 | mbedtls_aria_crypt_cfb128( &ctx, |
| 109 | MBEDTLS_ARIA_ENCRYPT, |
| 110 | sizeof( input ), |
| 111 | NULL, |
| 112 | iv, |
| 113 | input, |
| 114 | output ) ); |
| 115 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 116 | mbedtls_aria_crypt_cfb128( &ctx, |
| 117 | MBEDTLS_ARIA_ENCRYPT, |
| 118 | sizeof( input ), |
| 119 | &iv_off, |
| 120 | NULL, |
| 121 | input, |
| 122 | output ) ); |
| 123 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 124 | mbedtls_aria_crypt_cfb128( &ctx, |
| 125 | MBEDTLS_ARIA_ENCRYPT, |
| 126 | sizeof( input ), |
| 127 | &iv_off, |
| 128 | iv, |
| 129 | NULL, |
| 130 | output ) ); |
| 131 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 132 | mbedtls_aria_crypt_cfb128( &ctx, |
| 133 | MBEDTLS_ARIA_ENCRYPT, |
| 134 | sizeof( input ), |
| 135 | &iv_off, |
| 136 | iv, |
| 137 | input, |
| 138 | NULL ) ); |
| 139 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
| 140 | |
| 141 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
| 142 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 143 | mbedtls_aria_crypt_ctr( NULL, |
| 144 | sizeof( input ), |
| 145 | &iv_off, |
| 146 | iv, |
| 147 | iv, |
| 148 | input, |
| 149 | output ) ); |
| 150 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 151 | mbedtls_aria_crypt_ctr( &ctx, |
| 152 | sizeof( input ), |
| 153 | NULL, |
| 154 | iv, |
| 155 | iv, |
| 156 | input, |
| 157 | output ) ); |
| 158 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 159 | mbedtls_aria_crypt_ctr( &ctx, |
| 160 | sizeof( input ), |
| 161 | &iv_off, |
| 162 | NULL, |
| 163 | iv, |
| 164 | input, |
| 165 | output ) ); |
| 166 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 167 | mbedtls_aria_crypt_ctr( &ctx, |
| 168 | sizeof( input ), |
| 169 | &iv_off, |
| 170 | iv, |
| 171 | NULL, |
| 172 | input, |
| 173 | output ) ); |
| 174 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 175 | mbedtls_aria_crypt_ctr( &ctx, |
| 176 | sizeof( input ), |
| 177 | &iv_off, |
| 178 | iv, |
| 179 | iv, |
| 180 | NULL, |
| 181 | output ) ); |
| 182 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 183 | mbedtls_aria_crypt_ctr( &ctx, |
| 184 | sizeof( input ), |
| 185 | &iv_off, |
| 186 | iv, |
| 187 | iv, |
| 188 | input, |
| 189 | NULL ) ); |
| 190 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
| 191 | |
| 192 | exit: |
| 193 | return; |
| 194 | |
| 195 | } |
| 196 | /* END_CASE */ |
| 197 | |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 198 | /* BEGIN_CASE */ |
| 199 | void aria_encrypt_ecb( char *hex_key_string, char *hex_src_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 200 | char *hex_dst_string, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 201 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 202 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 203 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 204 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 205 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 206 | mbedtls_aria_context ctx; |
| 207 | int key_len, data_len, i; |
| 208 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 209 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 210 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 211 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 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 | |
| 215 | key_len = unhexify( key_str, hex_key_string ); |
| 216 | data_len = unhexify( src_str, hex_src_string ); |
| 217 | |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 218 | TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ) |
| 219 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 220 | if( setkey_result == 0 ) |
| 221 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 222 | for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 223 | { |
Simon Butcher | d08a2f7 | 2018-06-05 15:53:06 +0100 | [diff] [blame] | 224 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i ) |
| 225 | == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 226 | } |
| 227 | hexify( dst_str, output, data_len ); |
| 228 | |
| 229 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 230 | } |
| 231 | |
| 232 | exit: |
| 233 | mbedtls_aria_free( &ctx ); |
| 234 | } |
| 235 | /* END_CASE */ |
| 236 | |
| 237 | /* BEGIN_CASE */ |
| 238 | void aria_decrypt_ecb( char *hex_key_string, char *hex_src_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 239 | char *hex_dst_string, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 240 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 241 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 242 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 243 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 244 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 245 | mbedtls_aria_context ctx; |
| 246 | int key_len, data_len, i; |
| 247 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 248 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 249 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 250 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 251 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 252 | mbedtls_aria_init( &ctx ); |
| 253 | |
| 254 | key_len = unhexify( key_str, hex_key_string ); |
| 255 | data_len = unhexify( src_str, hex_src_string ); |
| 256 | |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 257 | TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 ) |
| 258 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 259 | if( setkey_result == 0 ) |
| 260 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 261 | for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 262 | { |
Simon Butcher | d08a2f7 | 2018-06-05 15:53:06 +0100 | [diff] [blame] | 263 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i ) |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 264 | == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 265 | } |
| 266 | hexify( dst_str, output, data_len ); |
| 267 | |
| 268 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 269 | } |
| 270 | |
| 271 | exit: |
| 272 | mbedtls_aria_free( &ctx ); |
| 273 | } |
| 274 | /* END_CASE */ |
| 275 | |
| 276 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
| 277 | void aria_encrypt_cbc( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 278 | char *hex_src_string, char *hex_dst_string, |
| 279 | int cbc_result ) |
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 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 282 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 283 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 284 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 285 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 286 | mbedtls_aria_context ctx; |
| 287 | int key_len, data_len; |
| 288 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 289 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 290 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 291 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 292 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 293 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 294 | mbedtls_aria_init( &ctx ); |
| 295 | |
| 296 | key_len = unhexify( key_str, hex_key_string ); |
| 297 | unhexify( iv_str, hex_iv_string ); |
| 298 | data_len = unhexify( src_str, hex_src_string ); |
| 299 | |
| 300 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 301 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, data_len, |
| 302 | iv_str, src_str, output ) |
| 303 | == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 304 | if( cbc_result == 0 ) |
| 305 | { |
| 306 | hexify( dst_str, output, data_len ); |
| 307 | |
| 308 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 309 | } |
| 310 | |
| 311 | exit: |
| 312 | mbedtls_aria_free( &ctx ); |
| 313 | } |
| 314 | /* END_CASE */ |
| 315 | |
| 316 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
| 317 | void aria_decrypt_cbc( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 318 | char *hex_src_string, char *hex_dst_string, |
| 319 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 320 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 321 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 322 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 323 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 324 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 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 | int key_len, data_len; |
| 328 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 329 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 330 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 331 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 332 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 333 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 334 | mbedtls_aria_init( &ctx ); |
| 335 | |
| 336 | key_len = unhexify( key_str, hex_key_string ); |
| 337 | unhexify( iv_str, hex_iv_string ); |
| 338 | data_len = unhexify( src_str, hex_src_string ); |
| 339 | |
| 340 | mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 341 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, data_len, |
| 342 | iv_str, src_str, output ) |
| 343 | == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 344 | if( cbc_result == 0 ) |
| 345 | { |
| 346 | hexify( dst_str, output, data_len ); |
| 347 | |
| 348 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 349 | } |
| 350 | |
| 351 | exit: |
| 352 | mbedtls_aria_free( &ctx ); |
| 353 | } |
| 354 | /* END_CASE */ |
| 355 | |
| 356 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
| 357 | void aria_encrypt_cfb128( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 358 | char *hex_src_string, char *hex_dst_string, |
| 359 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 360 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 361 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 362 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 363 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 364 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 365 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 366 | mbedtls_aria_context ctx; |
| 367 | size_t iv_offset = 0; |
| 368 | int key_len, data_len; |
| 369 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 370 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 371 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 372 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 373 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 374 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 375 | mbedtls_aria_init( &ctx ); |
| 376 | |
| 377 | key_len = unhexify( key_str, hex_key_string ); |
| 378 | unhexify( iv_str, hex_iv_string ); |
| 379 | data_len = unhexify( src_str, hex_src_string ); |
| 380 | |
| 381 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 382 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT, |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 383 | data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 384 | src_str, output ) |
| 385 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 386 | hexify( dst_str, output, data_len ); |
| 387 | |
| 388 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 389 | |
| 390 | exit: |
| 391 | mbedtls_aria_free( &ctx ); |
| 392 | } |
| 393 | /* END_CASE */ |
| 394 | |
| 395 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
| 396 | void aria_decrypt_cfb128( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 397 | char *hex_src_string, char *hex_dst_string, |
| 398 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 399 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 400 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 401 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 402 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 403 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 404 | unsigned char output[ARIA_MAX_DATASIZE]; |
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; |
| 407 | int key_len, data_len; |
| 408 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 409 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 410 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 411 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 412 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 413 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 414 | mbedtls_aria_init( &ctx ); |
| 415 | |
| 416 | key_len = unhexify( key_str, hex_key_string ); |
| 417 | unhexify( iv_str, hex_iv_string ); |
| 418 | data_len = unhexify( src_str, hex_src_string ); |
| 419 | |
| 420 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 421 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT, |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 422 | data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 423 | src_str, output ) |
| 424 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 425 | hexify( dst_str, output, data_len ); |
| 426 | |
| 427 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 428 | |
| 429 | exit: |
| 430 | mbedtls_aria_free( &ctx ); |
| 431 | } |
| 432 | /* END_CASE */ |
| 433 | |
| 434 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
| 435 | void aria_encrypt_ctr( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 436 | char *hex_src_string, char *hex_dst_string, |
| 437 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 438 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 439 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 440 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 441 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 442 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 443 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 444 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 445 | mbedtls_aria_context ctx; |
| 446 | size_t iv_offset = 0; |
| 447 | int key_len, data_len; |
| 448 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 449 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 450 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 451 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 452 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 453 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 454 | mbedtls_aria_init( &ctx ); |
| 455 | |
| 456 | key_len = unhexify( key_str, hex_key_string ); |
| 457 | unhexify( iv_str, hex_iv_string ); |
| 458 | data_len = unhexify( src_str, hex_src_string ); |
| 459 | |
| 460 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 461 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 462 | blk, src_str, output ) |
| 463 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 464 | hexify( dst_str, output, data_len ); |
| 465 | |
| 466 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 467 | |
| 468 | exit: |
| 469 | mbedtls_aria_free( &ctx ); |
| 470 | } |
| 471 | /* END_CASE */ |
| 472 | |
| 473 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
| 474 | void aria_decrypt_ctr( char *hex_key_string, char *hex_iv_string, |
Manuel Pégourié-Gonnard | d82d791 | 2018-03-01 09:43:21 +0100 | [diff] [blame] | 475 | char *hex_src_string, char *hex_dst_string, |
| 476 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 477 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 478 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 479 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 480 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 481 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 482 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 483 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 484 | mbedtls_aria_context ctx; |
| 485 | size_t iv_offset = 0; |
| 486 | int key_len, data_len; |
| 487 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 488 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 489 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 490 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 491 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 492 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 493 | mbedtls_aria_init( &ctx ); |
| 494 | |
| 495 | key_len = unhexify( key_str, hex_key_string ); |
| 496 | unhexify( iv_str, hex_iv_string ); |
| 497 | data_len = unhexify( src_str, hex_src_string ); |
| 498 | |
| 499 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 500 | TEST_ASSERT( mbedtls_aria_crypt_ctr( &ctx, data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 501 | blk, src_str, output ) |
| 502 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 503 | hexify( dst_str, output, data_len ); |
| 504 | |
| 505 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 506 | |
| 507 | exit: |
| 508 | mbedtls_aria_free( &ctx ); |
| 509 | } |
| 510 | /* END_CASE */ |
| 511 | |
| 512 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
| 513 | void aria_selftest() |
| 514 | { |
| 515 | TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 ); |
| 516 | } |
| 517 | /* END_CASE */ |