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 | |
Shaun Case | 0e7791f | 2021-12-20 21:14:10 -0800 | [diff] [blame] | 4 | /* Maximum size of data used by test vectors |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 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 */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 9 | #define ARIA_MAX_KEY_STR (2 * MBEDTLS_ARIA_MAX_KEYSIZE + 1) |
| 10 | #define ARIA_BLOCK_STR (2 * MBEDTLS_ARIA_BLOCKSIZE + 1) |
| 11 | #define ARIA_MAX_DATA_STR (2 * ARIA_MAX_DATASIZE + 1) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 12 | /* END_HEADER */ |
| 13 | |
| 14 | /* BEGIN_DEPENDENCIES |
| 15 | * depends_on:MBEDTLS_ARIA_C |
| 16 | * END_DEPENDENCIES |
| 17 | */ |
| 18 | |
| 19 | /* BEGIN_CASE */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 20 | void aria_valid_param() |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 21 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 22 | TEST_VALID_PARAM(mbedtls_aria_free(NULL)); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 23 | } |
| 24 | /* END_CASE */ |
| 25 | |
| 26 | /* BEGIN_CASE depends_on:MBEDTLS_CHECK_PARAMS:!MBEDTLS_PARAM_FAILED_ALT */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 27 | void aria_invalid_param() |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 28 | { |
| 29 | mbedtls_aria_context ctx; |
| 30 | unsigned char key[128 / 8] = { 0 }; |
| 31 | unsigned char input[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 32 | unsigned char output[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 33 | unsigned char iv[MBEDTLS_ARIA_BLOCKSIZE] = { 0 }; |
| 34 | size_t iv_off = 0; |
| 35 | |
| 36 | ((void) iv_off); |
| 37 | ((void) iv); |
| 38 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 39 | TEST_INVALID_PARAM(mbedtls_aria_init(NULL)); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 40 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 41 | TEST_INVALID_PARAM_RET(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 42 | mbedtls_aria_setkey_enc(NULL, key, |
| 43 | sizeof(key))); |
| 44 | TEST_INVALID_PARAM_RET(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 45 | mbedtls_aria_setkey_enc(&ctx, NULL, |
| 46 | sizeof(key))); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 47 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 48 | TEST_INVALID_PARAM_RET(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 49 | mbedtls_aria_setkey_dec(NULL, key, |
| 50 | sizeof(key))); |
| 51 | TEST_INVALID_PARAM_RET(MBEDTLS_ERR_ARIA_BAD_INPUT_DATA, |
| 52 | mbedtls_aria_setkey_dec(&ctx, NULL, |
| 53 | sizeof(key))); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 54 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 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)); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 61 | |
| 62 | #if defined(MBEDTLS_CIPHER_MODE_CBC) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 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)); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 98 | #endif /* MBEDTLS_CIPHER_MODE_CBC */ |
| 99 | |
| 100 | #if defined(MBEDTLS_CIPHER_MODE_CFB) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 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)); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 149 | #endif /* MBEDTLS_CIPHER_MODE_CFB */ |
| 150 | |
| 151 | #if defined(MBEDTLS_CIPHER_MODE_CTR) |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 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)); |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 200 | #endif /* MBEDTLS_CIPHER_MODE_CTR */ |
| 201 | |
| 202 | exit: |
| 203 | return; |
| 204 | |
| 205 | } |
| 206 | /* END_CASE */ |
| 207 | |
| 208 | /* BEGIN_CASE */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 209 | void aria_encrypt_ecb(data_t *key_str, data_t *src_str, |
| 210 | data_t *expected_output, 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 output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 213 | mbedtls_aria_context ctx; |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 214 | size_t i; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 215 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 216 | memset(output, 0x00, sizeof(output)); |
| 217 | mbedtls_aria_init(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 218 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 219 | TEST_ASSERT(mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8) |
| 220 | == setkey_result); |
| 221 | if (setkey_result == 0) { |
| 222 | for (i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE) { |
| 223 | TEST_ASSERT(mbedtls_aria_crypt_ecb(&ctx, src_str->x + i, |
| 224 | output + i) == 0); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 225 | } |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 226 | |
Tom Cosgrove | ba3b14d | 2023-09-04 11:23:02 +0100 | [diff] [blame] | 227 | TEST_MEMORY_COMPARE(output, expected_output->len, |
Tom Cosgrove | a240fe3 | 2023-09-04 11:29:39 +0100 | [diff] [blame] | 228 | expected_output->x, expected_output->len); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 232 | mbedtls_aria_free(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 233 | } |
| 234 | /* END_CASE */ |
| 235 | |
| 236 | /* BEGIN_CASE */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 237 | void aria_decrypt_ecb(data_t *key_str, data_t *src_str, |
| 238 | data_t *expected_output, int setkey_result) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 239 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 240 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 241 | mbedtls_aria_context ctx; |
Ronald Cron | 9ed4073 | 2020-06-25 09:03:34 +0200 | [diff] [blame] | 242 | size_t i; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 243 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 244 | memset(output, 0x00, sizeof(output)); |
| 245 | mbedtls_aria_init(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 246 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 247 | TEST_ASSERT(mbedtls_aria_setkey_dec(&ctx, key_str->x, key_str->len * 8) |
| 248 | == setkey_result); |
| 249 | if (setkey_result == 0) { |
| 250 | for (i = 0; i < src_str->len; i += MBEDTLS_ARIA_BLOCKSIZE) { |
| 251 | TEST_ASSERT(mbedtls_aria_crypt_ecb(&ctx, src_str->x + i, |
| 252 | output + i) == 0); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 253 | } |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 254 | |
Tom Cosgrove | ba3b14d | 2023-09-04 11:23:02 +0100 | [diff] [blame] | 255 | TEST_MEMORY_COMPARE(output, expected_output->len, |
Tom Cosgrove | a240fe3 | 2023-09-04 11:29:39 +0100 | [diff] [blame] | 256 | expected_output->x, expected_output->len); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 260 | mbedtls_aria_free(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 261 | } |
| 262 | /* END_CASE */ |
| 263 | |
| 264 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 265 | void aria_encrypt_cbc(data_t *key_str, data_t *iv_str, |
| 266 | data_t *src_str, data_t *expected_output, |
| 267 | int cbc_result) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 268 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 269 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 270 | mbedtls_aria_context ctx; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 271 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 272 | memset(output, 0x00, sizeof(output)); |
| 273 | mbedtls_aria_init(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 274 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 275 | mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8); |
| 276 | TEST_ASSERT(mbedtls_aria_crypt_cbc(&ctx, MBEDTLS_ARIA_ENCRYPT, |
| 277 | src_str->len, iv_str->x, src_str->x, |
| 278 | output) == cbc_result); |
| 279 | if (cbc_result == 0) { |
Tom Cosgrove | ba3b14d | 2023-09-04 11:23:02 +0100 | [diff] [blame] | 280 | TEST_MEMORY_COMPARE(output, expected_output->len, |
Tom Cosgrove | a240fe3 | 2023-09-04 11:29:39 +0100 | [diff] [blame] | 281 | expected_output->x, expected_output->len); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 285 | mbedtls_aria_free(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 286 | } |
| 287 | /* END_CASE */ |
| 288 | |
| 289 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 290 | void aria_decrypt_cbc(data_t *key_str, data_t *iv_str, |
| 291 | data_t *src_str, data_t *expected_output, |
| 292 | int cbc_result) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 293 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 294 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 295 | mbedtls_aria_context ctx; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 296 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 297 | memset(output, 0x00, sizeof(output)); |
| 298 | mbedtls_aria_init(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 299 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 300 | mbedtls_aria_setkey_dec(&ctx, key_str->x, key_str->len * 8); |
| 301 | TEST_ASSERT(mbedtls_aria_crypt_cbc(&ctx, MBEDTLS_ARIA_DECRYPT, |
| 302 | src_str->len, iv_str->x, src_str->x, |
| 303 | output) == cbc_result); |
| 304 | if (cbc_result == 0) { |
Tom Cosgrove | ba3b14d | 2023-09-04 11:23:02 +0100 | [diff] [blame] | 305 | TEST_MEMORY_COMPARE(output, expected_output->len, |
Tom Cosgrove | a240fe3 | 2023-09-04 11:29:39 +0100 | [diff] [blame] | 306 | expected_output->x, expected_output->len); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 310 | mbedtls_aria_free(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 311 | } |
| 312 | /* END_CASE */ |
| 313 | |
| 314 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 315 | void aria_encrypt_cfb128(data_t *key_str, data_t *iv_str, |
| 316 | data_t *src_str, data_t *expected_output, |
| 317 | int result) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 318 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 319 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 320 | mbedtls_aria_context ctx; |
| 321 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 322 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 323 | memset(output, 0x00, sizeof(output)); |
| 324 | mbedtls_aria_init(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 325 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 326 | mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8); |
| 327 | TEST_ASSERT(mbedtls_aria_crypt_cfb128(&ctx, MBEDTLS_ARIA_ENCRYPT, |
| 328 | src_str->len, &iv_offset, |
| 329 | iv_str->x, src_str->x, output) |
| 330 | == result); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 331 | |
Tom Cosgrove | ba3b14d | 2023-09-04 11:23:02 +0100 | [diff] [blame] | 332 | TEST_MEMORY_COMPARE(output, expected_output->len, |
Tom Cosgrove | a240fe3 | 2023-09-04 11:29:39 +0100 | [diff] [blame] | 333 | expected_output->x, expected_output->len); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 334 | |
| 335 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 336 | mbedtls_aria_free(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 337 | } |
| 338 | /* END_CASE */ |
| 339 | |
| 340 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 341 | void aria_decrypt_cfb128(data_t *key_str, data_t *iv_str, |
| 342 | data_t *src_str, data_t *expected_output, |
| 343 | int result) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 344 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 345 | unsigned char output[ARIA_MAX_DATASIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 346 | mbedtls_aria_context ctx; |
| 347 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 348 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 349 | memset(output, 0x00, sizeof(output)); |
| 350 | mbedtls_aria_init(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 351 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 352 | mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8); |
| 353 | TEST_ASSERT(mbedtls_aria_crypt_cfb128(&ctx, MBEDTLS_ARIA_DECRYPT, |
| 354 | src_str->len, &iv_offset, |
| 355 | iv_str->x, src_str->x, output) |
| 356 | == result); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 357 | |
Tom Cosgrove | ba3b14d | 2023-09-04 11:23:02 +0100 | [diff] [blame] | 358 | TEST_MEMORY_COMPARE(output, expected_output->len, |
Tom Cosgrove | a240fe3 | 2023-09-04 11:29:39 +0100 | [diff] [blame] | 359 | expected_output->x, expected_output->len); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 360 | |
| 361 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 362 | mbedtls_aria_free(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 363 | } |
| 364 | /* END_CASE */ |
| 365 | |
| 366 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 367 | void aria_encrypt_ctr(data_t *key_str, data_t *iv_str, |
| 368 | data_t *src_str, data_t *expected_output, |
| 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 output[ARIA_MAX_DATASIZE]; |
| 372 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
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; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 375 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 376 | memset(output, 0x00, sizeof(output)); |
| 377 | mbedtls_aria_init(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 378 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 379 | mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8); |
| 380 | TEST_ASSERT(mbedtls_aria_crypt_ctr(&ctx, src_str->len, &iv_offset, |
| 381 | iv_str->x, blk, src_str->x, output) |
| 382 | == result); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 383 | |
Tom Cosgrove | ba3b14d | 2023-09-04 11:23:02 +0100 | [diff] [blame] | 384 | TEST_MEMORY_COMPARE(output, expected_output->len, |
Tom Cosgrove | a240fe3 | 2023-09-04 11:29:39 +0100 | [diff] [blame] | 385 | expected_output->x, expected_output->len); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 386 | |
| 387 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 388 | mbedtls_aria_free(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 389 | } |
| 390 | /* END_CASE */ |
| 391 | |
| 392 | /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CTR */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 393 | void aria_decrypt_ctr(data_t *key_str, data_t *iv_str, |
| 394 | data_t *src_str, data_t *expected_output, |
| 395 | int result) |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 396 | { |
Manuel Pégourié-Gonnard | 8abc349 | 2018-03-01 10:02:47 +0100 | [diff] [blame] | 397 | unsigned char output[ARIA_MAX_DATASIZE]; |
| 398 | unsigned char blk[MBEDTLS_ARIA_BLOCKSIZE]; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 399 | mbedtls_aria_context ctx; |
| 400 | size_t iv_offset = 0; |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 401 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 402 | memset(output, 0x00, sizeof(output)); |
| 403 | mbedtls_aria_init(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 404 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 405 | mbedtls_aria_setkey_enc(&ctx, key_str->x, key_str->len * 8); |
| 406 | TEST_ASSERT(mbedtls_aria_crypt_ctr(&ctx, src_str->len, &iv_offset, |
| 407 | iv_str->x, blk, src_str->x, output) |
| 408 | == result); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 409 | |
Tom Cosgrove | ba3b14d | 2023-09-04 11:23:02 +0100 | [diff] [blame] | 410 | TEST_MEMORY_COMPARE(output, expected_output->len, |
Tom Cosgrove | a240fe3 | 2023-09-04 11:29:39 +0100 | [diff] [blame] | 411 | expected_output->x, expected_output->len); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 412 | |
| 413 | exit: |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 414 | mbedtls_aria_free(&ctx); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 415 | } |
| 416 | /* END_CASE */ |
| 417 | |
| 418 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
| 419 | void aria_selftest() |
| 420 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 421 | TEST_ASSERT(mbedtls_aria_self_test(1) == 0); |
Markku-Juhani O. Saarinen | 8df81e0 | 2017-12-01 14:26:40 +0000 | [diff] [blame] | 422 | } |
| 423 | /* END_CASE */ |