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