Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [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 | #include <test/helpers.h> |
| 21 | |
| 22 | #if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST) |
| 23 | #include "psa_crypto_pake.h" |
| 24 | |
| 25 | #include "test/drivers/pake.h" |
| 26 | #include "string.h" |
| 27 | |
| 28 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) |
| 29 | #include "libtestdriver1/library/psa_crypto_pake.h" |
| 30 | #endif |
| 31 | |
| 32 | mbedtls_test_driver_pake_hooks_t mbedtls_test_driver_pake_hooks = |
| 33 | MBEDTLS_TEST_DRIVER_PAKE_INIT; |
| 34 | |
| 35 | |
| 36 | psa_status_t mbedtls_test_transparent_pake_setup( |
| 37 | mbedtls_transparent_test_driver_pake_operation_t *operation, |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 38 | const psa_crypto_driver_pake_inputs_t *inputs) |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 39 | { |
| 40 | mbedtls_test_driver_pake_hooks.hits++; |
| 41 | |
Przemek Stekiel | 95629ab | 2022-12-14 08:22:25 +0100 | [diff] [blame] | 42 | if (mbedtls_test_driver_pake_hooks.forced_setup_status != PSA_SUCCESS) { |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 43 | mbedtls_test_driver_pake_hooks.driver_status = |
Przemek Stekiel | 95629ab | 2022-12-14 08:22:25 +0100 | [diff] [blame] | 44 | mbedtls_test_driver_pake_hooks.forced_setup_status; |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 45 | } else { |
| 46 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 47 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_PAKE) |
| 48 | mbedtls_test_driver_pake_hooks.driver_status = |
| 49 | libtestdriver1_mbedtls_psa_pake_setup( |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 50 | operation, (const libtestdriver1_psa_crypto_driver_pake_inputs_t *) inputs); |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 51 | #elif defined(MBEDTLS_PSA_BUILTIN_PAKE) |
| 52 | mbedtls_test_driver_pake_hooks.driver_status = |
| 53 | mbedtls_psa_pake_setup( |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 54 | operation, inputs); |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 55 | #else |
| 56 | (void) operation; |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 57 | (void) inputs; |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 58 | mbedtls_test_driver_pake_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 59 | #endif |
| 60 | } |
| 61 | |
| 62 | return mbedtls_test_driver_pake_hooks.driver_status; |
| 63 | } |
| 64 | |
| 65 | psa_status_t mbedtls_test_transparent_pake_output( |
| 66 | mbedtls_transparent_test_driver_pake_operation_t *operation, |
| 67 | psa_pake_step_t step, |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 68 | const psa_pake_computation_stage_t *computation_stage, |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 69 | uint8_t *output, |
| 70 | size_t output_size, |
| 71 | size_t *output_length) |
| 72 | { |
| 73 | mbedtls_test_driver_pake_hooks.hits++; |
| 74 | |
| 75 | if (mbedtls_test_driver_pake_hooks.forced_output != NULL) { |
| 76 | if (output_size < mbedtls_test_driver_pake_hooks.forced_output_length) { |
| 77 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 78 | } |
| 79 | |
| 80 | memcpy(output, |
| 81 | mbedtls_test_driver_pake_hooks.forced_output, |
| 82 | mbedtls_test_driver_pake_hooks.forced_output_length); |
| 83 | *output_length = mbedtls_test_driver_pake_hooks.forced_output_length; |
| 84 | |
| 85 | return mbedtls_test_driver_pake_hooks.forced_status; |
| 86 | } |
| 87 | |
| 88 | if (mbedtls_test_driver_pake_hooks.forced_status != PSA_SUCCESS) { |
| 89 | mbedtls_test_driver_pake_hooks.driver_status = |
| 90 | mbedtls_test_driver_pake_hooks.forced_status; |
| 91 | } else { |
| 92 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 93 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_PAKE) |
| 94 | mbedtls_test_driver_pake_hooks.driver_status = |
| 95 | libtestdriver1_mbedtls_psa_pake_output( |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 96 | operation, |
| 97 | step, |
| 98 | (libtestdriver1_psa_pake_computation_stage_t *) computation_stage, |
| 99 | output, |
| 100 | output_size, |
| 101 | output_length); |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 102 | #elif defined(MBEDTLS_PSA_BUILTIN_PAKE) |
| 103 | mbedtls_test_driver_pake_hooks.driver_status = |
| 104 | mbedtls_psa_pake_output( |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 105 | operation, step, computation_stage, output, output_size, output_length); |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 106 | #else |
| 107 | (void) operation; |
| 108 | (void) step; |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 109 | (void) computation_stage; |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 110 | (void) output; |
| 111 | (void) output_size; |
| 112 | (void) output_length; |
| 113 | mbedtls_test_driver_pake_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 114 | #endif |
| 115 | } |
| 116 | |
| 117 | return mbedtls_test_driver_pake_hooks.driver_status; |
| 118 | } |
| 119 | |
| 120 | psa_status_t mbedtls_test_transparent_pake_input( |
| 121 | mbedtls_transparent_test_driver_pake_operation_t *operation, |
| 122 | psa_pake_step_t step, |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 123 | const psa_pake_computation_stage_t *computation_stage, |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 124 | const uint8_t *input, |
| 125 | size_t input_length) |
| 126 | { |
| 127 | mbedtls_test_driver_pake_hooks.hits++; |
| 128 | |
| 129 | if (mbedtls_test_driver_pake_hooks.forced_status != PSA_SUCCESS) { |
| 130 | mbedtls_test_driver_pake_hooks.driver_status = |
| 131 | mbedtls_test_driver_pake_hooks.forced_status; |
| 132 | } else { |
| 133 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 134 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_PAKE) |
| 135 | mbedtls_test_driver_pake_hooks.driver_status = |
| 136 | libtestdriver1_mbedtls_psa_pake_input( |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 137 | operation, |
| 138 | step, |
| 139 | (libtestdriver1_psa_pake_computation_stage_t *) computation_stage, |
| 140 | input, |
| 141 | input_length); |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 142 | #elif defined(MBEDTLS_PSA_BUILTIN_PAKE) |
| 143 | mbedtls_test_driver_pake_hooks.driver_status = |
| 144 | mbedtls_psa_pake_input( |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 145 | operation, step, computation_stage, input, input_length); |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 146 | #else |
| 147 | (void) operation; |
| 148 | (void) step; |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 149 | (void) computation_stage; |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 150 | (void) input; |
| 151 | (void) input_length; |
| 152 | mbedtls_test_driver_pake_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 153 | #endif |
| 154 | } |
| 155 | |
| 156 | return mbedtls_test_driver_pake_hooks.driver_status; |
| 157 | } |
| 158 | |
| 159 | psa_status_t mbedtls_test_transparent_pake_get_implicit_key( |
| 160 | mbedtls_transparent_test_driver_pake_operation_t *operation, |
Przemek Stekiel | 0c78180 | 2022-11-29 14:53:13 +0100 | [diff] [blame] | 161 | uint8_t *output, size_t *output_size) |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 162 | { |
| 163 | mbedtls_test_driver_pake_hooks.hits++; |
| 164 | |
| 165 | if (mbedtls_test_driver_pake_hooks.forced_status != PSA_SUCCESS) { |
| 166 | mbedtls_test_driver_pake_hooks.driver_status = |
| 167 | mbedtls_test_driver_pake_hooks.forced_status; |
| 168 | } else { |
| 169 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 170 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_PAKE) |
| 171 | mbedtls_test_driver_pake_hooks.driver_status = |
| 172 | libtestdriver1_mbedtls_psa_pake_get_implicit_key( |
Przemek Stekiel | 0c78180 | 2022-11-29 14:53:13 +0100 | [diff] [blame] | 173 | operation, output, output_size); |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 174 | #elif defined(MBEDTLS_PSA_BUILTIN_PAKE) |
| 175 | mbedtls_test_driver_pake_hooks.driver_status = |
| 176 | mbedtls_psa_pake_get_implicit_key( |
Przemek Stekiel | 0c78180 | 2022-11-29 14:53:13 +0100 | [diff] [blame] | 177 | operation, output, output_size); |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 178 | #else |
| 179 | (void) operation; |
| 180 | (void) output; |
| 181 | mbedtls_test_driver_pake_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 182 | #endif |
| 183 | } |
| 184 | |
| 185 | return mbedtls_test_driver_pake_hooks.driver_status; |
| 186 | } |
| 187 | |
| 188 | psa_status_t mbedtls_test_transparent_pake_abort( |
| 189 | mbedtls_transparent_test_driver_pake_operation_t *operation) |
| 190 | { |
| 191 | mbedtls_test_driver_pake_hooks.hits++; |
| 192 | |
| 193 | if (mbedtls_test_driver_pake_hooks.forced_status != PSA_SUCCESS) { |
| 194 | mbedtls_test_driver_pake_hooks.driver_status = |
| 195 | mbedtls_test_driver_pake_hooks.forced_status; |
| 196 | } else { |
| 197 | #if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \ |
| 198 | defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_PAKE) |
| 199 | mbedtls_test_driver_pake_hooks.driver_status = |
| 200 | libtestdriver1_mbedtls_psa_pake_abort( |
| 201 | operation); |
| 202 | #elif defined(MBEDTLS_PSA_BUILTIN_PAKE) |
| 203 | mbedtls_test_driver_pake_hooks.driver_status = |
| 204 | mbedtls_psa_pake_abort( |
| 205 | operation); |
| 206 | #else |
| 207 | (void) operation; |
| 208 | mbedtls_test_driver_pake_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED; |
| 209 | #endif |
| 210 | } |
| 211 | |
| 212 | return mbedtls_test_driver_pake_hooks.driver_status; |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * opaque versions, to do |
| 217 | */ |
| 218 | psa_status_t mbedtls_test_opaque_pake_setup( |
| 219 | mbedtls_opaque_test_driver_pake_operation_t *operation, |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 220 | const psa_crypto_driver_pake_inputs_t *inputs) |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 221 | { |
| 222 | (void) operation; |
Przemek Stekiel | 51eac53 | 2022-12-07 11:04:51 +0100 | [diff] [blame] | 223 | (void) inputs; |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 224 | return PSA_ERROR_NOT_SUPPORTED; |
| 225 | } |
| 226 | |
| 227 | psa_status_t mbedtls_test_opaque_set_password_key( |
| 228 | const psa_key_attributes_t *attributes, |
| 229 | mbedtls_opaque_test_driver_pake_operation_t *operation, |
| 230 | uint8_t *key_buffer, |
| 231 | size_t key_size) |
| 232 | { |
| 233 | (void) attributes; |
| 234 | (void) operation; |
| 235 | (void) key_buffer; |
| 236 | (void) key_size; |
| 237 | return PSA_ERROR_NOT_SUPPORTED; |
| 238 | } |
| 239 | |
| 240 | psa_status_t mbedtls_test_opaque_pake_set_user( |
| 241 | mbedtls_opaque_test_driver_pake_operation_t *operation, |
| 242 | const uint8_t *user_id, |
| 243 | size_t user_id_len) |
| 244 | { |
| 245 | (void) operation; |
| 246 | (void) user_id; |
| 247 | (void) user_id_len; |
| 248 | return PSA_ERROR_NOT_SUPPORTED; |
| 249 | } |
| 250 | |
| 251 | psa_status_t mbedtls_test_opaque_pake_set_peer( |
| 252 | mbedtls_opaque_test_driver_pake_operation_t *operation, |
| 253 | const uint8_t *peer_id, |
| 254 | size_t peer_id_len) |
| 255 | { |
| 256 | (void) operation; |
| 257 | (void) peer_id; |
| 258 | (void) peer_id_len; |
| 259 | return PSA_ERROR_NOT_SUPPORTED; |
| 260 | } |
| 261 | |
| 262 | psa_status_t mbedtls_test_opaque_pake_set_role( |
| 263 | mbedtls_opaque_test_driver_pake_operation_t *operation, |
| 264 | psa_pake_role_t role) |
| 265 | { |
| 266 | (void) operation; |
| 267 | (void) role; |
| 268 | return PSA_ERROR_NOT_SUPPORTED; |
| 269 | } |
| 270 | |
| 271 | psa_status_t mbedtls_test_opaque_pake_output( |
| 272 | mbedtls_opaque_test_driver_pake_operation_t *operation, |
| 273 | psa_pake_step_t step, |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 274 | const psa_pake_computation_stage_t *computation_stage, |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 275 | uint8_t *output, |
| 276 | size_t output_size, |
| 277 | size_t *output_length) |
| 278 | { |
| 279 | (void) operation; |
| 280 | (void) step; |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 281 | (void) computation_stage; |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 282 | (void) output; |
| 283 | (void) output_size; |
| 284 | (void) output_length; |
| 285 | |
| 286 | return PSA_ERROR_NOT_SUPPORTED; |
| 287 | } |
| 288 | |
| 289 | psa_status_t mbedtls_test_opaque_pake_input( |
| 290 | mbedtls_opaque_test_driver_pake_operation_t *operation, |
| 291 | psa_pake_step_t step, |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 292 | const psa_pake_computation_stage_t *computation_stage, |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 293 | const uint8_t *input, |
| 294 | size_t input_length) |
| 295 | { |
| 296 | (void) operation; |
| 297 | (void) step; |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 298 | (void) computation_stage; |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 299 | (void) input; |
| 300 | (void) input_length; |
| 301 | return PSA_ERROR_NOT_SUPPORTED; |
| 302 | } |
| 303 | |
| 304 | psa_status_t mbedtls_test_opaque_pake_get_implicit_key( |
| 305 | mbedtls_opaque_test_driver_pake_operation_t *operation, |
Przemek Stekiel | 0c78180 | 2022-11-29 14:53:13 +0100 | [diff] [blame] | 306 | uint8_t *output, size_t *output_size) |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 307 | { |
| 308 | (void) operation; |
| 309 | (void) output; |
Przemek Stekiel | 0c78180 | 2022-11-29 14:53:13 +0100 | [diff] [blame] | 310 | (void) output_size; |
Przemek Stekiel | d3da040 | 2022-11-22 13:53:26 +0100 | [diff] [blame] | 311 | return PSA_ERROR_NOT_SUPPORTED; |
| 312 | } |
| 313 | |
| 314 | psa_status_t mbedtls_test_opaque_pake_abort( |
| 315 | mbedtls_opaque_test_driver_pake_operation_t *operation) |
| 316 | { |
| 317 | (void) operation; |
| 318 | return PSA_ERROR_NOT_SUPPORTED; |
| 319 | } |
| 320 | |
| 321 | #endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */ |