blob: 8af1335c24bcaf094cc51bee8e0b42aa1e13482a [file] [log] [blame]
Steven Cooreman2d9a3f92021-04-29 21:10:11 +02001/*
2 * Test driver for MAC driver 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#ifndef PSA_CRYPTO_TEST_DRIVERS_MAC_H
21#define PSA_CRYPTO_TEST_DRIVERS_MAC_H
22
23#if !defined(MBEDTLS_CONFIG_FILE)
24#include "mbedtls/config.h"
25#else
26#include MBEDTLS_CONFIG_FILE
27#endif
28
29#if defined(PSA_CRYPTO_DRIVER_TEST)
30#include <psa/crypto_driver_common.h>
31
32typedef struct {
33 /* If not PSA_SUCCESS, return this error code instead of processing the
34 * function call. */
35 psa_status_t forced_status;
36 /* Count the amount of times MAC driver functions are called. */
37 unsigned long hits;
38 /* Status returned by the last MAC driver function call. */
39 psa_status_t driver_status;
Steven Cooremanbe21dab2021-05-10 11:18:20 +020040} mbedtls_test_driver_mac_hooks_t;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020041
42#define MBEDTLS_TEST_DRIVER_MAC_INIT { 0, 0, 0 }
Steven Cooremanbe21dab2021-05-10 11:18:20 +020043static inline mbedtls_test_driver_mac_hooks_t
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010044mbedtls_test_driver_mac_hooks_init(void)
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020045{
Steven Cooremanbe21dab2021-05-10 11:18:20 +020046 const mbedtls_test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT;
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010047 return v;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020048}
49
Steven Cooremanbe21dab2021-05-10 11:18:20 +020050extern mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks;
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020051
52psa_status_t mbedtls_test_transparent_mac_compute(
53 const psa_key_attributes_t *attributes,
54 const uint8_t *key_buffer,
55 size_t key_buffer_size,
56 psa_algorithm_t alg,
57 const uint8_t *input,
58 size_t input_length,
59 uint8_t *mac,
60 size_t mac_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010061 size_t *mac_length);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020062
63psa_status_t mbedtls_test_transparent_mac_sign_setup(
64 mbedtls_transparent_test_driver_mac_operation_t *operation,
65 const psa_key_attributes_t *attributes,
66 const uint8_t *key_buffer,
67 size_t key_buffer_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010068 psa_algorithm_t alg);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020069
70psa_status_t mbedtls_test_transparent_mac_verify_setup(
71 mbedtls_transparent_test_driver_mac_operation_t *operation,
72 const psa_key_attributes_t *attributes,
73 const uint8_t *key_buffer,
74 size_t key_buffer_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010075 psa_algorithm_t alg);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020076
77psa_status_t mbedtls_test_transparent_mac_update(
78 mbedtls_transparent_test_driver_mac_operation_t *operation,
79 const uint8_t *input,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010080 size_t input_length);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020081
82psa_status_t mbedtls_test_transparent_mac_sign_finish(
83 mbedtls_transparent_test_driver_mac_operation_t *operation,
84 uint8_t *mac,
85 size_t mac_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010086 size_t *mac_length);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020087
88psa_status_t mbedtls_test_transparent_mac_verify_finish(
89 mbedtls_transparent_test_driver_mac_operation_t *operation,
90 const uint8_t *mac,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010091 size_t mac_length);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020092
93psa_status_t mbedtls_test_transparent_mac_abort(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010094 mbedtls_transparent_test_driver_mac_operation_t *operation);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +020095
96psa_status_t mbedtls_test_opaque_mac_compute(
97 const psa_key_attributes_t *attributes,
98 const uint8_t *key_buffer,
99 size_t key_buffer_size,
100 psa_algorithm_t alg,
101 const uint8_t *input,
102 size_t input_length,
103 uint8_t *mac,
104 size_t mac_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100105 size_t *mac_length);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200106
107psa_status_t mbedtls_test_opaque_mac_sign_setup(
108 mbedtls_opaque_test_driver_mac_operation_t *operation,
109 const psa_key_attributes_t *attributes,
110 const uint8_t *key_buffer,
111 size_t key_buffer_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100112 psa_algorithm_t alg);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200113
114psa_status_t mbedtls_test_opaque_mac_verify_setup(
115 mbedtls_opaque_test_driver_mac_operation_t *operation,
116 const psa_key_attributes_t *attributes,
117 const uint8_t *key_buffer,
118 size_t key_buffer_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100119 psa_algorithm_t alg);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200120
121psa_status_t mbedtls_test_opaque_mac_update(
122 mbedtls_opaque_test_driver_mac_operation_t *operation,
123 const uint8_t *input,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100124 size_t input_length);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200125
126psa_status_t mbedtls_test_opaque_mac_sign_finish(
127 mbedtls_opaque_test_driver_mac_operation_t *operation,
128 uint8_t *mac,
129 size_t mac_size,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100130 size_t *mac_length);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200131
132psa_status_t mbedtls_test_opaque_mac_verify_finish(
133 mbedtls_opaque_test_driver_mac_operation_t *operation,
134 const uint8_t *mac,
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100135 size_t mac_length);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200136
137psa_status_t mbedtls_test_opaque_mac_abort(
Gilles Peskine1b6c09a2023-01-11 14:52:35 +0100138 mbedtls_opaque_test_driver_mac_operation_t *operation);
Steven Cooreman2d9a3f92021-04-29 21:10:11 +0200139
140#endif /* PSA_CRYPTO_DRIVER_TEST */
141#endif /* PSA_CRYPTO_TEST_DRIVERS_MAC_H */