From e09631b7c4d0216400cc7fc40fd5c29ce4d8bf97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Mon, 12 Aug 2013 15:44:31 +0200 Subject: [PATCH] Create ecp_group_copy() and use it --- include/polarssl/ecp.h | 11 +++++++++++ library/ecp.c | 8 ++++++++ programs/pkey/ecdsa.c | 4 ++-- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h index 2c0009cdd..2082bd960 100644 --- a/include/polarssl/ecp.h +++ b/include/polarssl/ecp.h @@ -219,6 +219,17 @@ int ecp_is_zero( ecp_point *pt ); */ int ecp_copy( ecp_point *P, const ecp_point *Q ); +/** + * \brief Copy the contents of a group object + * + * \param dst Destination group + * \param src Source group + * + * \return 0 if successful, + * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed + */ +int ecp_group_copy( ecp_group *dst, const ecp_group *src ); + /** * \brief Import a non-zero point from two ASCII strings * diff --git a/library/ecp.c b/library/ecp.c index a2d13c444..09a021bf8 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -181,6 +181,14 @@ cleanup: return( ret ); } +/* + * Copy the contents of a group object + */ +int ecp_group_copy( ecp_group *dst, const ecp_group *src ) +{ + return ecp_use_known_dp( dst, src->id ); +} + /* * Import a non-zero point from ASCII strings */ diff --git a/programs/pkey/ecdsa.c b/programs/pkey/ecdsa.c index 06f112309..94e00dff3 100644 --- a/programs/pkey/ecdsa.c +++ b/programs/pkey/ecdsa.c @@ -152,9 +152,9 @@ int main( int argc, char *argv[] ) printf( " . Preparing verification context..." ); fflush( stdout ); - if( ( ret = ecp_use_known_dp( &ctx_verify.grp, ctx_sign.grp.id ) ) != 0 ) + if( ( ret = ecp_group_copy( &ctx_verify.grp, &ctx_sign.grp ) ) != 0 ) { - printf( " failed\n ! ecp_use_known_dp returned %d\n", ret ); + printf( " failed\n ! ecp_group_copy returned %d\n", ret ); goto exit; }