mbed TLS v2.28.4
Loading...
Searching...
No Matches
ecdh.h
Go to the documentation of this file.
1
15/*
16 * Copyright The Mbed TLS Contributors
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.
30 */
31
32#ifndef MBEDTLS_ECDH_H
33#define MBEDTLS_ECDH_H
34
35#if !defined(MBEDTLS_CONFIG_FILE)
36#include "mbedtls/config.h"
37#else
38#include MBEDTLS_CONFIG_FILE
39#endif
40
41#include "mbedtls/ecp.h"
42
43#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
44#undef MBEDTLS_ECDH_LEGACY_CONTEXT
45#include "everest/everest.h"
46#endif
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
55typedef enum {
59
60#if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
67typedef enum {
68 MBEDTLS_ECDH_VARIANT_NONE = 0,
69 MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,
70#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
71 MBEDTLS_ECDH_VARIANT_EVEREST
72#endif
73} mbedtls_ecdh_variant;
74
82typedef struct mbedtls_ecdh_context_mbed {
84 mbedtls_mpi d;
87 mbedtls_mpi z;
88#if defined(MBEDTLS_ECP_RESTARTABLE)
90#endif
91} mbedtls_ecdh_context_mbed;
92#endif
93
101typedef struct mbedtls_ecdh_context {
102#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
112#if defined(MBEDTLS_ECP_RESTARTABLE)
113 int restart_enabled;
115#endif /* MBEDTLS_ECP_RESTARTABLE */
116#else
117 uint8_t point_format;
120 mbedtls_ecdh_variant var;
121 union {
122 mbedtls_ecdh_context_mbed mbed_ecdh;
123#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
124 mbedtls_ecdh_context_everest everest_ecdh;
125#endif
126 } ctx;
129#if defined(MBEDTLS_ECP_RESTARTABLE)
130 uint8_t restart_enabled;
135#endif /* MBEDTLS_ECP_RESTARTABLE */
136#endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
137}
139
148
175 int (*f_rng)(void *, unsigned char *, size_t),
176 void *p_rng);
177
213 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
214 int (*f_rng)(void *, unsigned char *, size_t),
215 void *p_rng);
216
223
241 mbedtls_ecp_group_id grp_id);
242
251
278 unsigned char *buf, size_t blen,
279 int (*f_rng)(void *, unsigned char *, size_t),
280 void *p_rng);
281
307 const unsigned char **buf,
308 const unsigned char *end);
309
330 const mbedtls_ecp_keypair *key,
331 mbedtls_ecdh_side side);
332
360 unsigned char *buf, size_t blen,
361 int (*f_rng)(void *, unsigned char *, size_t),
362 void *p_rng);
363
384 const unsigned char *buf, size_t blen);
385
417 unsigned char *buf, size_t blen,
418 int (*f_rng)(void *, unsigned char *, size_t),
419 void *p_rng);
420
421#if defined(MBEDTLS_ECP_RESTARTABLE)
434void mbedtls_ecdh_enable_restart(mbedtls_ecdh_context *ctx);
435#endif /* MBEDTLS_ECP_RESTARTABLE */
436
437#ifdef __cplusplus
438}
439#endif
440
441#endif /* ecdh.h */
Configuration options (set of defines)
int mbedtls_ecdh_setup(mbedtls_ecdh_context *ctx, mbedtls_ecp_group_id grp_id)
This function sets up the ECDH context with the information given.
int mbedtls_ecdh_get_params(mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key, mbedtls_ecdh_side side)
This function sets up an ECDH context from an EC key.
int mbedtls_ecdh_gen_public(mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates an ECDH keypair on an elliptic curve.
int mbedtls_ecdh_make_public(mbedtls_ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates a public key and exports it as a TLS ClientKeyExchange payload.
int mbedtls_ecdh_calc_secret(mbedtls_ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function derives and exports the shared secret.
int mbedtls_ecdh_can_do(mbedtls_ecp_group_id gid)
Check whether a given group can be used for ECDH.
int mbedtls_ecdh_make_params(mbedtls_ecdh_context *ctx, size_t *olen, unsigned char *buf, size_t blen, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function generates an EC key pair and exports its in the format used in a TLS ServerKeyExchange ...
void mbedtls_ecdh_free(mbedtls_ecdh_context *ctx)
This function frees a context.
void mbedtls_ecdh_init(mbedtls_ecdh_context *ctx)
This function initializes an ECDH context.
int mbedtls_ecdh_read_public(mbedtls_ecdh_context *ctx, const unsigned char *buf, size_t blen)
This function parses and processes the ECDHE payload of a TLS ClientKeyExchange message.
int mbedtls_ecdh_compute_shared(mbedtls_ecp_group *grp, mbedtls_mpi *z, const mbedtls_ecp_point *Q, const mbedtls_mpi *d, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
This function computes the shared secret.
mbedtls_ecdh_side
Definition ecdh.h:55
@ MBEDTLS_ECDH_OURS
Definition ecdh.h:56
@ MBEDTLS_ECDH_THEIRS
Definition ecdh.h:57
int mbedtls_ecdh_read_params(mbedtls_ecdh_context *ctx, const unsigned char **buf, const unsigned char *end)
This function parses the ECDHE parameters in a TLS ServerKeyExchange handshake message.
This file provides an API for Elliptic Curves over GF(P) (ECP).
void mbedtls_ecp_restart_ctx
Definition ecp.h:414
mbedtls_ecp_group_id
Definition ecp.h:120
The ECDH context structure.
Definition ecdh.h:101
mbedtls_mpi d
Definition ecdh.h:104
mbedtls_ecp_point Vf
Definition ecdh.h:110
mbedtls_ecp_point Qp
Definition ecdh.h:106
mbedtls_ecp_point Vi
Definition ecdh.h:109
mbedtls_ecp_group grp
Definition ecdh.h:103
mbedtls_mpi z
Definition ecdh.h:107
mbedtls_ecp_point Q
Definition ecdh.h:105
mbedtls_mpi _d
Definition ecdh.h:111
The ECP group structure.
Definition ecp.h:256
The ECP key-pair structure.
Definition ecp.h:426
The ECP point structure, in Jacobian coordinates.
Definition ecp.h:174
MPI structure.
Definition bignum.h:208