00001
00023 #ifndef MBEDTLS_ECDH_H
00024 #define MBEDTLS_ECDH_H
00025
00026 #include "ecp.h"
00027
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031
00035 typedef enum
00036 {
00037 MBEDTLS_ECDH_OURS,
00038 MBEDTLS_ECDH_THEIRS,
00039 } mbedtls_ecdh_side;
00040
00044 typedef struct
00045 {
00046 mbedtls_ecp_group grp;
00047 mbedtls_mpi d;
00048 mbedtls_ecp_point Q;
00049 mbedtls_ecp_point Qp;
00050 mbedtls_mpi z;
00051 int point_format;
00052 mbedtls_ecp_point Vi;
00053 mbedtls_ecp_point Vf;
00054 mbedtls_mpi _d;
00055 }
00056 mbedtls_ecdh_context;
00057
00071 int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
00072 int (*f_rng)(void *, unsigned char *, size_t),
00073 void *p_rng );
00074
00093 int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
00094 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
00095 int (*f_rng)(void *, unsigned char *, size_t),
00096 void *p_rng );
00097
00103 void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
00104
00110 void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
00111
00128 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
00129 unsigned char *buf, size_t blen,
00130 int (*f_rng)(void *, unsigned char *, size_t),
00131 void *p_rng );
00132
00143 int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
00144 const unsigned char **buf, const unsigned char *end );
00145
00158 int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key,
00159 mbedtls_ecdh_side side );
00160
00174 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
00175 unsigned char *buf, size_t blen,
00176 int (*f_rng)(void *, unsigned char *, size_t),
00177 void *p_rng );
00178
00189 int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
00190 const unsigned char *buf, size_t blen );
00191
00205 int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
00206 unsigned char *buf, size_t blen,
00207 int (*f_rng)(void *, unsigned char *, size_t),
00208 void *p_rng );
00209
00210 #ifdef __cplusplus
00211 }
00212 #endif
00213
00214 #endif