Mbed TLS v3.6.0
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 OR GPL-2.0-or-later
18 */
19
20#ifndef MBEDTLS_ECDH_H
21#define MBEDTLS_ECDH_H
23
24#include "mbedtls/build_info.h"
25
26#include "mbedtls/ecp.h"
27
28/*
29 * Mbed TLS supports two formats for ECDH contexts (#mbedtls_ecdh_context
30 * defined in `ecdh.h`). For most applications, the choice of format makes
31 * no difference, since all library functions can work with either format,
32 * except that the new format is incompatible with MBEDTLS_ECP_RESTARTABLE.
33
34 * The new format used when this option is disabled is smaller
35 * (56 bytes on a 32-bit platform). In future versions of the library, it
36 * will support alternative implementations of ECDH operations.
37 * The new format is incompatible with applications that access
38 * context fields directly and with restartable ECP operations.
39 */
40
41#if defined(MBEDTLS_ECP_RESTARTABLE)
42#define MBEDTLS_ECDH_LEGACY_CONTEXT
43#else
44#undef MBEDTLS_ECDH_LEGACY_CONTEXT
45#endif
46
47#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
48#undef MBEDTLS_ECDH_LEGACY_CONTEXT
49#include "everest/everest.h"
50#endif
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55
59typedef enum {
63
64#if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
71typedef enum {
74#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
75 MBEDTLS_ECDH_VARIANT_EVEREST
76#endif
78
92#if defined(MBEDTLS_ECP_RESTARTABLE)
94#endif
96#endif
97
105typedef struct mbedtls_ecdh_context {
106#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
112 int MBEDTLS_PRIVATE(point_format);
116#if defined(MBEDTLS_ECP_RESTARTABLE)
117 int MBEDTLS_PRIVATE(restart_enabled);
119#endif /* MBEDTLS_ECP_RESTARTABLE */
120#else
121 uint8_t MBEDTLS_PRIVATE(point_format);
125 union {
127#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
128 mbedtls_ecdh_context_everest MBEDTLS_PRIVATE(everest_ecdh);
129#endif
130 } MBEDTLS_PRIVATE(ctx);
133#if defined(MBEDTLS_ECP_RESTARTABLE)
134 uint8_t MBEDTLS_PRIVATE(restart_enabled);
139#endif /* MBEDTLS_ECP_RESTARTABLE */
140#endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
141}
143
156
165
192 int (*f_rng)(void *, unsigned char *, size_t),
193 void *p_rng);
194
227 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
228 int (*f_rng)(void *, unsigned char *, size_t),
229 void *p_rng);
230
237
255 mbedtls_ecp_group_id grp_id);
256
265
292 unsigned char *buf, size_t blen,
293 int (*f_rng)(void *, unsigned char *, size_t),
294 void *p_rng);
295
321 const unsigned char **buf,
322 const unsigned char *end);
323
344 const mbedtls_ecp_keypair *key,
345 mbedtls_ecdh_side side);
346
374 unsigned char *buf, size_t blen,
375 int (*f_rng)(void *, unsigned char *, size_t),
376 void *p_rng);
377
398 const unsigned char *buf, size_t blen);
399
430 unsigned char *buf, size_t blen,
431 int (*f_rng)(void *, unsigned char *, size_t),
432 void *p_rng);
433
434#if defined(MBEDTLS_ECP_RESTARTABLE)
447void mbedtls_ecdh_enable_restart(mbedtls_ecdh_context *ctx);
448#endif /* MBEDTLS_ECP_RESTARTABLE */
449
450#ifdef __cplusplus
451}
452#endif
453
454#endif /* ecdh.h */
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.
mbedtls_ecdh_variant
Definition ecdh.h:71
@ MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0
Definition ecdh.h:73
@ MBEDTLS_ECDH_VARIANT_NONE
Definition ecdh.h:72
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.
mbedtls_ecp_group_id mbedtls_ecdh_get_grp_id(mbedtls_ecdh_context *ctx)
Return the ECP group for provided 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:59
@ MBEDTLS_ECDH_OURS
Definition ecdh.h:60
@ MBEDTLS_ECDH_THEIRS
Definition ecdh.h:61
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:416
mbedtls_ecp_group_id
Definition ecp.h:102
Build-time configuration info.
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
The ECDH context structure.
Definition ecdh.h:105
The ECP group structure.
Definition ecp.h:233
The ECP key-pair structure.
Definition ecp.h:428
The ECP point structure, in Jacobian coordinates.
Definition ecp.h:158
MPI structure.
Definition bignum.h:207