Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
| 2 | #include "mbedtls/cipher.h" |
| 3 | #include "mbedtls/cmac.h" |
| 4 | /* END_HEADER */ |
| 5 | |
| 6 | /* BEGIN_DEPENDENCIES |
| 7 | * depends_on:MBEDTLS_CMAC_C |
| 8 | * END_DEPENDENCIES |
| 9 | */ |
| 10 | |
| 11 | /* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 12 | void mbedtls_cmac_self_test() |
Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 13 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 14 | TEST_ASSERT(mbedtls_cmac_self_test(1) == 0); |
Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 15 | } |
| 16 | /* END_CASE */ |
| 17 | |
| 18 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 19 | void mbedtls_cmac_null_args() |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 20 | { |
| 21 | mbedtls_cipher_context_t ctx; |
| 22 | const mbedtls_cipher_info_t *cipher_info; |
| 23 | unsigned char test_key[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| 24 | unsigned char test_data[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| 25 | unsigned char test_output[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| 26 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 27 | mbedtls_cipher_init(&ctx); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 28 | |
| 29 | /* Test NULL cipher info */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 30 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, test_data, 16) == |
| 31 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 32 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 33 | cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_ECB); |
| 34 | TEST_ASSERT(mbedtls_cipher_setup(&ctx, cipher_info) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 35 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 36 | TEST_ASSERT(mbedtls_cipher_cmac_starts(NULL, test_key, 128) == |
| 37 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 38 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 39 | TEST_ASSERT(mbedtls_cipher_cmac_starts(&ctx, NULL, 128) == |
| 40 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 41 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 42 | TEST_ASSERT(mbedtls_cipher_cmac_update(NULL, test_data, 16) == |
| 43 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 44 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 45 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, NULL, 16) == |
| 46 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 47 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 48 | TEST_ASSERT(mbedtls_cipher_cmac_finish(NULL, test_output) == |
| 49 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 50 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 51 | TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, NULL) == |
| 52 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 53 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 54 | TEST_ASSERT(mbedtls_cipher_cmac_reset(NULL) == |
| 55 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 56 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 57 | TEST_ASSERT(mbedtls_cipher_cmac(NULL, |
| 58 | test_key, 128, |
| 59 | test_data, 16, |
| 60 | test_output) == |
| 61 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 62 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 63 | TEST_ASSERT(mbedtls_cipher_cmac(cipher_info, |
| 64 | NULL, 128, |
| 65 | test_data, 16, |
| 66 | test_output) == |
| 67 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 68 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 69 | TEST_ASSERT(mbedtls_cipher_cmac(cipher_info, |
| 70 | test_key, 128, |
| 71 | NULL, 16, |
| 72 | test_output) == |
| 73 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 74 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 75 | TEST_ASSERT(mbedtls_cipher_cmac(cipher_info, |
| 76 | test_key, 128, |
| 77 | test_data, 16, |
| 78 | NULL) == |
| 79 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Andrzej Kurek | f502bcb | 2022-09-27 09:27:56 -0400 | [diff] [blame] | 80 | #if defined(MBEDTLS_AES_C) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 81 | TEST_ASSERT(mbedtls_aes_cmac_prf_128(NULL, 16, |
| 82 | test_data, 16, |
| 83 | test_output) == |
| 84 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 85 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 86 | TEST_ASSERT(mbedtls_aes_cmac_prf_128(test_key, 16, |
| 87 | NULL, 16, |
| 88 | test_output) == |
| 89 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 90 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 91 | TEST_ASSERT(mbedtls_aes_cmac_prf_128(test_key, 16, |
| 92 | test_data, 16, |
| 93 | NULL) == |
| 94 | MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA); |
Andrzej Kurek | f502bcb | 2022-09-27 09:27:56 -0400 | [diff] [blame] | 95 | #endif |
Andres AG | 8abc6b8 | 2016-10-11 15:41:40 +0100 | [diff] [blame] | 96 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 97 | mbedtls_cipher_free(&ctx); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 98 | } |
| 99 | /* END_CASE */ |
| 100 | |
| 101 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 102 | void mbedtls_cmac_setkey(int cipher_type, int key_size, int result) |
Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 103 | { |
| 104 | const mbedtls_cipher_info_t *cipher_info; |
| 105 | unsigned char key[32]; |
| 106 | unsigned char buf[16]; |
| 107 | unsigned char tmp[16]; |
| 108 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 109 | memset(key, 0x2A, sizeof(key)); |
| 110 | TEST_ASSERT((unsigned) key_size <= 8 * sizeof(key)); |
Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 111 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 112 | TEST_ASSERT((cipher_info = mbedtls_cipher_info_from_type(cipher_type)) |
| 113 | != NULL); |
Gilles Peskine | 4f4d4b2 | 2023-06-14 17:34:31 +0200 | [diff] [blame] | 114 | TEST_LE_U(mbedtls_cipher_info_get_block_size(cipher_info), |
| 115 | MBEDTLS_CIPHER_BLKSIZE_MAX); |
Gilles Peskine | 7282a9e | 2023-06-14 17:49:02 +0200 | [diff] [blame^] | 116 | TEST_LE_U(mbedtls_cipher_info_get_block_size(cipher_info), |
| 117 | MBEDTLS_CMAC_MAX_BLOCK_SIZE); |
Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 118 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 119 | memset(buf, 0x2A, sizeof(buf)); |
| 120 | TEST_ASSERT((result == mbedtls_cipher_cmac(cipher_info, key, key_size, |
| 121 | buf, 16, tmp)) != 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 122 | } |
| 123 | /* END_CASE */ |
| 124 | |
| 125 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 126 | void mbedtls_cmac_multiple_blocks(int cipher_type, data_t *key, |
| 127 | int keybits, int block_size, |
| 128 | data_t *block1, int block1_len, |
| 129 | data_t *block2, int block2_len, |
| 130 | data_t *block3, int block3_len, |
| 131 | data_t *block4, int block4_len, |
| 132 | data_t *expected_result) |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 133 | { |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 134 | const mbedtls_cipher_info_t *cipher_info; |
| 135 | mbedtls_cipher_context_t ctx; |
| 136 | unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| 137 | |
| 138 | /* Convert the test parameters to binary data */ |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 139 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 140 | mbedtls_cipher_init(&ctx); |
Andres AG | 8abc6b8 | 2016-10-11 15:41:40 +0100 | [diff] [blame] | 141 | |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 142 | /* Validate the test inputs */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 143 | TEST_ASSERT(block1_len <= 100); |
| 144 | TEST_ASSERT(block2_len <= 100); |
| 145 | TEST_ASSERT(block3_len <= 100); |
| 146 | TEST_ASSERT(block4_len <= 100); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 147 | |
| 148 | /* Set up */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 149 | TEST_ASSERT((cipher_info = mbedtls_cipher_info_from_type(cipher_type)) |
| 150 | != NULL); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 151 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 152 | TEST_ASSERT(mbedtls_cipher_setup(&ctx, cipher_info) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 153 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 154 | TEST_ASSERT(mbedtls_cipher_cmac_starts(&ctx, |
| 155 | (const unsigned char *) key->x, |
| 156 | keybits) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 157 | |
| 158 | /* Multiple partial and complete blocks. A negative length means skip the |
| 159 | * update operation */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 160 | if (block1_len >= 0) { |
| 161 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 162 | (unsigned char *) block1->x, |
| 163 | block1_len) == 0); |
| 164 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 165 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 166 | if (block2_len >= 0) { |
| 167 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 168 | (unsigned char *) block2->x, |
| 169 | block2_len) == 0); |
| 170 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 171 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 172 | if (block3_len >= 0) { |
| 173 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 174 | (unsigned char *) block3->x, |
| 175 | block3_len) == 0); |
| 176 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 177 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 178 | if (block4_len >= 0) { |
| 179 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 180 | (unsigned char *) block4->x, |
| 181 | block4_len) == 0); |
| 182 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 183 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 184 | TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 185 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 186 | TEST_ASSERT(memcmp(output, expected_result->x, block_size) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 187 | |
Simon Butcher | bd8d221 | 2016-10-11 12:05:51 +0100 | [diff] [blame] | 188 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 189 | mbedtls_cipher_free(&ctx); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 190 | } |
| 191 | /* END_CASE */ |
| 192 | |
| 193 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 194 | void mbedtls_cmac_multiple_operations_same_key(int cipher_type, |
| 195 | data_t *key, int keybits, |
| 196 | int block_size, |
| 197 | data_t *block_a1, |
| 198 | int block_a1_len, |
| 199 | data_t *block_a2, |
| 200 | int block_a2_len, |
| 201 | data_t *block_a3, |
| 202 | int block_a3_len, |
| 203 | data_t *expected_result_a, |
| 204 | data_t *block_b1, |
| 205 | int block_b1_len, |
| 206 | data_t *block_b2, |
| 207 | int block_b2_len, |
| 208 | data_t *block_b3, |
| 209 | int block_b3_len, |
| 210 | data_t *expected_result_b |
| 211 | ) |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 212 | { |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 213 | const mbedtls_cipher_info_t *cipher_info; |
| 214 | mbedtls_cipher_context_t ctx; |
| 215 | unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| 216 | |
| 217 | /* Convert the test parameters to binary data */ |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 218 | |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 219 | |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 220 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 221 | mbedtls_cipher_init(&ctx); |
Andres AG | 8abc6b8 | 2016-10-11 15:41:40 +0100 | [diff] [blame] | 222 | |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 223 | /* Validate the test inputs */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 224 | TEST_ASSERT(block_a1_len <= 100); |
| 225 | TEST_ASSERT(block_a2_len <= 100); |
| 226 | TEST_ASSERT(block_a3_len <= 100); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 227 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 228 | TEST_ASSERT(block_b1_len <= 100); |
| 229 | TEST_ASSERT(block_b2_len <= 100); |
| 230 | TEST_ASSERT(block_b3_len <= 100); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 231 | |
| 232 | /* Set up */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 233 | TEST_ASSERT((cipher_info = mbedtls_cipher_info_from_type(cipher_type)) |
| 234 | != NULL); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 235 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 236 | TEST_ASSERT(mbedtls_cipher_setup(&ctx, cipher_info) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 237 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 238 | TEST_ASSERT(mbedtls_cipher_cmac_starts(&ctx, |
| 239 | (const unsigned char *) key->x, |
| 240 | keybits) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 241 | |
| 242 | /* Sequence A */ |
| 243 | |
| 244 | /* Multiple partial and complete blocks. A negative length means skip the |
| 245 | * update operation */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 246 | if (block_a1_len >= 0) { |
| 247 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 248 | (unsigned char *) block_a1->x, |
| 249 | block_a1_len) == 0); |
| 250 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 251 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 252 | if (block_a2_len >= 0) { |
| 253 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 254 | (unsigned char *) block_a2->x, |
| 255 | block_a2_len) == 0); |
| 256 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 257 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 258 | if (block_a3_len >= 0) { |
| 259 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 260 | (unsigned char *) block_a3->x, |
| 261 | block_a3_len) == 0); |
| 262 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 263 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 264 | TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 265 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 266 | TEST_ASSERT(memcmp(output, expected_result_a->x, block_size) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 267 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 268 | TEST_ASSERT(mbedtls_cipher_cmac_reset(&ctx) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 269 | |
| 270 | /* Sequence B */ |
| 271 | |
| 272 | /* Multiple partial and complete blocks. A negative length means skip the |
| 273 | * update operation */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 274 | if (block_b1_len >= 0) { |
| 275 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 276 | (unsigned char *) block_b1->x, |
| 277 | block_b1_len) == 0); |
| 278 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 279 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 280 | if (block_b2_len >= 0) { |
| 281 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 282 | (unsigned char *) block_b2->x, |
| 283 | block_b2_len) == 0); |
| 284 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 285 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 286 | if (block_b3_len >= 0) { |
| 287 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 288 | (unsigned char *) block_b3->x, |
| 289 | block_b3_len) == 0); |
| 290 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 291 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 292 | TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 293 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 294 | TEST_ASSERT(memcmp(output, expected_result_b->x, block_size) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 295 | |
Simon Butcher | bd8d221 | 2016-10-11 12:05:51 +0100 | [diff] [blame] | 296 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 297 | mbedtls_cipher_free(&ctx); |
Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 298 | } |
| 299 | /* END_CASE */ |