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. |
| 5 | * |
| 6 | * The Elliptic Curve Diffie-Hellman (ECDH) protocol is an anonymous |
| 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 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 53 | * \brief The ECDH context structure. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 54 | */ |
| 55 | typedef struct |
| 56 | { |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 57 | mbedtls_ecp_group grp; /*!< The elliptic curve used. */ |
| 58 | mbedtls_mpi d; /*!< The private key. */ |
| 59 | mbedtls_ecp_point Q; /*!< The public key. */ |
| 60 | mbedtls_ecp_point Qp; /*!< The value of the public key of the peer. */ |
| 61 | mbedtls_mpi z; /*!< The shared secret. */ |
| 62 | int point_format; /*!< The format of point export in TLS messages. */ |
| 63 | mbedtls_ecp_point Vi; /*!< The blinding value. */ |
| 64 | mbedtls_ecp_point Vf; /*!< The unblinding value. */ |
| 65 | mbedtls_mpi _d; /*!< The previous \p d. */ |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 66 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 67 | mbedtls_ecdh_context; |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 68 | |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 69 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 70 | * \brief This function generates an ECDH keypair on an elliptic |
| 71 | * curve. |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 72 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 73 | * This function performs the first of two core computations |
| 74 | * implemented during the ECDH key exchange. The second core |
| 75 | * computation is performed by mbedtls_ecdh_compute_shared(). |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 76 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 77 | * \see ecp.h |
| 78 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 79 | * \param grp The ECP group. |
| 80 | * \param d The destination MPI (private key). |
| 81 | * \param Q The destination point (public key). |
| 82 | * \param f_rng The RNG function. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 83 | * \param p_rng The RNG context. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 84 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 85 | * \return \c 0 on success. |
| 86 | * \return An \c MBEDTLS_ERR_ECP_XXX or |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 87 | * \c MBEDTLS_MPI_XXX error code on failure. |
| 88 | * |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 89 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 90 | 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] | 91 | int (*f_rng)(void *, unsigned char *, size_t), |
| 92 | void *p_rng ); |
| 93 | |
| 94 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 95 | * \brief This function computes the shared secret. |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 96 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 97 | * This function performs the second of two core computations |
| 98 | * implemented during the ECDH key exchange. The first core |
| 99 | * computation is performed by mbedtls_ecdh_gen_public(). |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 100 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 101 | * \see ecp.h |
| 102 | * |
| 103 | * \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^] | 104 | * countermeasures against side-channel attacks. |
| 105 | * For more information, see mbedtls_ecp_mul(). |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 106 | * |
| 107 | * \param grp The ECP group. |
| 108 | * \param z The destination MPI (shared secret). |
| 109 | * \param Q The public key from another party. |
| 110 | * \param d Our secret exponent (private key). |
| 111 | * \param f_rng The RNG function. |
| 112 | * \param p_rng The RNG context. |
| 113 | * |
| 114 | * \return \c 0 on success. |
| 115 | * \return An \c MBEDTLS_ERR_ECP_XXX or |
| 116 | * \c MBEDTLS_MPI_XXX error code on failure. |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 117 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 118 | int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z, |
| 119 | const mbedtls_ecp_point *Q, const mbedtls_mpi *d, |
Manuel Pégourié-Gonnard | e09d2f8 | 2013-09-02 14:29:09 +0200 | [diff] [blame] | 120 | int (*f_rng)(void *, unsigned char *, size_t), |
| 121 | void *p_rng ); |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 122 | |
| 123 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 124 | * \brief This function initializes an ECDH context. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 125 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 126 | * \param ctx The ECDH context to initialize. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 127 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 128 | void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx ); |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 129 | |
| 130 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 131 | * \brief This function frees a context. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 132 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 133 | * \param ctx The context to free. |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 134 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 135 | void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx ); |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 136 | |
| 137 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 138 | * \brief This function generates a public key and a TLS |
| 139 | * ServerKeyExchange payload. |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 140 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 141 | * This is the first function used by a TLS server for ECDHE |
| 142 | * ciphersuites. |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 143 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 144 | * \note This function assumes that the ECP group (grp) of the |
| 145 | * \p ctx context has already been properly set, |
| 146 | * for example, using mbedtls_ecp_group_load(). |
| 147 | * |
| 148 | * \see ecp.h |
| 149 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 150 | * \param ctx The ECDH context. |
| 151 | * \param olen The number of characters written. |
| 152 | * \param buf The destination buffer. |
| 153 | * \param blen The length of the destination buffer. |
| 154 | * \param f_rng The RNG function. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 155 | * \param p_rng The RNG context. |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 156 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 157 | * \return \c 0 on success. |
| 158 | * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 159 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 160 | 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] | 161 | unsigned char *buf, size_t blen, |
| 162 | int (*f_rng)(void *, unsigned char *, size_t), |
| 163 | void *p_rng ); |
| 164 | |
| 165 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 166 | * \brief This function parses and processes a TLS ServerKeyExhange |
| 167 | * payload. |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 168 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 169 | * This is the first function used by a TLS client for ECDHE |
| 170 | * ciphersuites. |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 171 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 172 | * \see ecp.h |
| 173 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 174 | * \param ctx The ECDH context. |
| 175 | * \param buf The pointer to the start of the input buffer. |
| 176 | * \param end The address for one Byte past the end of the buffer. |
| 177 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 178 | * \return \c 0 on success. |
| 179 | * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 180 | * |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 181 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 182 | int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx, |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 183 | const unsigned char **buf, const unsigned char *end ); |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 184 | |
| 185 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 186 | * \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] | 187 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 188 | * It is used by clients and servers in place of the |
| 189 | * ServerKeyEchange for static ECDH, and imports ECDH |
| 190 | * parameters from the EC key information of a certificate. |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 191 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 192 | * \see ecp.h |
| 193 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 194 | * \param ctx The ECDH context to set up. |
| 195 | * \param key The EC key to use. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 196 | * \param side Defines the source of the key: 1: Our key, or |
| 197 | * 0: The key of the peer. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 198 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 199 | * \return \c 0 on success. |
| 200 | * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 201 | * |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 202 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 203 | int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key, |
| 204 | mbedtls_ecdh_side side ); |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 205 | |
| 206 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 207 | * \brief This function generates a public key and a TLS |
| 208 | * ClientKeyExchange payload. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 209 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 210 | * This is the second function used by a TLS client for ECDH(E) |
| 211 | * ciphersuites. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 212 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 213 | * \see ecp.h |
| 214 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 215 | * \param ctx The ECDH context. |
| 216 | * \param olen The number of Bytes written. |
| 217 | * \param buf The destination buffer. |
| 218 | * \param blen The size of the destination buffer. |
| 219 | * \param f_rng The RNG function. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 220 | * \param p_rng The RNG context. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 221 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 222 | * \return \c 0 on success. |
| 223 | * \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] | 224 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 225 | 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] | 226 | unsigned char *buf, size_t blen, |
| 227 | int (*f_rng)(void *, unsigned char *, size_t), |
| 228 | void *p_rng ); |
| 229 | |
| 230 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 231 | * \brief This function parses and processes a TLS ClientKeyExchange |
| 232 | * payload. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 233 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 234 | * This is the second function used by a TLS server for ECDH(E) |
| 235 | * ciphersuites. |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 236 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 237 | * \see ecp.h |
| 238 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 239 | * \param ctx The ECDH context. |
| 240 | * \param buf The start of the input buffer. |
| 241 | * \param blen The length of the input buffer. |
| 242 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 243 | * \return \c 0 on success. |
| 244 | * \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] | 245 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 246 | int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx, |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 247 | const unsigned char *buf, size_t blen ); |
| 248 | |
| 249 | /** |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 250 | * \brief This function derives and exports the shared secret. |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 251 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 252 | * This is the last function used by both TLS client |
| 253 | * and servers. |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 254 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 255 | * \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^] | 256 | * countermeasures against side-channel attacks. |
| 257 | * For more information, see mbedtls_ecp_mul(). |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 258 | * |
| 259 | * \see ecp.h |
| 260 | * |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 261 | * \param ctx The ECDH context. |
| 262 | * \param olen The number of Bytes written. |
| 263 | * \param buf The destination buffer. |
| 264 | * \param blen The length of the destination buffer. |
| 265 | * \param f_rng The RNG function. |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 266 | * \param p_rng The RNG context. |
Rose Zadik | de2d622 | 2018-01-25 21:57:43 +0000 | [diff] [blame] | 267 | * |
Rose Zadik | 6899328 | 2018-03-27 11:12:25 +0100 | [diff] [blame] | 268 | * \return \c 0 on success. |
| 269 | * \return An \c MBEDTLS_ERR_ECP_XXX error code on failure. |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 270 | */ |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 271 | 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] | 272 | unsigned char *buf, size_t blen, |
| 273 | int (*f_rng)(void *, unsigned char *, size_t), |
| 274 | void *p_rng ); |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 275 | |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 276 | #ifdef __cplusplus |
| 277 | } |
| 278 | #endif |
| 279 | |
Paul Bakker | 9af723c | 2014-05-01 13:03:14 +0200 | [diff] [blame] | 280 | #endif /* ecdh.h */ |