Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * PSA PAKE layer on top of Mbed TLS software crypto |
| 3 | */ |
| 4 | /* |
| 5 | * Copyright The Mbed TLS Contributors |
| 6 | * SPDX-License-Identifier: Apache-2.0 |
| 7 | * |
| 8 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 9 | * not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, software |
| 15 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 16 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | * See the License for the specific language governing permissions and |
| 18 | * limitations under the License. |
| 19 | */ |
| 20 | |
| 21 | #include "common.h" |
| 22 | |
| 23 | #if defined(MBEDTLS_PSA_CRYPTO_C) |
| 24 | |
| 25 | #include <psa/crypto.h> |
| 26 | #include "psa_crypto_core.h" |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 27 | #include "psa_crypto_pake.h" |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 28 | #include "psa_crypto_slot_management.h" |
| 29 | |
| 30 | #include <mbedtls/ecjpake.h> |
| 31 | #include <mbedtls/psa_util.h> |
| 32 | |
| 33 | #include <mbedtls/platform.h> |
| 34 | #include <mbedtls/error.h> |
| 35 | #include <string.h> |
| 36 | |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 37 | /* |
| 38 | * State sequence: |
| 39 | * |
| 40 | * psa_pake_setup() |
| 41 | * | |
| 42 | * |-- In any order: |
| 43 | * | | psa_pake_set_password_key() |
| 44 | * | | psa_pake_set_user() |
| 45 | * | | psa_pake_set_peer() |
Neil Armstrong | c29f847 | 2022-06-08 13:34:49 +0200 | [diff] [blame] | 46 | * | | psa_pake_set_role() |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 47 | * | |
| 48 | * |--- In any order: (First round input before or after first round output) |
| 49 | * | | |
| 50 | * | |------ In Order |
| 51 | * | | | psa_pake_output(PSA_PAKE_STEP_KEY_SHARE) |
| 52 | * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PUBLIC) |
| 53 | * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PROOF) |
| 54 | * | | | psa_pake_output(PSA_PAKE_STEP_KEY_SHARE) |
| 55 | * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PUBLIC) |
| 56 | * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PROOF) |
| 57 | * | | |
| 58 | * | |------ In Order: |
| 59 | * | | psa_pake_input(PSA_PAKE_STEP_KEY_SHARE) |
| 60 | * | | psa_pake_input(PSA_PAKE_STEP_ZK_PUBLIC) |
| 61 | * | | psa_pake_input(PSA_PAKE_STEP_ZK_PROOF) |
| 62 | * | | psa_pake_input(PSA_PAKE_STEP_KEY_SHARE) |
| 63 | * | | psa_pake_input(PSA_PAKE_STEP_ZK_PUBLIC) |
| 64 | * | | psa_pake_input(PSA_PAKE_STEP_ZK_PROOF) |
| 65 | * | |
| 66 | * |--- In any order: (Second round input before or after second round output) |
| 67 | * | | |
| 68 | * | |------ In Order |
| 69 | * | | | psa_pake_output(PSA_PAKE_STEP_KEY_SHARE) |
| 70 | * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PUBLIC) |
| 71 | * | | | psa_pake_output(PSA_PAKE_STEP_ZK_PROOF) |
| 72 | * | | |
| 73 | * | |------ In Order: |
| 74 | * | | psa_pake_input(PSA_PAKE_STEP_KEY_SHARE) |
| 75 | * | | psa_pake_input(PSA_PAKE_STEP_ZK_PUBLIC) |
| 76 | * | | psa_pake_input(PSA_PAKE_STEP_ZK_PROOF) |
| 77 | * | |
| 78 | * psa_pake_get_implicit_key() |
| 79 | * psa_pake_abort() |
| 80 | */ |
| 81 | |
Neil Armstrong | db05cbf | 2022-06-15 15:25:45 +0200 | [diff] [blame] | 82 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 83 | static psa_status_t mbedtls_ecjpake_to_psa_error(int ret) |
Neil Armstrong | db05cbf | 2022-06-15 15:25:45 +0200 | [diff] [blame] | 84 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 85 | switch (ret) { |
Neil Armstrong | db05cbf | 2022-06-15 15:25:45 +0200 | [diff] [blame] | 86 | case MBEDTLS_ERR_MPI_BAD_INPUT_DATA: |
| 87 | case MBEDTLS_ERR_ECP_BAD_INPUT_DATA: |
| 88 | case MBEDTLS_ERR_ECP_INVALID_KEY: |
| 89 | case MBEDTLS_ERR_ECP_VERIFY_FAILED: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 90 | return PSA_ERROR_DATA_INVALID; |
Neil Armstrong | db05cbf | 2022-06-15 15:25:45 +0200 | [diff] [blame] | 91 | case MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL: |
| 92 | case MBEDTLS_ERR_ECP_BUFFER_TOO_SMALL: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 93 | return PSA_ERROR_BUFFER_TOO_SMALL; |
Neil Armstrong | db05cbf | 2022-06-15 15:25:45 +0200 | [diff] [blame] | 94 | case MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 95 | return PSA_ERROR_NOT_SUPPORTED; |
Neil Armstrong | db05cbf | 2022-06-15 15:25:45 +0200 | [diff] [blame] | 96 | case MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 97 | return PSA_ERROR_CORRUPTION_DETECTED; |
Neil Armstrong | db05cbf | 2022-06-15 15:25:45 +0200 | [diff] [blame] | 98 | default: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 99 | return PSA_ERROR_GENERIC_ERROR; |
Neil Armstrong | db05cbf | 2022-06-15 15:25:45 +0200 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | #endif |
| 103 | |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 104 | #if defined(MBEDTLS_PSA_BUILTIN_PAKE) |
Neil Armstrong | a557cb8 | 2022-06-10 08:58:32 +0200 | [diff] [blame] | 105 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE) |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 106 | static psa_status_t psa_pake_ecjpake_setup(mbedtls_psa_pake_operation_t *operation) |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 107 | { |
| 108 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 109 | |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 110 | mbedtls_ecjpake_init(&operation->ctx.jpake); |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 111 | |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 112 | ret = mbedtls_ecjpake_setup(&operation->ctx.jpake, |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 113 | operation->role, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 114 | MBEDTLS_MD_SHA256, |
| 115 | MBEDTLS_ECP_DP_SECP256R1, |
| 116 | operation->password, |
| 117 | operation->password_len); |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 118 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 119 | mbedtls_platform_zeroize(operation->password, operation->password_len); |
Przemek Stekiel | ad0f357 | 2022-11-21 15:04:37 +0100 | [diff] [blame] | 120 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 121 | if (ret != 0) { |
| 122 | return mbedtls_ecjpake_to_psa_error(ret); |
| 123 | } |
Przemek Stekiel | 0bdec19 | 2022-11-22 09:10:35 +0100 | [diff] [blame] | 124 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 125 | return PSA_SUCCESS; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 126 | } |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 127 | #endif |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 128 | |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 129 | /* The only two JPAKE user/peer identifiers supported in built-in implementation. */ |
| 130 | static const uint8_t jpake_server_id[] = { 's', 'e', 'r', 'v', 'e', 'r' }; |
| 131 | static const uint8_t jpake_client_id[] = { 'c', 'l', 'i', 'e', 'n', 't' }; |
| 132 | |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 133 | psa_status_t mbedtls_psa_pake_setup(mbedtls_psa_pake_operation_t *operation, |
| 134 | const psa_crypto_driver_pake_inputs_t *inputs) |
| 135 | { |
| 136 | psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 137 | size_t user_len = 0, peer_len = 0, password_len = 0; |
| 138 | uint8_t *peer = NULL, *user = NULL; |
| 139 | size_t actual_user_len = 0, actual_peer_len = 0, actual_password_len = 0; |
Przemek Stekiel | 5cbca79 | 2023-01-17 16:51:19 +0100 | [diff] [blame] | 140 | psa_pake_cipher_suite_t cipher_suite = psa_pake_cipher_suite_init(); |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 141 | |
Przemek Stekiel | 5cbca79 | 2023-01-17 16:51:19 +0100 | [diff] [blame] | 142 | status = psa_crypto_driver_pake_get_password_len(inputs, &password_len); |
| 143 | if (status != PSA_SUCCESS) { |
| 144 | return status; |
| 145 | } |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 146 | |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 147 | psa_crypto_driver_pake_get_user_len(inputs, &user_len); |
| 148 | if (status != PSA_SUCCESS) { |
| 149 | return status; |
| 150 | } |
| 151 | |
| 152 | psa_crypto_driver_pake_get_peer_len(inputs, &peer_len); |
Przemek Stekiel | 5cbca79 | 2023-01-17 16:51:19 +0100 | [diff] [blame] | 153 | if (status != PSA_SUCCESS) { |
| 154 | return status; |
| 155 | } |
| 156 | |
| 157 | status = psa_crypto_driver_pake_get_cipher_suite(inputs, &cipher_suite); |
| 158 | if (status != PSA_SUCCESS) { |
| 159 | return status; |
| 160 | } |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 161 | |
Przemek Stekiel | a54dc69 | 2023-02-20 10:18:10 +0100 | [diff] [blame] | 162 | operation->password = mbedtls_calloc(1, password_len); |
| 163 | if (operation->password == NULL) { |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 164 | status = PSA_ERROR_INSUFFICIENT_MEMORY; |
| 165 | goto error; |
| 166 | } |
| 167 | |
| 168 | user = mbedtls_calloc(1, user_len); |
| 169 | if (user == NULL) { |
| 170 | status = PSA_ERROR_INSUFFICIENT_MEMORY; |
| 171 | goto error; |
| 172 | } |
| 173 | |
| 174 | peer = mbedtls_calloc(1, peer_len); |
| 175 | if (peer == NULL) { |
| 176 | status = PSA_ERROR_INSUFFICIENT_MEMORY; |
| 177 | goto error; |
Przemek Stekiel | a54dc69 | 2023-02-20 10:18:10 +0100 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | status = psa_crypto_driver_pake_get_password(inputs, operation->password, |
Przemek Stekiel | 083745e | 2023-02-23 17:28:23 +0100 | [diff] [blame] | 181 | password_len, &actual_password_len); |
Przemek Stekiel | a54dc69 | 2023-02-20 10:18:10 +0100 | [diff] [blame] | 182 | if (status != PSA_SUCCESS) { |
| 183 | goto error; |
| 184 | } |
| 185 | |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 186 | status = psa_crypto_driver_pake_get_user(inputs, user, |
| 187 | user_len, &actual_user_len); |
| 188 | if (status != PSA_SUCCESS) { |
| 189 | goto error; |
| 190 | } |
| 191 | |
| 192 | status = psa_crypto_driver_pake_get_peer(inputs, peer, |
| 193 | peer_len, &actual_peer_len); |
| 194 | if (status != PSA_SUCCESS) { |
| 195 | goto error; |
| 196 | } |
| 197 | |
Przemek Stekiel | a54dc69 | 2023-02-20 10:18:10 +0100 | [diff] [blame] | 198 | operation->password_len = actual_password_len; |
| 199 | operation->alg = cipher_suite.algorithm; |
| 200 | |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 201 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE) |
| 202 | if (cipher_suite.algorithm == PSA_ALG_JPAKE) { |
| 203 | if (cipher_suite.type != PSA_PAKE_PRIMITIVE_TYPE_ECC || |
| 204 | cipher_suite.family != PSA_ECC_FAMILY_SECP_R1 || |
| 205 | cipher_suite.bits != 256 || |
| 206 | cipher_suite.hash != PSA_ALG_SHA_256) { |
Przemek Stekiel | a54dc69 | 2023-02-20 10:18:10 +0100 | [diff] [blame] | 207 | status = PSA_ERROR_NOT_SUPPORTED; |
| 208 | goto error; |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 211 | const size_t user_peer_len = sizeof(jpake_client_id); // client and server have the same length |
| 212 | if (actual_user_len != user_peer_len || |
| 213 | actual_peer_len != user_peer_len) { |
| 214 | status = PSA_ERROR_NOT_SUPPORTED; |
| 215 | goto error; |
| 216 | } |
| 217 | |
| 218 | if (memcmp(user, jpake_client_id, actual_user_len) == 0 && |
| 219 | memcmp(peer, jpake_server_id, actual_peer_len) == 0) { |
| 220 | operation->role = MBEDTLS_ECJPAKE_CLIENT; |
| 221 | } else |
| 222 | if (memcmp(user, jpake_server_id, actual_user_len) == 0 && |
| 223 | memcmp(peer, jpake_client_id, actual_peer_len) == 0) { |
| 224 | operation->role = MBEDTLS_ECJPAKE_SERVER; |
| 225 | } else { |
| 226 | status = PSA_ERROR_NOT_SUPPORTED; |
| 227 | goto error; |
| 228 | } |
| 229 | |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 230 | operation->buffer_length = 0; |
| 231 | operation->buffer_offset = 0; |
| 232 | |
| 233 | status = psa_pake_ecjpake_setup(operation); |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 234 | if (status != PSA_SUCCESS) { |
Przemek Stekiel | a54dc69 | 2023-02-20 10:18:10 +0100 | [diff] [blame] | 235 | goto error; |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Przemek Stekiel | aede2ad | 2023-04-25 14:30:34 +0200 | [diff] [blame] | 238 | /* Role has been set, release user/peer buffers. */ |
| 239 | mbedtls_free(user); mbedtls_free(peer); |
| 240 | |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 241 | return PSA_SUCCESS; |
| 242 | } else |
| 243 | #else |
| 244 | (void) operation; |
| 245 | (void) inputs; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 246 | #endif |
Przemek Stekiel | ce131bf | 2023-02-21 12:19:27 +0100 | [diff] [blame] | 247 | { status = PSA_ERROR_NOT_SUPPORTED; } |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 248 | |
Przemek Stekiel | a54dc69 | 2023-02-20 10:18:10 +0100 | [diff] [blame] | 249 | error: |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 250 | mbedtls_free(user); mbedtls_free(peer); |
Przemek Stekiel | d93de32 | 2023-02-24 08:39:04 +0100 | [diff] [blame] | 251 | /* In case of failure of the setup of a multipart operation, the PSA driver interface |
| 252 | * specifies that the core does not call any other driver entry point thus does not |
| 253 | * call mbedtls_psa_pake_abort(). Therefore call it here to do the needed clean |
| 254 | * up like freeing the memory that may have been allocated to store the password. |
| 255 | */ |
Przemek Stekiel | ce131bf | 2023-02-21 12:19:27 +0100 | [diff] [blame] | 256 | mbedtls_psa_pake_abort(operation); |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 257 | return status; |
| 258 | } |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 259 | |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 260 | static psa_status_t mbedtls_psa_pake_output_internal( |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 261 | mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 262 | psa_crypto_driver_pake_step_t step, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 263 | uint8_t *output, |
| 264 | size_t output_size, |
| 265 | size_t *output_length) |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 266 | { |
| 267 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 268 | size_t length; |
Przemek Stekiel | 9a5b812 | 2022-12-22 13:34:47 +0100 | [diff] [blame] | 269 | (void) step; // Unused parameter |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 270 | |
Neil Armstrong | a557cb8 | 2022-06-10 08:58:32 +0200 | [diff] [blame] | 271 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE) |
Neil Armstrong | fa84962 | 2022-09-13 15:10:46 +0200 | [diff] [blame] | 272 | /* |
| 273 | * The PSA CRYPTO PAKE and MbedTLS JPAKE API have a different |
| 274 | * handling of output sequencing. |
| 275 | * |
Neil Armstrong | 6a12a77 | 2022-09-14 12:17:42 +0200 | [diff] [blame] | 276 | * The MbedTLS JPAKE API outputs the whole X1+X2 and X2S steps data |
Neil Armstrong | fa84962 | 2022-09-13 15:10:46 +0200 | [diff] [blame] | 277 | * at once, on the other side the PSA CRYPTO PAKE api requires |
| 278 | * the KEY_SHARE/ZP_PUBLIC/ZK_PROOF parts of X1, X2 & X2S to be |
| 279 | * retrieved in sequence. |
| 280 | * |
| 281 | * In order to achieve API compatibility, the whole X1+X2 or X2S steps |
| 282 | * data is stored in an intermediate buffer at first step output call, |
| 283 | * and data is sliced down by parsing the ECPoint records in order |
| 284 | * to return the right parts on each step. |
| 285 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 286 | if (operation->alg == PSA_ALG_JPAKE) { |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 287 | /* Initialize & write round on KEY_SHARE sequences */ |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 288 | if (step == PSA_JPAKE_X1_STEP_KEY_SHARE) { |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 289 | ret = mbedtls_ecjpake_write_round_one(&operation->ctx.jpake, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 290 | operation->buffer, |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 291 | sizeof(operation->buffer), |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 292 | &operation->buffer_length, |
| 293 | mbedtls_psa_get_random, |
| 294 | MBEDTLS_PSA_RANDOM_STATE); |
| 295 | if (ret != 0) { |
| 296 | return mbedtls_ecjpake_to_psa_error(ret); |
| 297 | } |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 298 | |
| 299 | operation->buffer_offset = 0; |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 300 | } else if (step == PSA_JPAKE_X2S_STEP_KEY_SHARE) { |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 301 | ret = mbedtls_ecjpake_write_round_two(&operation->ctx.jpake, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 302 | operation->buffer, |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 303 | sizeof(operation->buffer), |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 304 | &operation->buffer_length, |
| 305 | mbedtls_psa_get_random, |
| 306 | MBEDTLS_PSA_RANDOM_STATE); |
| 307 | if (ret != 0) { |
| 308 | return mbedtls_ecjpake_to_psa_error(ret); |
| 309 | } |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 310 | |
| 311 | operation->buffer_offset = 0; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Neil Armstrong | 1d0294f | 2022-09-13 14:49:24 +0200 | [diff] [blame] | 314 | /* |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 315 | * mbedtls_ecjpake_write_round_xxx() outputs thing in the format |
| 316 | * defined by draft-cragie-tls-ecjpake-01 section 7. The summary is |
| 317 | * that the data for each step is prepended with a length byte, and |
| 318 | * then they're concatenated. Additionally, the server's second round |
| 319 | * output is prepended with a 3-bytes ECParameters structure. |
Neil Armstrong | 1d0294f | 2022-09-13 14:49:24 +0200 | [diff] [blame] | 320 | * |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 321 | * In PSA, we output each step separately, and don't prepend the |
| 322 | * output with a length byte, even less a curve identifier, as that |
| 323 | * information is already available. |
Neil Armstrong | 1d0294f | 2022-09-13 14:49:24 +0200 | [diff] [blame] | 324 | */ |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 325 | if (step == PSA_JPAKE_X2S_STEP_KEY_SHARE && |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 326 | operation->role == MBEDTLS_ECJPAKE_SERVER) { |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 327 | /* Skip ECParameters, with is 3 bytes (RFC 8422) */ |
| 328 | operation->buffer_offset += 3; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 329 | } |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 330 | |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 331 | /* Read the length byte then move past it to the data */ |
| 332 | length = operation->buffer[operation->buffer_offset]; |
| 333 | operation->buffer_offset += 1; |
| 334 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 335 | if (operation->buffer_offset + length > operation->buffer_length) { |
| 336 | return PSA_ERROR_DATA_CORRUPT; |
| 337 | } |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 338 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 339 | if (output_size < length) { |
| 340 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 341 | } |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 342 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 343 | memcpy(output, |
| 344 | operation->buffer + operation->buffer_offset, |
| 345 | length); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 346 | *output_length = length; |
| 347 | |
| 348 | operation->buffer_offset += length; |
| 349 | |
| 350 | /* Reset buffer after ZK_PROOF sequence */ |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 351 | if ((step == PSA_JPAKE_X2_STEP_ZK_PROOF) || |
| 352 | (step == PSA_JPAKE_X2S_STEP_ZK_PROOF)) { |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 353 | mbedtls_platform_zeroize(operation->buffer, sizeof(operation->buffer)); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 354 | operation->buffer_length = 0; |
| 355 | operation->buffer_offset = 0; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 356 | } |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 357 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 358 | return PSA_SUCCESS; |
| 359 | } else |
Neil Armstrong | 5ae6096 | 2022-09-15 11:29:46 +0200 | [diff] [blame] | 360 | #else |
| 361 | (void) step; |
| 362 | (void) output; |
| 363 | (void) output_size; |
| 364 | (void) output_length; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 365 | #endif |
Neil Armstrong | 5ae6096 | 2022-09-15 11:29:46 +0200 | [diff] [blame] | 366 | { return PSA_ERROR_NOT_SUPPORTED; } |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 367 | } |
| 368 | |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 369 | psa_status_t mbedtls_psa_pake_output(mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 370 | psa_crypto_driver_pake_step_t step, |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 371 | uint8_t *output, |
| 372 | size_t output_size, |
| 373 | size_t *output_length) |
Manuel Pégourié-Gonnard | f155ab9 | 2022-10-13 13:11:52 +0200 | [diff] [blame] | 374 | { |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 375 | psa_status_t status = mbedtls_psa_pake_output_internal( |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 376 | operation, step, output, output_size, output_length); |
Manuel Pégourié-Gonnard | f155ab9 | 2022-10-13 13:11:52 +0200 | [diff] [blame] | 377 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 378 | return status; |
Manuel Pégourié-Gonnard | f155ab9 | 2022-10-13 13:11:52 +0200 | [diff] [blame] | 379 | } |
| 380 | |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 381 | static psa_status_t mbedtls_psa_pake_input_internal( |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 382 | mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 383 | psa_crypto_driver_pake_step_t step, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 384 | const uint8_t *input, |
| 385 | size_t input_length) |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 386 | { |
| 387 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Przemek Stekiel | 9a5b812 | 2022-12-22 13:34:47 +0100 | [diff] [blame] | 388 | (void) step; // Unused parameter |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 389 | |
Neil Armstrong | a557cb8 | 2022-06-10 08:58:32 +0200 | [diff] [blame] | 390 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE) |
Neil Armstrong | fa84962 | 2022-09-13 15:10:46 +0200 | [diff] [blame] | 391 | /* |
| 392 | * The PSA CRYPTO PAKE and MbedTLS JPAKE API have a different |
| 393 | * handling of input sequencing. |
| 394 | * |
| 395 | * The MbedTLS JPAKE API takes the whole X1+X2 or X4S steps data |
| 396 | * at once as input, on the other side the PSA CRYPTO PAKE api requires |
| 397 | * the KEY_SHARE/ZP_PUBLIC/ZK_PROOF parts of X1, X2 & X4S to be |
| 398 | * given in sequence. |
| 399 | * |
| 400 | * In order to achieve API compatibility, each X1+X2 or X4S step data |
| 401 | * is stored sequentially in an intermediate buffer and given to the |
| 402 | * MbedTLS JPAKE API on the last step. |
| 403 | * |
| 404 | * This causes any input error to be only detected on the last step. |
| 405 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 406 | if (operation->alg == PSA_ALG_JPAKE) { |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 407 | /* |
| 408 | * Copy input to local buffer and format it as the Mbed TLS API |
| 409 | * expects, i.e. as defined by draft-cragie-tls-ecjpake-01 section 7. |
| 410 | * The summary is that the data for each step is prepended with a |
| 411 | * length byte, and then they're concatenated. Additionally, the |
| 412 | * server's second round output is prepended with a 3-bytes |
| 413 | * ECParameters structure - which means we have to prepend that when |
| 414 | * we're a client. |
| 415 | */ |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 416 | if (step == PSA_JPAKE_X4S_STEP_KEY_SHARE && |
Przemek Stekiel | e80ec0a | 2023-03-21 16:49:43 +0100 | [diff] [blame] | 417 | operation->role == MBEDTLS_ECJPAKE_CLIENT) { |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 418 | /* We only support secp256r1. */ |
| 419 | /* This is the ECParameters structure defined by RFC 8422. */ |
| 420 | unsigned char ecparameters[3] = { |
| 421 | 3, /* named_curve */ |
| 422 | 0, 23 /* secp256r1 */ |
| 423 | }; |
Przemek Stekiel | 4dc83d4 | 2023-02-27 11:49:35 +0100 | [diff] [blame] | 424 | |
Przemek Stekiel | 691e91a | 2023-03-07 16:26:37 +0100 | [diff] [blame] | 425 | if (operation->buffer_length + sizeof(ecparameters) > |
| 426 | sizeof(operation->buffer)) { |
Przemek Stekiel | 4dc83d4 | 2023-02-27 11:49:35 +0100 | [diff] [blame] | 427 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 428 | } |
| 429 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 430 | memcpy(operation->buffer + operation->buffer_length, |
| 431 | ecparameters, sizeof(ecparameters)); |
| 432 | operation->buffer_length += sizeof(ecparameters); |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Przemek Stekiel | 4dc83d4 | 2023-02-27 11:49:35 +0100 | [diff] [blame] | 435 | /* |
Przemek Stekiel | 691e91a | 2023-03-07 16:26:37 +0100 | [diff] [blame] | 436 | * The core checks that input_length is smaller than |
| 437 | * PSA_PAKE_INPUT_MAX_SIZE. |
| 438 | * Thus no risk of integer overflow here. |
Przemek Stekiel | 4dc83d4 | 2023-02-27 11:49:35 +0100 | [diff] [blame] | 439 | */ |
| 440 | if (operation->buffer_length + input_length + 1 > sizeof(operation->buffer)) { |
| 441 | return PSA_ERROR_BUFFER_TOO_SMALL; |
| 442 | } |
| 443 | |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 444 | /* Write the length byte */ |
Manuel Pégourié-Gonnard | 0771d41 | 2022-10-06 09:30:34 +0200 | [diff] [blame] | 445 | operation->buffer[operation->buffer_length] = (uint8_t) input_length; |
Manuel Pégourié-Gonnard | ec7012d | 2022-10-05 12:17:34 +0200 | [diff] [blame] | 446 | operation->buffer_length += 1; |
| 447 | |
| 448 | /* Finally copy the data */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 449 | memcpy(operation->buffer + operation->buffer_length, |
| 450 | input, input_length); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 451 | operation->buffer_length += input_length; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 452 | |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 453 | /* Load buffer at each last round ZK_PROOF */ |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 454 | if (step == PSA_JPAKE_X2_STEP_ZK_PROOF) { |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 455 | ret = mbedtls_ecjpake_read_round_one(&operation->ctx.jpake, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 456 | operation->buffer, |
| 457 | operation->buffer_length); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 458 | |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 459 | mbedtls_platform_zeroize(operation->buffer, sizeof(operation->buffer)); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 460 | operation->buffer_length = 0; |
| 461 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 462 | if (ret != 0) { |
| 463 | return mbedtls_ecjpake_to_psa_error(ret); |
| 464 | } |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 465 | } else if (step == PSA_JPAKE_X4S_STEP_ZK_PROOF) { |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 466 | ret = mbedtls_ecjpake_read_round_two(&operation->ctx.jpake, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 467 | operation->buffer, |
| 468 | operation->buffer_length); |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 469 | |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 470 | mbedtls_platform_zeroize(operation->buffer, sizeof(operation->buffer)); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 471 | operation->buffer_length = 0; |
| 472 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 473 | if (ret != 0) { |
| 474 | return mbedtls_ecjpake_to_psa_error(ret); |
| 475 | } |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 476 | } |
| 477 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 478 | return PSA_SUCCESS; |
| 479 | } else |
Neil Armstrong | 5ae6096 | 2022-09-15 11:29:46 +0200 | [diff] [blame] | 480 | #else |
| 481 | (void) step; |
| 482 | (void) input; |
| 483 | (void) input_length; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 484 | #endif |
Neil Armstrong | 5ae6096 | 2022-09-15 11:29:46 +0200 | [diff] [blame] | 485 | { return PSA_ERROR_NOT_SUPPORTED; } |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 486 | } |
| 487 | |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 488 | psa_status_t mbedtls_psa_pake_input(mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 251e86a | 2023-02-17 14:30:50 +0100 | [diff] [blame] | 489 | psa_crypto_driver_pake_step_t step, |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 490 | const uint8_t *input, |
| 491 | size_t input_length) |
Manuel Pégourié-Gonnard | f155ab9 | 2022-10-13 13:11:52 +0200 | [diff] [blame] | 492 | { |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 493 | psa_status_t status = mbedtls_psa_pake_input_internal( |
Przemek Stekiel | b09c487 | 2023-01-17 12:05:38 +0100 | [diff] [blame] | 494 | operation, step, input, input_length); |
Manuel Pégourié-Gonnard | f155ab9 | 2022-10-13 13:11:52 +0200 | [diff] [blame] | 495 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 496 | return status; |
Manuel Pégourié-Gonnard | f155ab9 | 2022-10-13 13:11:52 +0200 | [diff] [blame] | 497 | } |
| 498 | |
Neil Armstrong | 56b8d23 | 2022-06-01 18:05:57 +0200 | [diff] [blame] | 499 | psa_status_t mbedtls_psa_pake_get_implicit_key( |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 500 | mbedtls_psa_pake_operation_t *operation, |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 501 | uint8_t *output, size_t output_size, |
| 502 | size_t *output_length) |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 503 | { |
| 504 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 505 | |
Neil Armstrong | a557cb8 | 2022-06-10 08:58:32 +0200 | [diff] [blame] | 506 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 507 | if (operation->alg == PSA_ALG_JPAKE) { |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 508 | ret = mbedtls_ecjpake_write_shared_key(&operation->ctx.jpake, |
| 509 | output, |
Przemek Stekiel | 6b64862 | 2023-02-19 22:55:33 +0100 | [diff] [blame] | 510 | output_size, |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 511 | output_length, |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 512 | mbedtls_psa_get_random, |
| 513 | MBEDTLS_PSA_RANDOM_STATE); |
| 514 | if (ret != 0) { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 515 | return mbedtls_ecjpake_to_psa_error(ret); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 516 | } |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 517 | |
Przemek Stekiel | 0c78180 | 2022-11-29 14:53:13 +0100 | [diff] [blame] | 518 | return PSA_SUCCESS; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 519 | } else |
Neil Armstrong | 5ae6096 | 2022-09-15 11:29:46 +0200 | [diff] [blame] | 520 | #else |
| 521 | (void) output; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 522 | #endif |
Przemek Stekiel | e12ed36 | 2022-12-21 12:54:46 +0100 | [diff] [blame] | 523 | { return PSA_ERROR_NOT_SUPPORTED; } |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 524 | } |
| 525 | |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 526 | psa_status_t mbedtls_psa_pake_abort(mbedtls_psa_pake_operation_t *operation) |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 527 | { |
Przemek Stekiel | ce131bf | 2023-02-21 12:19:27 +0100 | [diff] [blame] | 528 | mbedtls_platform_zeroize(operation->password, operation->password_len); |
| 529 | mbedtls_free(operation->password); |
| 530 | operation->password = NULL; |
| 531 | operation->password_len = 0; |
Przemek Stekiel | 6c76441 | 2022-11-22 14:05:12 +0100 | [diff] [blame] | 532 | |
Przemek Stekiel | ce131bf | 2023-02-21 12:19:27 +0100 | [diff] [blame] | 533 | #if defined(MBEDTLS_PSA_BUILTIN_ALG_JPAKE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 534 | if (operation->alg == PSA_ALG_JPAKE) { |
Przemek Stekiel | 6e628a4 | 2023-04-25 13:11:36 +0200 | [diff] [blame] | 535 | operation->role = MBEDTLS_ECJPAKE_NONE; |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 536 | mbedtls_platform_zeroize(operation->buffer, sizeof(operation->buffer)); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 537 | operation->buffer_length = 0; |
| 538 | operation->buffer_offset = 0; |
Przemek Stekiel | e3ef3a1 | 2023-02-27 10:20:06 +0100 | [diff] [blame] | 539 | mbedtls_ecjpake_free(&operation->ctx.jpake); |
Neil Armstrong | 4efd7a4 | 2022-06-08 17:18:31 +0200 | [diff] [blame] | 540 | } |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 541 | #endif |
| 542 | |
Neil Armstrong | cb679f2 | 2022-09-13 14:43:07 +0200 | [diff] [blame] | 543 | operation->alg = PSA_ALG_NONE; |
Neil Armstrong | fbc4b4a | 2022-06-10 08:54:53 +0200 | [diff] [blame] | 544 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 545 | return PSA_SUCCESS; |
Neil Armstrong | a4cc7d6 | 2022-05-25 11:30:48 +0200 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | #endif /* MBEDTLS_PSA_BUILTIN_PAKE */ |
| 549 | |
| 550 | #endif /* MBEDTLS_PSA_CRYPTO_C */ |