00001
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef MBEDTLS_ECDH_H
00034 #define MBEDTLS_ECDH_H
00035
00036 #include "ecp.h"
00037
00038 #ifdef __cplusplus
00039 extern "C" {
00040 #endif
00041
00047 typedef enum
00048 {
00049 MBEDTLS_ECDH_OURS,
00050 MBEDTLS_ECDH_THEIRS,
00051 } mbedtls_ecdh_side;
00052
00056 typedef struct
00057 {
00058 mbedtls_ecp_group grp;
00059 mbedtls_mpi d;
00060 mbedtls_ecp_point Q;
00061 mbedtls_ecp_point Qp;
00062 mbedtls_mpi z;
00063 int point_format;
00064 mbedtls_ecp_point Vi;
00065 mbedtls_ecp_point Vf;
00066 mbedtls_mpi _d;
00067 }
00068 mbedtls_ecdh_context;
00069
00089 int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
00090 int (*f_rng)(void *, unsigned char *, size_t),
00091 void *p_rng );
00092
00116 int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
00117 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
00118 int (*f_rng)(void *, unsigned char *, size_t),
00119 void *p_rng );
00120
00126 void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
00127
00133 void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
00134
00158 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
00159 unsigned char *buf, size_t blen,
00160 int (*f_rng)(void *, unsigned char *, size_t),
00161 void *p_rng );
00162
00179 int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
00180 const unsigned char **buf, const unsigned char *end );
00181
00200 int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key,
00201 mbedtls_ecdh_side side );
00202
00222 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
00223 unsigned char *buf, size_t blen,
00224 int (*f_rng)(void *, unsigned char *, size_t),
00225 void *p_rng );
00226
00243 int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
00244 const unsigned char *buf, size_t blen );
00245
00268 int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
00269 unsigned char *buf, size_t blen,
00270 int (*f_rng)(void *, unsigned char *, size_t),
00271 void *p_rng );
00272
00273 #ifdef __cplusplus
00274 }
00275 #endif
00276
00277 #endif