Commit b8c6e0e3 authored by Manuel Pégourié-Gonnard's avatar Manuel Pégourié-Gonnard
Browse files

Add ecp_keypair struct, init/free and constants

parent 7c8934ea
......@@ -91,6 +91,25 @@ typedef struct
}
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.
*
......@@ -139,6 +158,16 @@ ecp_group;
*/
#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)
*/
......@@ -149,6 +178,11 @@ void ecp_point_init( ecp_point *pt );
*/
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
*/
......@@ -159,6 +193,11 @@ void ecp_point_free( ecp_point *pt );
*/
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
*
......
......@@ -90,6 +90,20 @@ void ecp_group_init( ecp_group *grp )
grp->modp = NULL;
}
/*
* 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
*/
......@@ -117,6 +131,20 @@ void ecp_group_free( ecp_group *grp )
mpi_free( &grp->N );
}
/*
* 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
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment