From da179e48705a9948834348220425e92b3d9ca9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 18 Sep 2013 15:31:24 +0200 Subject: [PATCH] Add ecp_curve_list(), hide ecp_supported_curves --- include/polarssl/ecp.h | 14 ++++++++------ library/ecp.c | 12 ++++++++++-- library/ssl_cli.c | 2 +- programs/pkey/ecdsa.c | 2 +- programs/test/benchmark.c | 4 ++-- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h index cd1568cf7..353dd8bb3 100644 --- a/include/polarssl/ecp.h +++ b/include/polarssl/ecp.h @@ -64,7 +64,7 @@ typedef enum } ecp_group_id; /** - * Curve information for use by the SSL module + * Curve information for use by other modules */ typedef struct { @@ -74,11 +74,6 @@ typedef struct const char *name; /*!< Human-friendly name */ } ecp_curve_info; -/** - * List of supported curves - */ -extern const ecp_curve_info ecp_supported_curves[]; - /** * \brief ECP point structure (jacobian coordinates) * @@ -180,6 +175,13 @@ ecp_keypair; extern "C" { #endif +/** + * \brief Return the list of supported curves with associated info + * + * \return A statically allocated array, the last entry is 0. + */ +const ecp_curve_info *ecp_curve_list( void ); + /** * \brief Initialize a point (as zero) */ diff --git a/library/ecp.c b/library/ecp.c index 0b6650d43..9ab376317 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -94,6 +94,14 @@ const ecp_curve_info ecp_supported_curves[] = { POLARSSL_ECP_DP_NONE, 0, 0, NULL }, }; +/* + * List of supported curves and associated info + */ +const ecp_curve_info *ecp_curve_list( void ) +{ + return ecp_supported_curves; +} + /* * Initialize (the components of) a point */ @@ -755,7 +763,7 @@ ecp_group_id ecp_grp_id_from_named_curve( uint16_t tls_id ) { const ecp_curve_info *curve_info; - for( curve_info = ecp_supported_curves; + for( curve_info = ecp_curve_list(); curve_info->grp_id != POLARSSL_ECP_DP_NONE; curve_info++ ) { @@ -773,7 +781,7 @@ uint16_t ecp_named_curve_from_grp_id( ecp_group_id grp_id ) { const ecp_curve_info *curve_info; - for( curve_info = ecp_supported_curves; + for( curve_info = ecp_curve_list(); curve_info->grp_id != POLARSSL_ECP_DP_NONE; curve_info++ ) { diff --git a/library/ssl_cli.c b/library/ssl_cli.c index bfdd7e43f..b134b9217 100644 --- a/library/ssl_cli.c +++ b/library/ssl_cli.c @@ -240,7 +240,7 @@ static void ssl_write_supported_elliptic_curves_ext( ssl_context *ssl, SSL_DEBUG_MSG( 3, ( "client hello, adding supported_elliptic_curves extension" ) ); - for( curve = ecp_supported_curves; + for( curve = ecp_curve_list(); curve->grp_id != POLARSSL_ECP_DP_NONE; curve++ ) { diff --git a/programs/pkey/ecdsa.c b/programs/pkey/ecdsa.c index d6200f12b..ac3bdeee9 100644 --- a/programs/pkey/ecdsa.c +++ b/programs/pkey/ecdsa.c @@ -38,7 +38,7 @@ */ #if !defined(ECPARAMS) -#define ECPARAMS ecp_supported_curves[0].grp_id +#define ECPARAMS ecp_curve_list()->grp_id #endif #if !defined(POLARSSL_ECDSA_C) || \ diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c index 3f6c72f86..b35d4c665 100644 --- a/programs/test/benchmark.c +++ b/programs/test/benchmark.c @@ -447,7 +447,7 @@ int main( int argc, char *argv[] ) memset( buf, 0x2A, sizeof( buf ) ); - for( curve_info = ecp_supported_curves; + for( curve_info = ecp_curve_list(); curve_info->grp_id != POLARSSL_ECP_DP_NONE; curve_info++ ) { @@ -478,7 +478,7 @@ int main( int argc, char *argv[] ) const ecp_curve_info *curve_info; size_t olen; - for( curve_info = ecp_supported_curves; + for( curve_info = ecp_curve_list(); curve_info->grp_id != POLARSSL_ECP_DP_NONE; curve_info++ ) {