Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file ecdh.h |
| 3 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 4 | * \brief This file contains ECDH definitions and functions. |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 5 | * |
Darryl Green | 11999bb | 2018-03-13 15:22:58 +0000 | [diff] [blame] | 6 | * The Elliptic Curve Diffie-Hellman (ECDH) protocol is an anonymous |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 7 | * key agreement protocol allowing two parties to establish a shared |
| 8 | * secret over an insecure channel. Each party must have an |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 9 | * elliptic-curve public–private key pair. |
| 10 | * |
| 11 | * For more information, see <em>NIST SP 800-56A Rev. 2: Recommendation for |
| 12 | * Pair-Wise Key Establishment Schemes Using Discrete Logarithm |
| 13 | * Cryptography</em>. |
Darryl Green | a40a101 | 2018-01-05 15:33:17 +0000 | [diff] [blame] | 14 | */ |
| 15 | /* |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 16 | * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved |
Manuel Pégourié-Gonnard | 37ff140 | 2015-09-04 14:21:07 +0200 | [diff] [blame] | 17 | * SPDX-License-Identifier: Apache-2.0 |
| 18 | * |
| 19 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 20 | * not use this file except in compliance with the License. |
| 21 | * You may obtain a copy of the License at |
| 22 | * |
| 23 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 24 | * |
| 25 | * Unless required by applicable law or agreed to in writing, software |
| 26 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 27 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 28 | * See the License for the specific language governing permissions and |
| 29 | * limitations under the License. |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 30 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 31 | * This file is part of Mbed TLS (https://tls.mbed.org) |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 32 | */ |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 33 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 34 | #ifndef MBEDTLS_ECDH_H |
| 35 | #define MBEDTLS_ECDH_H |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 36 | |
Manuel Pégourié-Gonnard | bdc9676 | 2013-10-03 11:50:39 +0200 | [diff] [blame] | 37 | #include "ecp.h" |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 38 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 39 | #ifdef __cplusplus |
| 40 | extern "C" { |
| 41 | #endif |
| 42 | |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 43 | /** |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 44 | * Defines the source of the imported EC key. |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 45 | */ |
| 46 | typedef enum |
| 47 | { |
Rose Zadik | 7375b0f | 2018-04-16 16:04:57 +0100 | [diff] [blame] | 48 | MBEDTLS_ECDH_OURS, /**< Our key. */ |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 49 | MBEDTLS_ECDH_THEIRS, /**< The key of the peer. */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 50 | } mbedtls_ecdh_side; |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 51 | |
| 52 | /** |
Manuel Pégourié-Gonnard | eaf55be | 2017-08-23 14:40:21 +0200 | [diff] [blame] | 53 | * |
| 54 | * \warning Performing multiple operations concurrently on the same |
| 55 | * ECDSA context is not supported; objects of this type |
| 56 | * should not be shared between multiple threads. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 57 | * \brief The ECDH context structure. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 58 | */ |
Dawid Drozd | 428cc52 | 2018-07-24 10:02:47 +0200 | [diff] [blame] | 59 | typedef struct mbedtls_ecdh_context |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 60 | { |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 61 | mbedtls_ecp_group grp; /*!< The elliptic curve used. */ |
| 62 | mbedtls_mpi d; /*!< The private key. */ |
| 63 | mbedtls_ecp_point Q; /*!< The public key. */ |
| 64 | mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */ |
| 65 | mbedtls_mpi z; /*!< The shared secret. */ |
| 66 | int point_format; /*!< The format of point export in TLS messages. */ |
| 67 | mbedtls_ecp_point Vi; /*!< The blinding value. */ |
| 68 | mbedtls_ecp_point Vf; /*!< The unblinding value. */ |
| 69 | mbedtls_mpi _d; /*!< The previous \p d. */ |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 70 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 71 | int restart_enabled; /*!< The flag for restartable mode. */ |
| 72 | mbedtls_ecp_restart_ctx rs; /*!< The restart context for EC computations. */ |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 73 | #endif |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 74 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 75 | mbedtls_ecdh_context; |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 76 | |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 77 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 78 | * \brief This function generates an ECDH keypair on an elliptic |
| 79 | * curve. |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 80 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 81 | * This function performs the first of two core computations |
| 82 | * implemented during the ECDH key exchange. The second core |
| 83 | * computation is performed by mbedtls_ecdh_compute_shared(). |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 84 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 85 | * \see ecp.h |
| 86 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 87 | * \param grp The ECP group. |
| 88 | * \param d The destination MPI (private key). |
| 89 | * \param Q The destination point (public key). |
| 90 | * \param f_rng The RNG function. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 91 | * \param p_rng The RNG context. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 92 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 93 | * \return \c 0 on success. |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 94 | * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of |
Manuel Pégourié-Gonnard | c90d3b0 | 2017-04-27 10:48:29 +0200 | [diff] [blame] | 95 | * operations was reached: see \c mbedtls_ecp_set_max_ops(). |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame^] | 96 | * \return Another \c MBEDTLS_ERR_ECP_XXX or |
| 97 | * \c MBEDTLS_MPI_XXX error code on failure. |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 98 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 99 | int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q, |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 100 | int (*f_rng)(void *, unsigned char *, size_t), |
| 101 | void *p_rng ); |
| 102 | |
| 103 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 104 | * \brief This function computes the shared secret. |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 105 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 106 | * This function performs the second of two core computations |
| 107 | * implemented during the ECDH key exchange. The first core |
| 108 | * computation is performed by mbedtls_ecdh_gen_public(). |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 109 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 110 | * \see ecp.h |
| 111 | * |
| 112 | * \note If \p f_rng is not NULL, it is used to implement |
Rose Zadik | 7375b0f | 2018-04-16 16:04:57 +0100 | [diff] [blame] | 113 | * countermeasures against side-channel attacks. |
| 114 | * For more information, see mbedtls_ecp_mul(). |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 115 | * |
| 116 | * \param grp The ECP group. |
| 117 | * \param z The destination MPI (shared secret). |
| 118 | * \param Q The public key from another party. |
| 119 | * \param d Our secret exponent (private key). |
| 120 | * \param f_rng The RNG function. |
| 121 | * \param p_rng The RNG context. |
| 122 | * |
| 123 | * \return \c 0 on success. |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 124 | * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of |
Manuel Pégourié-Gonnard | c90d3b0 | 2017-04-27 10:48:29 +0200 | [diff] [blame] | 125 | * operations was reached: see \c mbedtls_ecp_set_max_ops(). |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame^] | 126 | * \return Another \c MBEDTLS_ERR_ECP_XXX or |
| 127 | * \c MBEDTLS_MPI_XXX error code on failure. |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 128 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 129 | int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z, |
| 130 | const mbedtls_ecp_point *Q, const mbedtls_mpi *d, |
Manuel Pégourié-Gonnard | e09d2f8 | 2013-09-02 14:29:09 +0200 | [diff] [blame] | 131 | int (*f_rng)(void *, unsigned char *, size_t), |
| 132 | void *p_rng ); |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 133 | |
| 134 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 135 | * \brief This function initializes an ECDH context. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 136 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 137 | * \param ctx The ECDH context to initialize. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 138 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 139 | void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx ); |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 140 | |
| 141 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 142 | * \brief This function frees a context. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 143 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 144 | * \param ctx The context to free. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 145 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 146 | void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx ); |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 147 | |
| 148 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 149 | * \brief This function generates a public key and a TLS |
| 150 | * ServerKeyExchange payload. |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 151 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 152 | * This is the first function used by a TLS server for ECDHE |
| 153 | * ciphersuites. |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 154 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 155 | * \note This function assumes that the ECP group (grp) of the |
| 156 | * \p ctx context has already been properly set, |
| 157 | * for example, using mbedtls_ecp_group_load(). |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 158 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 159 | * \see ecp.h |
| 160 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 161 | * \param ctx The ECDH context. |
| 162 | * \param olen The number of characters written. |
| 163 | * \param buf The destination buffer. |
| 164 | * \param blen The length of the destination buffer. |
| 165 | * \param f_rng The RNG function. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 166 | * \param p_rng The RNG context. |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 167 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 168 | * \return \c 0 on success. |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 169 | * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of |
Manuel Pégourié-Gonnard | c90d3b0 | 2017-04-27 10:48:29 +0200 | [diff] [blame] | 170 | * operations was reached: see \c mbedtls_ecp_set_max_ops(). |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame^] | 171 | * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 172 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 173 | int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen, |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 174 | unsigned char *buf, size_t blen, |
| 175 | int (*f_rng)(void *, unsigned char *, size_t), |
| 176 | void *p_rng ); |
| 177 | |
| 178 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 179 | * \brief This function parses and processes a TLS ServerKeyExhange |
| 180 | * payload. |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 181 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 182 | * This is the first function used by a TLS client for ECDHE |
| 183 | * ciphersuites. |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 184 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 185 | * \see ecp.h |
| 186 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 187 | * \param ctx The ECDH context. |
| 188 | * \param buf The pointer to the start of the input buffer. |
| 189 | * \param end The address for one Byte past the end of the buffer. |
| 190 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 191 | * \return \c 0 on success. |
| 192 | * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 193 | * |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 194 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 195 | int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx, |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 196 | const unsigned char **buf, const unsigned char *end ); |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 197 | |
| 198 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 199 | * \brief This function sets up an ECDH context from an EC key. |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 200 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 201 | * It is used by clients and servers in place of the |
| 202 | * ServerKeyEchange for static ECDH, and imports ECDH |
| 203 | * parameters from the EC key information of a certificate. |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 204 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 205 | * \see ecp.h |
| 206 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 207 | * \param ctx The ECDH context to set up. |
| 208 | * \param key The EC key to use. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 209 | * \param side Defines the source of the key: 1: Our key, or |
| 210 | * 0: The key of the peer. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 211 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 212 | * \return \c 0 on success. |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 213 | * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of |
| 214 | * operations was reached: see \c mbedtls_ecp_set_max_ops(). |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame^] | 215 | * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 216 | * |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 217 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 218 | int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key, |
| 219 | mbedtls_ecdh_side side ); |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 220 | |
| 221 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 222 | * \brief This function generates a public key and a TLS |
| 223 | * ClientKeyExchange payload. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 224 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 225 | * This is the second function used by a TLS client for ECDH(E) |
| 226 | * ciphersuites. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 227 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 228 | * \see ecp.h |
| 229 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 230 | * \param ctx The ECDH context. |
| 231 | * \param olen The number of Bytes written. |
| 232 | * \param buf The destination buffer. |
| 233 | * \param blen The size of the destination buffer. |
| 234 | * \param f_rng The RNG function. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 235 | * \param p_rng The RNG context. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 236 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 237 | * \return \c 0 on success. |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 238 | * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of |
Manuel Pégourié-Gonnard | c90d3b0 | 2017-04-27 10:48:29 +0200 | [diff] [blame] | 239 | * operations was reached: see \c mbedtls_ecp_set_max_ops(). |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame^] | 240 | * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 241 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 242 | int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen, |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 243 | unsigned char *buf, size_t blen, |
| 244 | int (*f_rng)(void *, unsigned char *, size_t), |
| 245 | void *p_rng ); |
| 246 | |
| 247 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 248 | * \brief This function parses and processes a TLS ClientKeyExchange |
| 249 | * payload. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 250 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 251 | * This is the second function used by a TLS server for ECDH(E) |
| 252 | * ciphersuites. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 253 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 254 | * \see ecp.h |
| 255 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 256 | * \param ctx The ECDH context. |
| 257 | * \param buf The start of the input buffer. |
| 258 | * \param blen The length of the input buffer. |
| 259 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 260 | * \return \c 0 on success. |
| 261 | * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 262 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 263 | int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx, |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 264 | const unsigned char *buf, size_t blen ); |
| 265 | |
| 266 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 267 | * \brief This function derives and exports the shared secret. |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 268 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 269 | * This is the last function used by both TLS client |
| 270 | * and servers. |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 271 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 272 | * \note If \p f_rng is not NULL, it is used to implement |
Rose Zadik | 7375b0f | 2018-04-16 16:04:57 +0100 | [diff] [blame] | 273 | * countermeasures against side-channel attacks. |
| 274 | * For more information, see mbedtls_ecp_mul(). |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 275 | * |
| 276 | * \see ecp.h |
| 277 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 278 | * \param ctx The ECDH context. |
| 279 | * \param olen The number of Bytes written. |
| 280 | * \param buf The destination buffer. |
| 281 | * \param blen The length of the destination buffer. |
| 282 | * \param f_rng The RNG function. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 283 | * \param p_rng The RNG context. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 284 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 285 | * \return \c 0 on success. |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 286 | * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of |
Manuel Pégourié-Gonnard | c90d3b0 | 2017-04-27 10:48:29 +0200 | [diff] [blame] | 287 | * operations was reached: see \c mbedtls_ecp_set_max_ops(). |
Manuel Pégourié-Gonnard | f0bbd7e | 2018-10-15 13:22:41 +0200 | [diff] [blame^] | 288 | * \return Another \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 289 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 290 | int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen, |
Manuel Pégourié-Gonnard | e09d2f8 | 2013-09-02 14:29:09 +0200 | [diff] [blame] | 291 | unsigned char *buf, size_t blen, |
| 292 | int (*f_rng)(void *, unsigned char *, size_t), |
| 293 | void *p_rng ); |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 294 | |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 295 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 296 | /** |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 297 | * \brief This function enables restartable EC computations for this |
| 298 | * context. (Default: disabled.) |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 299 | * |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 300 | * \see \c mbedtls_ecp_set_max_ops() |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 301 | * |
| 302 | * \note It is not possible to safely disable restartable |
| 303 | * computations once enabled, except by free-ing the context, |
| 304 | * which cancels possible in-progress operations. |
| 305 | * |
Manuel Pégourié-Gonnard | da19f4c | 2018-06-12 12:40:54 +0200 | [diff] [blame] | 306 | * \param ctx The ECDH context. |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 307 | */ |
| 308 | void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx ); |
| 309 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
| 310 | |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 311 | #ifdef __cplusplus |
| 312 | } |
| 313 | #endif |
| 314 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 315 | #endif /* ecdh.h */ |