blob: a6c2c88a6c93dd9a7e55e61d1ebc8bd16bbc3791 [file] [log] [blame]
Steven Cooreman2d9a3f92021-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
20#if !defined(MBEDTLS_CONFIG_FILE)
21#include "mbedtls/config.h"
22#else
23#include MBEDTLS_CONFIG_FILE
24#endif
25
26#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
27#include "psa_crypto_mac.h"
28
29#include "test/drivers/mac.h"
30
Steven Cooremanbe21dab2021-05-10 11:18:20 +020031mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks =
32 MBEDTLS_TEST_DRIVER_MAC_INIT;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020033
34psa_status_t mbedtls_test_transparent_mac_compute(
35 const psa_key_attributes_t *attributes,
36 const uint8_t *key_buffer,
37 size_t key_buffer_size,
38 psa_algorithm_t alg,
39 const uint8_t *input,
40 size_t input_length,
41 uint8_t *mac,
42 size_t mac_size,
43 size_t *mac_length )
44{
Steven Cooremanbe21dab2021-05-10 11:18:20 +020045 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020046
Steven Cooremanbe21dab2021-05-10 11:18:20 +020047 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020048 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +020049 mbedtls_test_driver_mac_hooks.driver_status =
50 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020051 }
52 else
53 {
Ronald Cron2091eed2021-04-09 11:09:54 +020054#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanbe21dab2021-05-10 11:18:20 +020055 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +010056 libtestdriver1_mbedtls_psa_mac_compute(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020057 attributes, key_buffer, key_buffer_size, alg,
58 input, input_length,
59 mac, mac_size, mac_length );
Ronald Cron2091eed2021-04-09 11:09:54 +020060#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
61 mbedtls_test_driver_mac_hooks.driver_status =
62 mbedtls_psa_mac_compute(
63 attributes, key_buffer, key_buffer_size, alg,
64 input, input_length,
65 mac, mac_size, mac_length );
66#else
67 (void) attributes;
68 (void) key_buffer;
69 (void) key_buffer_size;
70 (void) alg;
71 (void) input;
72 (void) input_length;
73 (void) mac;
74 (void) mac_size;
75 (void) mac_length;
76 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
77#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020078 }
79
Steven Cooremanbe21dab2021-05-10 11:18:20 +020080 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020081}
82
83psa_status_t mbedtls_test_transparent_mac_sign_setup(
84 mbedtls_transparent_test_driver_mac_operation_t *operation,
85 const psa_key_attributes_t *attributes,
86 const uint8_t *key_buffer,
87 size_t key_buffer_size,
88 psa_algorithm_t alg )
89{
Steven Cooremanbe21dab2021-05-10 11:18:20 +020090 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020091
Steven Cooremanbe21dab2021-05-10 11:18:20 +020092 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020093 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +020094 mbedtls_test_driver_mac_hooks.driver_status =
95 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020096 }
97 else
98 {
Ronald Cron2091eed2021-04-09 11:09:54 +020099#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200100 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100101 libtestdriver1_mbedtls_psa_mac_sign_setup(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200102 operation, attributes, key_buffer, key_buffer_size, alg );
Ronald Cron2091eed2021-04-09 11:09:54 +0200103#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
104 mbedtls_test_driver_mac_hooks.driver_status =
105 mbedtls_psa_mac_sign_setup(
106 operation, attributes, key_buffer, key_buffer_size, alg );
107#else
108 (void) operation;
109 (void) attributes;
110 (void) key_buffer;
111 (void) key_buffer_size;
112 (void) alg;
113 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
114#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200115 }
116
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200117 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200118}
119
120psa_status_t mbedtls_test_transparent_mac_verify_setup(
121 mbedtls_transparent_test_driver_mac_operation_t *operation,
122 const psa_key_attributes_t *attributes,
123 const uint8_t *key_buffer,
124 size_t key_buffer_size,
125 psa_algorithm_t alg )
126{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200127 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200128
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200129 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200130 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200131 mbedtls_test_driver_mac_hooks.driver_status =
132 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200133 }
134 else
135 {
Ronald Cron2091eed2021-04-09 11:09:54 +0200136#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200137 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100138 libtestdriver1_mbedtls_psa_mac_verify_setup(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200139 operation, attributes, key_buffer, key_buffer_size, alg );
Ronald Cron2091eed2021-04-09 11:09:54 +0200140#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
141 mbedtls_test_driver_mac_hooks.driver_status =
142 mbedtls_psa_mac_verify_setup(
143 operation, attributes, key_buffer, key_buffer_size, alg );
144#else
145 (void) operation;
146 (void) attributes;
147 (void) key_buffer;
148 (void) key_buffer_size;
149 (void) alg;
150 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
151#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200152 }
153
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200154 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200155}
156
157psa_status_t mbedtls_test_transparent_mac_update(
158 mbedtls_transparent_test_driver_mac_operation_t *operation,
159 const uint8_t *input,
160 size_t input_length )
161{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200162 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200163
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200164 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200165 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200166 mbedtls_test_driver_mac_hooks.driver_status =
167 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200168 }
169 else
170 {
Ronald Cron2091eed2021-04-09 11:09:54 +0200171#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200172 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100173 libtestdriver1_mbedtls_psa_mac_update(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200174 operation, input, input_length );
Ronald Cron2091eed2021-04-09 11:09:54 +0200175#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
176 mbedtls_test_driver_mac_hooks.driver_status =
177 mbedtls_psa_mac_update(
178 operation, input, input_length );
179#else
180 (void) operation;
181 (void) input;
182 (void) input_length;
183 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
184#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200185 }
186
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200187 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200188}
189
190psa_status_t mbedtls_test_transparent_mac_sign_finish(
191 mbedtls_transparent_test_driver_mac_operation_t *operation,
192 uint8_t *mac,
193 size_t mac_size,
194 size_t *mac_length )
195{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200196 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200197
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200198 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200199 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200200 mbedtls_test_driver_mac_hooks.driver_status =
201 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200202 }
203 else
204 {
Ronald Cron2091eed2021-04-09 11:09:54 +0200205#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200206 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100207 libtestdriver1_mbedtls_psa_mac_sign_finish(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200208 operation, mac, mac_size, mac_length );
Ronald Cron2091eed2021-04-09 11:09:54 +0200209#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
210 mbedtls_test_driver_mac_hooks.driver_status =
211 mbedtls_psa_mac_sign_finish(
212 operation, mac, mac_size, mac_length );
213#else
214 (void) operation;
215 (void) mac;
216 (void) mac_size;
217 (void) mac_length;
218 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
219#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200220 }
221
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200222 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200223}
224
225psa_status_t mbedtls_test_transparent_mac_verify_finish(
226 mbedtls_transparent_test_driver_mac_operation_t *operation,
227 const uint8_t *mac,
228 size_t mac_length )
229{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200230 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200231
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200232 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200233 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200234 mbedtls_test_driver_mac_hooks.driver_status =
235 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200236 }
237 else
238 {
Ronald Cron2091eed2021-04-09 11:09:54 +0200239#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200240 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100241 libtestdriver1_mbedtls_psa_mac_verify_finish(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200242 operation, mac, mac_length );
Ronald Cron2091eed2021-04-09 11:09:54 +0200243#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
244 mbedtls_test_driver_mac_hooks.driver_status =
245 mbedtls_psa_mac_verify_finish(
246 operation, mac, mac_length );
247#else
248 (void) operation;
249 (void) mac;
250 (void) mac_length;
251 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
252#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200253 }
254
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200255 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200256}
257
258psa_status_t mbedtls_test_transparent_mac_abort(
259 mbedtls_transparent_test_driver_mac_operation_t *operation )
260{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200261 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200262
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200263 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200264 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200265 mbedtls_test_driver_mac_hooks.driver_status =
266 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200267 }
268 else
269 {
Ronald Cron2091eed2021-04-09 11:09:54 +0200270#if defined(MBEDTLS_PSA_CRYPTO_CONFIG)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200271 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100272 libtestdriver1_mbedtls_psa_mac_abort( operation );
Ronald Cron2091eed2021-04-09 11:09:54 +0200273#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
274 mbedtls_test_driver_mac_hooks.driver_status =
275 mbedtls_psa_mac_abort( operation );
276#else
277 (void) operation;
278 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
279#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200280 }
281
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200282 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200283}
284
285psa_status_t mbedtls_test_opaque_mac_compute(
286 const psa_key_attributes_t *attributes,
287 const uint8_t *key_buffer,
288 size_t key_buffer_size,
289 psa_algorithm_t alg,
290 const uint8_t *input,
291 size_t input_length,
292 uint8_t *mac,
293 size_t mac_size,
294 size_t *mac_length )
295{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200296 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200297
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200298 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200299 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200300 mbedtls_test_driver_mac_hooks.driver_status =
301 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200302 }
303 else
304 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200305 (void) attributes;
306 (void) key_buffer;
307 (void) key_buffer_size;
308 (void) alg;
309 (void) input;
310 (void) input_length;
311 (void) mac;
312 (void) mac_size;
313 (void) mac_length;
314 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200315 }
316
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200317 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200318}
319
320psa_status_t mbedtls_test_opaque_mac_sign_setup(
321 mbedtls_opaque_test_driver_mac_operation_t *operation,
322 const psa_key_attributes_t *attributes,
323 const uint8_t *key_buffer,
324 size_t key_buffer_size,
325 psa_algorithm_t alg )
326{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200327 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200328
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200329 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200330 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200331 mbedtls_test_driver_mac_hooks.driver_status =
332 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200333 }
334 else
335 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200336 (void) operation;
337 (void) attributes;
338 (void) key_buffer;
339 (void) key_buffer_size;
340 (void) alg;
341 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200342 }
343
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200344 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200345}
346
347psa_status_t mbedtls_test_opaque_mac_verify_setup(
348 mbedtls_opaque_test_driver_mac_operation_t *operation,
349 const psa_key_attributes_t *attributes,
350 const uint8_t *key_buffer,
351 size_t key_buffer_size,
352 psa_algorithm_t alg )
353{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200354 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200355
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200356 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200357 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200358 mbedtls_test_driver_mac_hooks.driver_status =
359 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200360 }
361 else
362 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200363 (void) operation;
364 (void) attributes;
365 (void) key_buffer;
366 (void) key_buffer_size;
367 (void) alg;
368 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200369 }
370
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200371 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200372}
373
374psa_status_t mbedtls_test_opaque_mac_update(
375 mbedtls_opaque_test_driver_mac_operation_t *operation,
376 const uint8_t *input,
377 size_t input_length )
378{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200379 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200380
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200381 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200382 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200383 mbedtls_test_driver_mac_hooks.driver_status =
384 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200385 }
386 else
387 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200388 (void) operation;
389 (void) input;
390 (void) input_length;
391 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200392 }
393
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200394 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200395}
396
397psa_status_t mbedtls_test_opaque_mac_sign_finish(
398 mbedtls_opaque_test_driver_mac_operation_t *operation,
399 uint8_t *mac,
400 size_t mac_size,
401 size_t *mac_length )
402{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200403 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200404
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200405 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200406 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200407 mbedtls_test_driver_mac_hooks.driver_status =
408 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200409 }
410 else
411 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200412 (void) operation;
413 (void) mac;
414 (void) mac_size;
415 (void) mac_length;
416 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200417 }
418
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200419 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200420}
421
422psa_status_t mbedtls_test_opaque_mac_verify_finish(
423 mbedtls_opaque_test_driver_mac_operation_t *operation,
424 const uint8_t *mac,
425 size_t mac_length )
426{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200427 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200428
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200429 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200430 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200431 mbedtls_test_driver_mac_hooks.driver_status =
432 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200433 }
434 else
435 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200436 (void) operation;
437 (void) mac;
438 (void) mac_length;
439 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200440 }
441
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200442 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200443}
444
445psa_status_t mbedtls_test_opaque_mac_abort(
446 mbedtls_opaque_test_driver_mac_operation_t *operation )
447{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200448 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200449
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200450 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200451 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200452 mbedtls_test_driver_mac_hooks.driver_status =
453 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200454 }
455 else
456 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200457 (void) operation;
458 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200459 }
460
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200461 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200462}
463
464#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */