mbed TLS v2.28.2
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
56{
60
61#if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
68typedef enum
69{
70 MBEDTLS_ECDH_VARIANT_NONE = 0,
71 MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,
72#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
73 MBEDTLS_ECDH_VARIANT_EVEREST
74#endif
75} mbedtls_ecdh_variant;
76
84typedef struct mbedtls_ecdh_context_mbed
85{
87 mbedtls_mpi d;
90 mbedtls_mpi z;
91#if defined(MBEDTLS_ECP_RESTARTABLE)
93#endif
94} mbedtls_ecdh_context_mbed;
95#endif
96
105{
106#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
116#if defined(MBEDTLS_ECP_RESTARTABLE)
117 int restart_enabled;
119#endif /* MBEDTLS_ECP_RESTARTABLE */
120#else
121 uint8_t point_format;
124 mbedtls_ecdh_variant var;
125 union
126 {
127 mbedtls_ecdh_context_mbed mbed_ecdh;
128#if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
129 mbedtls_ecdh_context_everest everest_ecdh;
130#endif
131 } ctx;
134#if defined(MBEDTLS_ECP_RESTARTABLE)
135 uint8_t restart_enabled;
140#endif /* MBEDTLS_ECP_RESTARTABLE */
141#endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
142}
144
153
180 int (*f_rng)(void *, unsigned char *, size_t),
181 void *p_rng );
182
218 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
219 int (*f_rng)(void *, unsigned char *, size_t),
220 void *p_rng );
221
228
246 mbedtls_ecp_group_id grp_id );
247
256
283 unsigned char *buf, size_t blen,
284 int (*f_rng)(void *, unsigned char *, size_t),
285 void *p_rng );
286
312 const unsigned char **buf,
313 const unsigned char *end );
314
335 const mbedtls_ecp_keypair *key,
336 mbedtls_ecdh_side side );
337
365 unsigned char *buf, size_t blen,
366 int (*f_rng)(void *, unsigned char *, size_t),
367 void *p_rng );
368
389 const unsigned char *buf, size_t blen );
390
422 unsigned char *buf, size_t blen,
423 int (*f_rng)(void *, unsigned char *, size_t),
424 void *p_rng );
425
426#if defined(MBEDTLS_ECP_RESTARTABLE)
439void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx );
440#endif /* MBEDTLS_ECP_RESTARTABLE */
441
442#ifdef __cplusplus
443}
444#endif
445
446#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:56
@ MBEDTLS_ECDH_OURS
Definition: ecdh.h:57
@ MBEDTLS_ECDH_THEIRS
Definition: ecdh.h:58
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:420
mbedtls_ecp_group_id
Definition: ecp.h:121
The ECDH context structure.
Definition: ecdh.h:105
mbedtls_mpi d
Definition: ecdh.h:108
mbedtls_ecp_point Vf
Definition: ecdh.h:114
mbedtls_ecp_point Qp
Definition: ecdh.h:110
mbedtls_ecp_point Vi
Definition: ecdh.h:113
mbedtls_ecp_group grp
Definition: ecdh.h:107
mbedtls_mpi z
Definition: ecdh.h:111
mbedtls_ecp_point Q
Definition: ecdh.h:109
mbedtls_mpi _d
Definition: ecdh.h:115
The ECP group structure.
Definition: ecp.h:261
The ECP key-pair structure.
Definition: ecp.h:433
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:178
MPI structure.
Definition: bignum.h:207