blob: f909785dfd1720fa1f847bf27e51e11d2aabce2a [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
Ronald Cron7975fae2021-09-13 14:50:42 +020027#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
28#include "libtestdriver1/library/psa_crypto_mac.h"
29#endif
30
Steven Cooremanae3ec522021-05-10 11:18:20 +020031mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks =
32 MBEDTLS_TEST_DRIVER_MAC_INIT;
Steven Cooremanc7f0a572021-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 Cooremanae3ec522021-05-10 11:18:20 +020045 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020046
Steven Cooremanae3ec522021-05-10 11:18:20 +020047 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +020048 {
Steven Cooremanae3ec522021-05-10 11:18:20 +020049 mbedtls_test_driver_mac_hooks.driver_status =
50 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020051 }
52 else
53 {
Ronald Cron7975fae2021-09-13 14:50:42 +020054#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
55 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanae3ec522021-05-10 11:18:20 +020056 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +010057 libtestdriver1_mbedtls_psa_mac_compute(
Ronald Cron7975fae2021-09-13 14:50:42 +020058 (const libtestdriver1_psa_key_attributes_t *)attributes,
59 key_buffer, key_buffer_size, alg,
Steven Cooremanc7f0a572021-04-29 21:10:11 +020060 input, input_length,
61 mac, mac_size, mac_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +020062#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
63 mbedtls_test_driver_mac_hooks.driver_status =
64 mbedtls_psa_mac_compute(
65 attributes, key_buffer, key_buffer_size, alg,
66 input, input_length,
67 mac, mac_size, mac_length );
68#else
69 (void) attributes;
70 (void) key_buffer;
71 (void) key_buffer_size;
72 (void) alg;
73 (void) input;
74 (void) input_length;
75 (void) mac;
76 (void) mac_size;
77 (void) mac_length;
78 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
79#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +020080 }
81
Steven Cooremanae3ec522021-05-10 11:18:20 +020082 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +020083}
84
85psa_status_t mbedtls_test_transparent_mac_sign_setup(
86 mbedtls_transparent_test_driver_mac_operation_t *operation,
87 const psa_key_attributes_t *attributes,
88 const uint8_t *key_buffer,
89 size_t key_buffer_size,
90 psa_algorithm_t alg )
91{
Steven Cooremanae3ec522021-05-10 11:18:20 +020092 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020093
Steven Cooremanae3ec522021-05-10 11:18:20 +020094 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +020095 {
Steven Cooremanae3ec522021-05-10 11:18:20 +020096 mbedtls_test_driver_mac_hooks.driver_status =
97 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +020098 }
99 else
100 {
Ronald Cron7975fae2021-09-13 14:50:42 +0200101#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
102 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200103 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100104 libtestdriver1_mbedtls_psa_mac_sign_setup(
Ronald Cron7975fae2021-09-13 14:50:42 +0200105 operation,
106 (const libtestdriver1_psa_key_attributes_t *)attributes,
107 key_buffer, key_buffer_size, alg );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200108#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
109 mbedtls_test_driver_mac_hooks.driver_status =
110 mbedtls_psa_mac_sign_setup(
111 operation, attributes, key_buffer, key_buffer_size, alg );
112#else
113 (void) operation;
114 (void) attributes;
115 (void) key_buffer;
116 (void) key_buffer_size;
117 (void) alg;
118 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
119#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200120 }
121
Steven Cooremanae3ec522021-05-10 11:18:20 +0200122 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200123}
124
125psa_status_t mbedtls_test_transparent_mac_verify_setup(
126 mbedtls_transparent_test_driver_mac_operation_t *operation,
127 const psa_key_attributes_t *attributes,
128 const uint8_t *key_buffer,
129 size_t key_buffer_size,
130 psa_algorithm_t alg )
131{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200132 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200133
Steven Cooremanae3ec522021-05-10 11:18:20 +0200134 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200135 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200136 mbedtls_test_driver_mac_hooks.driver_status =
137 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200138 }
139 else
140 {
Ronald Cron7975fae2021-09-13 14:50:42 +0200141#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
142 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200143 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100144 libtestdriver1_mbedtls_psa_mac_verify_setup(
Ronald Cron7975fae2021-09-13 14:50:42 +0200145 operation,
146 (const libtestdriver1_psa_key_attributes_t *)attributes,
147 key_buffer, key_buffer_size, alg );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200148#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
149 mbedtls_test_driver_mac_hooks.driver_status =
150 mbedtls_psa_mac_verify_setup(
151 operation, attributes, key_buffer, key_buffer_size, alg );
152#else
153 (void) operation;
154 (void) attributes;
155 (void) key_buffer;
156 (void) key_buffer_size;
157 (void) alg;
158 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
159#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200160 }
161
Steven Cooremanae3ec522021-05-10 11:18:20 +0200162 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200163}
164
165psa_status_t mbedtls_test_transparent_mac_update(
166 mbedtls_transparent_test_driver_mac_operation_t *operation,
167 const uint8_t *input,
168 size_t input_length )
169{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200170 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200171
Steven Cooremanae3ec522021-05-10 11:18:20 +0200172 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200173 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200174 mbedtls_test_driver_mac_hooks.driver_status =
175 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200176 }
177 else
178 {
Ronald Cron7975fae2021-09-13 14:50:42 +0200179#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
180 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200181 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100182 libtestdriver1_mbedtls_psa_mac_update(
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200183 operation, input, input_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200184#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
185 mbedtls_test_driver_mac_hooks.driver_status =
186 mbedtls_psa_mac_update(
187 operation, input, input_length );
188#else
189 (void) operation;
190 (void) input;
191 (void) input_length;
192 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
193#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200194 }
195
Steven Cooremanae3ec522021-05-10 11:18:20 +0200196 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200197}
198
199psa_status_t mbedtls_test_transparent_mac_sign_finish(
200 mbedtls_transparent_test_driver_mac_operation_t *operation,
201 uint8_t *mac,
202 size_t mac_size,
203 size_t *mac_length )
204{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200205 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200206
Steven Cooremanae3ec522021-05-10 11:18:20 +0200207 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200208 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200209 mbedtls_test_driver_mac_hooks.driver_status =
210 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200211 }
212 else
213 {
Ronald Cron7975fae2021-09-13 14:50:42 +0200214#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
215 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200216 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100217 libtestdriver1_mbedtls_psa_mac_sign_finish(
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200218 operation, mac, mac_size, mac_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200219#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
220 mbedtls_test_driver_mac_hooks.driver_status =
221 mbedtls_psa_mac_sign_finish(
222 operation, mac, mac_size, mac_length );
223#else
224 (void) operation;
225 (void) mac;
226 (void) mac_size;
227 (void) mac_length;
228 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
229#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200230 }
231
Steven Cooremanae3ec522021-05-10 11:18:20 +0200232 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200233}
234
235psa_status_t mbedtls_test_transparent_mac_verify_finish(
236 mbedtls_transparent_test_driver_mac_operation_t *operation,
237 const uint8_t *mac,
238 size_t mac_length )
239{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200240 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200241
Steven Cooremanae3ec522021-05-10 11:18:20 +0200242 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200243 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200244 mbedtls_test_driver_mac_hooks.driver_status =
245 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200246 }
247 else
248 {
Ronald Cron7975fae2021-09-13 14:50:42 +0200249#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
250 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200251 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100252 libtestdriver1_mbedtls_psa_mac_verify_finish(
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200253 operation, mac, mac_length );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200254#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
255 mbedtls_test_driver_mac_hooks.driver_status =
256 mbedtls_psa_mac_verify_finish(
257 operation, mac, mac_length );
258#else
259 (void) operation;
260 (void) mac;
261 (void) mac_length;
262 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
263#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200264 }
265
Steven Cooremanae3ec522021-05-10 11:18:20 +0200266 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200267}
268
269psa_status_t mbedtls_test_transparent_mac_abort(
270 mbedtls_transparent_test_driver_mac_operation_t *operation )
271{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200272 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200273
Steven Cooremanae3ec522021-05-10 11:18:20 +0200274 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200275 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200276 mbedtls_test_driver_mac_hooks.driver_status =
277 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200278 }
279 else
280 {
Ronald Cron7975fae2021-09-13 14:50:42 +0200281#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
282 defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
Steven Cooremanae3ec522021-05-10 11:18:20 +0200283 mbedtls_test_driver_mac_hooks.driver_status =
Ronald Cron40170d92021-03-13 18:19:08 +0100284 libtestdriver1_mbedtls_psa_mac_abort( operation );
Ronald Cron73c9d9e2021-04-09 11:09:54 +0200285#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
286 mbedtls_test_driver_mac_hooks.driver_status =
287 mbedtls_psa_mac_abort( operation );
288#else
289 (void) operation;
290 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
291#endif
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200292 }
293
Steven Cooremanae3ec522021-05-10 11:18:20 +0200294 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200295}
296
297psa_status_t mbedtls_test_opaque_mac_compute(
298 const psa_key_attributes_t *attributes,
299 const uint8_t *key_buffer,
300 size_t key_buffer_size,
301 psa_algorithm_t alg,
302 const uint8_t *input,
303 size_t input_length,
304 uint8_t *mac,
305 size_t mac_size,
306 size_t *mac_length )
307{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200308 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200309
Steven Cooremanae3ec522021-05-10 11:18:20 +0200310 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200311 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200312 mbedtls_test_driver_mac_hooks.driver_status =
313 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200314 }
315 else
316 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200317 (void) attributes;
318 (void) key_buffer;
319 (void) key_buffer_size;
320 (void) alg;
321 (void) input;
322 (void) input_length;
323 (void) mac;
324 (void) mac_size;
325 (void) mac_length;
326 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200327 }
328
Steven Cooremanae3ec522021-05-10 11:18:20 +0200329 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200330}
331
332psa_status_t mbedtls_test_opaque_mac_sign_setup(
333 mbedtls_opaque_test_driver_mac_operation_t *operation,
334 const psa_key_attributes_t *attributes,
335 const uint8_t *key_buffer,
336 size_t key_buffer_size,
337 psa_algorithm_t alg )
338{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200339 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200340
Steven Cooremanae3ec522021-05-10 11:18:20 +0200341 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200342 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200343 mbedtls_test_driver_mac_hooks.driver_status =
344 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200345 }
346 else
347 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200348 (void) operation;
349 (void) attributes;
350 (void) key_buffer;
351 (void) key_buffer_size;
352 (void) alg;
353 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200354 }
355
Steven Cooremanae3ec522021-05-10 11:18:20 +0200356 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200357}
358
359psa_status_t mbedtls_test_opaque_mac_verify_setup(
360 mbedtls_opaque_test_driver_mac_operation_t *operation,
361 const psa_key_attributes_t *attributes,
362 const uint8_t *key_buffer,
363 size_t key_buffer_size,
364 psa_algorithm_t alg )
365{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200366 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200367
Steven Cooremanae3ec522021-05-10 11:18:20 +0200368 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200369 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200370 mbedtls_test_driver_mac_hooks.driver_status =
371 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200372 }
373 else
374 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200375 (void) operation;
376 (void) attributes;
377 (void) key_buffer;
378 (void) key_buffer_size;
379 (void) alg;
380 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200381 }
382
Steven Cooremanae3ec522021-05-10 11:18:20 +0200383 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200384}
385
386psa_status_t mbedtls_test_opaque_mac_update(
387 mbedtls_opaque_test_driver_mac_operation_t *operation,
388 const uint8_t *input,
389 size_t input_length )
390{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200391 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200392
Steven Cooremanae3ec522021-05-10 11:18:20 +0200393 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200394 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200395 mbedtls_test_driver_mac_hooks.driver_status =
396 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200397 }
398 else
399 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200400 (void) operation;
401 (void) input;
402 (void) input_length;
403 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200404 }
405
Steven Cooremanae3ec522021-05-10 11:18:20 +0200406 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200407}
408
409psa_status_t mbedtls_test_opaque_mac_sign_finish(
410 mbedtls_opaque_test_driver_mac_operation_t *operation,
411 uint8_t *mac,
412 size_t mac_size,
413 size_t *mac_length )
414{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200415 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200416
Steven Cooremanae3ec522021-05-10 11:18:20 +0200417 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200418 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200419 mbedtls_test_driver_mac_hooks.driver_status =
420 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200421 }
422 else
423 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200424 (void) operation;
425 (void) mac;
426 (void) mac_size;
427 (void) mac_length;
428 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200429 }
430
Steven Cooremanae3ec522021-05-10 11:18:20 +0200431 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200432}
433
434psa_status_t mbedtls_test_opaque_mac_verify_finish(
435 mbedtls_opaque_test_driver_mac_operation_t *operation,
436 const uint8_t *mac,
437 size_t mac_length )
438{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200439 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200440
Steven Cooremanae3ec522021-05-10 11:18:20 +0200441 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200442 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200443 mbedtls_test_driver_mac_hooks.driver_status =
444 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200445 }
446 else
447 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200448 (void) operation;
449 (void) mac;
450 (void) mac_length;
451 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200452 }
453
Steven Cooremanae3ec522021-05-10 11:18:20 +0200454 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200455}
456
457psa_status_t mbedtls_test_opaque_mac_abort(
458 mbedtls_opaque_test_driver_mac_operation_t *operation )
459{
Steven Cooremanae3ec522021-05-10 11:18:20 +0200460 mbedtls_test_driver_mac_hooks.hits++;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200461
Steven Cooremanae3ec522021-05-10 11:18:20 +0200462 if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200463 {
Steven Cooremanae3ec522021-05-10 11:18:20 +0200464 mbedtls_test_driver_mac_hooks.driver_status =
465 mbedtls_test_driver_mac_hooks.forced_status;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200466 }
467 else
468 {
Ronald Crona72b12d2021-07-01 11:24:02 +0200469 (void) operation;
470 mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200471 }
472
Steven Cooremanae3ec522021-05-10 11:18:20 +0200473 return( mbedtls_test_driver_mac_hooks.driver_status );
Steven Cooremanc7f0a572021-04-29 21:10:11 +0200474}
475
476#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */