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