mbed TLS v2.14.1

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 #include "ecp.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
46 typedef enum
47 {
48 MBEDTLS_ECDH_OURS,
49 MBEDTLS_ECDH_THEIRS,
50 } mbedtls_ecdh_side;
51
59 typedef struct mbedtls_ecdh_context
60 {
61 mbedtls_ecp_group grp;
62 mbedtls_mpi d;
63 mbedtls_ecp_point Q;
64 mbedtls_ecp_point Qp;
65 mbedtls_mpi z;
66 int point_format;
67 mbedtls_ecp_point Vi;
68 mbedtls_ecp_point Vf;
69 mbedtls_mpi _d;
70 #if defined(MBEDTLS_ECP_RESTARTABLE)
71 int restart_enabled;
72 mbedtls_ecp_restart_ctx rs;
73 #endif
74 }
75 mbedtls_ecdh_context;
76
97 int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
98 int (*f_rng)(void *, unsigned char *, size_t),
99 void *p_rng );
100
125 int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
126 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
127 int (*f_rng)(void *, unsigned char *, size_t),
128 void *p_rng );
129
135 void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
136
142 void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
143
169 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
170 unsigned char *buf, size_t blen,
171 int (*f_rng)(void *, unsigned char *, size_t),
172 void *p_rng );
173
191 int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
192 const unsigned char **buf, const unsigned char *end );
193
212 int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key,
213 mbedtls_ecdh_side side );
214
236 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
237 unsigned char *buf, size_t blen,
238 int (*f_rng)(void *, unsigned char *, size_t),
239 void *p_rng );
240
257 int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
258 const unsigned char *buf, size_t blen );
259
284 int mbedtls_ecdh_calc_secret( 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
289 #if defined(MBEDTLS_ECP_RESTARTABLE)
290
302 void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx );
303 #endif /* MBEDTLS_ECP_RESTARTABLE */
304
305 #ifdef __cplusplus
306 }
307 #endif
308
309 #endif /* ecdh.h */
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 a public key and a TLS ServerKeyExchange payload.
mbedtls_ecdh_context::z
mbedtls_mpi z
Definition: ecdh.h:65
ecp.h
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbedtls_ecdh_context::d
mbedtls_mpi d
Definition: ecdh.h:62
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 a TLS ClientKeyExchange payload.
mbedtls_ecp_keypair
The ECP key-pair structure.
Definition: ecp.h:322
MBEDTLS_ECDH_OURS
Definition: ecdh.h:48
mbedtls_ecdh_free
void mbedtls_ecdh_free(mbedtls_ecdh_context *ctx)
This function frees a context.
mbedtls_ecdh_context::_d
mbedtls_mpi _d
Definition: ecdh.h:69
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 a TLS ClientKeyExchange payload.
mbedtls_ecp_group
The ECP group structure.
Definition: ecp.h:163
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_context::Vi
mbedtls_ecp_point Vi
Definition: ecdh.h:67
mbedtls_ecdh_context::grp
mbedtls_ecp_group grp
Definition: ecdh.h:61
mbedtls_ecdh_init
void mbedtls_ecdh_init(mbedtls_ecdh_context *ctx)
This function initializes an ECDH context.
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_side
mbedtls_ecdh_side
Definition: ecdh.h:46
mbedtls_ecp_restart_ctx
void mbedtls_ecp_restart_ctx
Definition: ecp.h:248
mbedtls_ecdh_read_params
int mbedtls_ecdh_read_params(mbedtls_ecdh_context *ctx, const unsigned char **buf, const unsigned char *end)
This function parses and processes a TLS ServerKeyExhange payload.
mbedtls_ecdh_context::point_format
int point_format
Definition: ecdh.h:66
mbedtls_ecdh_context
struct mbedtls_ecdh_context mbedtls_ecdh_context
The ECDH context structure.
mbedtls_ecdh_context
The ECDH context structure.
Definition: ecdh.h:59
mbedtls_ecdh_context::Qp
mbedtls_ecp_point Qp
Definition: ecdh.h:64
mbedtls_ecdh_context::Q
mbedtls_ecp_point Q
Definition: ecdh.h:63
mbedtls_ecdh_context::Vf
mbedtls_ecp_point Vf
Definition: ecdh.h:68
mbedtls_mpi
MPI structure.
Definition: bignum.h:180
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_ecp_point
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:118
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_THEIRS
Definition: ecdh.h:49