1 /*
2  * Test driver for MAC driver entry points.
3  */
4 /*  Copyright The Mbed TLS Contributors
5  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6  */
7 
8 #ifndef PSA_CRYPTO_TEST_DRIVERS_MAC_H
9 #define PSA_CRYPTO_TEST_DRIVERS_MAC_H
10 
11 #include "mbedtls/build_info.h"
12 
13 #if defined(PSA_CRYPTO_DRIVER_TEST)
14 #include <psa/crypto_driver_common.h>
15 
16 typedef struct {
17     /* If not PSA_SUCCESS, return this error code instead of processing the
18      * function call. */
19     psa_status_t forced_status;
20     /* Count the amount of times MAC driver functions are called. */
21     unsigned long hits;
22     /* Status returned by the last MAC driver function call. */
23     psa_status_t driver_status;
24 } mbedtls_test_driver_mac_hooks_t;
25 
26 #define MBEDTLS_TEST_DRIVER_MAC_INIT { 0, 0, 0 }
27 static inline mbedtls_test_driver_mac_hooks_t
mbedtls_test_driver_mac_hooks_init(void)28 mbedtls_test_driver_mac_hooks_init(void)
29 {
30     const mbedtls_test_driver_mac_hooks_t v = MBEDTLS_TEST_DRIVER_MAC_INIT;
31     return v;
32 }
33 
34 extern mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks;
35 
36 psa_status_t mbedtls_test_transparent_mac_compute(
37     const psa_key_attributes_t *attributes,
38     const uint8_t *key_buffer,
39     size_t key_buffer_size,
40     psa_algorithm_t alg,
41     const uint8_t *input,
42     size_t input_length,
43     uint8_t *mac,
44     size_t mac_size,
45     size_t *mac_length);
46 
47 psa_status_t mbedtls_test_transparent_mac_sign_setup(
48     mbedtls_transparent_test_driver_mac_operation_t *operation,
49     const psa_key_attributes_t *attributes,
50     const uint8_t *key_buffer,
51     size_t key_buffer_size,
52     psa_algorithm_t alg);
53 
54 psa_status_t mbedtls_test_transparent_mac_verify_setup(
55     mbedtls_transparent_test_driver_mac_operation_t *operation,
56     const psa_key_attributes_t *attributes,
57     const uint8_t *key_buffer,
58     size_t key_buffer_size,
59     psa_algorithm_t alg);
60 
61 psa_status_t mbedtls_test_transparent_mac_update(
62     mbedtls_transparent_test_driver_mac_operation_t *operation,
63     const uint8_t *input,
64     size_t input_length);
65 
66 psa_status_t mbedtls_test_transparent_mac_sign_finish(
67     mbedtls_transparent_test_driver_mac_operation_t *operation,
68     uint8_t *mac,
69     size_t mac_size,
70     size_t *mac_length);
71 
72 psa_status_t mbedtls_test_transparent_mac_verify_finish(
73     mbedtls_transparent_test_driver_mac_operation_t *operation,
74     const uint8_t *mac,
75     size_t mac_length);
76 
77 psa_status_t mbedtls_test_transparent_mac_abort(
78     mbedtls_transparent_test_driver_mac_operation_t *operation);
79 
80 psa_status_t mbedtls_test_opaque_mac_compute(
81     const psa_key_attributes_t *attributes,
82     const uint8_t *key_buffer,
83     size_t key_buffer_size,
84     psa_algorithm_t alg,
85     const uint8_t *input,
86     size_t input_length,
87     uint8_t *mac,
88     size_t mac_size,
89     size_t *mac_length);
90 
91 psa_status_t mbedtls_test_opaque_mac_sign_setup(
92     mbedtls_opaque_test_driver_mac_operation_t *operation,
93     const psa_key_attributes_t *attributes,
94     const uint8_t *key_buffer,
95     size_t key_buffer_size,
96     psa_algorithm_t alg);
97 
98 psa_status_t mbedtls_test_opaque_mac_verify_setup(
99     mbedtls_opaque_test_driver_mac_operation_t *operation,
100     const psa_key_attributes_t *attributes,
101     const uint8_t *key_buffer,
102     size_t key_buffer_size,
103     psa_algorithm_t alg);
104 
105 psa_status_t mbedtls_test_opaque_mac_update(
106     mbedtls_opaque_test_driver_mac_operation_t *operation,
107     const uint8_t *input,
108     size_t input_length);
109 
110 psa_status_t mbedtls_test_opaque_mac_sign_finish(
111     mbedtls_opaque_test_driver_mac_operation_t *operation,
112     uint8_t *mac,
113     size_t mac_size,
114     size_t *mac_length);
115 
116 psa_status_t mbedtls_test_opaque_mac_verify_finish(
117     mbedtls_opaque_test_driver_mac_operation_t *operation,
118     const uint8_t *mac,
119     size_t mac_length);
120 
121 psa_status_t mbedtls_test_opaque_mac_abort(
122     mbedtls_opaque_test_driver_mac_operation_t *operation);
123 
124 #endif /* PSA_CRYPTO_DRIVER_TEST */
125 #endif /* PSA_CRYPTO_TEST_DRIVERS_MAC_H */
126