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