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