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 #if !defined(MBEDTLS_CONFIG_FILE)
00037 #include "config.h"
00038 #else
00039 #include MBEDTLS_CONFIG_FILE
00040 #endif
00041
00042 #include "ecp.h"
00043
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047
00053 typedef enum
00054 {
00055 MBEDTLS_ECDH_OURS,
00056 MBEDTLS_ECDH_THEIRS,
00057 } mbedtls_ecdh_side;
00058
00062 typedef struct
00063 {
00064 mbedtls_ecp_group grp;
00065 mbedtls_mpi d;
00066 mbedtls_ecp_point Q;
00067 mbedtls_ecp_point Qp;
00068 mbedtls_mpi z;
00069 int point_format;
00070 mbedtls_ecp_point Vi;
00071 mbedtls_ecp_point Vf;
00072 mbedtls_mpi _d;
00073 }
00074 mbedtls_ecdh_context;
00075
00095 int mbedtls_ecdh_gen_public( mbedtls_ecp_group *grp, mbedtls_mpi *d, mbedtls_ecp_point *Q,
00096 int (*f_rng)(void *, unsigned char *, size_t),
00097 void *p_rng );
00098
00122 int mbedtls_ecdh_compute_shared( mbedtls_ecp_group *grp, mbedtls_mpi *z,
00123 const mbedtls_ecp_point *Q, const mbedtls_mpi *d,
00124 int (*f_rng)(void *, unsigned char *, size_t),
00125 void *p_rng );
00126
00132 void mbedtls_ecdh_init( mbedtls_ecdh_context *ctx );
00133
00139 void mbedtls_ecdh_free( mbedtls_ecdh_context *ctx );
00140
00164 int mbedtls_ecdh_make_params( mbedtls_ecdh_context *ctx, size_t *olen,
00165 unsigned char *buf, size_t blen,
00166 int (*f_rng)(void *, unsigned char *, size_t),
00167 void *p_rng );
00168
00185 int mbedtls_ecdh_read_params( mbedtls_ecdh_context *ctx,
00186 const unsigned char **buf, const unsigned char *end );
00187
00206 int mbedtls_ecdh_get_params( mbedtls_ecdh_context *ctx, const mbedtls_ecp_keypair *key,
00207 mbedtls_ecdh_side side );
00208
00228 int mbedtls_ecdh_make_public( mbedtls_ecdh_context *ctx, size_t *olen,
00229 unsigned char *buf, size_t blen,
00230 int (*f_rng)(void *, unsigned char *, size_t),
00231 void *p_rng );
00232
00249 int mbedtls_ecdh_read_public( mbedtls_ecdh_context *ctx,
00250 const unsigned char *buf, size_t blen );
00251
00274 int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
00275 unsigned char *buf, size_t blen,
00276 int (*f_rng)(void *, unsigned char *, size_t),
00277 void *p_rng );
00278
00279 #ifdef __cplusplus
00280 }
00281 #endif
00282
00283 #endif