Interface change in ECP info functions
ecp_named_curve_from_grp_id() -> ecp_curve_info_from_grp_id()
ecp_grp_id_from_named_curve() -> ecp_curve_info_from_tls_id()
diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h
index 353dd8b..94618e7 100644
--- a/include/polarssl/ecp.h
+++ b/include/polarssl/ecp.h
@@ -64,6 +64,11 @@
} ecp_group_id;
/**
+ * Number of supported curves (plus one for NONE)
+ */
+#define POLARSSL_ECP_DP_MAX 6
+
+/**
* Curve information for use by other modules
*/
typedef struct
@@ -365,24 +370,22 @@
unsigned char *buf, size_t blen );
/**
- * \brief Get a TLS NamedCurve value from an internal group identifier
+ * \brief Get curve information from an internal group identifier
*
* \param grp_id A POLARSSL_ECP_DP_XXX value
*
- * \return The associated TLS NamedCurve value on success,
- * 0 on failure.
+ * \return The associated curve information or NULL
*/
-uint16_t ecp_named_curve_from_grp_id( ecp_group_id id );
+const ecp_curve_info *ecp_curve_info_from_grp_id( ecp_group_id grp_id );
/**
- * \brief Get an internal group identifier from a TLS NamedCurve value
+ * \brief Get curve information from a TLS NamedCurve value
*
- * \param curve A value from TLS's enum NamedCurve
+ * \param grp_id A POLARSSL_ECP_DP_XXX value
*
- * \return The associated POLARSSL_ECP_DP_XXX identifer on success,
- * POLARSSL_ECP_DP_NONE on failure.
+ * \return The associated curve information or NULL
*/
-ecp_group_id ecp_grp_id_from_named_curve( uint16_t curve );
+const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id );
/**
* \brief Import a point from a TLS ECPoint record
diff --git a/library/ecp.c b/library/ecp.c
index 9ab3763..c8ee3a7 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -703,7 +703,8 @@
*/
int ecp_tls_read_group( ecp_group *grp, const unsigned char **buf, size_t len )
{
- unsigned int named_curve;
+ uint16_t tls_id;
+ const ecp_curve_info *curve_info;
/*
* We expect at least three bytes (see below)
@@ -720,10 +721,14 @@
/*
* Next two bytes are the namedcurve value
*/
- named_curve = *(*buf)++;
- named_curve <<= 8;
- named_curve |= *(*buf)++;
- return ecp_use_known_dp( grp, ecp_grp_id_from_named_curve( named_curve ) );
+ tls_id = *(*buf)++;
+ tls_id <<= 8;
+ tls_id |= *(*buf)++;
+
+ if( ( curve_info = ecp_curve_info_from_tls_id( tls_id ) ) == NULL )
+ return( POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE );
+
+ return ecp_use_known_dp( grp, curve_info->grp_id );
}
/*
@@ -732,7 +737,10 @@
int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
unsigned char *buf, size_t blen )
{
- unsigned int named_curve;
+ const ecp_curve_info *curve_info;
+
+ if( ( curve_info = ecp_curve_info_from_grp_id( grp->id ) ) == NULL )
+ return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
/*
* We are going to write 3 bytes (see below)
@@ -749,17 +757,16 @@
/*
* Next two bytes are the namedcurve value
*/
- named_curve = ecp_named_curve_from_grp_id( grp->id );
- buf[0] = named_curve >> 8;
- buf[1] = named_curve & 0xFF;
+ buf[0] = curve_info->tls_id >> 8;
+ buf[1] = curve_info->tls_id & 0xFF;
return 0;
}
/*
- * Get the internal identifer from the TLS name
+ * Get the curve info from the TLS identifier
*/
-ecp_group_id ecp_grp_id_from_named_curve( uint16_t tls_id )
+const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id )
{
const ecp_curve_info *curve_info;
@@ -768,16 +775,16 @@
curve_info++ )
{
if( curve_info->tls_id == tls_id )
- return( curve_info->grp_id );
+ return( curve_info );
}
- return( POLARSSL_ECP_DP_NONE );
+ return( NULL );
}
/*
- * Get the TLS name for the internal identifer
+ * Get the curve info for the internal identifer
*/
-uint16_t ecp_named_curve_from_grp_id( ecp_group_id grp_id )
+const ecp_curve_info *ecp_curve_info_from_grp_id( ecp_group_id grp_id )
{
const ecp_curve_info *curve_info;
@@ -786,10 +793,10 @@
curve_info++ )
{
if( curve_info->grp_id == grp_id )
- return( curve_info->tls_id );
+ return( curve_info );
}
- return( 0 );
+ return( NULL );
}
/*
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index d1d5ec7..9c90268 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -503,7 +503,7 @@
{
size_t list_size;
const unsigned char *p;
- ecp_group_id grp_id;
+ const ecp_curve_info *curve_info;
list_size = ( ( buf[0] << 8 ) | ( buf[1] ) );
if( list_size + 2 != len ||
@@ -516,11 +516,11 @@
p = buf + 2;
while( list_size > 0 )
{
- grp_id = ecp_grp_id_from_named_curve( ( p[0] << 8 ) | p[1] );
+ curve_info = ecp_curve_info_from_tls_id( ( p[0] << 8 ) | p[1] );
- if( grp_id != POLARSSL_ECP_DP_NONE )
+ if( curve_info != NULL )
{
- ssl->handshake->ec_curve = grp_id;
+ ssl->handshake->ec_curve = curve_info->grp_id;
return( 0 );
}