mbed TLS v2.23.0: ecdh.h Source File

mbed TLS v2.23.0

ecdh.h
Go to the documentation of this file.
1
15 /*
16 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
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 * This file is part of Mbed TLS (https://tls.mbed.org)
32 */
33
34 #ifndef MBEDTLS_ECDH_H
35 #define MBEDTLS_ECDH_H
36
37 #if !defined(MBEDTLS_CONFIG_FILE)
38 #include "mbedtls/config.h"
39 #else
40 #include MBEDTLS_CONFIG_FILE
41 #endif
42
43 #include "mbedtls/ecp.h"
44
45 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
46 #undef MBEDTLS_ECDH_LEGACY_CONTEXT
47 #include "everest/everest.h"
48 #endif
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
57 typedef enum
58 {
59 MBEDTLS_ECDH_OURS,
60 MBEDTLS_ECDH_THEIRS,
61 } mbedtls_ecdh_side;
62
63 #if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
64
70 typedef enum
71 {
72 MBEDTLS_ECDH_VARIANT_NONE = 0,
73 MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,
74 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
75 MBEDTLS_ECDH_VARIANT_EVEREST
76 #endif
77 } mbedtls_ecdh_variant;
78
86 typedef struct mbedtls_ecdh_context_mbed
87 {
88 mbedtls_ecp_group grp;
89 mbedtls_mpi d;
90 mbedtls_ecp_point Q;
91 mbedtls_ecp_point Qp;
92 mbedtls_mpi z;
93 #if defined(MBEDTLS_ECP_RESTARTABLE)
94 mbedtls_ecp_restart_ctx rs;
95 #endif
96 } mbedtls_ecdh_context_mbed;
97 #endif
98
106 typedef struct mbedtls_ecdh_context
107 {
108 #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
109 mbedtls_ecp_group grp;
110 mbedtls_mpi d;
111 mbedtls_ecp_point Q;
112 mbedtls_ecp_point Qp;
113 mbedtls_mpi z;
114 int point_format;
115 mbedtls_ecp_point Vi;
116 mbedtls_ecp_point Vf;
117 mbedtls_mpi _d;
118 #if defined(MBEDTLS_ECP_RESTARTABLE)
119 int restart_enabled;
120 mbedtls_ecp_restart_ctx rs;
121 #endif /* MBEDTLS_ECP_RESTARTABLE */
122 #else
123 uint8_t point_format;
125 mbedtls_ecp_group_id grp_id;
126 mbedtls_ecdh_variant var;
127 union
128 {
129 mbedtls_ecdh_context_mbed mbed_ecdh;
130 #if defined(MBEDTLS_ECDH_VARIANT_EVEREST_ENABLED)
131 mbedtls_ecdh_context_everest everest_ecdh;
132 #endif
133 } ctx;
136 #if defined(MBEDTLS_ECP_RESTARTABLE)
137 uint8_t restart_enabled;
142 #endif /* MBEDTLS_ECP_RESTARTABLE */
143 #endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
144 }
145 mbedtls_ecdh_context;
146
154 int mbedtls_ecdh_can_do( mbedtls_ecp_group_id gid );
155
181 int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
182 int (*f_rng)(void *, unsigned char *, size_t),
183 void *p_rng );
184
219 int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
220 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
221 int (*f_rng)(void *, unsigned char *, size_t),
222 void *p_rng );
223
229 void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
230
247 int mbedtls_ecdh_setup( mbedtls_ecdh_context *ctx,
248 mbedtls_ecp_group_id grp_id );
249
257 void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
258
284 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
285 unsigned char *buf, size_t blen,
286 int (*f_rng)(void *, unsigned char *, size_t),
287 void *p_rng );
288
313 int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
314 const unsigned char **buf,
315 const unsigned char *end );
316
336 int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx,
337 const mbedtls_ecp_keypair *key,
338 mbedtls_ecdh_side side );
339
366 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
367 unsigned char *buf, size_t blen,
368 int (*f_rng)(void *, unsigned char *, size_t),
369 void *p_rng );
370
390 int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
391 const unsigned char *buf, size_t blen );
392
423 int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
424 unsigned char *buf, size_t blen,
425 int (*f_rng)(void *, unsigned char *, size_t),
426 void *p_rng );
427
428 #if defined(MBEDTLS_ECP_RESTARTABLE)
429
441 void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx );
442 #endif /* MBEDTLS_ECP_RESTARTABLE */
443
444 #ifdef __cplusplus
445 }
446 #endif
447
448 #endif /* ecdh.h */
mbedtls_ecdh_context::z
mbedtls_mpi z
Definition: ecdh.h:113
mbedtls_ecp_group
The ECP group structure.
Definition: ecp.h:184
ecp.h
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbedtls_ecdh_calc_secret
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.
mbedtls_ecdh_context::d
mbedtls_mpi d
Definition: ecdh.h:110
mbedtls_mpi
MPI structure.
Definition: bignum.h:187
mbedtls_ecdh_init
void mbedtls_ecdh_init(mbedtls_ecdh_context *ctx)
This function initializes an ECDH context.
mbedtls_ecdh_make_params
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 ...
mbedtls_ecdh_context
The ECDH context structure.
Definition: ecdh.h:107
mbedtls_ecdh_context::_d
mbedtls_mpi _d
Definition: ecdh.h:117
mbedtls_ecp_restart_ctx
void mbedtls_ecp_restart_ctx
Definition: ecp.h:330
mbedtls_ecdh_context
struct mbedtls_ecdh_context mbedtls_ecdh_context
The ECDH context structure.
mbedtls_ecdh_context::Vi
mbedtls_ecp_point Vi
Definition: ecdh.h:115
mbedtls_ecdh_context::grp
mbedtls_ecp_group grp
Definition: ecdh.h:109
mbedtls_ecp_keypair
The ECP key-pair structure.
Definition: ecp.h:343
mbedtls_ecp_group_id
mbedtls_ecp_group_id
Definition: ecp.h:78
mbedtls_ecdh_context::point_format
int point_format
Definition: ecdh.h:114
mbedtls_ecdh_context::Qp
mbedtls_ecp_point Qp
Definition: ecdh.h:112
mbedtls_ecdh_context::Q
mbedtls_ecp_point Q
Definition: ecdh.h:111
mbedtls_ecdh_gen_public
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.
mbedtls_ecdh_free
void mbedtls_ecdh_free(mbedtls_ecdh_context *ctx)
This function frees a context.
mbedtls_ecdh_side
mbedtls_ecdh_side
Definition: ecdh.h:58
MBEDTLS_ECDH_THEIRS
@ MBEDTLS_ECDH_THEIRS
Definition: ecdh.h:60
mbedtls_ecdh_context::Vf
mbedtls_ecp_point Vf
Definition: ecdh.h:116
mbedtls_ecdh_read_public
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.
mbedtls_ecdh_make_public
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.
config.h
Configuration options (set of defines)
mbedtls_ecdh_compute_shared
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_can_do
int mbedtls_ecdh_can_do(mbedtls_ecp_group_id gid)
Check whether a given group can be used for ECDH.
mbedtls_ecp_point
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:135
MBEDTLS_ECDH_OURS
@ MBEDTLS_ECDH_OURS
Definition: ecdh.h:59
mbedtls_ecdh_read_params
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.
mbedtls_ecdh_get_params
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_setup
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.