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