Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 1 | /* |
| 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 Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 31 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) |
| 32 | #include "libtestdriver1/library/psa_crypto_mac.h" |
| 33 | #endif |
| 34 | |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 35 | mbedtls_test_driver_mac_hooks_t mbedtls_test_driver_mac_hooks = |
| 36 | MBEDTLS_TEST_DRIVER_MAC_INIT; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 37 | |
| 38 | psa_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, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 47 | size_t *mac_length) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 48 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 49 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 50 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 51 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 52 | mbedtls_test_driver_mac_hooks.driver_status = |
| 53 | mbedtls_test_driver_mac_hooks.forced_status; |
| 54 | } else { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 55 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 56 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC) |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 57 | mbedtls_test_driver_mac_hooks.driver_status = |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 58 | libtestdriver1_mbedtls_psa_mac_compute( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 59 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 60 | key_buffer, key_buffer_size, alg, |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 61 | input, input_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 62 | mac, mac_size, mac_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 63 | #elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 64 | mbedtls_test_driver_mac_hooks.driver_status = |
| 65 | mbedtls_psa_mac_compute( |
| 66 | attributes, key_buffer, key_buffer_size, alg, |
| 67 | input, input_length, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 68 | mac, mac_size, mac_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 69 | #else |
| 70 | (void) attributes; |
| 71 | (void) key_buffer; |
| 72 | (void) key_buffer_size; |
| 73 | (void) alg; |
| 74 | (void) input; |
| 75 | (void) input_length; |
| 76 | (void) mac; |
| 77 | (void) mac_size; |
| 78 | (void) mac_length; |
| 79 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 80 | #endif |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 83 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | psa_status_t mbedtls_test_transparent_mac_sign_setup( |
| 87 | mbedtls_transparent_test_driver_mac_operation_t *operation, |
| 88 | const psa_key_attributes_t *attributes, |
| 89 | const uint8_t *key_buffer, |
| 90 | size_t key_buffer_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 91 | psa_algorithm_t alg) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 92 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 93 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 94 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 95 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 96 | mbedtls_test_driver_mac_hooks.driver_status = |
| 97 | mbedtls_test_driver_mac_hooks.forced_status; |
| 98 | } else { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 99 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 100 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC) |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 101 | mbedtls_test_driver_mac_hooks.driver_status = |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 102 | libtestdriver1_mbedtls_psa_mac_sign_setup( |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 103 | operation, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 104 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 105 | key_buffer, key_buffer_size, alg); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 106 | #elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 107 | mbedtls_test_driver_mac_hooks.driver_status = |
| 108 | mbedtls_psa_mac_sign_setup( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 109 | operation, attributes, key_buffer, key_buffer_size, alg); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 110 | #else |
| 111 | (void) operation; |
| 112 | (void) attributes; |
| 113 | (void) key_buffer; |
| 114 | (void) key_buffer_size; |
| 115 | (void) alg; |
| 116 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 117 | #endif |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 120 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | psa_status_t mbedtls_test_transparent_mac_verify_setup( |
| 124 | mbedtls_transparent_test_driver_mac_operation_t *operation, |
| 125 | const psa_key_attributes_t *attributes, |
| 126 | const uint8_t *key_buffer, |
| 127 | size_t key_buffer_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 128 | psa_algorithm_t alg) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 129 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 130 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 131 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 132 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 133 | mbedtls_test_driver_mac_hooks.driver_status = |
| 134 | mbedtls_test_driver_mac_hooks.forced_status; |
| 135 | } else { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 136 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 137 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC) |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 138 | mbedtls_test_driver_mac_hooks.driver_status = |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 139 | libtestdriver1_mbedtls_psa_mac_verify_setup( |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 140 | operation, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 141 | (const libtestdriver1_psa_key_attributes_t *) attributes, |
| 142 | key_buffer, key_buffer_size, alg); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 143 | #elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 144 | mbedtls_test_driver_mac_hooks.driver_status = |
| 145 | mbedtls_psa_mac_verify_setup( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 146 | operation, attributes, key_buffer, key_buffer_size, alg); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 147 | #else |
| 148 | (void) operation; |
| 149 | (void) attributes; |
| 150 | (void) key_buffer; |
| 151 | (void) key_buffer_size; |
| 152 | (void) alg; |
| 153 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 154 | #endif |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 157 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | psa_status_t mbedtls_test_transparent_mac_update( |
| 161 | mbedtls_transparent_test_driver_mac_operation_t *operation, |
| 162 | const uint8_t *input, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 163 | size_t input_length) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 164 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 165 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 166 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 167 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 168 | mbedtls_test_driver_mac_hooks.driver_status = |
| 169 | mbedtls_test_driver_mac_hooks.forced_status; |
| 170 | } else { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 171 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 172 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC) |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 173 | mbedtls_test_driver_mac_hooks.driver_status = |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 174 | libtestdriver1_mbedtls_psa_mac_update( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 175 | operation, input, input_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 176 | #elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 177 | mbedtls_test_driver_mac_hooks.driver_status = |
| 178 | mbedtls_psa_mac_update( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 179 | operation, input, input_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 180 | #else |
| 181 | (void) operation; |
| 182 | (void) input; |
| 183 | (void) input_length; |
| 184 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 185 | #endif |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 188 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | psa_status_t mbedtls_test_transparent_mac_sign_finish( |
| 192 | mbedtls_transparent_test_driver_mac_operation_t *operation, |
| 193 | uint8_t *mac, |
| 194 | size_t mac_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 195 | size_t *mac_length) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 196 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 197 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 198 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 199 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 200 | mbedtls_test_driver_mac_hooks.driver_status = |
| 201 | mbedtls_test_driver_mac_hooks.forced_status; |
| 202 | } else { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 203 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 204 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC) |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 205 | mbedtls_test_driver_mac_hooks.driver_status = |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 206 | libtestdriver1_mbedtls_psa_mac_sign_finish( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 207 | operation, mac, mac_size, mac_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 208 | #elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 209 | mbedtls_test_driver_mac_hooks.driver_status = |
| 210 | mbedtls_psa_mac_sign_finish( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 211 | operation, mac, mac_size, mac_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 212 | #else |
| 213 | (void) operation; |
| 214 | (void) mac; |
| 215 | (void) mac_size; |
| 216 | (void) mac_length; |
| 217 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 218 | #endif |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 219 | } |
| 220 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 221 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | psa_status_t mbedtls_test_transparent_mac_verify_finish( |
| 225 | mbedtls_transparent_test_driver_mac_operation_t *operation, |
| 226 | const uint8_t *mac, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 227 | size_t mac_length) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 228 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 229 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 230 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 231 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 232 | mbedtls_test_driver_mac_hooks.driver_status = |
| 233 | mbedtls_test_driver_mac_hooks.forced_status; |
| 234 | } else { |
Ronald Cron | b814bda | 2021-09-13 14:50:42 +0200 | [diff] [blame] | 235 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 236 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC) |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 237 | mbedtls_test_driver_mac_hooks.driver_status = |
Ronald Cron | 7b7854e | 2021-03-13 18:19:08 +0100 | [diff] [blame] | 238 | libtestdriver1_mbedtls_psa_mac_verify_finish( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 239 | operation, mac, mac_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 240 | #elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 241 | mbedtls_test_driver_mac_hooks.driver_status = |
| 242 | mbedtls_psa_mac_verify_finish( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 243 | operation, mac, mac_length); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 244 | #else |
| 245 | (void) operation; |
| 246 | (void) mac; |
| 247 | (void) mac_length; |
| 248 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 249 | #endif |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 250 | } |
| 251 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 252 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | psa_status_t mbedtls_test_transparent_mac_abort( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 256 | mbedtls_transparent_test_driver_mac_operation_t *operation) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 257 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 258 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 259 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 260 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 261 | mbedtls_test_driver_mac_hooks.driver_status = |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 262 | mbedtls_test_driver_mac_hooks.forced_status; |
| 263 | } else { |
| 264 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 265 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC) |
| 266 | mbedtls_test_driver_mac_hooks.driver_status = |
| 267 | libtestdriver1_mbedtls_psa_mac_abort(operation); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 268 | #elif defined(MBEDTLS_PSA_BUILTIN_MAC) |
| 269 | mbedtls_test_driver_mac_hooks.driver_status = |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 270 | mbedtls_psa_mac_abort(operation); |
Ronald Cron | 2091eed | 2021-04-09 11:09:54 +0200 | [diff] [blame] | 271 | #else |
| 272 | (void) operation; |
| 273 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 274 | #endif |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 277 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | psa_status_t mbedtls_test_opaque_mac_compute( |
| 281 | const psa_key_attributes_t *attributes, |
| 282 | const uint8_t *key_buffer, |
| 283 | size_t key_buffer_size, |
| 284 | psa_algorithm_t alg, |
| 285 | const uint8_t *input, |
| 286 | size_t input_length, |
| 287 | uint8_t *mac, |
| 288 | size_t mac_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 289 | size_t *mac_length) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 290 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 291 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 292 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 293 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 294 | mbedtls_test_driver_mac_hooks.driver_status = |
| 295 | mbedtls_test_driver_mac_hooks.forced_status; |
| 296 | } else { |
Ronald Cron | a2dbe66 | 2021-07-01 11:24:02 +0200 | [diff] [blame] | 297 | (void) attributes; |
| 298 | (void) key_buffer; |
| 299 | (void) key_buffer_size; |
| 300 | (void) alg; |
| 301 | (void) input; |
| 302 | (void) input_length; |
| 303 | (void) mac; |
| 304 | (void) mac_size; |
| 305 | (void) mac_length; |
| 306 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 307 | } |
| 308 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 309 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | psa_status_t mbedtls_test_opaque_mac_sign_setup( |
| 313 | mbedtls_opaque_test_driver_mac_operation_t *operation, |
| 314 | const psa_key_attributes_t *attributes, |
| 315 | const uint8_t *key_buffer, |
| 316 | size_t key_buffer_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 317 | psa_algorithm_t alg) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 318 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 319 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 320 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 321 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 322 | mbedtls_test_driver_mac_hooks.driver_status = |
| 323 | mbedtls_test_driver_mac_hooks.forced_status; |
| 324 | } else { |
Ronald Cron | a2dbe66 | 2021-07-01 11:24:02 +0200 | [diff] [blame] | 325 | (void) operation; |
| 326 | (void) attributes; |
| 327 | (void) key_buffer; |
| 328 | (void) key_buffer_size; |
| 329 | (void) alg; |
| 330 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 331 | } |
| 332 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 333 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | psa_status_t mbedtls_test_opaque_mac_verify_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, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 341 | psa_algorithm_t alg) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 342 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 343 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 344 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 345 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 346 | mbedtls_test_driver_mac_hooks.driver_status = |
| 347 | mbedtls_test_driver_mac_hooks.forced_status; |
| 348 | } else { |
Ronald Cron | a2dbe66 | 2021-07-01 11:24:02 +0200 | [diff] [blame] | 349 | (void) operation; |
| 350 | (void) attributes; |
| 351 | (void) key_buffer; |
| 352 | (void) key_buffer_size; |
| 353 | (void) alg; |
| 354 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 355 | } |
| 356 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 357 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | psa_status_t mbedtls_test_opaque_mac_update( |
| 361 | mbedtls_opaque_test_driver_mac_operation_t *operation, |
| 362 | const uint8_t *input, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 363 | size_t input_length) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 364 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 365 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 366 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 367 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 368 | mbedtls_test_driver_mac_hooks.driver_status = |
| 369 | mbedtls_test_driver_mac_hooks.forced_status; |
| 370 | } else { |
Ronald Cron | a2dbe66 | 2021-07-01 11:24:02 +0200 | [diff] [blame] | 371 | (void) operation; |
| 372 | (void) input; |
| 373 | (void) input_length; |
| 374 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 375 | } |
| 376 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 377 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | psa_status_t mbedtls_test_opaque_mac_sign_finish( |
| 381 | mbedtls_opaque_test_driver_mac_operation_t *operation, |
| 382 | uint8_t *mac, |
| 383 | size_t mac_size, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 384 | size_t *mac_length) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 385 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 386 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 387 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 388 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 389 | mbedtls_test_driver_mac_hooks.driver_status = |
| 390 | mbedtls_test_driver_mac_hooks.forced_status; |
| 391 | } else { |
Ronald Cron | a2dbe66 | 2021-07-01 11:24:02 +0200 | [diff] [blame] | 392 | (void) operation; |
| 393 | (void) mac; |
| 394 | (void) mac_size; |
| 395 | (void) mac_length; |
| 396 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 397 | } |
| 398 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 399 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | psa_status_t mbedtls_test_opaque_mac_verify_finish( |
| 403 | mbedtls_opaque_test_driver_mac_operation_t *operation, |
| 404 | const uint8_t *mac, |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 405 | size_t mac_length) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 406 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 407 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 408 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 409 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 410 | mbedtls_test_driver_mac_hooks.driver_status = |
| 411 | mbedtls_test_driver_mac_hooks.forced_status; |
| 412 | } else { |
Ronald Cron | a2dbe66 | 2021-07-01 11:24:02 +0200 | [diff] [blame] | 413 | (void) operation; |
| 414 | (void) mac; |
| 415 | (void) mac_length; |
| 416 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 419 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | psa_status_t mbedtls_test_opaque_mac_abort( |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 423 | mbedtls_opaque_test_driver_mac_operation_t *operation) |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 424 | { |
Steven Cooreman | be21dab | 2021-05-10 11:18:20 +0200 | [diff] [blame] | 425 | mbedtls_test_driver_mac_hooks.hits++; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 426 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 427 | if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) { |
| 428 | mbedtls_test_driver_mac_hooks.driver_status = |
| 429 | mbedtls_test_driver_mac_hooks.forced_status; |
| 430 | } else { |
Ronald Cron | a2dbe66 | 2021-07-01 11:24:02 +0200 | [diff] [blame] | 431 | (void) operation; |
| 432 | mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 435 | return mbedtls_test_driver_mac_hooks.driver_status; |
Steven Cooreman | 2d9a3f9 | 2021-04-29 21:10:11 +0200 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |