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 | |
Hanno Becker | 0294072 | 2018-12-18 18:18:45 +0000 | [diff] [blame] | 36 | ((void) iv_off); |
| 37 | ((void) iv); |
| 38 | |
Hanno Becker | 9e45c16 | 2018-12-11 21:51:38 +0000 | [diff] [blame] | 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, |
Hanno Becker | fac1d44 | 2018-12-17 12:07:01 +0000 | [diff] [blame] | 45 | mbedtls_aria_setkey_enc( &ctx, NULL, |
| 46 | sizeof( key ) ) ); |
Hanno Becker | 9e45c16 | 2018-12-11 21:51:38 +0000 | [diff] [blame] | 47 | |
| 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( NULL, key, |
| 50 | sizeof( key ) ) ); |
Hanno Becker | 9e45c16 | 2018-12-11 21:51:38 +0000 | [diff] [blame] | 51 | TEST_INVALID_PARAM_RET( MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
Hanno Becker | fac1d44 | 2018-12-17 12:07:01 +0000 | [diff] [blame] | 52 | mbedtls_aria_setkey_dec( &ctx, NULL, |
| 53 | sizeof( key ) ) ); |
Hanno Becker | 9e45c16 | 2018-12-11 21:51:38 +0000 | [diff] [blame] | 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 | |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 208 | /* BEGIN_CASE */ |
| 209 | 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] | 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 key_str[ARIA_MAX_KEY_STR]; |
| 213 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 214 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 215 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 216 | mbedtls_aria_context ctx; |
| 217 | int key_len, data_len, i; |
| 218 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 219 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 220 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 221 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 222 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 223 | mbedtls_aria_init( &ctx ); |
| 224 | |
| 225 | key_len = unhexify( key_str, hex_key_string ); |
| 226 | data_len = unhexify( src_str, hex_src_string ); |
| 227 | |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 228 | TEST_ASSERT( mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ) |
| 229 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 230 | if( setkey_result == 0 ) |
| 231 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 232 | for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 233 | { |
Simon Butcher | d08a2f7 | 2018-06-05 15:53:06 +0100 | [diff] [blame] | 234 | TEST_ASSERT( mbedtls_aria_crypt_ecb( &ctx, src_str + i, output + i ) |
| 235 | == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 236 | } |
| 237 | hexify( dst_str, output, data_len ); |
| 238 | |
| 239 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 240 | } |
| 241 | |
| 242 | exit: |
| 243 | mbedtls_aria_free( &ctx ); |
| 244 | } |
| 245 | /* END_CASE */ |
| 246 | |
| 247 | /* BEGIN_CASE */ |
| 248 | 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] | 249 | char *hex_dst_string, int setkey_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 250 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 251 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 252 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 253 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 254 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 255 | mbedtls_aria_context ctx; |
| 256 | int key_len, data_len, i; |
| 257 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 258 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 259 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 260 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 261 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 262 | mbedtls_aria_init( &ctx ); |
| 263 | |
| 264 | key_len = unhexify( key_str, hex_key_string ); |
| 265 | data_len = unhexify( src_str, hex_src_string ); |
| 266 | |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 267 | TEST_ASSERT( mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 ) |
| 268 | == setkey_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 269 | if( setkey_result == 0 ) |
| 270 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 271 | for( i = 0; i < data_len; i += MBEDTLS_ARIA_BLOCKSIZE ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 272 | { |
Simon Butcher | d08a2f7 | 2018-06-05 15:53:06 +0100 | [diff] [blame] | 273 | 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] | 274 | == 0 ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 275 | } |
| 276 | hexify( dst_str, output, data_len ); |
| 277 | |
| 278 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 279 | } |
| 280 | |
| 281 | exit: |
| 282 | mbedtls_aria_free( &ctx ); |
| 283 | } |
| 284 | /* END_CASE */ |
| 285 | |
| 286 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
| 287 | 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] | 288 | char *hex_src_string, char *hex_dst_string, |
| 289 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 290 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 291 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 292 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 293 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 294 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 295 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 296 | mbedtls_aria_context ctx; |
| 297 | int key_len, data_len; |
| 298 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 299 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 300 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 301 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 302 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 303 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 304 | mbedtls_aria_init( &ctx ); |
| 305 | |
| 306 | key_len = unhexify( key_str, hex_key_string ); |
| 307 | unhexify( iv_str, hex_iv_string ); |
| 308 | data_len = unhexify( src_str, hex_src_string ); |
| 309 | |
| 310 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 311 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_ENCRYPT, data_len, |
| 312 | iv_str, src_str, output ) |
| 313 | == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 314 | if( cbc_result == 0 ) |
| 315 | { |
| 316 | hexify( dst_str, output, data_len ); |
| 317 | |
| 318 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 319 | } |
| 320 | |
| 321 | exit: |
| 322 | mbedtls_aria_free( &ctx ); |
| 323 | } |
| 324 | /* END_CASE */ |
| 325 | |
| 326 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
| 327 | 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] | 328 | char *hex_src_string, char *hex_dst_string, |
| 329 | int cbc_result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 330 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 331 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 332 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 333 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 334 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 335 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 336 | mbedtls_aria_context ctx; |
| 337 | int key_len, data_len; |
| 338 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 339 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 340 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 341 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 342 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 343 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 344 | mbedtls_aria_init( &ctx ); |
| 345 | |
| 346 | key_len = unhexify( key_str, hex_key_string ); |
| 347 | unhexify( iv_str, hex_iv_string ); |
| 348 | data_len = unhexify( src_str, hex_src_string ); |
| 349 | |
| 350 | mbedtls_aria_setkey_dec( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 351 | TEST_ASSERT( mbedtls_aria_crypt_cbc( &ctx, MBEDTLS_ARIA_DECRYPT, data_len, |
| 352 | iv_str, src_str, output ) |
| 353 | == cbc_result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 354 | if( cbc_result == 0 ) |
| 355 | { |
| 356 | hexify( dst_str, output, data_len ); |
| 357 | |
| 358 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 359 | } |
| 360 | |
| 361 | exit: |
| 362 | mbedtls_aria_free( &ctx ); |
| 363 | } |
| 364 | /* END_CASE */ |
| 365 | |
| 366 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
| 367 | 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] | 368 | char *hex_src_string, char *hex_dst_string, |
| 369 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 370 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 371 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 372 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 373 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 374 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 375 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 376 | mbedtls_aria_context ctx; |
| 377 | size_t iv_offset = 0; |
| 378 | int key_len, data_len; |
| 379 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 380 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 381 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 382 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 383 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 384 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 385 | mbedtls_aria_init( &ctx ); |
| 386 | |
| 387 | key_len = unhexify( key_str, hex_key_string ); |
| 388 | unhexify( iv_str, hex_iv_string ); |
| 389 | data_len = unhexify( src_str, hex_src_string ); |
| 390 | |
| 391 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 392 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_ENCRYPT, |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 393 | data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 394 | src_str, output ) |
| 395 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 396 | hexify( dst_str, output, data_len ); |
| 397 | |
| 398 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 399 | |
| 400 | exit: |
| 401 | mbedtls_aria_free( &ctx ); |
| 402 | } |
| 403 | /* END_CASE */ |
| 404 | |
| 405 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
| 406 | 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] | 407 | char *hex_src_string, char *hex_dst_string, |
| 408 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 409 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 410 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 411 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 412 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 413 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 414 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 415 | mbedtls_aria_context ctx; |
| 416 | size_t iv_offset = 0; |
| 417 | int key_len, data_len; |
| 418 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 419 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 420 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 421 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 422 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 423 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 424 | mbedtls_aria_init( &ctx ); |
| 425 | |
| 426 | key_len = unhexify( key_str, hex_key_string ); |
| 427 | unhexify( iv_str, hex_iv_string ); |
| 428 | data_len = unhexify( src_str, hex_src_string ); |
| 429 | |
| 430 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
| 431 | TEST_ASSERT( mbedtls_aria_crypt_cfb128( &ctx, MBEDTLS_ARIA_DECRYPT, |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 432 | data_len, &iv_offset, iv_str, |
Manuel Pégourié-Gonnard | 977dc36 | 2018-03-01 13:51:52 +0100 | [diff] [blame] | 433 | src_str, output ) |
| 434 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 435 | hexify( dst_str, output, data_len ); |
| 436 | |
| 437 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 438 | |
| 439 | exit: |
| 440 | mbedtls_aria_free( &ctx ); |
| 441 | } |
| 442 | /* END_CASE */ |
| 443 | |
| 444 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
| 445 | 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] | 446 | char *hex_src_string, char *hex_dst_string, |
| 447 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 448 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 449 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 450 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 451 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 452 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 453 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 454 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 455 | mbedtls_aria_context ctx; |
| 456 | size_t iv_offset = 0; |
| 457 | int key_len, data_len; |
| 458 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 459 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 460 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 461 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 462 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 463 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 464 | mbedtls_aria_init( &ctx ); |
| 465 | |
| 466 | key_len = unhexify( key_str, hex_key_string ); |
| 467 | unhexify( iv_str, hex_iv_string ); |
| 468 | data_len = unhexify( src_str, hex_src_string ); |
| 469 | |
| 470 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 471 | 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] | 472 | blk, src_str, output ) |
| 473 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 474 | hexify( dst_str, output, data_len ); |
| 475 | |
| 476 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 477 | |
| 478 | exit: |
| 479 | mbedtls_aria_free( &ctx ); |
| 480 | } |
| 481 | /* END_CASE */ |
| 482 | |
| 483 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
| 484 | 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] | 485 | char *hex_src_string, char *hex_dst_string, |
| 486 | int result ) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 487 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 488 | unsigned char key_str[ARIA_MAX_KEY_STR]; |
| 489 | unsigned char iv_str[ARIA_BLOCK_STR]; |
| 490 | unsigned char src_str[ARIA_MAX_DATA_STR]; |
| 491 | unsigned char dst_str[ARIA_MAX_DATA_STR]; |
| 492 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 493 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 494 | mbedtls_aria_context ctx; |
| 495 | size_t iv_offset = 0; |
| 496 | int key_len, data_len; |
| 497 | |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 498 | memset( key_str, 0x00, sizeof( key_str ) ); |
| 499 | memset( iv_str, 0x00, sizeof( iv_str ) ); |
| 500 | memset( src_str, 0x00, sizeof( src_str ) ); |
| 501 | memset( dst_str, 0x00, sizeof( dst_str ) ); |
| 502 | memset( output, 0x00, sizeof( output ) ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 503 | mbedtls_aria_init( &ctx ); |
| 504 | |
| 505 | key_len = unhexify( key_str, hex_key_string ); |
| 506 | unhexify( iv_str, hex_iv_string ); |
| 507 | data_len = unhexify( src_str, hex_src_string ); |
| 508 | |
| 509 | mbedtls_aria_setkey_enc( &ctx, key_str, key_len * 8 ); |
Manuel Pégourié-Gonnard | 4231e7f | 2018-02-28 10:54:31 +0100 | [diff] [blame] | 510 | 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] | 511 | blk, src_str, output ) |
| 512 | == result ); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 513 | hexify( dst_str, output, data_len ); |
| 514 | |
| 515 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
| 516 | |
| 517 | exit: |
| 518 | mbedtls_aria_free( &ctx ); |
| 519 | } |
| 520 | /* END_CASE */ |
| 521 | |
| 522 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
| 523 | void aria_selftest() |
| 524 | { |
| 525 | TEST_ASSERT( mbedtls_aria_self_test( 1 ) == 0 ); |
| 526 | } |
| 527 | /* END_CASE */ |