Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file ecjpake.h |
| 3 | * |
| 4 | * \brief Elliptic curve J-PAKE |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 7 | * Copyright The Mbed TLS Contributors |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: Apache-2.0 |
| 9 | * |
| 10 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 11 | * not use this file except in compliance with the License. |
| 12 | * You may obtain a copy of the License at |
| 13 | * |
| 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | * |
| 16 | * Unless required by applicable law or agreed to in writing, software |
| 17 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 18 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | * See the License for the specific language governing permissions and |
| 20 | * limitations under the License. |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 21 | */ |
| 22 | #ifndef MBEDTLS_ECJPAKE_H |
| 23 | #define MBEDTLS_ECJPAKE_H |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 24 | #include "mbedtls/private_access.h" |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 25 | |
Manuel Pégourié-Gonnard | 6b798b9 | 2015-08-14 11:18:30 +0200 | [diff] [blame] | 26 | /* |
Manuel Pégourié-Gonnard | d8204a7 | 2015-08-14 13:36:55 +0200 | [diff] [blame] | 27 | * J-PAKE is a password-authenticated key exchange that allows deriving a |
| 28 | * strong shared secret from a (potentially low entropy) pre-shared |
| 29 | * passphrase, with forward secrecy and mutual authentication. |
| 30 | * https://en.wikipedia.org/wiki/Password_Authenticated_Key_Exchange_by_Juggling |
| 31 | * |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 32 | * This file implements the Elliptic Curve variant of J-PAKE, |
| 33 | * as defined in Chapter 7.4 of the Thread v1.0 Specification, |
| 34 | * available to members of the Thread Group http://threadgroup.org/ |
Manuel Pégourié-Gonnard | d8204a7 | 2015-08-14 13:36:55 +0200 | [diff] [blame] | 35 | * |
| 36 | * As the J-PAKE algorithm is inherently symmetric, so is our API. |
| 37 | * Each party needs to send its first round message, in any order, to the |
| 38 | * other party, then each sends its second round message, in any order. |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 39 | * The payloads are serialized in a way suitable for use in TLS, but could |
| 40 | * also be use outside TLS. |
Manuel Pégourié-Gonnard | 6b798b9 | 2015-08-14 11:18:30 +0200 | [diff] [blame] | 41 | */ |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 42 | #if !defined(MBEDTLS_CONFIG_FILE) |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 43 | #include "mbedtls/config.h" |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 44 | #else |
| 45 | #include MBEDTLS_CONFIG_FILE |
| 46 | #endif |
Manuel Pégourié-Gonnard | 6b798b9 | 2015-08-14 11:18:30 +0200 | [diff] [blame] | 47 | |
Jaeden Amero | c49fbbf | 2019-07-04 20:01:14 +0100 | [diff] [blame] | 48 | #include "mbedtls/ecp.h" |
| 49 | #include "mbedtls/md.h" |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 50 | |
| 51 | #ifdef __cplusplus |
| 52 | extern "C" { |
| 53 | #endif |
| 54 | |
Manuel Pégourié-Gonnard | 6b798b9 | 2015-08-14 11:18:30 +0200 | [diff] [blame] | 55 | /** |
| 56 | * Roles in the EC J-PAKE exchange |
| 57 | */ |
Manuel Pégourié-Gonnard | 6449391 | 2015-08-13 20:19:51 +0200 | [diff] [blame] | 58 | typedef enum { |
Manuel Pégourié-Gonnard | 6b798b9 | 2015-08-14 11:18:30 +0200 | [diff] [blame] | 59 | MBEDTLS_ECJPAKE_CLIENT = 0, /**< Client */ |
| 60 | MBEDTLS_ECJPAKE_SERVER, /**< Server */ |
Manuel Pégourié-Gonnard | 6449391 | 2015-08-13 20:19:51 +0200 | [diff] [blame] | 61 | } mbedtls_ecjpake_role; |
| 62 | |
Ron Eldor | 4e6d55d | 2018-02-07 16:36:15 +0200 | [diff] [blame] | 63 | #if !defined(MBEDTLS_ECJPAKE_ALT) |
Manuel Pégourié-Gonnard | 6b798b9 | 2015-08-14 11:18:30 +0200 | [diff] [blame] | 64 | /** |
Manuel Pégourié-Gonnard | ce45676 | 2015-08-14 11:54:35 +0200 | [diff] [blame] | 65 | * EC J-PAKE context structure. |
| 66 | * |
| 67 | * J-PAKE is a symmetric protocol, except for the identifiers used in |
| 68 | * Zero-Knowledge Proofs, and the serialization of the second message |
| 69 | * (KeyExchange) as defined by the Thread spec. |
| 70 | * |
| 71 | * In order to benefit from this symmetry, we choose a different naming |
| 72 | * convetion from the Thread v1.0 spec. Correspondance is indicated in the |
Simon Butcher | 5b331b9 | 2016-01-03 16:14:14 +0000 | [diff] [blame] | 73 | * description as a pair C: client name, S: server name |
Manuel Pégourié-Gonnard | 6b798b9 | 2015-08-14 11:18:30 +0200 | [diff] [blame] | 74 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 75 | typedef struct mbedtls_ecjpake_context |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 76 | { |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 77 | const mbedtls_md_info_t *MBEDTLS_PRIVATE(md_info); /**< Hash to use */ |
| 78 | mbedtls_ecp_group MBEDTLS_PRIVATE(grp); /**< Elliptic curve */ |
| 79 | mbedtls_ecjpake_role MBEDTLS_PRIVATE(role); /**< Are we client or server? */ |
| 80 | int MBEDTLS_PRIVATE(point_format); /**< Format for point export */ |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 81 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 82 | mbedtls_ecp_point MBEDTLS_PRIVATE(Xm1); /**< My public key 1 C: X1, S: X3 */ |
| 83 | mbedtls_ecp_point MBEDTLS_PRIVATE(Xm2); /**< My public key 2 C: X2, S: X4 */ |
| 84 | mbedtls_ecp_point MBEDTLS_PRIVATE(Xp1); /**< Peer public key 1 C: X3, S: X1 */ |
| 85 | mbedtls_ecp_point MBEDTLS_PRIVATE(Xp2); /**< Peer public key 2 C: X4, S: X2 */ |
| 86 | mbedtls_ecp_point MBEDTLS_PRIVATE(Xp); /**< Peer public key C: Xs, S: Xc */ |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 87 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 88 | mbedtls_mpi MBEDTLS_PRIVATE(xm1); /**< My private key 1 C: x1, S: x3 */ |
| 89 | mbedtls_mpi MBEDTLS_PRIVATE(xm2); /**< My private key 2 C: x2, S: x4 */ |
Manuel Pégourié-Gonnard | 23dcbe3 | 2015-08-13 09:37:00 +0200 | [diff] [blame] | 90 | |
Mateusz Starzyk | 846f021 | 2021-05-19 19:44:07 +0200 | [diff] [blame] | 91 | mbedtls_mpi MBEDTLS_PRIVATE(s); /**< Pre-shared secret (passphrase) */ |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 92 | } mbedtls_ecjpake_context; |
| 93 | |
Ron Eldor | 4e6d55d | 2018-02-07 16:36:15 +0200 | [diff] [blame] | 94 | #else /* MBEDTLS_ECJPAKE_ALT */ |
| 95 | #include "ecjpake_alt.h" |
| 96 | #endif /* MBEDTLS_ECJPAKE_ALT */ |
| 97 | |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 98 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 99 | * \brief Initialize an ECJPAKE context. |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 100 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 101 | * \param ctx The ECJPAKE context to initialize. |
| 102 | * This must not be \c NULL. |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 103 | */ |
| 104 | void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx ); |
| 105 | |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 106 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 107 | * \brief Set up an ECJPAKE context for use. |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 108 | * |
| 109 | * \note Currently the only values for hash/curve allowed by the |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 110 | * standard are #MBEDTLS_MD_SHA256/#MBEDTLS_ECP_DP_SECP256R1. |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 111 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 112 | * \param ctx The ECJPAKE context to set up. This must be initialized. |
| 113 | * \param role The role of the caller. This must be either |
| 114 | * #MBEDTLS_ECJPAKE_CLIENT or #MBEDTLS_ECJPAKE_SERVER. |
| 115 | * \param hash The identifier of the hash function to use, |
| 116 | * for example #MBEDTLS_MD_SHA256. |
| 117 | * \param curve The identifier of the elliptic curve to use, |
| 118 | * for example #MBEDTLS_ECP_DP_SECP256R1. |
| 119 | * \param secret The pre-shared secret (passphrase). This must be |
| 120 | * a readable buffer of length \p len Bytes. It need |
| 121 | * only be valid for the duration of this call. |
| 122 | * \param len The length of the pre-shared secret \p secret. |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 123 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 124 | * \return \c 0 if successful. |
| 125 | * \return A negative error code on failure. |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 126 | */ |
| 127 | int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx, |
Manuel Pégourié-Gonnard | 6449391 | 2015-08-13 20:19:51 +0200 | [diff] [blame] | 128 | mbedtls_ecjpake_role role, |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 129 | mbedtls_md_type_t hash, |
Manuel Pégourié-Gonnard | 23dcbe3 | 2015-08-13 09:37:00 +0200 | [diff] [blame] | 130 | mbedtls_ecp_group_id curve, |
| 131 | const unsigned char *secret, |
| 132 | size_t len ); |
Manuel Pégourié-Gonnard | 7af8bc1 | 2015-08-12 16:58:50 +0200 | [diff] [blame] | 133 | |
Andres Amaya Garcia | af610a0 | 2016-12-14 10:13:43 +0000 | [diff] [blame] | 134 | /** |
Gilles Peskine | cd07e22 | 2021-05-27 23:17:34 +0200 | [diff] [blame^] | 135 | * \brief Set the point format for future reads and writes. |
| 136 | * |
| 137 | * \param ctx The ECJPAKE context to configure. |
| 138 | * \param point_format The point format to use: |
| 139 | * #MBEDTLS_ECP_PF_UNCOMPRESSED (default) |
| 140 | * or #MBEDTLS_ECP_PF_COMPRESSED. |
| 141 | * |
| 142 | * \return \c 0 if successful. |
| 143 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA if \p point_format |
| 144 | * is invalid. |
| 145 | */ |
| 146 | int mbedtls_ecjpake_set_point_format( mbedtls_ecjpake_context *ctx, |
| 147 | int point_format ); |
| 148 | |
| 149 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 150 | * \brief Check if an ECJPAKE context is ready for use. |
Manuel Pégourié-Gonnard | b813acc | 2015-09-15 15:34:09 +0200 | [diff] [blame] | 151 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 152 | * \param ctx The ECJPAKE context to check. This must be |
| 153 | * initialized. |
Manuel Pégourié-Gonnard | b813acc | 2015-09-15 15:34:09 +0200 | [diff] [blame] | 154 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 155 | * \return \c 0 if the context is ready for use. |
| 156 | * \return #MBEDTLS_ERR_ECP_BAD_INPUT_DATA otherwise. |
Manuel Pégourié-Gonnard | b813acc | 2015-09-15 15:34:09 +0200 | [diff] [blame] | 157 | */ |
| 158 | int mbedtls_ecjpake_check( const mbedtls_ecjpake_context *ctx ); |
| 159 | |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 160 | /** |
Manuel Pégourié-Gonnard | d8204a7 | 2015-08-14 13:36:55 +0200 | [diff] [blame] | 161 | * \brief Generate and write the first round message |
| 162 | * (TLS: contents of the Client/ServerHello extension, |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 163 | * excluding extension type and length bytes). |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 164 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 165 | * \param ctx The ECJPAKE context to use. This must be |
| 166 | * initialized and set up. |
| 167 | * \param buf The buffer to write the contents to. This must be a |
| 168 | * writable buffer of length \p len Bytes. |
| 169 | * \param len The length of \p buf in Bytes. |
| 170 | * \param olen The address at which to store the total number |
| 171 | * of Bytes written to \p buf. This must not be \c NULL. |
| 172 | * \param f_rng The RNG function to use. This must not be \c NULL. |
| 173 | * \param p_rng The RNG parameter to be passed to \p f_rng. This |
| 174 | * may be \c NULL if \p f_rng doesn't use a context. |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 175 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 176 | * \return \c 0 if successful. |
| 177 | * \return A negative error code on failure. |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 178 | */ |
Manuel Pégourié-Gonnard | d8204a7 | 2015-08-14 13:36:55 +0200 | [diff] [blame] | 179 | int mbedtls_ecjpake_write_round_one( mbedtls_ecjpake_context *ctx, |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 180 | unsigned char *buf, size_t len, size_t *olen, |
| 181 | int (*f_rng)(void *, unsigned char *, size_t), |
| 182 | void *p_rng ); |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * \brief Read and process the first round message |
Manuel Pégourié-Gonnard | d8204a7 | 2015-08-14 13:36:55 +0200 | [diff] [blame] | 186 | * (TLS: contents of the Client/ServerHello extension, |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 187 | * excluding extension type and length bytes). |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 188 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 189 | * \param ctx The ECJPAKE context to use. This must be initialized |
| 190 | * and set up. |
| 191 | * \param buf The buffer holding the first round message. This must |
| 192 | * be a readable buffer of length \p len Bytes. |
| 193 | * \param len The length in Bytes of \p buf. |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 194 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 195 | * \return \c 0 if successful. |
| 196 | * \return A negative error code on failure. |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 197 | */ |
Manuel Pégourié-Gonnard | d8204a7 | 2015-08-14 13:36:55 +0200 | [diff] [blame] | 198 | int mbedtls_ecjpake_read_round_one( mbedtls_ecjpake_context *ctx, |
| 199 | const unsigned char *buf, |
| 200 | size_t len ); |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 201 | |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 202 | /** |
| 203 | * \brief Generate and write the second round message |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 204 | * (TLS: contents of the Client/ServerKeyExchange). |
Manuel Pégourié-Gonnard | 614bd5e | 2015-08-13 20:19:16 +0200 | [diff] [blame] | 205 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 206 | * \param ctx The ECJPAKE context to use. This must be initialized, |
| 207 | * set up, and already have performed round one. |
| 208 | * \param buf The buffer to write the round two contents to. |
| 209 | * This must be a writable buffer of length \p len Bytes. |
| 210 | * \param len The size of \p buf in Bytes. |
| 211 | * \param olen The address at which to store the total number of Bytes |
| 212 | * written to \p buf. This must not be \c NULL. |
| 213 | * \param f_rng The RNG function to use. This must not be \c NULL. |
| 214 | * \param p_rng The RNG parameter to be passed to \p f_rng. This |
| 215 | * may be \c NULL if \p f_rng doesn't use a context. |
Manuel Pégourié-Gonnard | 614bd5e | 2015-08-13 20:19:16 +0200 | [diff] [blame] | 216 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 217 | * \return \c 0 if successful. |
| 218 | * \return A negative error code on failure. |
Manuel Pégourié-Gonnard | 614bd5e | 2015-08-13 20:19:16 +0200 | [diff] [blame] | 219 | */ |
Manuel Pégourié-Gonnard | e192710 | 2015-08-14 14:20:48 +0200 | [diff] [blame] | 220 | int mbedtls_ecjpake_write_round_two( mbedtls_ecjpake_context *ctx, |
Manuel Pégourié-Gonnard | 614bd5e | 2015-08-13 20:19:16 +0200 | [diff] [blame] | 221 | unsigned char *buf, size_t len, size_t *olen, |
| 222 | int (*f_rng)(void *, unsigned char *, size_t), |
| 223 | void *p_rng ); |
| 224 | |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 225 | /** |
| 226 | * \brief Read and process the second round message |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 227 | * (TLS: contents of the Client/ServerKeyExchange). |
Manuel Pégourié-Gonnard | ec0eece | 2015-08-13 19:13:20 +0200 | [diff] [blame] | 228 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 229 | * \param ctx The ECJPAKE context to use. This must be initialized |
| 230 | * and set up and already have performed round one. |
| 231 | * \param buf The buffer holding the second round message. This must |
| 232 | * be a readable buffer of length \p len Bytes. |
| 233 | * \param len The length in Bytes of \p buf. |
Manuel Pégourié-Gonnard | ec0eece | 2015-08-13 19:13:20 +0200 | [diff] [blame] | 234 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 235 | * \return \c 0 if successful. |
| 236 | * \return A negative error code on failure. |
Manuel Pégourié-Gonnard | ec0eece | 2015-08-13 19:13:20 +0200 | [diff] [blame] | 237 | */ |
Manuel Pégourié-Gonnard | e192710 | 2015-08-14 14:20:48 +0200 | [diff] [blame] | 238 | int mbedtls_ecjpake_read_round_two( mbedtls_ecjpake_context *ctx, |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 239 | const unsigned char *buf, |
| 240 | size_t len ); |
Manuel Pégourié-Gonnard | ec0eece | 2015-08-13 19:13:20 +0200 | [diff] [blame] | 241 | |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 242 | /** |
| 243 | * \brief Derive the shared secret |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 244 | * (TLS: Pre-Master Secret). |
Manuel Pégourié-Gonnard | 5f18829 | 2015-08-14 10:52:39 +0200 | [diff] [blame] | 245 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 246 | * \param ctx The ECJPAKE context to use. This must be initialized, |
| 247 | * set up and have performed both round one and two. |
| 248 | * \param buf The buffer to write the derived secret to. This must |
| 249 | * be a writable buffer of length \p len Bytes. |
| 250 | * \param len The length of \p buf in Bytes. |
| 251 | * \param olen The address at which to store the total number of Bytes |
| 252 | * written to \p buf. This must not be \c NULL. |
| 253 | * \param f_rng The RNG function to use. This must not be \c NULL. |
| 254 | * \param p_rng The RNG parameter to be passed to \p f_rng. This |
| 255 | * may be \c NULL if \p f_rng doesn't use a context. |
Manuel Pégourié-Gonnard | 5f18829 | 2015-08-14 10:52:39 +0200 | [diff] [blame] | 256 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 257 | * \return \c 0 if successful. |
| 258 | * \return A negative error code on failure. |
Manuel Pégourié-Gonnard | 5f18829 | 2015-08-14 10:52:39 +0200 | [diff] [blame] | 259 | */ |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 260 | int mbedtls_ecjpake_derive_secret( mbedtls_ecjpake_context *ctx, |
Manuel Pégourié-Gonnard | 5f18829 | 2015-08-14 10:52:39 +0200 | [diff] [blame] | 261 | unsigned char *buf, size_t len, size_t *olen, |
| 262 | int (*f_rng)(void *, unsigned char *, size_t), |
| 263 | void *p_rng ); |
| 264 | |
Manuel Pégourié-Gonnard | f7368c9 | 2015-08-14 14:33:05 +0200 | [diff] [blame] | 265 | /** |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 266 | * \brief This clears an ECJPAKE context and frees any |
| 267 | * embedded data structure. |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 268 | * |
Andrzej Kurek | c470b6b | 2019-01-31 08:20:20 -0500 | [diff] [blame] | 269 | * \param ctx The ECJPAKE context to free. This may be \c NULL, |
| 270 | * in which case this function does nothing. If it is not |
| 271 | * \c NULL, it must point to an initialized ECJPAKE context. |
Manuel Pégourié-Gonnard | 4e8bc78 | 2015-08-12 20:50:31 +0200 | [diff] [blame] | 272 | */ |
| 273 | void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx ); |
| 274 | |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 275 | #if defined(MBEDTLS_SELF_TEST) |
Hanno Becker | 616d1ca | 2018-01-24 10:25:05 +0000 | [diff] [blame] | 276 | |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 277 | /** |
| 278 | * \brief Checkup routine |
| 279 | * |
| 280 | * \return 0 if successful, or 1 if a test failed |
| 281 | */ |
| 282 | int mbedtls_ecjpake_self_test( int verbose ); |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 283 | |
Ron Eldor | 4e6d55d | 2018-02-07 16:36:15 +0200 | [diff] [blame] | 284 | #endif /* MBEDTLS_SELF_TEST */ |
| 285 | |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 286 | #ifdef __cplusplus |
| 287 | } |
| 288 | #endif |
| 289 | |
Hanno Becker | 616d1ca | 2018-01-24 10:25:05 +0000 | [diff] [blame] | 290 | |
Manuel Pégourié-Gonnard | 4d8685b | 2015-08-05 15:44:42 +0200 | [diff] [blame] | 291 | #endif /* ecjpake.h */ |