blob: 43fc7e6c825a8f279d0ff84505dd2e3b75d5e9da [file] [log] [blame]
Steven Cooremanc7f0a572021-04-29 21:10:11 +02001/*
2 * Test driver for MAC entry points.
3 */
4/* Copyright The Mbed TLS Contributors
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
Mateusz Starzykb4a01292021-05-27 14:49:25 +020020#include <test/helpers.h>
Steven Cooremanc7f0a572021-04-29 21:10:11 +020021
22#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
23#include "psa_crypto_mac.h"
24
25#include "test/drivers/mac.h"
26
Steven Cooremanae3ec522021-05-10 11:18:20 +020027mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks =
28 MBEDTLS_TEST_DRIVER_MAC_INIT;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020029
30psa_status_t mbedtls_test_transparent_mac_compute(
31 const psa_key_attributes_t *attributes,
32 const uint8_t *key_buffer,
33 size_t key_buffer_size,
34 psa_algorithm_t alg,
35 const uint8_t *input,
36 size_t input_length,
37 uint8_t *mac,
38 size_t mac_size,
39 size_t *mac_length )
40{
Steven Cooremanae3ec522021-05-10 11:18:20 +020041 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020042
Steven Cooremanae3ec522021-05-10 11:18:20 +020043 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +020044 {
Steven Cooremanae3ec522021-05-10 11:18:20 +020045 mbedtls_test_driver_mac_hooks.driver_status =
46 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020047 }
48 else
49 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +020050#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanae3ec522021-05-10 11:18:20 +020051 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +010052 libtestdriver1_mbedtls_psa_mac_compute(
Steven Cooremanc7f0a572021-04-29 21:10:11 +020053 attributes, key_buffer, key_buffer_size, alg,
54 input, input_length,
55 mac, mac_size, mac_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +020056#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
57 mbedtls_test_driver_mac_hooks.driver_status =
58 mbedtls_psa_mac_compute(
59 attributes, key_buffer, key_buffer_size, alg,
60 input, input_length,
61 mac, mac_size, mac_length );
62#else
63 (void) attributes;
64 (void) key_buffer;
65 (void) key_buffer_size;
66 (void) alg;
67 (void) input;
68 (void) input_length;
69 (void) mac;
70 (void) mac_size;
71 (void) mac_length;
72 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
73#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +020074 }
75
Steven Cooremanae3ec522021-05-10 11:18:20 +020076 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +020077}
78
79psa_status_t mbedtls_test_transparent_mac_sign_setup(
80 mbedtls_transparent_test_driver_mac_operation_t *operation,
81 const psa_key_attributes_t *attributes,
82 const uint8_t *key_buffer,
83 size_t key_buffer_size,
84 psa_algorithm_t alg )
85{
Steven Cooremanae3ec522021-05-10 11:18:20 +020086 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020087
Steven Cooremanae3ec522021-05-10 11:18:20 +020088 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +020089 {
Steven Cooremanae3ec522021-05-10 11:18:20 +020090 mbedtls_test_driver_mac_hooks.driver_status =
91 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020092 }
93 else
94 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +020095#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanae3ec522021-05-10 11:18:20 +020096 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +010097 libtestdriver1_mbedtls_psa_mac_sign_setup(
Steven Cooremanc7f0a572021-04-29 21:10:11 +020098 operation, attributes, key_buffer, key_buffer_size, alg );
Ronald Cron73c9d9e2021-04-09 11:09:54 +020099#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
100 mbedtls_test_driver_mac_hooks.driver_status =
101 mbedtls_psa_mac_sign_setup(
102 operation, attributes, key_buffer, key_buffer_size, alg );
103#else
104 (void) operation;
105 (void) attributes;
106 (void) key_buffer;
107 (void) key_buffer_size;
108 (void) alg;
109 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
110#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200111 }
112
Steven Cooremanae3ec522021-05-10 11:18:20 +0200113 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200114}
115
116psa_status_t mbedtls_test_transparent_mac_verify_setup(
117 mbedtls_transparent_test_driver_mac_operation_t *operation,
118 const psa_key_attributes_t *attributes,
119 const uint8_t *key_buffer,
120 size_t key_buffer_size,
121 psa_algorithm_t alg )
122{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200123 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200124
Steven Cooremanae3ec522021-05-10 11:18:20 +0200125 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200126 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200127 mbedtls_test_driver_mac_hooks.driver_status =
128 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200129 }
130 else
131 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200132#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200133 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100134 libtestdriver1_mbedtls_psa_mac_verify_setup(
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200135 operation, attributes, key_buffer, key_buffer_size, alg );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200136#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
137 mbedtls_test_driver_mac_hooks.driver_status =
138 mbedtls_psa_mac_verify_setup(
139 operation, attributes, key_buffer, key_buffer_size, alg );
140#else
141 (void) operation;
142 (void) attributes;
143 (void) key_buffer;
144 (void) key_buffer_size;
145 (void) alg;
146 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
147#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200148 }
149
Steven Cooremanae3ec522021-05-10 11:18:20 +0200150 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200151}
152
153psa_status_t mbedtls_test_transparent_mac_update(
154 mbedtls_transparent_test_driver_mac_operation_t *operation,
155 const uint8_t *input,
156 size_t input_length )
157{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200158 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200159
Steven Cooremanae3ec522021-05-10 11:18:20 +0200160 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200161 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200162 mbedtls_test_driver_mac_hooks.driver_status =
163 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200164 }
165 else
166 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200167#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200168 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100169 libtestdriver1_mbedtls_psa_mac_update(
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200170 operation, input, input_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200171#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
172 mbedtls_test_driver_mac_hooks.driver_status =
173 mbedtls_psa_mac_update(
174 operation, input, input_length );
175#else
176 (void) operation;
177 (void) input;
178 (void) input_length;
179 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
180#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200181 }
182
Steven Cooremanae3ec522021-05-10 11:18:20 +0200183 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200184}
185
186psa_status_t mbedtls_test_transparent_mac_sign_finish(
187 mbedtls_transparent_test_driver_mac_operation_t *operation,
188 uint8_t *mac,
189 size_t mac_size,
190 size_t *mac_length )
191{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200192 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200193
Steven Cooremanae3ec522021-05-10 11:18:20 +0200194 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200195 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200196 mbedtls_test_driver_mac_hooks.driver_status =
197 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200198 }
199 else
200 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200201#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200202 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100203 libtestdriver1_mbedtls_psa_mac_sign_finish(
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200204 operation, mac, mac_size, mac_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200205#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
206 mbedtls_test_driver_mac_hooks.driver_status =
207 mbedtls_psa_mac_sign_finish(
208 operation, mac, mac_size, mac_length );
209#else
210 (void) operation;
211 (void) mac;
212 (void) mac_size;
213 (void) mac_length;
214 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
215#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200216 }
217
Steven Cooremanae3ec522021-05-10 11:18:20 +0200218 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200219}
220
221psa_status_t mbedtls_test_transparent_mac_verify_finish(
222 mbedtls_transparent_test_driver_mac_operation_t *operation,
223 const uint8_t *mac,
224 size_t mac_length )
225{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200226 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200227
Steven Cooremanae3ec522021-05-10 11:18:20 +0200228 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200229 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200230 mbedtls_test_driver_mac_hooks.driver_status =
231 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200232 }
233 else
234 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200235#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200236 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100237 libtestdriver1_mbedtls_psa_mac_verify_finish(
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200238 operation, mac, mac_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200239#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
240 mbedtls_test_driver_mac_hooks.driver_status =
241 mbedtls_psa_mac_verify_finish(
242 operation, mac, mac_length );
243#else
244 (void) operation;
245 (void) mac;
246 (void) mac_length;
247 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
248#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200249 }
250
Steven Cooremanae3ec522021-05-10 11:18:20 +0200251 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200252}
253
254psa_status_t mbedtls_test_transparent_mac_abort(
255 mbedtls_transparent_test_driver_mac_operation_t *operation )
256{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200257 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200258
Steven Cooremanae3ec522021-05-10 11:18:20 +0200259 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200260 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200261 mbedtls_test_driver_mac_hooks.driver_status =
262 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200263 }
264 else
265 {
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200266#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200267 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100268 libtestdriver1_mbedtls_psa_mac_abort( operation );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200269#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
270 mbedtls_test_driver_mac_hooks.driver_status =
271 mbedtls_psa_mac_abort( operation );
272#else
273 (void) operation;
274 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
275#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200276 }
277
Steven Cooremanae3ec522021-05-10 11:18:20 +0200278 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200279}
280
281psa_status_t mbedtls_test_opaque_mac_compute(
282 const psa_key_attributes_t *attributes,
283 const uint8_t *key_buffer,
284 size_t key_buffer_size,
285 psa_algorithm_t alg,
286 const uint8_t *input,
287 size_t input_length,
288 uint8_t *mac,
289 size_t mac_size,
290 size_t *mac_length )
291{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200292 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200293
Steven Cooremanae3ec522021-05-10 11:18:20 +0200294 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200295 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200296 mbedtls_test_driver_mac_hooks.driver_status =
297 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200298 }
299 else
300 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200301 (void) attributes;
302 (void) key_buffer;
303 (void) key_buffer_size;
304 (void) alg;
305 (void) input;
306 (void) input_length;
307 (void) mac;
308 (void) mac_size;
309 (void) mac_length;
310 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200311 }
312
Steven Cooremanae3ec522021-05-10 11:18:20 +0200313 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200314}
315
316psa_status_t mbedtls_test_opaque_mac_sign_setup(
317 mbedtls_opaque_test_driver_mac_operation_t *operation,
318 const psa_key_attributes_t *attributes,
319 const uint8_t *key_buffer,
320 size_t key_buffer_size,
321 psa_algorithm_t alg )
322{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200323 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200324
Steven Cooremanae3ec522021-05-10 11:18:20 +0200325 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200326 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200327 mbedtls_test_driver_mac_hooks.driver_status =
328 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200329 }
330 else
331 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200332 (void) operation;
333 (void) attributes;
334 (void) key_buffer;
335 (void) key_buffer_size;
336 (void) alg;
337 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200338 }
339
Steven Cooremanae3ec522021-05-10 11:18:20 +0200340 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200341}
342
343psa_status_t mbedtls_test_opaque_mac_verify_setup(
344 mbedtls_opaque_test_driver_mac_operation_t *operation,
345 const psa_key_attributes_t *attributes,
346 const uint8_t *key_buffer,
347 size_t key_buffer_size,
348 psa_algorithm_t alg )
349{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200350 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200351
Steven Cooremanae3ec522021-05-10 11:18:20 +0200352 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200353 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200354 mbedtls_test_driver_mac_hooks.driver_status =
355 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200356 }
357 else
358 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200359 (void) operation;
360 (void) attributes;
361 (void) key_buffer;
362 (void) key_buffer_size;
363 (void) alg;
364 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200365 }
366
Steven Cooremanae3ec522021-05-10 11:18:20 +0200367 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200368}
369
370psa_status_t mbedtls_test_opaque_mac_update(
371 mbedtls_opaque_test_driver_mac_operation_t *operation,
372 const uint8_t *input,
373 size_t input_length )
374{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200375 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200376
Steven Cooremanae3ec522021-05-10 11:18:20 +0200377 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200378 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200379 mbedtls_test_driver_mac_hooks.driver_status =
380 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200381 }
382 else
383 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200384 (void) operation;
385 (void) input;
386 (void) input_length;
387 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200388 }
389
Steven Cooremanae3ec522021-05-10 11:18:20 +0200390 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200391}
392
393psa_status_t mbedtls_test_opaque_mac_sign_finish(
394 mbedtls_opaque_test_driver_mac_operation_t *operation,
395 uint8_t *mac,
396 size_t mac_size,
397 size_t *mac_length )
398{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200399 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200400
Steven Cooremanae3ec522021-05-10 11:18:20 +0200401 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200402 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200403 mbedtls_test_driver_mac_hooks.driver_status =
404 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200405 }
406 else
407 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200408 (void) operation;
409 (void) mac;
410 (void) mac_size;
411 (void) mac_length;
412 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200413 }
414
Steven Cooremanae3ec522021-05-10 11:18:20 +0200415 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200416}
417
418psa_status_t mbedtls_test_opaque_mac_verify_finish(
419 mbedtls_opaque_test_driver_mac_operation_t *operation,
420 const uint8_t *mac,
421 size_t mac_length )
422{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200423 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200424
Steven Cooremanae3ec522021-05-10 11:18:20 +0200425 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200426 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200427 mbedtls_test_driver_mac_hooks.driver_status =
428 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200429 }
430 else
431 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200432 (void) operation;
433 (void) mac;
434 (void) mac_length;
435 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200436 }
437
Steven Cooremanae3ec522021-05-10 11:18:20 +0200438 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200439}
440
441psa_status_t mbedtls_test_opaque_mac_abort(
442 mbedtls_opaque_test_driver_mac_operation_t *operation )
443{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200444 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200445
Steven Cooremanae3ec522021-05-10 11:18:20 +0200446 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200447 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200448 mbedtls_test_driver_mac_hooks.driver_status =
449 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200450 }
451 else
452 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200453 (void) operation;
454 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200455 }
456
Steven Cooremanae3ec522021-05-10 11:18:20 +0200457 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200458}
459
460#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */