OPTIGA Trust M  1.1.0
C++ library for Optiga Trust M Chip Security Controller
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 /*
40  * Use a backward compatible ECDH context.
41  *
42  * This flag is always enabled for now and future versions might add a
43  * configuration option that conditionally undefines this flag.
44  * The configuration option in question may have a different name.
45  *
46  * Features undefining this flag, must have a warning in their description in
47  * config.h stating that the feature breaks backward compatibility.
48  */
49 #define MBEDTLS_ECDH_LEGACY_CONTEXT
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
58 typedef enum
59 {
63 
64 #if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
65 
71 typedef enum
72 {
73  MBEDTLS_ECDH_VARIANT_NONE = 0,
74  MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,
75 } mbedtls_ecdh_variant;
76 
84 typedef struct mbedtls_ecdh_context_mbed
85 {
86  mbedtls_ecp_group grp;
87  mbedtls_mpi d;
90  mbedtls_mpi z;
91 #if defined(MBEDTLS_ECP_RESTARTABLE)
93 #endif
94 } mbedtls_ecdh_context_mbed;
95 #endif
96 
104 typedef struct mbedtls_ecdh_context
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;
123  mbedtls_ecp_group_id grp_id;
124  mbedtls_ecdh_variant var;
125  union
126  {
127  mbedtls_ecdh_context_mbed mbed_ecdh;
128  } ctx;
131 #if defined(MBEDTLS_ECP_RESTARTABLE)
132  uint8_t restart_enabled;
137 #endif /* MBEDTLS_ECP_RESTARTABLE */
138 #endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
139 }
141 
168  int (*f_rng)(void *, unsigned char *, size_t),
169  void *p_rng );
170 
206  const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
207  int (*f_rng)(void *, unsigned char *, size_t),
208  void *p_rng );
209 
216 
234  mbedtls_ecp_group_id grp_id );
235 
244 
270 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
271  unsigned char *buf, size_t blen,
272  int (*f_rng)(void *, unsigned char *, size_t),
273  void *p_rng );
274 
300  const unsigned char **buf,
301  const unsigned char *end );
302 
323  const mbedtls_ecp_keypair *key,
324  mbedtls_ecdh_side side );
325 
352 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
353  unsigned char *buf, size_t blen,
354  int (*f_rng)(void *, unsigned char *, size_t),
355  void *p_rng );
356 
377  const unsigned char *buf, size_t blen );
378 
409 int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
410  unsigned char *buf, size_t blen,
411  int (*f_rng)(void *, unsigned char *, size_t),
412  void *p_rng );
413 
414 #if defined(MBEDTLS_ECP_RESTARTABLE)
415 
427 void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx );
428 #endif /* MBEDTLS_ECP_RESTARTABLE */
429 
430 #ifdef __cplusplus
431 }
432 #endif
433 
434 #endif /* ecdh.h */
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_mpi z
Definition: ecdh.h:111
This file provides an API for Elliptic Curves over GF(P) (ECP).
mbedtls_mpi d
Definition: ecdh.h:108
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.
The ECP key-pair structure.
Definition: ecp.h:326
Definition: ecdh.h:60
void mbedtls_ecdh_free(mbedtls_ecdh_context *ctx)
This function frees a context.
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.
mbedtls_mpi _d
Definition: ecdh.h:115
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.
The ECP group structure.
Definition: ecp.h:167
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_ecp_point Vi
Definition: ecdh.h:113
mbedtls_ecp_group grp
Definition: ecdh.h:107
void mbedtls_ecdh_init(mbedtls_ecdh_context *ctx)
This function initializes an ECDH context.
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
Definition: ecdh.h:58
void mbedtls_ecp_restart_ctx
Definition: ecp.h:252
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.
int point_format
Definition: ecdh.h:112
mbedtls_ecp_group_id
Definition: ecp.h:71
struct mbedtls_ecdh_context mbedtls_ecdh_context
The ECDH context structure.
The ECDH context structure.
Definition: ecdh.h:104
mbedtls_ecp_point Qp
Definition: ecdh.h:110
mbedtls_ecp_point Q
Definition: ecdh.h:109
mbedtls_ecp_point Vf
Definition: ecdh.h:114
MPI structure.
Definition: bignum.h:180
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.
The ECP point structure, in Jacobian coordinates.
Definition: ecp.h:118
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.
Definition: ecdh.h:61