Add ecp_keypair struct, init/free and constants
diff --git a/include/polarssl/ecp.h b/include/polarssl/ecp.h
index 4b02181..db59a93 100644
--- a/include/polarssl/ecp.h
+++ b/include/polarssl/ecp.h
@@ -92,6 +92,25 @@
ecp_group;
/**
+ * \brief ECP key pair structure
+ *
+ * A generic key pair that could be used for ECDSA, fixed ECDH, etc.
+ * Usage can be restricted to a particular algorithm by the 'alg' field,
+ * see POLARSSL_ECP_KEY_ALG_* constants (default: unrestricted).
+ *
+ * \sa ecdh_context
+ * \sa ecdsa_context
+ */
+typedef struct
+{
+ ecp_group grp; /*!< Elliptic curve and base point */
+ mpi d; /*!< our secret value */
+ ecp_point Q; /*!< our public value */
+ int alg; /*!< algorithm to use this key with */
+}
+ecp_keypair;
+
+/**
* RFC 5114 defines a number of standardized ECP groups for use with TLS.
*
* These also are the NIST-recommended ECP groups, are the random ECP groups
@@ -139,6 +158,16 @@
*/
#define POLARSSL_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */
+/*
+ * Algorithm identifiers from RFC 5480 for use with EC keys
+ */
+#define POLARSSL_ECP_KEY_ALG_UNRESTRICTED 0 /**< RFC 5480 2.1.1 */
+#define POLARSSL_ECP_KEY_ALG_ECDH 1 /**< RFC 5480 2.1.2 */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/**
* \brief Initialize a point (as zero)
*/
@@ -150,6 +179,11 @@
void ecp_group_init( ecp_group *grp );
/**
+ * \brief Initialize a key pair (as an invalid one)
+ */
+void ecp_keypair_init( ecp_keypair *key );
+
+/**
* \brief Free the components of a point
*/
void ecp_point_free( ecp_point *pt );
@@ -160,6 +194,11 @@
void ecp_group_free( ecp_group *grp );
/**
+ * \brief Free the components of a key pair
+ */
+void ecp_keypair_free( ecp_keypair *key );
+
+/**
* \brief Set a point to zero
*
* \param pt Destination point
diff --git a/library/ecp.c b/library/ecp.c
index af18e5b..216fc43 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -91,6 +91,20 @@
}
/*
+ * Initialize (the components of) a key pair
+ */
+void ecp_keypair_init( ecp_keypair *key )
+{
+ if ( key == NULL )
+ return;
+
+ ecp_group_init( &key->grp );
+ mpi_init( &key->d );
+ ecp_point_init( &key->Q );
+ key->alg = POLARSSL_ECP_KEY_ALG_UNRESTRICTED;
+}
+
+/*
* Unallocate (the components of) a point
*/
void ecp_point_free( ecp_point *pt )
@@ -118,6 +132,20 @@
}
/*
+ * Unallocate (the components of) a key pair
+ */
+void ecp_keypair_free( ecp_keypair *key )
+{
+ if ( key == NULL )
+ return;
+
+ ecp_group_free( &key->grp );
+ mpi_free( &key->d );
+ ecp_point_free( &key->Q );
+ key->alg = POLARSSL_ECP_KEY_ALG_UNRESTRICTED;
+}
+
+/*
* Set point to zero
*/
int ecp_set_zero( ecp_point *pt )