From 883f313516ad0c797c9e9394e0c3028241ac2bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 2 Nov 2012 09:40:25 +0100 Subject: [PATCH] Added ecp_copy() (for points) --- include/polarssl/ecp.h | 31 +++++++++++++++++++++---------- library/ecp.c | 24 +++++++++++++++++++----- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h index e76cd9eb0..23d3fbd68 100644 --- a/include/polarssl/ecp.h +++ b/include/polarssl/ecp.h @@ -33,6 +33,7 @@ * ECP Error codes */ + /** * \brief ECP point structure (affine coordinates) */ @@ -144,6 +145,26 @@ ecp_group; extern "C" { #endif +/** + * \brief Free the components of a point + */ +void ecp_point_free( ecp_point *pt ); + +/** + * \brief Free the components of an ECP group + */ +void ecp_group_free( ecp_group *grp ); + +/** + * \brief Copy the contents of point Q into P + * + * \param P Destination point + * \param Q Source point + * + * \return 0 if successful, or an POLARSSL_ERR_ECP_XXX error code + */ +int ecp_copy( ecp_point *P, const ecp_point *Q ); + /** * \brief Addition: R = P + Q * @@ -170,16 +191,6 @@ int ecp_add( const ecp_group *grp, ecp_point *R, int ecp_mul( const ecp_group *grp, ecp_point *R, const mpi *m, const ecp_point *P ); -/** - * \brief Free the components of a point - */ -void ecp_point_free( ecp_point *pt ); - -/** - * \brief Free the components of an ECP group - */ -void ecp_group_free( ecp_group *grp ); - /** * \brief Checkup routine * diff --git a/library/ecp.c b/library/ecp.c index 2173e2484..6c3b4a8b4 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -26,7 +26,7 @@ /* * References: * - * SEC1-v2 (XXX: insert url) + * SEC1 http://www.secg.org/index.php?action=secg,docs_secg * Guide to Elliptic Curve Cryptography - Hankerson, Menezes, Vanstone */ @@ -57,12 +57,26 @@ void ecp_group_free( ecp_group *grp ) if( grp == NULL ) return; - mpi_free( &( grp->P ) ); - mpi_free( &( grp->B ) ); - mpi_free( &( grp->N ) ); - ecp_point_free( &( grp->G ) ); + mpi_free( &grp->P ); + mpi_free( &grp->B ); + ecp_point_free( &grp->G ); + mpi_free( &grp->N ); } +/* + * Copy the contents of Q into P + */ +int ecp_copy( ecp_point *P, const ecp_point *Q ) +{ + int ret; + + P->is_zero = Q->is_zero; + MPI_CHK( mpi_copy( &P->X, &Q->X ) ); + MPI_CHK( mpi_copy( &P->Y, &Q->Y ) ); + +cleanup: + return( ret ); +} #if defined(POLARSSL_SELF_TEST)