blob: 252afca1f114a9c66538e4ef90907e8cb5cc7913 [file] [log] [blame]
Steven Cooreman896d51e2021-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
25#include <psa/crypto.h>
26#include "psa_crypto_core.h"
27#include "psa_crypto_mac.h"
Steven Cooreman32d56942021-03-19 17:39:17 +010028#include <mbedtls/md.h>
Steven Cooreman896d51e2021-03-19 15:24:23 +010029
30#include <mbedtls/error.h>
31#include <string.h>
32
33/* Use builtin defines specific to this compilation unit, since the test driver
34 * relies on the software driver. */
35#if( defined(MBEDTLS_PSA_BUILTIN_ALG_CMAC) || \
36 ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_CMAC) ) )
37#define BUILTIN_ALG_CMAC 1
38#endif
39#if( defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || \
40 ( defined(PSA_CRYPTO_DRIVER_TEST) && defined(MBEDTLS_PSA_ACCEL_ALG_HMAC) ) )
41#define BUILTIN_ALG_HMAC 1
42#endif
43
Steven Cooreman32d56942021-03-19 17:39:17 +010044#if defined(MBEDTLS_PSA_BUILTIN_ALG_HMAC) || defined(PSA_CRYPTO_DRIVER_TEST)
45static size_t psa_get_hash_block_size( psa_algorithm_t alg )
46{
47 switch( alg )
48 {
49 case PSA_ALG_MD2:
50 return( 16 );
51 case PSA_ALG_MD4:
52 return( 64 );
53 case PSA_ALG_MD5:
54 return( 64 );
55 case PSA_ALG_RIPEMD160:
56 return( 64 );
57 case PSA_ALG_SHA_1:
58 return( 64 );
59 case PSA_ALG_SHA_224:
60 return( 64 );
61 case PSA_ALG_SHA_256:
62 return( 64 );
63 case PSA_ALG_SHA_384:
64 return( 128 );
65 case PSA_ALG_SHA_512:
66 return( 128 );
67 default:
68 return( 0 );
69 }
70}
71
72psa_status_t psa_hmac_abort_internal( psa_hmac_internal_data *hmac )
73{
74 mbedtls_platform_zeroize( hmac->opad, sizeof( hmac->opad ) );
75 return( psa_hash_abort( &hmac->hash_ctx ) );
76}
77
78psa_status_t psa_hmac_setup_internal( psa_hmac_internal_data *hmac,
79 const uint8_t *key,
80 size_t key_length,
81 psa_algorithm_t hash_alg )
82{
83 uint8_t ipad[PSA_HMAC_MAX_HASH_BLOCK_SIZE];
84 size_t i;
85 size_t hash_size = PSA_HASH_LENGTH( hash_alg );
86 size_t block_size = psa_get_hash_block_size( hash_alg );
87 psa_status_t status;
88
89 hmac->alg = hash_alg;
90
91 /* Sanity checks on block_size, to guarantee that there won't be a buffer
92 * overflow below. This should never trigger if the hash algorithm
93 * is implemented correctly. */
94 /* The size checks against the ipad and opad buffers cannot be written
95 * `block_size > sizeof( ipad ) || block_size > sizeof( hmac->opad )`
96 * because that triggers -Wlogical-op on GCC 7.3. */
97 if( block_size > sizeof( ipad ) )
98 return( PSA_ERROR_NOT_SUPPORTED );
99 if( block_size > sizeof( hmac->opad ) )
100 return( PSA_ERROR_NOT_SUPPORTED );
101 if( block_size < hash_size )
102 return( PSA_ERROR_NOT_SUPPORTED );
103
104 if( key_length > block_size )
105 {
106 status = psa_hash_compute( hash_alg, key, key_length,
107 ipad, sizeof( ipad ), &key_length );
108 if( status != PSA_SUCCESS )
109 goto cleanup;
110 }
111 /* A 0-length key is not commonly used in HMAC when used as a MAC,
112 * but it is permitted. It is common when HMAC is used in HKDF, for
113 * example. Don't call `memcpy` in the 0-length because `key` could be
114 * an invalid pointer which would make the behavior undefined. */
115 else if( key_length != 0 )
116 memcpy( ipad, key, key_length );
117
118 /* ipad contains the key followed by garbage. Xor and fill with 0x36
119 * to create the ipad value. */
120 for( i = 0; i < key_length; i++ )
121 ipad[i] ^= 0x36;
122 memset( ipad + key_length, 0x36, block_size - key_length );
123
124 /* Copy the key material from ipad to opad, flipping the requisite bits,
125 * and filling the rest of opad with the requisite constant. */
126 for( i = 0; i < key_length; i++ )
127 hmac->opad[i] = ipad[i] ^ 0x36 ^ 0x5C;
128 memset( hmac->opad + key_length, 0x5C, block_size - key_length );
129
130 status = psa_hash_setup( &hmac->hash_ctx, hash_alg );
131 if( status != PSA_SUCCESS )
132 goto cleanup;
133
134 status = psa_hash_update( &hmac->hash_ctx, ipad, block_size );
135
136cleanup:
137 mbedtls_platform_zeroize( ipad, sizeof( ipad ) );
138
139 return( status );
140}
141
142psa_status_t psa_hmac_finish_internal( psa_hmac_internal_data *hmac,
143 uint8_t *mac,
144 size_t mac_size )
145{
146 uint8_t tmp[MBEDTLS_MD_MAX_SIZE];
147 psa_algorithm_t hash_alg = hmac->alg;
148 size_t hash_size = 0;
149 size_t block_size = psa_get_hash_block_size( hash_alg );
150 psa_status_t status;
151
152 status = psa_hash_finish( &hmac->hash_ctx, tmp, sizeof( tmp ), &hash_size );
153 if( status != PSA_SUCCESS )
154 return( status );
155 /* From here on, tmp needs to be wiped. */
156
157 status = psa_hash_setup( &hmac->hash_ctx, hash_alg );
158 if( status != PSA_SUCCESS )
159 goto exit;
160
161 status = psa_hash_update( &hmac->hash_ctx, hmac->opad, block_size );
162 if( status != PSA_SUCCESS )
163 goto exit;
164
165 status = psa_hash_update( &hmac->hash_ctx, tmp, hash_size );
166 if( status != PSA_SUCCESS )
167 goto exit;
168
169 status = psa_hash_finish( &hmac->hash_ctx, tmp, sizeof( tmp ), &hash_size );
170 if( status != PSA_SUCCESS )
171 goto exit;
172
173 memcpy( mac, tmp, mac_size );
174
175exit:
176 mbedtls_platform_zeroize( tmp, hash_size );
177 return( status );
178}
179#endif /* MBEDTLS_PSA_BUILTIN_ALG_HMAC || PSA_CRYPTO_DRIVER_TEST */
180
Steven Cooreman896d51e2021-03-19 15:24:23 +0100181/* Implement the PSA driver MAC interface on top of mbed TLS if either the
182 * software driver or the test driver requires it. */
183#if defined(MBEDTLS_PSA_BUILTIN_MAC) || defined(PSA_CRYPTO_DRIVER_TEST)
Steven Cooreman07897832021-03-19 18:28:56 +0100184
185#if defined(BUILTIN_ALG_CMAC)
186static psa_status_t cmac_setup( mbedtls_psa_mac_operation_t *operation,
187 const psa_key_attributes_t *attributes,
188 const uint8_t *key_buffer,
189 size_t key_buffer_size )
190{
191 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
192 const mbedtls_cipher_info_t * cipher_info_tmp =
193 mbedtls_cipher_info_from_psa(
194 PSA_ALG_CMAC,
195 psa_get_key_type( attributes ),
196 psa_get_key_bits( attributes ),
197 NULL );
198
199 if( cipher_info_tmp == NULL )
200 return( PSA_ERROR_NOT_SUPPORTED );
201
202 if( key_buffer_size < PSA_BITS_TO_BYTES( psa_get_key_bits( attributes ) ) )
203 return( PSA_ERROR_INVALID_ARGUMENT );
204
205 ret = mbedtls_cipher_setup( &operation->ctx.cmac, cipher_info_tmp );
206 if( ret != 0 )
207 goto exit;
208
209 ret = mbedtls_cipher_cmac_starts( &operation->ctx.cmac,
210 key_buffer,
211 psa_get_key_bits( attributes ) );
212exit:
213 return( mbedtls_to_psa_error( ret ) );
214}
215#endif /* BUILTIN_ALG_CMAC */
216
217/* Initialize this driver's MAC operation structure. Once this function has been
218 * called, mbedtls_psa_mac_abort can run and will do the right thing. */
219static psa_status_t mac_init(
220 mbedtls_psa_mac_operation_t *operation,
221 psa_algorithm_t alg )
222{
223 psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
224
225 operation->alg = PSA_ALG_FULL_LENGTH_MAC( alg );
226 operation->key_set = 0;
227 operation->iv_set = 0;
228 operation->iv_required = 0;
229 operation->has_input = 0;
230 operation->is_sign = 0;
231
232#if defined(BUILTIN_ALG_CMAC)
233 if( operation->alg == PSA_ALG_CMAC )
234 {
235 operation->iv_required = 0;
236 mbedtls_cipher_init( &operation->ctx.cmac );
237 status = PSA_SUCCESS;
238 }
239 else
240#endif /* BUILTIN_ALG_CMAC */
241#if defined(BUILTIN_ALG_HMAC)
242 if( PSA_ALG_IS_HMAC( operation->alg ) )
243 {
244 /* We'll set up the hash operation later in psa_hmac_setup_internal. */
245 operation->ctx.hmac.alg = 0;
246 status = PSA_SUCCESS;
247 }
248 else
249#endif /* BUILTIN_ALG_HMAC */
250 {
251 if( ! PSA_ALG_IS_MAC( alg ) )
252 status = PSA_ERROR_INVALID_ARGUMENT;
253 }
254
255 if( status != PSA_SUCCESS )
256 memset( operation, 0, sizeof( *operation ) );
257 return( status );
258}
259
260static psa_status_t mac_abort( mbedtls_psa_mac_operation_t *operation )
261{
262 if( operation->alg == 0 )
263 {
264 /* The object has (apparently) been initialized but it is not
265 * in use. It's ok to call abort on such an object, and there's
266 * nothing to do. */
267 return( PSA_SUCCESS );
268 }
269 else
270#if defined(BUILTIN_ALG_CMAC)
271 if( operation->alg == PSA_ALG_CMAC )
272 {
273 mbedtls_cipher_free( &operation->ctx.cmac );
274 }
275 else
276#endif /* BUILTIN_ALG_CMAC */
277#if defined(BUILTIN_ALG_HMAC)
278 if( PSA_ALG_IS_HMAC( operation->alg ) )
279 {
280 psa_hmac_abort_internal( &operation->ctx.hmac );
281 }
282 else
283#endif /* BUILTIN_ALG_HMAC */
284 {
285 /* Sanity check (shouldn't happen: operation->alg should
286 * always have been initialized to a valid value). */
287 goto bad_state;
288 }
289
290 operation->alg = 0;
291 operation->key_set = 0;
292 operation->iv_set = 0;
293 operation->iv_required = 0;
294 operation->has_input = 0;
295 operation->is_sign = 0;
296
297 return( PSA_SUCCESS );
298
299bad_state:
300 /* If abort is called on an uninitialized object, we can't trust
301 * anything. Wipe the object in case it contains confidential data.
302 * This may result in a memory leak if a pointer gets overwritten,
303 * but it's too late to do anything about this. */
304 memset( operation, 0, sizeof( *operation ) );
305 return( PSA_ERROR_BAD_STATE );
306}
307
308static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation,
309 const psa_key_attributes_t *attributes,
310 const uint8_t *key_buffer,
311 size_t key_buffer_size,
312 psa_algorithm_t alg,
313 int is_sign )
314{
315 psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
316
317 /* A context must be freshly initialized before it can be set up. */
318 if( operation->alg != 0 )
319 {
320 return( PSA_ERROR_BAD_STATE );
321 }
322
323 status = mac_init( operation, alg );
324 if( status != PSA_SUCCESS )
325 return( status );
326 if( is_sign )
327 operation->is_sign = 1;
328
329 /* Get the output length for the algorithm and key combination. None of the
330 * currently supported algorithms have an output length dependent on actual
331 * key size, so setting it to a bogus value is currently OK. */
332 operation->mac_size =
333 PSA_MAC_LENGTH( psa_get_key_type( attributes ), 0, alg );
334
335#if defined(BUILTIN_ALG_CMAC)
336 if( PSA_ALG_FULL_LENGTH_MAC( alg ) == PSA_ALG_CMAC )
337 {
338 status = cmac_setup( operation, attributes,
339 key_buffer, key_buffer_size );
340 }
341 else
342#endif /* BUILTIN_ALG_CMAC */
343#if defined(BUILTIN_ALG_HMAC)
344 if( PSA_ALG_IS_HMAC( alg ) )
345 {
346 /* Sanity check. This shouldn't fail on a valid configuration. */
347 if( operation->mac_size > sizeof( operation->ctx.hmac.opad ) )
348 {
349 status = PSA_ERROR_NOT_SUPPORTED;
350 goto exit;
351 }
352
353 if( psa_get_key_type( attributes ) != PSA_KEY_TYPE_HMAC )
354 {
355 status = PSA_ERROR_INVALID_ARGUMENT;
356 goto exit;
357 }
358
359 status = psa_hmac_setup_internal( &operation->ctx.hmac,
360 key_buffer,
361 key_buffer_size,
362 PSA_ALG_HMAC_GET_HASH( alg ) );
363 }
364 else
365#endif /* BUILTIN_ALG_HMAC */
366 {
367 status = PSA_ERROR_NOT_SUPPORTED;
368 }
369
370exit:
371 if( status == PSA_SUCCESS )
372 operation->key_set = 1;
373 else
374 mac_abort( operation );
375
376 return( status );
377}
378
Steven Cooreman896d51e2021-03-19 15:24:23 +0100379static psa_status_t mac_compute(
380 const psa_key_attributes_t *attributes,
381 const uint8_t *key_buffer,
382 size_t key_buffer_size,
383 psa_algorithm_t alg,
384 const uint8_t *input,
385 size_t input_length,
386 uint8_t *mac,
387 size_t mac_size,
388 size_t *mac_length )
389{
Steven Cooreman32d56942021-03-19 17:39:17 +0100390 /* One-shot MAC has not been implemented in this PSA implementation yet. */
Steven Cooreman896d51e2021-03-19 15:24:23 +0100391 (void) attributes;
392 (void) key_buffer;
393 (void) key_buffer_size;
394 (void) alg;
395 (void) input;
396 (void) input_length;
397 (void) mac;
398 (void) mac_size;
399 (void) mac_length;
400 return( PSA_ERROR_NOT_SUPPORTED );
401}
402
403static psa_status_t mac_sign_setup(
404 mbedtls_psa_mac_operation_t *operation,
405 const psa_key_attributes_t *attributes,
406 const uint8_t *key_buffer,
407 size_t key_buffer_size,
408 psa_algorithm_t alg )
409{
Steven Cooreman07897832021-03-19 18:28:56 +0100410 return( mac_setup( operation, attributes, key_buffer, key_buffer_size, alg,
411 1 ) );
Steven Cooreman896d51e2021-03-19 15:24:23 +0100412}
413
414static psa_status_t mac_verify_setup(
415 mbedtls_psa_mac_operation_t *operation,
416 const psa_key_attributes_t *attributes,
417 const uint8_t *key_buffer,
418 size_t key_buffer_size,
419 psa_algorithm_t alg )
420{
Steven Cooreman07897832021-03-19 18:28:56 +0100421 return( mac_setup( operation, attributes, key_buffer, key_buffer_size, alg,
422 0 ) );
Steven Cooreman896d51e2021-03-19 15:24:23 +0100423}
424
425static psa_status_t mac_update(
426 mbedtls_psa_mac_operation_t *operation,
427 const uint8_t *input,
428 size_t input_length )
429{
Steven Cooreman11743f92021-03-19 18:38:46 +0100430 if( ! operation->key_set )
431 return( PSA_ERROR_BAD_STATE );
432 if( operation->iv_required && ! operation->iv_set )
433 return( PSA_ERROR_BAD_STATE );
434 operation->has_input = 1;
435
436#if defined(BUILTIN_ALG_CMAC)
437 if( operation->alg == PSA_ALG_CMAC )
438 {
439 return( mbedtls_to_psa_error(
440 mbedtls_cipher_cmac_update( &operation->ctx.cmac,
441 input, input_length ) ) );
442 }
443 else
444#endif /* BUILTIN_ALG_CMAC */
445#if defined(BUILTIN_ALG_HMAC)
446 if( PSA_ALG_IS_HMAC( operation->alg ) )
447 {
448 return( psa_hash_update( &operation->ctx.hmac.hash_ctx, input,
449 input_length ) );
450 }
451 else
452#endif /* BUILTIN_ALG_HMAC */
453 {
454 /* This shouldn't happen if `operation` was initialized by
455 * a setup function. */
456 return( PSA_ERROR_BAD_STATE );
457 }
Steven Cooreman896d51e2021-03-19 15:24:23 +0100458}
459
460static psa_status_t mac_sign_finish(
461 mbedtls_psa_mac_operation_t *operation,
462 uint8_t *mac,
463 size_t mac_size,
464 size_t *mac_length )
465{
466 /* To be fleshed out in a subsequent commit */
467 (void) operation;
468 (void) mac;
469 (void) mac_size;
470 (void) mac_length;
471 return( PSA_ERROR_NOT_SUPPORTED );
472}
473
474static psa_status_t mac_verify_finish(
475 mbedtls_psa_mac_operation_t *operation,
476 const uint8_t *mac,
477 size_t mac_length )
478{
479 /* To be fleshed out in a subsequent commit */
480 (void) operation;
481 (void) mac;
482 (void) mac_length;
483 return( PSA_ERROR_NOT_SUPPORTED );
484}
Steven Cooreman896d51e2021-03-19 15:24:23 +0100485#endif /* MBEDTLS_PSA_BUILTIN_MAC || PSA_CRYPTO_DRIVER_TEST */
486
487#if defined(MBEDTLS_PSA_BUILTIN_MAC)
488psa_status_t mbedtls_psa_mac_compute(
489 const psa_key_attributes_t *attributes,
490 const uint8_t *key_buffer,
491 size_t key_buffer_size,
492 psa_algorithm_t alg,
493 const uint8_t *input,
494 size_t input_length,
495 uint8_t *mac,
496 size_t mac_size,
497 size_t *mac_length )
498{
499 return( mac_compute( attributes, key_buffer, key_buffer_size, alg,
500 input, input_length,
501 mac, mac_size, mac_length ) );
502}
503
504psa_status_t mbedtls_psa_mac_sign_setup(
505 mbedtls_psa_mac_operation_t *operation,
506 const psa_key_attributes_t *attributes,
507 const uint8_t *key_buffer,
508 size_t key_buffer_size,
509 psa_algorithm_t alg )
510{
511 return( mac_sign_setup( operation, attributes,
512 key_buffer, key_buffer_size, alg ) );
513}
514
515psa_status_t mbedtls_psa_mac_verify_setup(
516 mbedtls_psa_mac_operation_t *operation,
517 const psa_key_attributes_t *attributes,
518 const uint8_t *key_buffer,
519 size_t key_buffer_size,
520 psa_algorithm_t alg )
521{
522 return( mac_verify_setup( operation, attributes,
523 key_buffer, key_buffer_size, alg ) );
524}
525
526psa_status_t mbedtls_psa_mac_update(
527 mbedtls_psa_mac_operation_t *operation,
528 const uint8_t *input,
529 size_t input_length )
530{
531 return( mac_update( operation, input, input_length ) );
532}
533
534psa_status_t mbedtls_psa_mac_sign_finish(
535 mbedtls_psa_mac_operation_t *operation,
536 uint8_t *mac,
537 size_t mac_size,
538 size_t *mac_length )
539{
540 return( mac_sign_finish( operation, mac, mac_size, mac_length ) );
541}
542
543psa_status_t mbedtls_psa_mac_verify_finish(
544 mbedtls_psa_mac_operation_t *operation,
545 const uint8_t *mac,
546 size_t mac_length )
547{
548 return( mac_verify_finish( operation, mac, mac_length ) );
549}
550
551psa_status_t mbedtls_psa_mac_abort(
552 mbedtls_psa_mac_operation_t *operation )
553{
554 return( mac_abort( operation ) );
555}
556#endif /* MBEDTLS_PSA_BUILTIN_MAC */
557
558 /*
559 * BEYOND THIS POINT, TEST DRIVER ENTRY POINTS ONLY.
560 */
561#if defined(PSA_CRYPTO_DRIVER_TEST)
562
563static int is_mac_accelerated( psa_algorithm_t alg )
564{
565#if defined(MBEDTLS_PSA_ACCEL_ALG_HMAC)
566 if( PSA_ALG_IS_HMAC( alg ) )
567 return( 1 );
568#endif
569
570 switch( PSA_ALG_FULL_LENGTH_MAC( alg ) )
571 {
572#if defined(MBEDTLS_PSA_ACCEL_ALG_CMAC)
573 case PSA_ALG_CMAC:
574 return( 1 );
575#endif
576 default:
577 return( 0 );
578 }
579}
580
581psa_status_t mbedtls_transparent_test_driver_mac_compute(
582 const psa_key_attributes_t *attributes,
583 const uint8_t *key_buffer,
584 size_t key_buffer_size,
585 psa_algorithm_t alg,
586 const uint8_t *input,
587 size_t input_length,
588 uint8_t *mac,
589 size_t mac_size,
590 size_t *mac_length )
591{
592 if( is_mac_accelerated( alg ) )
593 return( mac_compute( attributes, key_buffer, key_buffer_size, alg,
594 input, input_length,
595 mac, mac_size, mac_length ) );
596 else
597 return( PSA_ERROR_NOT_SUPPORTED );
598}
599
600psa_status_t mbedtls_transparent_test_driver_mac_sign_setup(
601 mbedtls_transparent_test_driver_mac_operation_t *operation,
602 const psa_key_attributes_t *attributes,
603 const uint8_t *key_buffer,
604 size_t key_buffer_size,
605 psa_algorithm_t alg )
606{
607 if( is_mac_accelerated( alg ) )
608 return( mac_sign_setup( operation, attributes,
609 key_buffer, key_buffer_size, alg ) );
610 else
611 return( PSA_ERROR_NOT_SUPPORTED );
612}
613
614psa_status_t mbedtls_transparent_test_driver_mac_verify_setup(
615 mbedtls_transparent_test_driver_mac_operation_t *operation,
616 const psa_key_attributes_t *attributes,
617 const uint8_t *key_buffer,
618 size_t key_buffer_size,
619 psa_algorithm_t alg )
620{
621 if( is_mac_accelerated( alg ) )
622 return( mac_verify_setup( operation, attributes,
623 key_buffer, key_buffer_size, alg ) );
624 else
625 return( PSA_ERROR_NOT_SUPPORTED );
626}
627
628psa_status_t mbedtls_transparent_test_driver_mac_update(
629 mbedtls_transparent_test_driver_mac_operation_t *operation,
630 const uint8_t *input,
631 size_t input_length )
632{
633 if( is_mac_accelerated( operation->alg ) )
634 return( mac_update( operation, input, input_length ) );
635 else
636 return( PSA_ERROR_BAD_STATE );
637}
638
639psa_status_t mbedtls_transparent_test_driver_mac_sign_finish(
640 mbedtls_transparent_test_driver_mac_operation_t *operation,
641 uint8_t *mac,
642 size_t mac_size,
643 size_t *mac_length )
644{
645 if( is_mac_accelerated( operation->alg ) )
646 return( mac_sign_finish( operation, mac, mac_size, mac_length ) );
647 else
648 return( PSA_ERROR_BAD_STATE );
649}
650
651psa_status_t mbedtls_transparent_test_driver_mac_verify_finish(
652 mbedtls_transparent_test_driver_mac_operation_t *operation,
653 const uint8_t *mac,
654 size_t mac_length )
655{
656 if( is_mac_accelerated( operation->alg ) )
657 return( mac_verify_finish( operation, mac, mac_length ) );
658 else
659 return( PSA_ERROR_BAD_STATE );
660}
661
662psa_status_t mbedtls_transparent_test_driver_mac_abort(
663 mbedtls_transparent_test_driver_mac_operation_t *operation )
664{
665 return( mac_abort( operation ) );
666}
667
668psa_status_t mbedtls_opaque_test_driver_mac_compute(
669 const psa_key_attributes_t *attributes,
670 const uint8_t *key_buffer,
671 size_t key_buffer_size,
672 psa_algorithm_t alg,
673 const uint8_t *input,
674 size_t input_length,
675 uint8_t *mac,
676 size_t mac_size,
677 size_t *mac_length )
678{
679 /* Opaque driver testing is not implemented yet through this mechanism. */
680 (void) attributes;
681 (void) key_buffer;
682 (void) key_buffer_size;
683 (void) alg;
684 (void) input;
685 (void) input_length;
686 (void) mac;
687 (void) mac_size;
688 (void) mac_length;
689 return( PSA_ERROR_NOT_SUPPORTED );
690}
691
692psa_status_t mbedtls_opaque_test_driver_mac_sign_setup(
693 mbedtls_opaque_test_driver_mac_operation_t *operation,
694 const psa_key_attributes_t *attributes,
695 const uint8_t *key_buffer,
696 size_t key_buffer_size,
697 psa_algorithm_t alg )
698{
699 /* Opaque driver testing is not implemented yet through this mechanism. */
700 (void) operation;
701 (void) attributes;
702 (void) key_buffer;
703 (void) key_buffer_size;
704 (void) alg;
705 return( PSA_ERROR_NOT_SUPPORTED );
706}
707
708psa_status_t mbedtls_opaque_test_driver_mac_verify_setup(
709 mbedtls_opaque_test_driver_mac_operation_t *operation,
710 const psa_key_attributes_t *attributes,
711 const uint8_t *key_buffer,
712 size_t key_buffer_size,
713 psa_algorithm_t alg )
714{
715 /* Opaque driver testing is not implemented yet through this mechanism. */
716 (void) operation;
717 (void) attributes;
718 (void) key_buffer;
719 (void) key_buffer_size;
720 (void) alg;
721 return( PSA_ERROR_NOT_SUPPORTED );
722}
723
724psa_status_t mbedtls_opaque_test_driver_mac_update(
725 mbedtls_opaque_test_driver_mac_operation_t *operation,
726 const uint8_t *input,
727 size_t input_length )
728{
729 /* Opaque driver testing is not implemented yet through this mechanism. */
730 (void) operation;
731 (void) input;
732 (void) input_length;
733 return( PSA_ERROR_NOT_SUPPORTED );
734}
735
736psa_status_t mbedtls_opaque_test_driver_mac_sign_finish(
737 mbedtls_opaque_test_driver_mac_operation_t *operation,
738 uint8_t *mac,
739 size_t mac_size,
740 size_t *mac_length )
741{
742 /* Opaque driver testing is not implemented yet through this mechanism. */
743 (void) operation;
744 (void) mac;
745 (void) mac_size;
746 (void) mac_length;
747 return( PSA_ERROR_NOT_SUPPORTED );
748}
749
750psa_status_t mbedtls_opaque_test_driver_mac_verify_finish(
751 mbedtls_opaque_test_driver_mac_operation_t *operation,
752 const uint8_t *mac,
753 size_t mac_length )
754{
755 /* Opaque driver testing is not implemented yet through this mechanism. */
756 (void) operation;
757 (void) mac;
758 (void) mac_length;
759 return( PSA_ERROR_NOT_SUPPORTED );
760}
761
762psa_status_t mbedtls_opaque_test_driver_mac_abort(
763 mbedtls_opaque_test_driver_mac_operation_t *operation )
764{
765 /* Opaque driver testing is not implemented yet through this mechanism. */
766 (void) operation;
767 return( PSA_ERROR_NOT_SUPPORTED );
768}
769
770#endif /* PSA_CRYPTO_DRIVER_TEST */
771
772#endif /* MBEDTLS_PSA_CRYPTO_C */