blob: 567c673c3f9d0f48cc8ee56a80aa5546b6cd7718 [file] [log] [blame]
Steven Cooremand13a70f2021-03-19 15:24:23 +01001/*
2 * PSA MAC layer on top of Mbed TLS software crypto
3 */
4/*
5 * Copyright The Mbed TLS Contributors
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may
9 * not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#include "common.h"
22
23#if defined(MBEDTLS_PSA_CRYPTO_C)
24
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020025# include <psa/crypto.h>
26# include "psa_crypto_core.h"
27# include "psa_crypto_mac.h"
28# include <mbedtls/md.h>
Steven Cooremand13a70f2021-03-19 15:24:23 +010029
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020030# include <mbedtls/error.h>
31# include <string.h>
Steven Cooremand13a70f2021-03-19 15:24:23 +010032
33/* Use builtin defines specific to this compilation unit, since the test driver
34 * relies on the software driver. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020035# if (defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \
36 (defined(PSA_CRYPTO_DRIVER_TEST) && \
37 defined(MBEDTLS_PSA_ACCEL_ALG_CMAC)))
38# define BUILTIN_ALG_CMAC 1
39# endif
40# if (defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || \
41 (defined(PSA_CRYPTO_DRIVER_TEST) && \
42 defined(MBEDTLS_PSA_ACCEL_ALG_HMAC)))
43# define BUILTIN_ALG_HMAC 1
44# endif
Steven Cooremand13a70f2021-03-19 15:24:23 +010045
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020046# if defined(BUILTIN_ALG_HMAC)
47static size_t psa_get_hash_block_size(psa_algorithm_t alg)
Steven Cooreman82c66b62021-03-19 17:39:17 +010048{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020049 switch (alg) {
Steven Cooreman82c66b62021-03-19 17:39:17 +010050 case PSA_ALG_MD5:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020051 return 64;
Steven Cooreman82c66b62021-03-19 17:39:17 +010052 case PSA_ALG_RIPEMD160:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020053 return 64;
Steven Cooreman82c66b62021-03-19 17:39:17 +010054 case PSA_ALG_SHA_1:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020055 return 64;
Steven Cooreman82c66b62021-03-19 17:39:17 +010056 case PSA_ALG_SHA_224:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020057 return 64;
Steven Cooreman82c66b62021-03-19 17:39:17 +010058 case PSA_ALG_SHA_256:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020059 return 64;
Steven Cooreman82c66b62021-03-19 17:39:17 +010060 case PSA_ALG_SHA_384:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020061 return 128;
Steven Cooreman82c66b62021-03-19 17:39:17 +010062 case PSA_ALG_SHA_512:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020063 return 128;
Steven Cooreman82c66b62021-03-19 17:39:17 +010064 default:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020065 return 0;
Steven Cooreman82c66b62021-03-19 17:39:17 +010066 }
67}
68
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020069static psa_status_t psa_hmac_abort_internal(mbedtls_psa_hmac_operation_t *hmac)
Steven Cooreman82c66b62021-03-19 17:39:17 +010070{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020071 mbedtls_platform_zeroize(hmac->opad, sizeof(hmac->opad));
72 return psa_hash_abort(&hmac->hash_ctx);
Steven Cooreman82c66b62021-03-19 17:39:17 +010073}
74
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020075static psa_status_t psa_hmac_setup_internal(mbedtls_psa_hmac_operation_t *hmac,
76 const uint8_t *key,
77 size_t key_length,
78 psa_algorithm_t hash_alg)
Steven Cooreman82c66b62021-03-19 17:39:17 +010079{
80 uint8_t ipad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
81 size_t i;
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020082 size_t hash_size = PSA_HASH_LENGTH(hash_alg);
83 size_t block_size = psa_get_hash_block_size(hash_alg);
Steven Cooreman82c66b62021-03-19 17:39:17 +010084 psa_status_t status;
85
86 hmac->alg = hash_alg;
87
88 /* Sanity checks on block_size, to guarantee that there won't be a buffer
89 * overflow below. This should never trigger if the hash algorithm
90 * is implemented correctly. */
91 /* The size checks against the ipad and opad buffers cannot be written
92 * `block_size > sizeof( ipad ) || block_size > sizeof( hmac->opad )`
93 * because that triggers -Wlogical-op on GCC 7.3. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +020094 if (block_size > sizeof(ipad))
95 return PSA_ERROR_NOT_SUPPORTED;
96 if (block_size > sizeof(hmac->opad))
97 return PSA_ERROR_NOT_SUPPORTED;
98 if (block_size < hash_size)
99 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman82c66b62021-03-19 17:39:17 +0100100
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200101 if (key_length > block_size) {
102 status = psa_hash_compute(hash_alg, key, key_length, ipad, sizeof(ipad),
103 &key_length);
104 if (status != PSA_SUCCESS)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100105 goto cleanup;
106 }
107 /* A 0-length key is not commonly used in HMAC when used as a MAC,
108 * but it is permitted. It is common when HMAC is used in HKDF, for
109 * example. Don't call `memcpy` in the 0-length because `key` could be
110 * an invalid pointer which would make the behavior undefined. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200111 else if (key_length != 0)
112 memcpy(ipad, key, key_length);
Steven Cooreman82c66b62021-03-19 17:39:17 +0100113
114 /* ipad contains the key followed by garbage. Xor and fill with 0x36
115 * to create the ipad value. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200116 for (i = 0; i < key_length; i++)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100117 ipad[i] ^= 0x36;
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200118 memset(ipad + key_length, 0x36, block_size - key_length);
Steven Cooreman82c66b62021-03-19 17:39:17 +0100119
120 /* Copy the key material from ipad to opad, flipping the requisite bits,
121 * and filling the rest of opad with the requisite constant. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200122 for (i = 0; i < key_length; i++)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100123 hmac->opad[i] = ipad[i] ^ 0x36 ^ 0x5C;
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200124 memset(hmac->opad + key_length, 0x5C, block_size - key_length);
Steven Cooreman82c66b62021-03-19 17:39:17 +0100125
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200126 status = psa_hash_setup(&hmac->hash_ctx, hash_alg);
127 if (status != PSA_SUCCESS)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100128 goto cleanup;
129
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200130 status = psa_hash_update(&hmac->hash_ctx, ipad, block_size);
Steven Cooreman82c66b62021-03-19 17:39:17 +0100131
132cleanup:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200133 mbedtls_platform_zeroize(ipad, sizeof(ipad));
Steven Cooreman82c66b62021-03-19 17:39:17 +0100134
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200135 return status;
Steven Cooreman82c66b62021-03-19 17:39:17 +0100136}
137
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200138static psa_status_t psa_hmac_update_internal(mbedtls_psa_hmac_operation_t *hmac,
139 const uint8_t *data,
140 size_t data_length)
Steven Cooreman4fdf0602021-03-22 12:21:10 +0100141{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200142 return psa_hash_update(&hmac->hash_ctx, data, data_length);
Steven Cooreman4fdf0602021-03-22 12:21:10 +0100143}
144
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200145static psa_status_t psa_hmac_finish_internal(mbedtls_psa_hmac_operation_t *hmac,
146 uint8_t *mac,
147 size_t mac_size)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100148{
149 uint8_t tmp[MBEDTLS_MD_MAX_SIZE];
150 psa_algorithm_t hash_alg = hmac->alg;
151 size_t hash_size = 0;
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200152 size_t block_size = psa_get_hash_block_size(hash_alg);
Steven Cooreman82c66b62021-03-19 17:39:17 +0100153 psa_status_t status;
154
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200155 status = psa_hash_finish(&hmac->hash_ctx, tmp, sizeof(tmp), &hash_size);
156 if (status != PSA_SUCCESS)
157 return status;
Steven Cooreman82c66b62021-03-19 17:39:17 +0100158 /* From here on, tmp needs to be wiped. */
159
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200160 status = psa_hash_setup(&hmac->hash_ctx, hash_alg);
161 if (status != PSA_SUCCESS)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100162 goto exit;
163
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200164 status = psa_hash_update(&hmac->hash_ctx, hmac->opad, block_size);
165 if (status != PSA_SUCCESS)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100166 goto exit;
167
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200168 status = psa_hash_update(&hmac->hash_ctx, tmp, hash_size);
169 if (status != PSA_SUCCESS)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100170 goto exit;
171
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200172 status = psa_hash_finish(&hmac->hash_ctx, tmp, sizeof(tmp), &hash_size);
173 if (status != PSA_SUCCESS)
Steven Cooreman82c66b62021-03-19 17:39:17 +0100174 goto exit;
175
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200176 memcpy(mac, tmp, mac_size);
Steven Cooreman82c66b62021-03-19 17:39:17 +0100177
178exit:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200179 mbedtls_platform_zeroize(tmp, hash_size);
180 return status;
Steven Cooreman82c66b62021-03-19 17:39:17 +0100181}
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200182# endif /* BUILTIN_ALG_HMAC */
Steven Cooremane6804192021-03-19 18:28:56 +0100183
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200184# if defined(BUILTIN_ALG_CMAC)
185static psa_status_t cmac_setup(mbedtls_psa_mac_operation_t *operation,
186 const psa_key_attributes_t *attributes,
187 const uint8_t *key_buffer)
Steven Cooremane6804192021-03-19 18:28:56 +0100188{
189 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
Steven Cooreman0c239652021-05-07 17:27:27 +0200190
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200191# if defined(PSA_WANT_KEY_TYPE_DES)
Steven Cooreman0c239652021-05-07 17:27:27 +0200192 /* Mbed TLS CMAC does not accept 3DES with only two keys, nor does it accept
193 * to do CMAC with pure DES, so return NOT_SUPPORTED here. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200194 if (psa_get_key_type(attributes) == PSA_KEY_TYPE_DES &&
195 (psa_get_key_bits(attributes) == 64 ||
196 psa_get_key_bits(attributes) == 128))
197 return PSA_ERROR_NOT_SUPPORTED;
198# endif
Steven Cooreman0c239652021-05-07 17:27:27 +0200199
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200200 const mbedtls_cipher_info_t *cipher_info =
201 mbedtls_cipher_info_from_psa(PSA_ALG_CMAC, psa_get_key_type(attributes),
202 psa_get_key_bits(attributes), NULL);
Steven Cooremane6804192021-03-19 18:28:56 +0100203
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200204 if (cipher_info == NULL)
205 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremane6804192021-03-19 18:28:56 +0100206
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200207 ret = mbedtls_cipher_setup(&operation->ctx.cmac, cipher_info);
208 if (ret != 0)
Steven Cooremane6804192021-03-19 18:28:56 +0100209 goto exit;
210
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200211 ret = mbedtls_cipher_cmac_starts(&operation->ctx.cmac, key_buffer,
212 psa_get_key_bits(attributes));
Steven Cooremane6804192021-03-19 18:28:56 +0100213exit:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200214 return mbedtls_to_psa_error(ret);
Steven Cooremane6804192021-03-19 18:28:56 +0100215}
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200216# endif /* BUILTIN_ALG_CMAC */
Steven Cooremane6804192021-03-19 18:28:56 +0100217
Steven Cooreman02865f52021-05-07 15:55:27 +0200218/* Implement the PSA driver MAC interface on top of mbed TLS if either the
219 * software driver or the test driver requires it. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200220# if defined(BUILTIN_ALG_HMAC) || defined(BUILTIN_ALG_CMAC)
Steven Cooreman02865f52021-05-07 15:55:27 +0200221
Steven Cooremane6804192021-03-19 18:28:56 +0100222/* Initialize this driver's MAC operation structure. Once this function has been
223 * called, mbedtls_psa_mac_abort can run and will do the right thing. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200224static psa_status_t mac_init(mbedtls_psa_mac_operation_t *operation,
225 psa_algorithm_t alg)
Steven Cooremane6804192021-03-19 18:28:56 +0100226{
Steven Cooremanba9a5bf2021-04-29 16:21:24 +0200227 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Steven Cooremane6804192021-03-19 18:28:56 +0100228
Steven Cooreman72f736a2021-05-07 14:14:37 +0200229 operation->alg = alg;
Steven Cooremane6804192021-03-19 18:28:56 +0100230
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200231# if defined(BUILTIN_ALG_CMAC)
232 if (PSA_ALG_FULL_LENGTH_MAC(operation->alg) == PSA_ALG_CMAC) {
233 mbedtls_cipher_init(&operation->ctx.cmac);
Steven Cooremane6804192021-03-19 18:28:56 +0100234 status = PSA_SUCCESS;
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200235 } else
236# endif /* BUILTIN_ALG_CMAC */
237# if defined(BUILTIN_ALG_HMAC)
238 if (PSA_ALG_IS_HMAC(operation->alg)) {
Steven Cooremane6804192021-03-19 18:28:56 +0100239 /* We'll set up the hash operation later in psa_hmac_setup_internal. */
240 operation->ctx.hmac.alg = 0;
241 status = PSA_SUCCESS;
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200242 } else
243# endif /* BUILTIN_ALG_HMAC */
Steven Cooremane6804192021-03-19 18:28:56 +0100244 {
Steven Cooremanba9a5bf2021-04-29 16:21:24 +0200245 status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremane6804192021-03-19 18:28:56 +0100246 }
247
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200248 if (status != PSA_SUCCESS)
249 memset(operation, 0, sizeof(*operation));
250 return status;
Steven Cooremane6804192021-03-19 18:28:56 +0100251}
252
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200253static psa_status_t mac_abort(mbedtls_psa_mac_operation_t *operation)
Steven Cooremane6804192021-03-19 18:28:56 +0100254{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200255 if (operation->alg == 0) {
Steven Cooremane6804192021-03-19 18:28:56 +0100256 /* The object has (apparently) been initialized but it is not
257 * in use. It's ok to call abort on such an object, and there's
258 * nothing to do. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200259 return PSA_SUCCESS;
260 } else
261# if defined(BUILTIN_ALG_CMAC)
262 if (PSA_ALG_FULL_LENGTH_MAC(operation->alg) == PSA_ALG_CMAC) {
263 mbedtls_cipher_free(&operation->ctx.cmac);
264 } else
265# endif /* BUILTIN_ALG_CMAC */
266# if defined(BUILTIN_ALG_HMAC)
267 if (PSA_ALG_IS_HMAC(operation->alg)) {
268 psa_hmac_abort_internal(&operation->ctx.hmac);
269 } else
270# endif /* BUILTIN_ALG_HMAC */
Steven Cooremane6804192021-03-19 18:28:56 +0100271 {
272 /* Sanity check (shouldn't happen: operation->alg should
273 * always have been initialized to a valid value). */
274 goto bad_state;
275 }
276
277 operation->alg = 0;
Steven Cooremane6804192021-03-19 18:28:56 +0100278
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200279 return PSA_SUCCESS;
Steven Cooremane6804192021-03-19 18:28:56 +0100280
281bad_state:
282 /* If abort is called on an uninitialized object, we can't trust
283 * anything. Wipe the object in case it contains confidential data.
284 * This may result in a memory leak if a pointer gets overwritten,
285 * but it's too late to do anything about this. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200286 memset(operation, 0, sizeof(*operation));
287 return PSA_ERROR_BAD_STATE;
Steven Cooremane6804192021-03-19 18:28:56 +0100288}
289
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200290static psa_status_t mac_setup(mbedtls_psa_mac_operation_t *operation,
291 const psa_key_attributes_t *attributes,
292 const uint8_t *key_buffer,
293 size_t key_buffer_size,
294 psa_algorithm_t alg)
Steven Cooremane6804192021-03-19 18:28:56 +0100295{
296 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
297
298 /* A context must be freshly initialized before it can be set up. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200299 if (operation->alg != 0)
300 return PSA_ERROR_BAD_STATE;
Steven Cooremane6804192021-03-19 18:28:56 +0100301
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200302 status = mac_init(operation, alg);
303 if (status != PSA_SUCCESS)
304 return status;
Steven Cooremane6804192021-03-19 18:28:56 +0100305
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200306# if defined(BUILTIN_ALG_CMAC)
307 if (PSA_ALG_FULL_LENGTH_MAC(alg) == PSA_ALG_CMAC) {
Steven Cooremandcd08112021-05-06 18:00:37 +0200308 /* Key buffer size for CMAC is dictated by the key bits set on the
309 * attributes, and previously validated by the core on key import. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200310 (void)key_buffer_size;
311 status = cmac_setup(operation, attributes, key_buffer);
312 } else
313# endif /* BUILTIN_ALG_CMAC */
314# if defined(BUILTIN_ALG_HMAC)
315 if (PSA_ALG_IS_HMAC(alg)) {
316 status = psa_hmac_setup_internal(&operation->ctx.hmac, key_buffer,
317 key_buffer_size,
318 PSA_ALG_HMAC_GET_HASH(alg));
319 } else
320# endif /* BUILTIN_ALG_HMAC */
Steven Cooremane6804192021-03-19 18:28:56 +0100321 {
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200322 (void)attributes;
323 (void)key_buffer;
324 (void)key_buffer_size;
Steven Cooremane6804192021-03-19 18:28:56 +0100325 status = PSA_ERROR_NOT_SUPPORTED;
326 }
327
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200328 if (status != PSA_SUCCESS)
329 mac_abort(operation);
Steven Cooremane6804192021-03-19 18:28:56 +0100330
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200331 return status;
Steven Cooremane6804192021-03-19 18:28:56 +0100332}
333
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200334static psa_status_t mac_update(mbedtls_psa_mac_operation_t *operation,
335 const uint8_t *input,
336 size_t input_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100337{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200338 if (operation->alg == 0)
339 return PSA_ERROR_BAD_STATE;
Steven Cooreman6e7f2912021-03-19 18:38:46 +0100340
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200341# if defined(BUILTIN_ALG_CMAC)
342 if (PSA_ALG_FULL_LENGTH_MAC(operation->alg) == PSA_ALG_CMAC) {
343 return (mbedtls_to_psa_error(mbedtls_cipher_cmac_update(
344 &operation->ctx.cmac, input, input_length)));
345 } else
346# endif /* BUILTIN_ALG_CMAC */
347# if defined(BUILTIN_ALG_HMAC)
348 if (PSA_ALG_IS_HMAC(operation->alg)) {
349 return (psa_hmac_update_internal(&operation->ctx.hmac, input,
350 input_length));
351 } else
352# endif /* BUILTIN_ALG_HMAC */
Steven Cooreman6e7f2912021-03-19 18:38:46 +0100353 {
354 /* This shouldn't happen if `operation` was initialized by
355 * a setup function. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200356 (void)input;
357 (void)input_length;
358 return PSA_ERROR_BAD_STATE;
Steven Cooreman6e7f2912021-03-19 18:38:46 +0100359 }
Steven Cooremand13a70f2021-03-19 15:24:23 +0100360}
361
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200362static psa_status_t mac_finish_internal(mbedtls_psa_mac_operation_t *operation,
363 uint8_t *mac,
364 size_t mac_size)
Steven Cooremana5b860a2021-03-19 19:04:39 +0100365{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200366# if defined(BUILTIN_ALG_CMAC)
367 if (PSA_ALG_FULL_LENGTH_MAC(operation->alg) == PSA_ALG_CMAC) {
Steven Cooremana5b860a2021-03-19 19:04:39 +0100368 uint8_t tmp[PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE];
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200369 int ret = mbedtls_cipher_cmac_finish(&operation->ctx.cmac, tmp);
370 if (ret == 0)
371 memcpy(mac, tmp, mac_size);
372 mbedtls_platform_zeroize(tmp, sizeof(tmp));
373 return mbedtls_to_psa_error(ret);
374 } else
375# endif /* BUILTIN_ALG_CMAC */
376# if defined(BUILTIN_ALG_HMAC)
377 if (PSA_ALG_IS_HMAC(operation->alg)) {
378 return (psa_hmac_finish_internal(&operation->ctx.hmac, mac, mac_size));
379 } else
380# endif /* BUILTIN_ALG_HMAC */
Steven Cooremana5b860a2021-03-19 19:04:39 +0100381 {
382 /* This shouldn't happen if `operation` was initialized by
383 * a setup function. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200384 (void)operation;
385 (void)mac;
386 (void)mac_size;
387 return PSA_ERROR_BAD_STATE;
Steven Cooremana5b860a2021-03-19 19:04:39 +0100388 }
389}
390
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200391static psa_status_t mac_sign_finish(mbedtls_psa_mac_operation_t *operation,
392 uint8_t *mac,
393 size_t mac_size,
394 size_t *mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100395{
Steven Cooreman094a77e2021-05-06 17:58:36 +0200396 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Steven Cooremana5b860a2021-03-19 19:04:39 +0100397
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200398 if (operation->alg == 0)
399 return PSA_ERROR_BAD_STATE;
Steven Cooremana5b860a2021-03-19 19:04:39 +0100400
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200401 status = mac_finish_internal(operation, mac, mac_size);
Steven Cooremana5b860a2021-03-19 19:04:39 +0100402
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200403 if (status == PSA_SUCCESS)
Steven Cooreman72f736a2021-05-07 14:14:37 +0200404 *mac_length = mac_size;
Steven Cooremana5b860a2021-03-19 19:04:39 +0100405
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200406 return status;
Steven Cooremana5b860a2021-03-19 19:04:39 +0100407}
408
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200409static psa_status_t mac_verify_finish(mbedtls_psa_mac_operation_t *operation,
410 const uint8_t *mac,
411 size_t mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100412{
Steven Cooremana5b860a2021-03-19 19:04:39 +0100413 uint8_t actual_mac[PSA_MAC_MAX_SIZE];
Steven Cooreman094a77e2021-05-06 17:58:36 +0200414 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
Steven Cooremana5b860a2021-03-19 19:04:39 +0100415
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200416 if (operation->alg == 0)
417 return PSA_ERROR_BAD_STATE;
Steven Cooremana5b860a2021-03-19 19:04:39 +0100418
Steven Cooreman72f736a2021-05-07 14:14:37 +0200419 /* Consistency check: requested MAC length fits our local buffer */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200420 if (mac_length > sizeof(actual_mac))
421 return PSA_ERROR_INVALID_ARGUMENT;
Steven Cooremana5b860a2021-03-19 19:04:39 +0100422
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200423 status = mac_finish_internal(operation, actual_mac, mac_length);
424 if (status != PSA_SUCCESS)
Steven Cooremana5b860a2021-03-19 19:04:39 +0100425 goto cleanup;
426
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200427 if (mbedtls_psa_safer_memcmp(mac, actual_mac, mac_length) != 0)
Steven Cooremana5b860a2021-03-19 19:04:39 +0100428 status = PSA_ERROR_INVALID_SIGNATURE;
429
430cleanup:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200431 mbedtls_platform_zeroize(actual_mac, sizeof(actual_mac));
Steven Cooremana5b860a2021-03-19 19:04:39 +0100432
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200433 return status;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100434}
Ronald Cron76be3e02021-06-17 17:34:43 +0200435
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200436static psa_status_t mac_compute(const psa_key_attributes_t *attributes,
437 const uint8_t *key_buffer,
438 size_t key_buffer_size,
439 psa_algorithm_t alg,
440 const uint8_t *input,
441 size_t input_length,
442 uint8_t *mac,
443 size_t mac_size,
444 size_t *mac_length)
Ronald Cron76be3e02021-06-17 17:34:43 +0200445{
446 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
447 mbedtls_psa_mac_operation_t operation = MBEDTLS_PSA_MAC_OPERATION_INIT;
448
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200449 status =
450 mac_setup(&operation, attributes, key_buffer, key_buffer_size, alg);
451 if (status != PSA_SUCCESS)
Ronald Cron76be3e02021-06-17 17:34:43 +0200452 goto exit;
453
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200454 if (input_length > 0) {
455 status = mac_update(&operation, input, input_length);
456 if (status != PSA_SUCCESS)
Ronald Cron76be3e02021-06-17 17:34:43 +0200457 goto exit;
458 }
459
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200460 status = mac_finish_internal(&operation, mac, mac_size);
461 if (status == PSA_SUCCESS)
Ronald Cron76be3e02021-06-17 17:34:43 +0200462 *mac_length = mac_size;
463
464exit:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200465 mac_abort(&operation);
Ronald Cron76be3e02021-06-17 17:34:43 +0200466
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200467 return status;
Ronald Cron76be3e02021-06-17 17:34:43 +0200468}
469
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200470# endif /* BUILTIN_ALG_HMAC || BUILTIN_ALG_CMAC */
Steven Cooremand13a70f2021-03-19 15:24:23 +0100471
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200472# if defined(MBEDTLS_PSA_BUILTIN_MAC)
473psa_status_t mbedtls_psa_mac_compute(const psa_key_attributes_t *attributes,
474 const uint8_t *key_buffer,
475 size_t key_buffer_size,
476 psa_algorithm_t alg,
477 const uint8_t *input,
478 size_t input_length,
479 uint8_t *mac,
480 size_t mac_size,
481 size_t *mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100482{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200483 return (mac_compute(attributes, key_buffer, key_buffer_size, alg, input,
484 input_length, mac, mac_size, mac_length));
Steven Cooremand13a70f2021-03-19 15:24:23 +0100485}
486
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200487psa_status_t mbedtls_psa_mac_sign_setup(mbedtls_psa_mac_operation_t *operation,
488 const psa_key_attributes_t *attributes,
489 const uint8_t *key_buffer,
490 size_t key_buffer_size,
491 psa_algorithm_t alg)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100492{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200493 return (mac_setup(operation, attributes, key_buffer, key_buffer_size, alg));
Steven Cooremand13a70f2021-03-19 15:24:23 +0100494}
495
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200496psa_status_t
497mbedtls_psa_mac_verify_setup(mbedtls_psa_mac_operation_t *operation,
498 const psa_key_attributes_t *attributes,
499 const uint8_t *key_buffer,
500 size_t key_buffer_size,
501 psa_algorithm_t alg)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100502{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200503 return (mac_setup(operation, attributes, key_buffer, key_buffer_size, alg));
Steven Cooremand13a70f2021-03-19 15:24:23 +0100504}
505
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200506psa_status_t mbedtls_psa_mac_update(mbedtls_psa_mac_operation_t *operation,
507 const uint8_t *input,
508 size_t input_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100509{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200510 return mac_update(operation, input, input_length);
Steven Cooremand13a70f2021-03-19 15:24:23 +0100511}
512
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200513psa_status_t mbedtls_psa_mac_sign_finish(mbedtls_psa_mac_operation_t *operation,
514 uint8_t *mac,
515 size_t mac_size,
516 size_t *mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100517{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200518 return mac_sign_finish(operation, mac, mac_size, mac_length);
Steven Cooremand13a70f2021-03-19 15:24:23 +0100519}
520
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200521psa_status_t
522mbedtls_psa_mac_verify_finish(mbedtls_psa_mac_operation_t *operation,
523 const uint8_t *mac,
524 size_t mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100525{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200526 return mac_verify_finish(operation, mac, mac_length);
Steven Cooremand13a70f2021-03-19 15:24:23 +0100527}
528
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200529psa_status_t mbedtls_psa_mac_abort(mbedtls_psa_mac_operation_t *operation)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100530{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200531 return mac_abort(operation);
Steven Cooremand13a70f2021-03-19 15:24:23 +0100532}
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200533# endif /* MBEDTLS_PSA_BUILTIN_MAC */
Steven Cooremand13a70f2021-03-19 15:24:23 +0100534
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200535/*
536 * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
537 */
538# if defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100539
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200540static int is_mac_accelerated(psa_algorithm_t alg)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100541{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200542# if defined(MBEDTLS_PSA_ACCEL_ALG_HMAC)
543 if (PSA_ALG_IS_HMAC(alg))
544 return 1;
545# endif
Steven Cooremand13a70f2021-03-19 15:24:23 +0100546
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200547 switch (PSA_ALG_FULL_LENGTH_MAC(alg)) {
548# if defined(MBEDTLS_PSA_ACCEL_ALG_CMAC)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100549 case PSA_ALG_CMAC:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200550 return 1;
551# endif
Steven Cooremand13a70f2021-03-19 15:24:23 +0100552 default:
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200553 return 0;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100554 }
555}
556
557psa_status_t mbedtls_transparent_test_driver_mac_compute(
558 const psa_key_attributes_t *attributes,
559 const uint8_t *key_buffer,
560 size_t key_buffer_size,
561 psa_algorithm_t alg,
562 const uint8_t *input,
563 size_t input_length,
564 uint8_t *mac,
565 size_t mac_size,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200566 size_t *mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100567{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200568 if (is_mac_accelerated(alg))
569 return (mac_compute(attributes, key_buffer, key_buffer_size, alg, input,
570 input_length, mac, mac_size, mac_length));
Steven Cooremand13a70f2021-03-19 15:24:23 +0100571 else
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200572 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100573}
574
575psa_status_t mbedtls_transparent_test_driver_mac_sign_setup(
576 mbedtls_transparent_test_driver_mac_operation_t *operation,
577 const psa_key_attributes_t *attributes,
578 const uint8_t *key_buffer,
579 size_t key_buffer_size,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200580 psa_algorithm_t alg)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100581{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200582 if (is_mac_accelerated(alg))
583 return (
584 mac_setup(operation, attributes, key_buffer, key_buffer_size, alg));
Steven Cooremand13a70f2021-03-19 15:24:23 +0100585 else
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200586 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100587}
588
589psa_status_t mbedtls_transparent_test_driver_mac_verify_setup(
590 mbedtls_transparent_test_driver_mac_operation_t *operation,
591 const psa_key_attributes_t *attributes,
592 const uint8_t *key_buffer,
593 size_t key_buffer_size,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200594 psa_algorithm_t alg)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100595{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200596 if (is_mac_accelerated(alg))
597 return (
598 mac_setup(operation, attributes, key_buffer, key_buffer_size, alg));
Steven Cooremand13a70f2021-03-19 15:24:23 +0100599 else
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200600 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100601}
602
603psa_status_t mbedtls_transparent_test_driver_mac_update(
604 mbedtls_transparent_test_driver_mac_operation_t *operation,
605 const uint8_t *input,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200606 size_t input_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100607{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200608 if (is_mac_accelerated(operation->alg))
609 return mac_update(operation, input, input_length);
Steven Cooremand13a70f2021-03-19 15:24:23 +0100610 else
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200611 return PSA_ERROR_BAD_STATE;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100612}
613
614psa_status_t mbedtls_transparent_test_driver_mac_sign_finish(
615 mbedtls_transparent_test_driver_mac_operation_t *operation,
616 uint8_t *mac,
617 size_t mac_size,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200618 size_t *mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100619{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200620 if (is_mac_accelerated(operation->alg))
621 return mac_sign_finish(operation, mac, mac_size, mac_length);
Steven Cooremand13a70f2021-03-19 15:24:23 +0100622 else
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200623 return PSA_ERROR_BAD_STATE;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100624}
625
626psa_status_t mbedtls_transparent_test_driver_mac_verify_finish(
627 mbedtls_transparent_test_driver_mac_operation_t *operation,
628 const uint8_t *mac,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200629 size_t mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100630{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200631 if (is_mac_accelerated(operation->alg))
632 return mac_verify_finish(operation, mac, mac_length);
Steven Cooremand13a70f2021-03-19 15:24:23 +0100633 else
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200634 return PSA_ERROR_BAD_STATE;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100635}
636
637psa_status_t mbedtls_transparent_test_driver_mac_abort(
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200638 mbedtls_transparent_test_driver_mac_operation_t *operation)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100639{
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200640 return mac_abort(operation);
Steven Cooremand13a70f2021-03-19 15:24:23 +0100641}
642
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200643psa_status_t
644mbedtls_opaque_test_driver_mac_compute(const psa_key_attributes_t *attributes,
645 const uint8_t *key_buffer,
646 size_t key_buffer_size,
647 psa_algorithm_t alg,
648 const uint8_t *input,
649 size_t input_length,
650 uint8_t *mac,
651 size_t mac_size,
652 size_t *mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100653{
654 /* Opaque driver testing is not implemented yet through this mechanism. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200655 (void)attributes;
656 (void)key_buffer;
657 (void)key_buffer_size;
658 (void)alg;
659 (void)input;
660 (void)input_length;
661 (void)mac;
662 (void)mac_size;
663 (void)mac_length;
664 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100665}
666
667psa_status_t mbedtls_opaque_test_driver_mac_sign_setup(
668 mbedtls_opaque_test_driver_mac_operation_t *operation,
669 const psa_key_attributes_t *attributes,
670 const uint8_t *key_buffer,
671 size_t key_buffer_size,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200672 psa_algorithm_t alg)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100673{
674 /* Opaque driver testing is not implemented yet through this mechanism. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200675 (void)operation;
676 (void)attributes;
677 (void)key_buffer;
678 (void)key_buffer_size;
679 (void)alg;
680 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100681}
682
683psa_status_t mbedtls_opaque_test_driver_mac_verify_setup(
684 mbedtls_opaque_test_driver_mac_operation_t *operation,
685 const psa_key_attributes_t *attributes,
686 const uint8_t *key_buffer,
687 size_t key_buffer_size,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200688 psa_algorithm_t alg)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100689{
690 /* Opaque driver testing is not implemented yet through this mechanism. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200691 (void)operation;
692 (void)attributes;
693 (void)key_buffer;
694 (void)key_buffer_size;
695 (void)alg;
696 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100697}
698
699psa_status_t mbedtls_opaque_test_driver_mac_update(
700 mbedtls_opaque_test_driver_mac_operation_t *operation,
701 const uint8_t *input,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200702 size_t input_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100703{
704 /* Opaque driver testing is not implemented yet through this mechanism. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200705 (void)operation;
706 (void)input;
707 (void)input_length;
708 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100709}
710
711psa_status_t mbedtls_opaque_test_driver_mac_sign_finish(
712 mbedtls_opaque_test_driver_mac_operation_t *operation,
713 uint8_t *mac,
714 size_t mac_size,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200715 size_t *mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100716{
717 /* Opaque driver testing is not implemented yet through this mechanism. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200718 (void)operation;
719 (void)mac;
720 (void)mac_size;
721 (void)mac_length;
722 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100723}
724
725psa_status_t mbedtls_opaque_test_driver_mac_verify_finish(
726 mbedtls_opaque_test_driver_mac_operation_t *operation,
727 const uint8_t *mac,
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200728 size_t mac_length)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100729{
730 /* Opaque driver testing is not implemented yet through this mechanism. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200731 (void)operation;
732 (void)mac;
733 (void)mac_length;
734 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100735}
736
737psa_status_t mbedtls_opaque_test_driver_mac_abort(
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200738 mbedtls_opaque_test_driver_mac_operation_t *operation)
Steven Cooremand13a70f2021-03-19 15:24:23 +0100739{
740 /* Opaque driver testing is not implemented yet through this mechanism. */
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200741 (void)operation;
742 return PSA_ERROR_NOT_SUPPORTED;
Steven Cooremand13a70f2021-03-19 15:24:23 +0100743}
744
Mateusz Starzykc0eabdc2021-08-03 14:09:02 +0200745# endif /* PSA_CRYPTO_DRIVER_TEST */
Steven Cooremand13a70f2021-03-19 15:24:23 +0100746
747#endif /* MBEDTLS_PSA_CRYPTO_C */