From 1f82b041e775aafa81107edc6ed95f592db93625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 6 Dec 2013 12:51:50 +0100 Subject: [PATCH] Adapt ecp_group_free() to static constants --- include/polarssl/ecp.h | 2 +- library/ecp.c | 17 ++++++++--------- library/ecp_curves.c | 2 ++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h index 2ab458aea..ff1072e0c 100644 --- a/include/polarssl/ecp.h +++ b/include/polarssl/ecp.h @@ -136,7 +136,7 @@ typedef struct mpi N; /*!< 1. the order of G, or 2. unused */ size_t pbits; /*!< number of bits in P */ size_t nbits; /*!< number of bits in 1. P, or 2. private keys */ - unsigned int h; /*!< unused */ + unsigned int h; /*!< internal: 1 if the constants are static */ int (*modp)(mpi *); /*!< function for fast reduction mod P */ int (*t_pre)(ecp_point *, void *); /*!< unused */ int (*t_post)(ecp_point *, void *); /*!< unused */ diff --git a/library/ecp.c b/library/ecp.c index 8e162e7e2..8c5c06e69 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -277,18 +277,17 @@ void ecp_group_free( ecp_group *grp ) { size_t i; - /* FIXME WIP */ - if( grp->id != 0 ) - return; - if( grp == NULL ) return; - mpi_free( &grp->P ); - mpi_free( &grp->A ); - mpi_free( &grp->B ); - ecp_point_free( &grp->G ); - mpi_free( &grp->N ); + if( grp->h != 1 ) + { + mpi_free( &grp->P ); + mpi_free( &grp->A ); + mpi_free( &grp->B ); + ecp_point_free( &grp->G ); + mpi_free( &grp->N ); + } if( grp->T != NULL ) { diff --git a/library/ecp_curves.c b/library/ecp_curves.c index f29b68792..e20a1debd 100644 --- a/library/ecp_curves.c +++ b/library/ecp_curves.c @@ -485,6 +485,8 @@ static int ecp_group_load( ecp_group *grp, grp->pbits = mpi_msb( &grp->P ); grp->nbits = mpi_msb( &grp->N ); + grp->h = 1; + return( 0 ); }