blob: 06b6eb77ab7ad1d9b32e704d562cdd7e23062407 [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
Ronald Cronb814bda2021-09-13 14:50:42 +020031#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
32#include "libtestdriver1/library/psa_crypto_mac.h"
33#endif
34
Steven Cooremanbe21dab2021-05-10 11:18:20 +020035mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks =
36 MBEDTLS_TEST_DRIVER_MAC_INIT;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020037
38psa_status_t mbedtls_test_transparent_mac_compute(
39 const psa_key_attributes_t *attributes,
40 const uint8_t *key_buffer,
41 size_t key_buffer_size,
42 psa_algorithm_t alg,
43 const uint8_t *input,
44 size_t input_length,
45 uint8_t *mac,
46 size_t mac_size,
47 size_t *mac_length )
48{
Steven Cooremanbe21dab2021-05-10 11:18:20 +020049 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020050
Steven Cooremanbe21dab2021-05-10 11:18:20 +020051 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020052 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +020053 mbedtls_test_driver_mac_hooks.driver_status =
54 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020055 }
56 else
57 {
Ronald Cronb814bda2021-09-13 14:50:42 +020058#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
59 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanbe21dab2021-05-10 11:18:20 +020060 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +010061 libtestdriver1_mbedtls_psa_mac_compute(
Ronald Cronb814bda2021-09-13 14:50:42 +020062 (const libtestdriver1_psa_key_attributes_t *)attributes,
63 key_buffer, key_buffer_size, alg,
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020064 input, input_length,
65 mac, mac_size, mac_length );
Ronald Cron2091eed2021-04-09 11:09:54 +020066#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
67 mbedtls_test_driver_mac_hooks.driver_status =
68 mbedtls_psa_mac_compute(
69 attributes, key_buffer, key_buffer_size, alg,
70 input, input_length,
71 mac, mac_size, mac_length );
72#else
73 (void) attributes;
74 (void) key_buffer;
75 (void) key_buffer_size;
76 (void) alg;
77 (void) input;
78 (void) input_length;
79 (void) mac;
80 (void) mac_size;
81 (void) mac_length;
82 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
83#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020084 }
85
Steven Cooremanbe21dab2021-05-10 11:18:20 +020086 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020087}
88
89psa_status_t mbedtls_test_transparent_mac_sign_setup(
90 mbedtls_transparent_test_driver_mac_operation_t *operation,
91 const psa_key_attributes_t *attributes,
92 const uint8_t *key_buffer,
93 size_t key_buffer_size,
94 psa_algorithm_t alg )
95{
Steven Cooremanbe21dab2021-05-10 11:18:20 +020096 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020097
Steven Cooremanbe21dab2021-05-10 11:18:20 +020098 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020099 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200100 mbedtls_test_driver_mac_hooks.driver_status =
101 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200102 }
103 else
104 {
Ronald Cronb814bda2021-09-13 14:50:42 +0200105#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
106 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200107 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100108 libtestdriver1_mbedtls_psa_mac_sign_setup(
Ronald Cronb814bda2021-09-13 14:50:42 +0200109 operation,
110 (const libtestdriver1_psa_key_attributes_t *)attributes,
111 key_buffer, key_buffer_size, alg );
Ronald Cron2091eed2021-04-09 11:09:54 +0200112#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
113 mbedtls_test_driver_mac_hooks.driver_status =
114 mbedtls_psa_mac_sign_setup(
115 operation, attributes, key_buffer, key_buffer_size, alg );
116#else
117 (void) operation;
118 (void) attributes;
119 (void) key_buffer;
120 (void) key_buffer_size;
121 (void) alg;
122 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
123#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200124 }
125
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200126 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200127}
128
129psa_status_t mbedtls_test_transparent_mac_verify_setup(
130 mbedtls_transparent_test_driver_mac_operation_t *operation,
131 const psa_key_attributes_t *attributes,
132 const uint8_t *key_buffer,
133 size_t key_buffer_size,
134 psa_algorithm_t alg )
135{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200136 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200137
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200138 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200139 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200140 mbedtls_test_driver_mac_hooks.driver_status =
141 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200142 }
143 else
144 {
Ronald Cronb814bda2021-09-13 14:50:42 +0200145#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
146 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200147 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100148 libtestdriver1_mbedtls_psa_mac_verify_setup(
Ronald Cronb814bda2021-09-13 14:50:42 +0200149 operation,
150 (const libtestdriver1_psa_key_attributes_t *)attributes,
151 key_buffer, key_buffer_size, alg );
Ronald Cron2091eed2021-04-09 11:09:54 +0200152#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
153 mbedtls_test_driver_mac_hooks.driver_status =
154 mbedtls_psa_mac_verify_setup(
155 operation, attributes, key_buffer, key_buffer_size, alg );
156#else
157 (void) operation;
158 (void) attributes;
159 (void) key_buffer;
160 (void) key_buffer_size;
161 (void) alg;
162 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
163#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200164 }
165
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200166 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200167}
168
169psa_status_t mbedtls_test_transparent_mac_update(
170 mbedtls_transparent_test_driver_mac_operation_t *operation,
171 const uint8_t *input,
172 size_t input_length )
173{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200174 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200175
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200176 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200177 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200178 mbedtls_test_driver_mac_hooks.driver_status =
179 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200180 }
181 else
182 {
Ronald Cronb814bda2021-09-13 14:50:42 +0200183#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
184 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200185 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100186 libtestdriver1_mbedtls_psa_mac_update(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200187 operation, input, input_length );
Ronald Cron2091eed2021-04-09 11:09:54 +0200188#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
189 mbedtls_test_driver_mac_hooks.driver_status =
190 mbedtls_psa_mac_update(
191 operation, input, input_length );
192#else
193 (void) operation;
194 (void) input;
195 (void) input_length;
196 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
197#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200198 }
199
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200200 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200201}
202
203psa_status_t mbedtls_test_transparent_mac_sign_finish(
204 mbedtls_transparent_test_driver_mac_operation_t *operation,
205 uint8_t *mac,
206 size_t mac_size,
207 size_t *mac_length )
208{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200209 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200210
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200211 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200212 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200213 mbedtls_test_driver_mac_hooks.driver_status =
214 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200215 }
216 else
217 {
Ronald Cronb814bda2021-09-13 14:50:42 +0200218#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
219 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200220 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100221 libtestdriver1_mbedtls_psa_mac_sign_finish(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200222 operation, mac, mac_size, mac_length );
Ronald Cron2091eed2021-04-09 11:09:54 +0200223#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
224 mbedtls_test_driver_mac_hooks.driver_status =
225 mbedtls_psa_mac_sign_finish(
226 operation, mac, mac_size, mac_length );
227#else
228 (void) operation;
229 (void) mac;
230 (void) mac_size;
231 (void) mac_length;
232 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
233#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200234 }
235
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200236 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200237}
238
239psa_status_t mbedtls_test_transparent_mac_verify_finish(
240 mbedtls_transparent_test_driver_mac_operation_t *operation,
241 const uint8_t *mac,
242 size_t mac_length )
243{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200244 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200245
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200246 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200247 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200248 mbedtls_test_driver_mac_hooks.driver_status =
249 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200250 }
251 else
252 {
Ronald Cronb814bda2021-09-13 14:50:42 +0200253#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
254 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200255 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100256 libtestdriver1_mbedtls_psa_mac_verify_finish(
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200257 operation, mac, mac_length );
Ronald Cron2091eed2021-04-09 11:09:54 +0200258#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
259 mbedtls_test_driver_mac_hooks.driver_status =
260 mbedtls_psa_mac_verify_finish(
261 operation, mac, mac_length );
262#else
263 (void) operation;
264 (void) mac;
265 (void) mac_length;
266 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
267#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200268 }
269
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200270 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200271}
272
273psa_status_t mbedtls_test_transparent_mac_abort(
274 mbedtls_transparent_test_driver_mac_operation_t *operation )
275{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200276 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200277
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200278 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200279 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200280 mbedtls_test_driver_mac_hooks.driver_status =
281 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200282 }
283 else
284 {
Ronald Cronb814bda2021-09-13 14:50:42 +0200285#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
286 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200287 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron7b7854e2021-03-13 18:19:08 +0100288 libtestdriver1_mbedtls_psa_mac_abort( operation );
Ronald Cron2091eed2021-04-09 11:09:54 +0200289#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
290 mbedtls_test_driver_mac_hooks.driver_status =
291 mbedtls_psa_mac_abort( operation );
292#else
293 (void) operation;
294 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
295#endif
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200296 }
297
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200298 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200299}
300
301psa_status_t mbedtls_test_opaque_mac_compute(
302 const psa_key_attributes_t *attributes,
303 const uint8_t *key_buffer,
304 size_t key_buffer_size,
305 psa_algorithm_t alg,
306 const uint8_t *input,
307 size_t input_length,
308 uint8_t *mac,
309 size_t mac_size,
310 size_t *mac_length )
311{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200312 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200313
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200314 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200315 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200316 mbedtls_test_driver_mac_hooks.driver_status =
317 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200318 }
319 else
320 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200321 (void) attributes;
322 (void) key_buffer;
323 (void) key_buffer_size;
324 (void) alg;
325 (void) input;
326 (void) input_length;
327 (void) mac;
328 (void) mac_size;
329 (void) mac_length;
330 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200331 }
332
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200333 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200334}
335
336psa_status_t mbedtls_test_opaque_mac_sign_setup(
337 mbedtls_opaque_test_driver_mac_operation_t *operation,
338 const psa_key_attributes_t *attributes,
339 const uint8_t *key_buffer,
340 size_t key_buffer_size,
341 psa_algorithm_t alg )
342{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200343 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200344
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200345 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200346 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200347 mbedtls_test_driver_mac_hooks.driver_status =
348 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200349 }
350 else
351 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200352 (void) operation;
353 (void) attributes;
354 (void) key_buffer;
355 (void) key_buffer_size;
356 (void) alg;
357 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200358 }
359
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200360 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200361}
362
363psa_status_t mbedtls_test_opaque_mac_verify_setup(
364 mbedtls_opaque_test_driver_mac_operation_t *operation,
365 const psa_key_attributes_t *attributes,
366 const uint8_t *key_buffer,
367 size_t key_buffer_size,
368 psa_algorithm_t alg )
369{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200370 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200371
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200372 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200373 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200374 mbedtls_test_driver_mac_hooks.driver_status =
375 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200376 }
377 else
378 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200379 (void) operation;
380 (void) attributes;
381 (void) key_buffer;
382 (void) key_buffer_size;
383 (void) alg;
384 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200385 }
386
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200387 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200388}
389
390psa_status_t mbedtls_test_opaque_mac_update(
391 mbedtls_opaque_test_driver_mac_operation_t *operation,
392 const uint8_t *input,
393 size_t input_length )
394{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200395 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200396
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200397 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200398 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200399 mbedtls_test_driver_mac_hooks.driver_status =
400 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200401 }
402 else
403 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200404 (void) operation;
405 (void) input;
406 (void) input_length;
407 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200408 }
409
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200410 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200411}
412
413psa_status_t mbedtls_test_opaque_mac_sign_finish(
414 mbedtls_opaque_test_driver_mac_operation_t *operation,
415 uint8_t *mac,
416 size_t mac_size,
417 size_t *mac_length )
418{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200419 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200420
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200421 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200422 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200423 mbedtls_test_driver_mac_hooks.driver_status =
424 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200425 }
426 else
427 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200428 (void) operation;
429 (void) mac;
430 (void) mac_size;
431 (void) mac_length;
432 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200433 }
434
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200435 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200436}
437
438psa_status_t mbedtls_test_opaque_mac_verify_finish(
439 mbedtls_opaque_test_driver_mac_operation_t *operation,
440 const uint8_t *mac,
441 size_t mac_length )
442{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200443 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200444
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200445 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200446 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200447 mbedtls_test_driver_mac_hooks.driver_status =
448 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200449 }
450 else
451 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200452 (void) operation;
453 (void) mac;
454 (void) mac_length;
455 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200456 }
457
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200458 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200459}
460
461psa_status_t mbedtls_test_opaque_mac_abort(
462 mbedtls_opaque_test_driver_mac_operation_t *operation )
463{
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200464 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200465
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200466 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200467 {
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200468 mbedtls_test_driver_mac_hooks.driver_status =
469 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200470 }
471 else
472 {
Ronald Crona2dbe662021-07-01 11:24:02 +0200473 (void) operation;
474 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200475 }
476
Steven Cooremanbe21dab2021-05-10 11:18:20 +0200477 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200478}
479
480#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */