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); |
Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 116 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 117 | memset(buf, 0x2A, sizeof(buf)); |
| 118 | TEST_ASSERT((result == mbedtls_cipher_cmac(cipher_info, key, key_size, |
| 119 | buf, 16, tmp)) != 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 120 | } |
| 121 | /* END_CASE */ |
| 122 | |
| 123 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 124 | void mbedtls_cmac_multiple_blocks(int cipher_type, data_t *key, |
| 125 | int keybits, int block_size, |
| 126 | data_t *block1, int block1_len, |
| 127 | data_t *block2, int block2_len, |
| 128 | data_t *block3, int block3_len, |
| 129 | data_t *block4, int block4_len, |
| 130 | data_t *expected_result) |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 131 | { |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 132 | const mbedtls_cipher_info_t *cipher_info; |
| 133 | mbedtls_cipher_context_t ctx; |
| 134 | unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| 135 | |
| 136 | /* Convert the test parameters to binary data */ |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 137 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 138 | mbedtls_cipher_init(&ctx); |
Andres AG | 8abc6b8 | 2016-10-11 15:41:40 +0100 | [diff] [blame] | 139 | |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 140 | /* Validate the test inputs */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 141 | TEST_ASSERT(block1_len <= 100); |
| 142 | TEST_ASSERT(block2_len <= 100); |
| 143 | TEST_ASSERT(block3_len <= 100); |
| 144 | TEST_ASSERT(block4_len <= 100); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 145 | |
| 146 | /* Set up */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 147 | TEST_ASSERT((cipher_info = mbedtls_cipher_info_from_type(cipher_type)) |
| 148 | != NULL); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 149 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 150 | TEST_ASSERT(mbedtls_cipher_setup(&ctx, cipher_info) == 0); |
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_cmac_starts(&ctx, |
| 153 | (const unsigned char *) key->x, |
| 154 | keybits) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 155 | |
| 156 | /* Multiple partial and complete blocks. A negative length means skip the |
| 157 | * update operation */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 158 | if (block1_len >= 0) { |
| 159 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 160 | (unsigned char *) block1->x, |
| 161 | block1_len) == 0); |
| 162 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 163 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 164 | if (block2_len >= 0) { |
| 165 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 166 | (unsigned char *) block2->x, |
| 167 | block2_len) == 0); |
| 168 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 169 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 170 | if (block3_len >= 0) { |
| 171 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 172 | (unsigned char *) block3->x, |
| 173 | block3_len) == 0); |
| 174 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 175 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 176 | if (block4_len >= 0) { |
| 177 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 178 | (unsigned char *) block4->x, |
| 179 | block4_len) == 0); |
| 180 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 181 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 182 | TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0); |
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(memcmp(output, expected_result->x, block_size) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 185 | |
Simon Butcher | bd8d221 | 2016-10-11 12:05:51 +0100 | [diff] [blame] | 186 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 187 | mbedtls_cipher_free(&ctx); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 188 | } |
| 189 | /* END_CASE */ |
| 190 | |
| 191 | /* BEGIN_CASE */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 192 | void mbedtls_cmac_multiple_operations_same_key(int cipher_type, |
| 193 | data_t *key, int keybits, |
| 194 | int block_size, |
| 195 | data_t *block_a1, |
| 196 | int block_a1_len, |
| 197 | data_t *block_a2, |
| 198 | int block_a2_len, |
| 199 | data_t *block_a3, |
| 200 | int block_a3_len, |
| 201 | data_t *expected_result_a, |
| 202 | data_t *block_b1, |
| 203 | int block_b1_len, |
| 204 | data_t *block_b2, |
| 205 | int block_b2_len, |
| 206 | data_t *block_b3, |
| 207 | int block_b3_len, |
| 208 | data_t *expected_result_b |
| 209 | ) |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 210 | { |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 211 | const mbedtls_cipher_info_t *cipher_info; |
| 212 | mbedtls_cipher_context_t ctx; |
| 213 | unsigned char output[MBEDTLS_CIPHER_BLKSIZE_MAX]; |
| 214 | |
| 215 | /* Convert the test parameters to binary data */ |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 216 | |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 217 | |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 218 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 219 | mbedtls_cipher_init(&ctx); |
Andres AG | 8abc6b8 | 2016-10-11 15:41:40 +0100 | [diff] [blame] | 220 | |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 221 | /* Validate the test inputs */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 222 | TEST_ASSERT(block_a1_len <= 100); |
| 223 | TEST_ASSERT(block_a2_len <= 100); |
| 224 | TEST_ASSERT(block_a3_len <= 100); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 225 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 226 | TEST_ASSERT(block_b1_len <= 100); |
| 227 | TEST_ASSERT(block_b2_len <= 100); |
| 228 | TEST_ASSERT(block_b3_len <= 100); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 229 | |
| 230 | /* Set up */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 231 | TEST_ASSERT((cipher_info = mbedtls_cipher_info_from_type(cipher_type)) |
| 232 | != NULL); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 233 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 234 | TEST_ASSERT(mbedtls_cipher_setup(&ctx, cipher_info) == 0); |
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_cmac_starts(&ctx, |
| 237 | (const unsigned char *) key->x, |
| 238 | keybits) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 239 | |
| 240 | /* Sequence A */ |
| 241 | |
| 242 | /* Multiple partial and complete blocks. A negative length means skip the |
| 243 | * update operation */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 244 | if (block_a1_len >= 0) { |
| 245 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 246 | (unsigned char *) block_a1->x, |
| 247 | block_a1_len) == 0); |
| 248 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 249 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 250 | if (block_a2_len >= 0) { |
| 251 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 252 | (unsigned char *) block_a2->x, |
| 253 | block_a2_len) == 0); |
| 254 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 255 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 256 | if (block_a3_len >= 0) { |
| 257 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 258 | (unsigned char *) block_a3->x, |
| 259 | block_a3_len) == 0); |
| 260 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 261 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 262 | TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0); |
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(memcmp(output, expected_result_a->x, block_size) == 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(mbedtls_cipher_cmac_reset(&ctx) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 267 | |
| 268 | /* Sequence B */ |
| 269 | |
| 270 | /* Multiple partial and complete blocks. A negative length means skip the |
| 271 | * update operation */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 272 | if (block_b1_len >= 0) { |
| 273 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 274 | (unsigned char *) block_b1->x, |
| 275 | block_b1_len) == 0); |
| 276 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 277 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 278 | if (block_b2_len >= 0) { |
| 279 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 280 | (unsigned char *) block_b2->x, |
| 281 | block_b2_len) == 0); |
| 282 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 283 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 284 | if (block_b3_len >= 0) { |
| 285 | TEST_ASSERT(mbedtls_cipher_cmac_update(&ctx, |
| 286 | (unsigned char *) block_b3->x, |
| 287 | block_b3_len) == 0); |
| 288 | } |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 289 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 290 | TEST_ASSERT(mbedtls_cipher_cmac_finish(&ctx, output) == 0); |
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(memcmp(output, expected_result_b->x, block_size) == 0); |
Simon Butcher | 33183fd | 2016-10-10 21:41:03 +0100 | [diff] [blame] | 293 | |
Simon Butcher | bd8d221 | 2016-10-11 12:05:51 +0100 | [diff] [blame] | 294 | exit: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 295 | mbedtls_cipher_free(&ctx); |
Simon Butcher | d812fa6 | 2016-10-05 14:13:31 +0100 | [diff] [blame] | 296 | } |
| 297 | /* END_CASE */ |