Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Elliptic curve Diffie-Hellman |
| 3 | * |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * References: |
| 10 | * |
Xiaokang Qian | 4704147 | 2023-04-12 06:07:23 +0000 | [diff] [blame] | 11 | * SEC1 https://www.secg.org/sec1-v2.pdf |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 12 | * RFC 4492 |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
Gilles Peskine | db09ef6 | 2020-06-03 01:43:33 +0200 | [diff] [blame] | 15 | #include "common.h" |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 16 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 17 | #if defined(MBEDTLS_ECDH_C) |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 18 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 19 | #include "mbedtls/ecdh.h" |
Hanno Becker | 91796d7 | 2018-12-17 18:10:51 +0000 | [diff] [blame] | 20 | #include "mbedtls/platform_util.h" |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 21 | #include "mbedtls/error.h" |
Jerry Yu | bdc7188 | 2021-09-14 19:30:36 +0800 | [diff] [blame] | 22 | |
Rich Evans | 00ab470 | 2015-02-06 13:43:58 +0000 | [diff] [blame] | 23 | #include <string.h> |
| 24 | |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 25 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
| 26 | typedef mbedtls_ecdh_context mbedtls_ecdh_context_mbed; |
| 27 | #endif |
| 28 | |
Gilles Peskine | 3081629 | 2019-02-22 12:31:25 +0100 | [diff] [blame] | 29 | static mbedtls_ecp_group_id mbedtls_ecdh_grp_id( |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 30 | const mbedtls_ecdh_context *ctx) |
Gilles Peskine | 3081629 | 2019-02-22 12:31:25 +0100 | [diff] [blame] | 31 | { |
| 32 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 33 | return ctx->grp.id; |
Gilles Peskine | 3081629 | 2019-02-22 12:31:25 +0100 | [diff] [blame] | 34 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 35 | return ctx->grp_id; |
Gilles Peskine | 3081629 | 2019-02-22 12:31:25 +0100 | [diff] [blame] | 36 | #endif |
| 37 | } |
| 38 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 39 | int mbedtls_ecdh_can_do(mbedtls_ecp_group_id gid) |
Gilles Peskine | 20b3ef3 | 2019-02-11 18:41:27 +0100 | [diff] [blame] | 40 | { |
| 41 | /* At this time, all groups support ECDH. */ |
| 42 | (void) gid; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 43 | return 1; |
Gilles Peskine | 20b3ef3 | 2019-02-11 18:41:27 +0100 | [diff] [blame] | 44 | } |
| 45 | |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 46 | /* |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 47 | * Generate public key (restartable version) |
Manuel Pégourié-Gonnard | c0edc96 | 2018-10-16 10:38:19 +0200 | [diff] [blame] | 48 | * |
| 49 | * Note: this internal function relies on its caller preserving the value of |
Manuel Pégourié-Gonnard | ca29fdf | 2018-10-22 09:56:53 +0200 | [diff] [blame] | 50 | * the output parameter 'd' across continuation calls. This would not be |
Manuel Pégourié-Gonnard | c0edc96 | 2018-10-16 10:38:19 +0200 | [diff] [blame] | 51 | * acceptable for a public function but is OK here as we control call sites. |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 52 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 53 | static int ecdh_gen_public_restartable(mbedtls_ecp_group *grp, |
| 54 | mbedtls_mpi *d, mbedtls_ecp_point *Q, |
| 55 | int (*f_rng)(void *, unsigned char *, size_t), |
| 56 | void *p_rng, |
| 57 | mbedtls_ecp_restart_ctx *rs_ctx) |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 58 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 59 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 60 | |
David Horstmann | 91e20a0 | 2022-10-06 19:11:28 +0100 | [diff] [blame] | 61 | int restarting = 0; |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 62 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 63 | restarting = (rs_ctx != NULL && rs_ctx->rsm != NULL); |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 64 | #endif |
David Horstmann | 91e20a0 | 2022-10-06 19:11:28 +0100 | [diff] [blame] | 65 | /* If multiplication is in progress, we already generated a privkey */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 66 | if (!restarting) { |
| 67 | MBEDTLS_MPI_CHK(mbedtls_ecp_gen_privkey(grp, d, f_rng, p_rng)); |
| 68 | } |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 69 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 70 | MBEDTLS_MPI_CHK(mbedtls_ecp_mul_restartable(grp, Q, d, &grp->G, |
| 71 | f_rng, p_rng, rs_ctx)); |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 72 | |
| 73 | cleanup: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 74 | return ret; |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
| 78 | * Generate public key |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 79 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 80 | int mbedtls_ecdh_gen_public(mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q, |
| 81 | int (*f_rng)(void *, unsigned char *, size_t), |
| 82 | void *p_rng) |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 83 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 84 | return ecdh_gen_public_restartable(grp, d, Q, f_rng, p_rng, NULL); |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Compute shared secret (SEC1 3.3.1) |
| 89 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 90 | static int ecdh_compute_shared_restartable(mbedtls_ecp_group *grp, |
| 91 | mbedtls_mpi *z, |
| 92 | const mbedtls_ecp_point *Q, const mbedtls_mpi *d, |
| 93 | int (*f_rng)(void *, unsigned char *, size_t), |
| 94 | void *p_rng, |
| 95 | mbedtls_ecp_restart_ctx *rs_ctx) |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 96 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 97 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 98 | mbedtls_ecp_point P; |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 99 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 100 | mbedtls_ecp_point_init(&P); |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 101 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 102 | MBEDTLS_MPI_CHK(mbedtls_ecp_mul_restartable(grp, &P, d, Q, |
| 103 | f_rng, p_rng, rs_ctx)); |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 104 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 105 | if (mbedtls_ecp_is_zero(&P)) { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 106 | ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
Paul Bakker | b548d77 | 2013-07-26 14:21:34 +0200 | [diff] [blame] | 107 | goto cleanup; |
| 108 | } |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 109 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 110 | MBEDTLS_MPI_CHK(mbedtls_mpi_copy(z, &P.X)); |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 111 | |
| 112 | cleanup: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 113 | mbedtls_ecp_point_free(&P); |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 114 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 115 | return ret; |
Manuel Pégourié-Gonnard | 6545ca7 | 2013-01-26 16:05:22 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 118 | /* |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 119 | * Compute shared secret (SEC1 3.3.1) |
| 120 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 121 | int mbedtls_ecdh_compute_shared(mbedtls_ecp_group *grp, mbedtls_mpi *z, |
| 122 | const mbedtls_ecp_point *Q, const mbedtls_mpi *d, |
| 123 | int (*f_rng)(void *, unsigned char *, size_t), |
| 124 | void *p_rng) |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 125 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 126 | return ecdh_compute_shared_restartable(grp, z, Q, d, |
| 127 | f_rng, p_rng, NULL); |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 130 | static void ecdh_init_internal(mbedtls_ecdh_context_mbed *ctx) |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 131 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 132 | mbedtls_ecp_group_init(&ctx->grp); |
| 133 | mbedtls_mpi_init(&ctx->d); |
| 134 | mbedtls_ecp_point_init(&ctx->Q); |
| 135 | mbedtls_ecp_point_init(&ctx->Qp); |
| 136 | mbedtls_mpi_init(&ctx->z); |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 137 | |
| 138 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 139 | mbedtls_ecp_restart_init(&ctx->rs); |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 140 | #endif |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Minos Galanakis | d753738 | 2024-02-23 12:17:59 +0000 | [diff] [blame] | 143 | mbedtls_ecp_group_id mbedtls_ecdh_get_grp_id(mbedtls_ecdh_context *ctx) |
| 144 | { |
| 145 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
| 146 | return ctx->MBEDTLS_PRIVATE(grp).id; |
| 147 | #else |
| 148 | return ctx->MBEDTLS_PRIVATE(grp_id); |
| 149 | #endif |
| 150 | } |
| 151 | |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 152 | /* |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 153 | * Initialize context |
Janos Follath | f61e486 | 2018-10-30 11:53:25 +0000 | [diff] [blame] | 154 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 155 | void mbedtls_ecdh_init(mbedtls_ecdh_context *ctx) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 156 | { |
| 157 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 158 | ecdh_init_internal(ctx); |
| 159 | mbedtls_ecp_point_init(&ctx->Vi); |
| 160 | mbedtls_ecp_point_init(&ctx->Vf); |
| 161 | mbedtls_mpi_init(&ctx->_d); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 162 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 163 | memset(ctx, 0, sizeof(mbedtls_ecdh_context)); |
Christoph M. Wintersteiger | d8c45d5 | 2019-02-20 17:16:53 +0000 | [diff] [blame] | 164 | |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 165 | ctx->var = MBEDTLS_ECDH_VARIANT_NONE; |
| 166 | #endif |
| 167 | ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED; |
| 168 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 169 | ctx->restart_enabled = 0; |
| 170 | #endif |
| 171 | } |
| 172 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 173 | static int ecdh_setup_internal(mbedtls_ecdh_context_mbed *ctx, |
| 174 | mbedtls_ecp_group_id grp_id) |
Janos Follath | f61e486 | 2018-10-30 11:53:25 +0000 | [diff] [blame] | 175 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 176 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Janos Follath | f61e486 | 2018-10-30 11:53:25 +0000 | [diff] [blame] | 177 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 178 | ret = mbedtls_ecp_group_load(&ctx->grp, grp_id); |
| 179 | if (ret != 0) { |
| 180 | return MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE; |
Janos Follath | f61e486 | 2018-10-30 11:53:25 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 183 | return 0; |
Janos Follath | f61e486 | 2018-10-30 11:53:25 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /* |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 187 | * Setup context |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 188 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 189 | int mbedtls_ecdh_setup(mbedtls_ecdh_context *ctx, mbedtls_ecp_group_id grp_id) |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 190 | { |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 191 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 192 | return ecdh_setup_internal(ctx, grp_id); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 193 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 194 | switch (grp_id) { |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 195 | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
Christoph M. Wintersteiger | 3ff60bc | 2019-02-15 12:59:59 +0000 | [diff] [blame] | 196 | case MBEDTLS_ECP_DP_CURVE25519: |
| 197 | ctx->point_format = MBEDTLS_ECP_PF_COMPRESSED; |
| 198 | ctx->var = MBEDTLS_ECDH_VARIANT_EVEREST; |
| 199 | ctx->grp_id = grp_id; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 200 | return mbedtls_everest_setup(&ctx->ctx.everest_ecdh, grp_id); |
Christoph M. Wintersteiger | 78c9c46 | 2018-12-06 17:16:32 +0000 | [diff] [blame] | 201 | #endif |
Christoph M. Wintersteiger | 3ff60bc | 2019-02-15 12:59:59 +0000 | [diff] [blame] | 202 | default: |
| 203 | ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED; |
| 204 | ctx->var = MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0; |
| 205 | ctx->grp_id = grp_id; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 206 | ecdh_init_internal(&ctx->ctx.mbed_ecdh); |
| 207 | return ecdh_setup_internal(&ctx->ctx.mbed_ecdh, grp_id); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 208 | } |
| 209 | #endif |
| 210 | } |
| 211 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 212 | static void ecdh_free_internal(mbedtls_ecdh_context_mbed *ctx) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 213 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 214 | mbedtls_ecp_group_free(&ctx->grp); |
| 215 | mbedtls_mpi_free(&ctx->d); |
| 216 | mbedtls_ecp_point_free(&ctx->Q); |
| 217 | mbedtls_ecp_point_free(&ctx->Qp); |
| 218 | mbedtls_mpi_free(&ctx->z); |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 219 | |
| 220 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 221 | mbedtls_ecp_restart_free(&ctx->rs); |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 222 | #endif |
Manuel Pégourié-Gonnard | 63533e4 | 2013-02-10 14:21:04 +0100 | [diff] [blame] | 223 | } |
| 224 | |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 225 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 226 | /* |
| 227 | * Enable restartable operations for context |
| 228 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 229 | void mbedtls_ecdh_enable_restart(mbedtls_ecdh_context *ctx) |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 230 | { |
| 231 | ctx->restart_enabled = 1; |
| 232 | } |
| 233 | #endif |
| 234 | |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 235 | /* |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 236 | * Free context |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 237 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 238 | void mbedtls_ecdh_free(mbedtls_ecdh_context *ctx) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 239 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 240 | if (ctx == NULL) { |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 241 | return; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 242 | } |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 243 | |
| 244 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 245 | mbedtls_ecp_point_free(&ctx->Vi); |
| 246 | mbedtls_ecp_point_free(&ctx->Vf); |
| 247 | mbedtls_mpi_free(&ctx->_d); |
| 248 | ecdh_free_internal(ctx); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 249 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 250 | switch (ctx->var) { |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 251 | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
| 252 | case MBEDTLS_ECDH_VARIANT_EVEREST: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 253 | mbedtls_everest_free(&ctx->ctx.everest_ecdh); |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 254 | break; |
| 255 | #endif |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 256 | case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 257 | ecdh_free_internal(&ctx->ctx.mbed_ecdh); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 258 | break; |
| 259 | default: |
| 260 | break; |
| 261 | } |
| 262 | |
| 263 | ctx->point_format = MBEDTLS_ECP_PF_UNCOMPRESSED; |
| 264 | ctx->var = MBEDTLS_ECDH_VARIANT_NONE; |
| 265 | ctx->grp_id = MBEDTLS_ECP_DP_NONE; |
| 266 | #endif |
| 267 | } |
| 268 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 269 | static int ecdh_make_params_internal(mbedtls_ecdh_context_mbed *ctx, |
| 270 | size_t *olen, int point_format, |
| 271 | unsigned char *buf, size_t blen, |
| 272 | int (*f_rng)(void *, |
| 273 | unsigned char *, |
| 274 | size_t), |
| 275 | void *p_rng, |
| 276 | int restart_enabled) |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 277 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 278 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 279 | size_t grp_len, pt_len; |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 280 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 281 | mbedtls_ecp_restart_ctx *rs_ctx = NULL; |
Ron Eldor | 936d284 | 2018-11-01 13:05:52 +0200 | [diff] [blame] | 282 | #endif |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 283 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 284 | if (ctx->grp.pbits == 0) { |
| 285 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 286 | } |
Manuel Pégourié-Gonnard | f35b739 | 2013-02-11 22:12:39 +0100 | [diff] [blame] | 287 | |
Ron Eldor | 19779c4 | 2018-11-05 16:58:13 +0200 | [diff] [blame] | 288 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 289 | if (restart_enabled) { |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 290 | rs_ctx = &ctx->rs; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 291 | } |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 292 | #else |
| 293 | (void) restart_enabled; |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 294 | #endif |
| 295 | |
Ron Eldor | 8493f80 | 2018-11-01 11:32:15 +0200 | [diff] [blame] | 296 | |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 297 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 298 | if ((ret = ecdh_gen_public_restartable(&ctx->grp, &ctx->d, &ctx->Q, |
| 299 | f_rng, p_rng, rs_ctx)) != 0) { |
| 300 | return ret; |
| 301 | } |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 302 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 303 | if ((ret = mbedtls_ecdh_gen_public(&ctx->grp, &ctx->d, &ctx->Q, |
| 304 | f_rng, p_rng)) != 0) { |
| 305 | return ret; |
| 306 | } |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 307 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 308 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 309 | if ((ret = mbedtls_ecp_tls_write_group(&ctx->grp, &grp_len, buf, |
| 310 | blen)) != 0) { |
| 311 | return ret; |
| 312 | } |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 313 | |
| 314 | buf += grp_len; |
| 315 | blen -= grp_len; |
| 316 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 317 | if ((ret = mbedtls_ecp_tls_write_point(&ctx->grp, &ctx->Q, point_format, |
| 318 | &pt_len, buf, blen)) != 0) { |
| 319 | return ret; |
| 320 | } |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 321 | |
| 322 | *olen = grp_len + pt_len; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 323 | return 0; |
Manuel Pégourié-Gonnard | 1372476 | 2013-02-10 15:01:54 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 326 | /* |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 327 | * Setup and write the ServerKeyExchange parameters (RFC 4492) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 328 | * struct { |
| 329 | * ECParameters curve_params; |
| 330 | * ECPoint public; |
| 331 | * } ServerECDHParams; |
| 332 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 333 | int mbedtls_ecdh_make_params(mbedtls_ecdh_context *ctx, size_t *olen, |
| 334 | unsigned char *buf, size_t blen, |
| 335 | int (*f_rng)(void *, unsigned char *, size_t), |
| 336 | void *p_rng) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 337 | { |
| 338 | int restart_enabled = 0; |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 339 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 340 | restart_enabled = ctx->restart_enabled; |
| 341 | #else |
| 342 | (void) restart_enabled; |
| 343 | #endif |
| 344 | |
| 345 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 346 | return ecdh_make_params_internal(ctx, olen, ctx->point_format, buf, blen, |
| 347 | f_rng, p_rng, restart_enabled); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 348 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 349 | switch (ctx->var) { |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 350 | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
| 351 | case MBEDTLS_ECDH_VARIANT_EVEREST: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 352 | return mbedtls_everest_make_params(&ctx->ctx.everest_ecdh, olen, |
| 353 | buf, blen, f_rng, p_rng); |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 354 | #endif |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 355 | case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 356 | return ecdh_make_params_internal(&ctx->ctx.mbed_ecdh, olen, |
| 357 | ctx->point_format, buf, blen, |
| 358 | f_rng, p_rng, |
| 359 | restart_enabled); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 360 | default: |
| 361 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 362 | } |
| 363 | #endif |
| 364 | } |
| 365 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 366 | static int ecdh_read_params_internal(mbedtls_ecdh_context_mbed *ctx, |
| 367 | const unsigned char **buf, |
| 368 | const unsigned char *end) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 369 | { |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 370 | return mbedtls_ecp_tls_read_point(&ctx->grp, &ctx->Qp, buf, |
Dave Rodgman | e4a6f5a | 2023-11-04 12:20:09 +0000 | [diff] [blame] | 371 | (size_t) (end - *buf)); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* |
bootstrap-prime | 6dbbf44 | 2022-05-17 19:30:44 -0400 | [diff] [blame] | 375 | * Read the ServerKeyExchange parameters (RFC 4492) |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 376 | * struct { |
| 377 | * ECParameters curve_params; |
| 378 | * ECPoint public; |
| 379 | * } ServerECDHParams; |
| 380 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 381 | int mbedtls_ecdh_read_params(mbedtls_ecdh_context *ctx, |
| 382 | const unsigned char **buf, |
| 383 | const unsigned char *end) |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 384 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 385 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Janos Follath | f61e486 | 2018-10-30 11:53:25 +0000 | [diff] [blame] | 386 | mbedtls_ecp_group_id grp_id; |
Dave Rodgman | e4a6f5a | 2023-11-04 12:20:09 +0000 | [diff] [blame] | 387 | if ((ret = mbedtls_ecp_tls_read_group_id(&grp_id, buf, (size_t) (end - *buf))) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 388 | != 0) { |
| 389 | return ret; |
| 390 | } |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 391 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 392 | if ((ret = mbedtls_ecdh_setup(ctx, grp_id)) != 0) { |
| 393 | return ret; |
| 394 | } |
Janos Follath | f61e486 | 2018-10-30 11:53:25 +0000 | [diff] [blame] | 395 | |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 396 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 397 | return ecdh_read_params_internal(ctx, buf, end); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 398 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 399 | switch (ctx->var) { |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 400 | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
| 401 | case MBEDTLS_ECDH_VARIANT_EVEREST: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 402 | return mbedtls_everest_read_params(&ctx->ctx.everest_ecdh, |
| 403 | buf, end); |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 404 | #endif |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 405 | case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 406 | return ecdh_read_params_internal(&ctx->ctx.mbed_ecdh, |
| 407 | buf, end); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 408 | default: |
| 409 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 410 | } |
| 411 | #endif |
Manuel Pégourié-Gonnard | 854fbd7 | 2013-02-11 20:28:55 +0100 | [diff] [blame] | 412 | } |
Manuel Pégourié-Gonnard | 0bad5c2 | 2013-01-26 15:30:46 +0100 | [diff] [blame] | 413 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 414 | static int ecdh_get_params_internal(mbedtls_ecdh_context_mbed *ctx, |
| 415 | const mbedtls_ecp_keypair *key, |
| 416 | mbedtls_ecdh_side side) |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 417 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 418 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 419 | |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 420 | /* If it's not our key, just import the public part as Qp */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 421 | if (side == MBEDTLS_ECDH_THEIRS) { |
| 422 | return mbedtls_ecp_copy(&ctx->Qp, &key->Q); |
| 423 | } |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 424 | |
| 425 | /* Our key: import public (as Q) and private parts */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 426 | if (side != MBEDTLS_ECDH_OURS) { |
| 427 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 428 | } |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 429 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 430 | if ((ret = mbedtls_ecp_copy(&ctx->Q, &key->Q)) != 0 || |
| 431 | (ret = mbedtls_mpi_copy(&ctx->d, &key->d)) != 0) { |
| 432 | return ret; |
| 433 | } |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 434 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 435 | return 0; |
Manuel Pégourié-Gonnard | cdff3cf | 2013-12-12 09:55:52 +0100 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /* |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 439 | * Get parameters from a keypair |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 440 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 441 | int mbedtls_ecdh_get_params(mbedtls_ecdh_context *ctx, |
| 442 | const mbedtls_ecp_keypair *key, |
| 443 | mbedtls_ecdh_side side) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 444 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 445 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 446 | if (side != MBEDTLS_ECDH_OURS && side != MBEDTLS_ECDH_THEIRS) { |
| 447 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 448 | } |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 449 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 450 | if (mbedtls_ecdh_grp_id(ctx) == MBEDTLS_ECP_DP_NONE) { |
Gilles Peskine | 0b1b71d | 2018-11-07 22:10:59 +0100 | [diff] [blame] | 451 | /* This is the first call to get_params(). Set up the context |
| 452 | * for use with the group. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 453 | if ((ret = mbedtls_ecdh_setup(ctx, key->grp.id)) != 0) { |
| 454 | return ret; |
| 455 | } |
| 456 | } else { |
Gilles Peskine | 0b1b71d | 2018-11-07 22:10:59 +0100 | [diff] [blame] | 457 | /* This is not the first call to get_params(). Check that the |
| 458 | * current key's group is the same as the context's, which was set |
| 459 | * from the first key's group. */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 460 | if (mbedtls_ecdh_grp_id(ctx) != key->grp.id) { |
| 461 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 462 | } |
Gilles Peskine | 0b1b71d | 2018-11-07 22:10:59 +0100 | [diff] [blame] | 463 | } |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 464 | |
| 465 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 466 | return ecdh_get_params_internal(ctx, key, side); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 467 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 468 | switch (ctx->var) { |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 469 | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
| 470 | case MBEDTLS_ECDH_VARIANT_EVEREST: |
Christoph M. Wintersteiger | 4936beb | 2018-12-12 17:26:41 +0000 | [diff] [blame] | 471 | { |
Christoph M. Wintersteiger | 2e724a1 | 2019-01-07 14:19:41 +0000 | [diff] [blame] | 472 | mbedtls_everest_ecdh_side s = side == MBEDTLS_ECDH_OURS ? |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 473 | MBEDTLS_EVEREST_ECDH_OURS : |
| 474 | MBEDTLS_EVEREST_ECDH_THEIRS; |
| 475 | return mbedtls_everest_get_params(&ctx->ctx.everest_ecdh, |
| 476 | key, s); |
Christoph M. Wintersteiger | 4936beb | 2018-12-12 17:26:41 +0000 | [diff] [blame] | 477 | } |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 478 | #endif |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 479 | case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 480 | return ecdh_get_params_internal(&ctx->ctx.mbed_ecdh, |
| 481 | key, side); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 482 | default: |
| 483 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 484 | } |
| 485 | #endif |
| 486 | } |
| 487 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 488 | static int ecdh_make_public_internal(mbedtls_ecdh_context_mbed *ctx, |
| 489 | size_t *olen, int point_format, |
| 490 | unsigned char *buf, size_t blen, |
| 491 | int (*f_rng)(void *, |
| 492 | unsigned char *, |
| 493 | size_t), |
| 494 | void *p_rng, |
| 495 | int restart_enabled) |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 496 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 497 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 498 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 499 | mbedtls_ecp_restart_ctx *rs_ctx = NULL; |
Ron Eldor | 936d284 | 2018-11-01 13:05:52 +0200 | [diff] [blame] | 500 | #endif |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 501 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 502 | if (ctx->grp.pbits == 0) { |
| 503 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 504 | } |
Manuel Pégourié-Gonnard | f35b739 | 2013-02-11 22:12:39 +0100 | [diff] [blame] | 505 | |
Ron Eldor | b430d9f | 2018-11-05 17:18:29 +0200 | [diff] [blame] | 506 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 507 | if (restart_enabled) { |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 508 | rs_ctx = &ctx->rs; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 509 | } |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 510 | #else |
| 511 | (void) restart_enabled; |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 512 | #endif |
| 513 | |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 514 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 515 | if ((ret = ecdh_gen_public_restartable(&ctx->grp, &ctx->d, &ctx->Q, |
| 516 | f_rng, p_rng, rs_ctx)) != 0) { |
| 517 | return ret; |
| 518 | } |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 519 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 520 | if ((ret = mbedtls_ecdh_gen_public(&ctx->grp, &ctx->d, &ctx->Q, |
| 521 | f_rng, p_rng)) != 0) { |
| 522 | return ret; |
| 523 | } |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 524 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 525 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 526 | return mbedtls_ecp_tls_write_point(&ctx->grp, &ctx->Q, point_format, olen, |
| 527 | buf, blen); |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | /* |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 531 | * Setup and export the client public value |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 532 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 533 | int mbedtls_ecdh_make_public(mbedtls_ecdh_context *ctx, size_t *olen, |
| 534 | unsigned char *buf, size_t blen, |
| 535 | int (*f_rng)(void *, unsigned char *, size_t), |
| 536 | void *p_rng) |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 537 | { |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 538 | int restart_enabled = 0; |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 539 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 540 | restart_enabled = ctx->restart_enabled; |
| 541 | #endif |
| 542 | |
| 543 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 544 | return ecdh_make_public_internal(ctx, olen, ctx->point_format, buf, blen, |
| 545 | f_rng, p_rng, restart_enabled); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 546 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 547 | switch (ctx->var) { |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 548 | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
| 549 | case MBEDTLS_ECDH_VARIANT_EVEREST: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 550 | return mbedtls_everest_make_public(&ctx->ctx.everest_ecdh, olen, |
| 551 | buf, blen, f_rng, p_rng); |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 552 | #endif |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 553 | case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 554 | return ecdh_make_public_internal(&ctx->ctx.mbed_ecdh, olen, |
| 555 | ctx->point_format, buf, blen, |
| 556 | f_rng, p_rng, |
| 557 | restart_enabled); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 558 | default: |
| 559 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 560 | } |
| 561 | #endif |
| 562 | } |
| 563 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 564 | static int ecdh_read_public_internal(mbedtls_ecdh_context_mbed *ctx, |
| 565 | const unsigned char *buf, size_t blen) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 566 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 567 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 568 | const unsigned char *p = buf; |
| 569 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 570 | if ((ret = mbedtls_ecp_tls_read_point(&ctx->grp, &ctx->Qp, &p, |
| 571 | blen)) != 0) { |
| 572 | return ret; |
| 573 | } |
Manuel Pégourié-Gonnard | 969ccc6 | 2014-03-26 19:53:25 +0100 | [diff] [blame] | 574 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 575 | if ((size_t) (p - buf) != blen) { |
| 576 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 577 | } |
Manuel Pégourié-Gonnard | 969ccc6 | 2014-03-26 19:53:25 +0100 | [diff] [blame] | 578 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 579 | return 0; |
Manuel Pégourié-Gonnard | 5cceb41 | 2013-02-11 21:51:45 +0100 | [diff] [blame] | 580 | } |
| 581 | |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 582 | /* |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 583 | * Parse and import the client's public value |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 584 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 585 | int mbedtls_ecdh_read_public(mbedtls_ecdh_context *ctx, |
| 586 | const unsigned char *buf, size_t blen) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 587 | { |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 588 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 589 | return ecdh_read_public_internal(ctx, buf, blen); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 590 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 591 | switch (ctx->var) { |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 592 | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
| 593 | case MBEDTLS_ECDH_VARIANT_EVEREST: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 594 | return mbedtls_everest_read_public(&ctx->ctx.everest_ecdh, |
| 595 | buf, blen); |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 596 | #endif |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 597 | case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 598 | return ecdh_read_public_internal(&ctx->ctx.mbed_ecdh, |
| 599 | buf, blen); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 600 | default: |
| 601 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 602 | } |
| 603 | #endif |
| 604 | } |
| 605 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 606 | static int ecdh_calc_secret_internal(mbedtls_ecdh_context_mbed *ctx, |
| 607 | size_t *olen, unsigned char *buf, |
| 608 | size_t blen, |
| 609 | int (*f_rng)(void *, |
| 610 | unsigned char *, |
| 611 | size_t), |
| 612 | void *p_rng, |
| 613 | int restart_enabled) |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 614 | { |
Janos Follath | 24eed8d | 2019-11-22 13:21:35 +0000 | [diff] [blame] | 615 | int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 616 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 617 | mbedtls_ecp_restart_ctx *rs_ctx = NULL; |
Ron Eldor | 936d284 | 2018-11-01 13:05:52 +0200 | [diff] [blame] | 618 | #endif |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 619 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 620 | if (ctx == NULL || ctx->grp.pbits == 0) { |
| 621 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 622 | } |
Manuel Pégourié-Gonnard | f35b739 | 2013-02-11 22:12:39 +0100 | [diff] [blame] | 623 | |
Ron Eldor | b430d9f | 2018-11-05 17:18:29 +0200 | [diff] [blame] | 624 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 625 | if (restart_enabled) { |
Manuel Pégourié-Gonnard | 23e4162 | 2017-05-18 12:35:37 +0200 | [diff] [blame] | 626 | rs_ctx = &ctx->rs; |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 627 | } |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 628 | #else |
| 629 | (void) restart_enabled; |
Manuel Pégourié-Gonnard | 66ba48a | 2017-04-27 11:38:26 +0200 | [diff] [blame] | 630 | #endif |
| 631 | |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 632 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 633 | if ((ret = ecdh_compute_shared_restartable(&ctx->grp, &ctx->z, &ctx->Qp, |
| 634 | &ctx->d, f_rng, p_rng, |
| 635 | rs_ctx)) != 0) { |
| 636 | return ret; |
Manuel Pégourié-Gonnard | e09d2f8 | 2013-09-02 14:29:09 +0200 | [diff] [blame] | 637 | } |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 638 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 639 | if ((ret = mbedtls_ecdh_compute_shared(&ctx->grp, &ctx->z, &ctx->Qp, |
| 640 | &ctx->d, f_rng, p_rng)) != 0) { |
| 641 | return ret; |
Ron Eldor | 2981d8f | 2018-11-05 18:07:10 +0200 | [diff] [blame] | 642 | } |
| 643 | #endif /* MBEDTLS_ECP_RESTARTABLE */ |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 644 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 645 | if (mbedtls_mpi_size(&ctx->z) > blen) { |
| 646 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
| 647 | } |
Paul Bakker | 41c83d3 | 2013-03-20 14:39:14 +0100 | [diff] [blame] | 648 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 649 | *olen = ctx->grp.pbits / 8 + ((ctx->grp.pbits % 8) != 0); |
Janos Follath | ab0f71a | 2019-02-20 10:48:49 +0000 | [diff] [blame] | 650 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 651 | if (mbedtls_ecp_get_type(&ctx->grp) == MBEDTLS_ECP_TYPE_MONTGOMERY) { |
| 652 | return mbedtls_mpi_write_binary_le(&ctx->z, buf, *olen); |
| 653 | } |
Janos Follath | ab0f71a | 2019-02-20 10:48:49 +0000 | [diff] [blame] | 654 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 655 | return mbedtls_mpi_write_binary(&ctx->z, buf, *olen); |
Manuel Pégourié-Gonnard | 424fda5 | 2013-02-11 22:05:42 +0100 | [diff] [blame] | 656 | } |
| 657 | |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 658 | /* |
| 659 | * Derive and export the shared secret |
| 660 | */ |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 661 | int mbedtls_ecdh_calc_secret(mbedtls_ecdh_context *ctx, size_t *olen, |
| 662 | unsigned char *buf, size_t blen, |
| 663 | int (*f_rng)(void *, unsigned char *, size_t), |
| 664 | void *p_rng) |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 665 | { |
| 666 | int restart_enabled = 0; |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 667 | #if defined(MBEDTLS_ECP_RESTARTABLE) |
| 668 | restart_enabled = ctx->restart_enabled; |
| 669 | #endif |
| 670 | |
| 671 | #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 672 | return ecdh_calc_secret_internal(ctx, olen, buf, blen, f_rng, p_rng, |
| 673 | restart_enabled); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 674 | #else |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 675 | switch (ctx->var) { |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 676 | #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED) |
| 677 | case MBEDTLS_ECDH_VARIANT_EVEREST: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 678 | return mbedtls_everest_calc_secret(&ctx->ctx.everest_ecdh, olen, |
| 679 | buf, blen, f_rng, p_rng); |
Christoph M. Wintersteiger | c9f737b | 2018-10-25 13:03:05 +0100 | [diff] [blame] | 680 | #endif |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 681 | case MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 682 | return ecdh_calc_secret_internal(&ctx->ctx.mbed_ecdh, olen, buf, |
| 683 | blen, f_rng, p_rng, |
| 684 | restart_enabled); |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 685 | default: |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 686 | return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; |
Janos Follath | 5a3e1bf | 2018-08-13 15:54:22 +0100 | [diff] [blame] | 687 | } |
| 688 | #endif |
| 689 | } |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 690 | #endif /* MBEDTLS_ECDH_C */ |