From 63533e44c25d1d8a131e5a8f04b712ac15236cc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Sun, 10 Feb 2013 14:21:04 +0100 Subject: [PATCH] Create ecdh_context structure --- include/polarssl/ecdh.h | 27 +++++++++++++++++++++++++++ library/ecdh.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/include/polarssl/ecdh.h b/include/polarssl/ecdh.h index ad131061c..2f1e51dd4 100644 --- a/include/polarssl/ecdh.h +++ b/include/polarssl/ecdh.h @@ -29,6 +29,19 @@ #include "polarssl/ecp.h" +/** + * \brief ECDH context structure + */ +typedef struct +{ + ecp_group grp; /*!< ellipitic curve used */ + mpi d; /*!< our secret value */ + ecp_point Q; /*!< our public value */ + ecp_point Qp; /*!< peer's public value */ + mpi z; /*!< shared secret */ +} +ecdh_context; + #ifdef __cplusplus extern "C" { #endif @@ -63,6 +76,20 @@ int ecdh_gen_public( const ecp_group *grp, mpi *d, ecp_point *Q, int ecdh_compute_shared( const ecp_group *grp, mpi *z, const ecp_point *Q, const mpi *d ); +/** + * \brief Initialize context + * + * \param ctx Context to initialize + */ +void ecdh_init( ecdh_context *ctx ); + +/** + * \brief Free context + * + * \param ctx Context to free + */ +void ecdh_free( ecdh_context *ctx ); + /** * \brief Checkup routine * diff --git a/library/ecdh.c b/library/ecdh.c index 1b4fcd3b2..0e2cfdf5b 100644 --- a/library/ecdh.c +++ b/library/ecdh.c @@ -27,6 +27,7 @@ * References: * * SEC1 http://www.secg.org/index.php?action=secg,docs_secg + * RFC 4492 */ #include "polarssl/config.h" @@ -74,6 +75,34 @@ cleanup: return( ret ); } +/* + * Initialize context + */ +void ecdh_init( ecdh_context *ctx ) +{ + ecp_group_init( &ctx->grp ); + mpi_init ( &ctx->d ); + ecp_point_init( &ctx->Q ); + ecp_point_init( &ctx->Qp ); + mpi_init ( &ctx->z ); +} + + +/* + * Free context + */ +void ecdh_free( ecdh_context *ctx ) +{ + if( ctx == NULL ) + return; + + ecp_group_free( &ctx->grp ); + mpi_free ( &ctx->d ); + ecp_point_free( &ctx->Q ); + ecp_point_free( &ctx->Qp ); + mpi_free ( &ctx->z ); +} + #if defined(POLARSSL_SELF_TEST)