Mbed TLS v2.28.7
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
22 
23 #if !defined(MBEDTLS_CONFIG_FILE)
24 #include "mbedtls/config.h"
25 #else
26 #include MBEDTLS_CONFIG_FILE
27 #endif
28 
29 #include "mbedtls/ecp.h"
30 
31 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
32 #undef MBEDTLS_ECDH_LEGACY_CONTEXT
33 #include "everest/everest.h"
34 #endif
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
43 typedef enum {
47 
48 #if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
55 typedef enum {
56  MBEDTLS_ECDH_VARIANT_NONE = 0,
57  MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,
58 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
59  MBEDTLS_ECDH_VARIANT_EVEREST
60 #endif
61 } mbedtls_ecdh_variant;
62 
70 typedef struct mbedtls_ecdh_context_mbed {
71  mbedtls_ecp_group grp;
72  mbedtls_mpi d;
75  mbedtls_mpi z;
76 #if defined(MBEDTLS_ECP_RESTARTABLE)
78 #endif
79 } mbedtls_ecdh_context_mbed;
80 #endif
81 
89 typedef struct mbedtls_ecdh_context {
90 #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
100 #if defined(MBEDTLS_ECP_RESTARTABLE)
101  int restart_enabled;
103 #endif /* MBEDTLS_ECP_RESTARTABLE */
104 #else
105  uint8_t point_format;
107  mbedtls_ecp_group_id grp_id;
108  mbedtls_ecdh_variant var;
109  union {
110  mbedtls_ecdh_context_mbed mbed_ecdh;
111 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
112  mbedtls_ecdh_context_everest everest_ecdh;
113 #endif
114  } ctx;
117 #if defined(MBEDTLS_ECP_RESTARTABLE)
118  uint8_t restart_enabled;
123 #endif /* MBEDTLS_ECP_RESTARTABLE */
124 #endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
125 }
127 
136 
163  int (*f_rng)(void *, unsigned char *, size_t),
164  void *p_rng);
165 
201  const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
202  int (*f_rng)(void *, unsigned char *, size_t),
203  void *p_rng);
204 
211 
229  mbedtls_ecp_group_id grp_id);
230 
239 
266  unsigned char *buf, size_t blen,
267  int (*f_rng)(void *, unsigned char *, size_t),
268  void *p_rng);
269 
295  const unsigned char **buf,
296  const unsigned char *end);
297 
318  const mbedtls_ecp_keypair *key,
319  mbedtls_ecdh_side side);
320 
348  unsigned char *buf, size_t blen,
349  int (*f_rng)(void *, unsigned char *, size_t),
350  void *p_rng);
351 
372  const unsigned char *buf, size_t blen);
373 
405  unsigned char *buf, size_t blen,
406  int (*f_rng)(void *, unsigned char *, size_t),
407  void *p_rng);
408 
409 #if defined(MBEDTLS_ECP_RESTARTABLE)
422 void mbedtls_ecdh_enable_restart(mbedtls_ecdh_context *ctx);
423 #endif /* MBEDTLS_ECP_RESTARTABLE */
424 
425 #ifdef __cplusplus
426 }
427 #endif
428 
429 #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.
struct mbedtls_ecdh_context mbedtls_ecdh_context
The ECDH context structure.
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:43
@ MBEDTLS_ECDH_OURS
Definition: ecdh.h:44
@ MBEDTLS_ECDH_THEIRS
Definition: ecdh.h:45
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:431
mbedtls_ecp_group_id
Definition: ecp.h:113
The ECDH context structure.
Definition: ecdh.h:89
mbedtls_mpi d
Definition: ecdh.h:92
mbedtls_ecp_point Vf
Definition: ecdh.h:98
mbedtls_ecp_point Qp
Definition: ecdh.h:94
mbedtls_ecp_point Vi
Definition: ecdh.h:97
mbedtls_ecp_group grp
Definition: ecdh.h:91
mbedtls_mpi z
Definition: ecdh.h:95
mbedtls_ecp_point Q
Definition: ecdh.h:93
mbedtls_mpi _d
Definition: ecdh.h:99
The ECP group structure.
Definition: ecp.h:270
The ECP key-pair structure.
Definition: ecp.h:443
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:167
MPI structure.
Definition: bignum.h:196