Added ecp_XXX_read_string()

This commit is contained in:
Manuel Pégourié-Gonnard 2012-11-05 13:13:44 +01:00 committed by Paul Bakker
parent 7cfcea349c
commit 847395a8a9
2 changed files with 65 additions and 1 deletions

View File

@ -150,7 +150,7 @@ extern "C" {
#endif
/**
* \brief Initialize a point
* \brief Initialize a point (as zero)
*/
void ecp_point_init( ecp_point *pt );
@ -180,6 +180,36 @@ void ecp_set_zero( ecp_point *pt );
*/
int ecp_copy( ecp_point *P, const ecp_point *Q );
/**
* \brief Import a non-zero point from two ASCII strings
*
* \param P Destination point
* \param radix Input numeric base
* \param x First affine coordinate as a null-terminated string
* \param y Second affine coordinate as a null-terminated string
*
* \return 0 if successful, or a POLARSSL_ERR_MPI_XXX error code
*/
int ecp_point_read_string( ecp_point *P, int radix,
const char *x, const char *y );
/**
* \brief Import an ECP group from null-terminated ASCII strings
*
* \param grp Destination group
* \param radix Input numric 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
*/
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 Addition: R = P + Q
*

View File

@ -101,6 +101,40 @@ cleanup:
return( ret );
}
/*
* Import a non-zero point from ASCII strings
*/
int ecp_point_read_string( ecp_point *P, int radix,
const char *x, const char *y )
{
int ret = 0;
P->is_zero = 0;
MPI_CHK( mpi_read_string( &P->X, radix, x ) );
MPI_CHK( mpi_read_string( &P->Y, radix, y ) );
cleanup:
return( ret );
}
/*
* Import an ECP group from ASCII strings
*/
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)
{
int ret = 0;
MPI_CHK( mpi_read_string( &grp->P, radix, p ) );
MPI_CHK( mpi_read_string( &grp->B, radix, b ) );
MPI_CHK( ecp_point_read_string( &grp->G, radix, gx, gy ) );
MPI_CHK( mpi_read_string( &grp->N, radix, n ) );
cleanup:
return( ret );
}
/*
* Addition: R = P + Q, generic case (P != Q, P != 0, Q != 0, R != 0)
* Cf SEC1 v2 p. 7, item 4