Reorganize code in ecp.c
diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h
index 7940b32..02f6f93 100644
--- a/include/polarssl/ecp.h
+++ b/include/polarssl/ecp.h
@@ -187,6 +187,24 @@
const ecp_curve_info *ecp_curve_list( void );
/**
+ * \brief Get curve information from an internal group identifier
+ *
+ * \param grp_id A POLARSSL_ECP_DP_XXX value
+ *
+ * \return The associated curve information or NULL
+ */
+const ecp_curve_info *ecp_curve_info_from_grp_id( ecp_group_id grp_id );
+
+/**
+ * \brief Get curve information from a TLS NamedCurve value
+ *
+ * \param grp_id A POLARSSL_ECP_DP_XXX value
+ *
+ * \return The associated curve information or NULL
+ */
+const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id );
+
+/**
* \brief Initialize a point (as zero)
*/
void ecp_point_init( ecp_point *pt );
@@ -217,25 +235,6 @@
void ecp_keypair_free( ecp_keypair *key );
/**
- * \brief Set a point to zero
- *
- * \param pt Destination point
- *
- * \return 0 if successful,
- * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
- */
-int ecp_set_zero( ecp_point *pt );
-
-/**
- * \brief Tell if a point is zero
- *
- * \param pt Point to test
- *
- * \return 1 if point is zero, 0 otherwise
- */
-int ecp_is_zero( ecp_point *pt );
-
-/**
* \brief Copy the contents of point Q into P
*
* \param P Destination point
@@ -258,6 +257,25 @@
int ecp_group_copy( ecp_group *dst, const ecp_group *src );
/**
+ * \brief Set a point to zero
+ *
+ * \param pt Destination point
+ *
+ * \return 0 if successful,
+ * POLARSSL_ERR_MPI_MALLOC_FAILED if memory allocation failed
+ */
+int ecp_set_zero( ecp_point *pt );
+
+/**
+ * \brief Tell if a point is zero
+ *
+ * \param pt Point to test
+ *
+ * \return 1 if point is zero, 0 otherwise
+ */
+int ecp_is_zero( ecp_point *pt );
+
+/**
* \brief Import a non-zero point from two ASCII strings
*
* \param P Destination point
@@ -271,25 +289,6 @@
const char *x, const char *y );
/**
- * \brief Import an ECP group from null-terminated ASCII strings
- *
- * \param grp Destination group
- * \param radix Input numeric base
- * \param p Prime modulus of the base field
- * \param b Constant term in the equation
- * \param gx The generator's X coordinate
- * \param gy The generator's Y coordinate
- * \param n The generator's order
- *
- * \return 0 if successful, or a POLARSSL_ERR_MPI_XXX error code
- *
- * \note Sets all fields except modp.
- */
-int ecp_group_read_string( ecp_group *grp, int radix,
- const char *p, const char *b,
- const char *gx, const char *gy, const char *n);
-
-/**
* \brief Export a point into unsigned binary data
*
* \param grp Group to which the point should belong
@@ -327,6 +326,58 @@
const unsigned char *buf, size_t ilen );
/**
+ * \brief Import a point from a TLS ECPoint record
+ *
+ * \param grp ECP group used
+ * \param pt Destination point
+ * \param buf $(Start of input buffer)
+ * \param len Buffer length
+ *
+ * \return O if successful,
+ * POLARSSL_ERR_MPI_XXX if initialization failed
+ * POLARSSL_ERR_ECP_BAD_INPUT_DATA if input is invalid
+ */
+int ecp_tls_read_point( const ecp_group *grp, ecp_point *pt,
+ const unsigned char **buf, size_t len );
+
+/**
+ * \brief Export a point as a TLS ECPoint record
+ *
+ * \param grp ECP group used
+ * \param pt Point to export
+ * \param format Export format
+ * \param olen length of data written
+ * \param buf Buffer to write to
+ * \param blen Buffer length
+ *
+ * \return 0 if successful,
+ * or POLARSSL_ERR_ECP_BAD_INPUT_DATA
+ * or POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
+ */
+int ecp_tls_write_point( const ecp_group *grp, const ecp_point *pt,
+ int format, size_t *olen,
+ unsigned char *buf, size_t blen );
+
+/**
+ * \brief Import an ECP group from null-terminated ASCII strings
+ *
+ * \param grp Destination group
+ * \param radix Input numeric base
+ * \param p Prime modulus of the base field
+ * \param b Constant term in the equation
+ * \param gx The generator's X coordinate
+ * \param gy The generator's Y coordinate
+ * \param n The generator's order
+ *
+ * \return 0 if successful, or a POLARSSL_ERR_MPI_XXX error code
+ *
+ * \note Sets all fields except modp.
+ */
+int ecp_group_read_string( ecp_group *grp, int radix,
+ const char *p, const char *b,
+ const char *gx, const char *gy, const char *n);
+
+/**
* \brief Set a group using well-known domain parameters
*
* \param grp Destination group
@@ -369,57 +420,6 @@
unsigned char *buf, size_t blen );
/**
- * \brief Get curve information from an internal group identifier
- *
- * \param grp_id A POLARSSL_ECP_DP_XXX value
- *
- * \return The associated curve information or NULL
- */
-const ecp_curve_info *ecp_curve_info_from_grp_id( ecp_group_id grp_id );
-
-/**
- * \brief Get curve information from a TLS NamedCurve value
- *
- * \param grp_id A POLARSSL_ECP_DP_XXX value
- *
- * \return The associated curve information or NULL
- */
-const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id );
-
-/**
- * \brief Import a point from a TLS ECPoint record
- *
- * \param grp ECP group used
- * \param pt Destination point
- * \param buf $(Start of input buffer)
- * \param len Buffer length
- *
- * \return O if successful,
- * POLARSSL_ERR_MPI_XXX if initialization failed
- * POLARSSL_ERR_ECP_BAD_INPUT_DATA if input is invalid
- */
-int ecp_tls_read_point( const ecp_group *grp, ecp_point *pt,
- const unsigned char **buf, size_t len );
-
-/**
- * \brief Export a point as a TLS ECPoint record
- *
- * \param grp ECP group used
- * \param pt Point to export
- * \param format Export format
- * \param olen length of data written
- * \param buf Buffer to write to
- * \param blen Buffer length
- *
- * \return 0 if successful,
- * or POLARSSL_ERR_ECP_BAD_INPUT_DATA
- * or POLARSSL_ERR_ECP_BUFFER_TOO_SMALL
- */
-int ecp_tls_write_point( const ecp_group *grp, const ecp_point *pt,
- int format, size_t *olen,
- unsigned char *buf, size_t blen );
-
-/**
* \brief Addition: R = P + Q
*
* \param grp ECP group