mbed TLS v2.16.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: GPL-2.0
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 2 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License along
30  * with this program; if not, write to the Free Software Foundation, Inc.,
31  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32  *
33  * This file is part of Mbed TLS (https://tls.mbed.org)
34  */
35 
36 #ifndef MBEDTLS_ECDH_H
37 #define MBEDTLS_ECDH_H
38 
39 #if !defined(MBEDTLS_CONFIG_FILE)
40 #include "config.h"
41 #else
42 #include MBEDTLS_CONFIG_FILE
43 #endif
44 
45 #include "ecp.h"
46 
47 /*
48  * Use a backward compatible ECDH context.
49  *
50  * This flag is always enabled for now and future versions might add a
51  * configuration option that conditionally undefines this flag.
52  * The configuration option in question may have a different name.
53  *
54  * Features undefining this flag, must have a warning in their description in
55  * config.h stating that the feature breaks backward compatibility.
56  */
57 #define MBEDTLS_ECDH_LEGACY_CONTEXT
58 
59 #ifdef __cplusplus
60 extern "C" {
61 #endif
62 
66 typedef enum
67 {
71 
72 #if !defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
73 
79 typedef enum
80 {
81  MBEDTLS_ECDH_VARIANT_NONE = 0,
82  MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0,
83 } mbedtls_ecdh_variant;
84 
92 typedef struct mbedtls_ecdh_context_mbed
93 {
94  mbedtls_ecp_group grp;
95  mbedtls_mpi d;
98  mbedtls_mpi z;
99 #if defined(MBEDTLS_ECP_RESTARTABLE)
101 #endif
102 } mbedtls_ecdh_context_mbed;
103 #endif
104 
112 typedef struct mbedtls_ecdh_context
113 {
114 #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
124 #if defined(MBEDTLS_ECP_RESTARTABLE)
125  int restart_enabled;
127 #endif /* MBEDTLS_ECP_RESTARTABLE */
128 #else
129  uint8_t point_format;
131  mbedtls_ecp_group_id grp_id;
132  mbedtls_ecdh_variant var;
133  union
134  {
135  mbedtls_ecdh_context_mbed mbed_ecdh;
136  } ctx;
139 #if defined(MBEDTLS_ECP_RESTARTABLE)
140  uint8_t restart_enabled;
145 #endif /* MBEDTLS_ECP_RESTARTABLE */
146 #endif /* MBEDTLS_ECDH_LEGACY_CONTEXT */
147 }
149 
176  int (*f_rng)(void *, unsigned char *, size_t),
177  void *p_rng );
178 
214  const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
215  int (*f_rng)(void *, unsigned char *, size_t),
216  void *p_rng );
217 
224 
242  mbedtls_ecp_group_id grp_id );
243 
252 
278 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
279  unsigned char *buf, size_t blen,
280  int (*f_rng)(void *, unsigned char *, size_t),
281  void *p_rng );
282 
308  const unsigned char **buf,
309  const unsigned char *end );
310 
331  const mbedtls_ecp_keypair *key,
332  mbedtls_ecdh_side side );
333 
360 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
361  unsigned char *buf, size_t blen,
362  int (*f_rng)(void *, unsigned char *, size_t),
363  void *p_rng );
364 
385  const unsigned char *buf, size_t blen );
386 
417 int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
418  unsigned char *buf, size_t blen,
419  int (*f_rng)(void *, unsigned char *, size_t),
420  void *p_rng );
421 
422 #if defined(MBEDTLS_ECP_RESTARTABLE)
423 
435 void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx );
436 #endif /* MBEDTLS_ECP_RESTARTABLE */
437 
438 #ifdef __cplusplus
439 }
440 #endif
441 
442 #endif /* ecdh.h */