1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Added ecp_write_binary().

This commit is contained in:
Manuel Pégourié-Gonnard
2012-11-24 14:10:14 +01:00
committed by Paul Bakker
parent 1c33057a63
commit e19feb5b46
4 changed files with 96 additions and 0 deletions

View File

@ -173,6 +173,43 @@ cleanup:
return( ret );
}
/*
* Export a point into unsigned binary data, uncompressed format (SEC1 2.3.3)
*/
int ecp_write_binary( const ecp_group *grp, const ecp_point *P,
size_t *olen, unsigned char *buf, size_t buflen )
{
int ret;
size_t plen;
/*
* Case P == 0
*/
if( mpi_cmp_int( &P->Z, 0 ) == 0 )
{
if( buflen < 1 )
return( POLARSSL_ERR_ECP_GENERIC );
buf[0] = 0x00;
*olen = 1;
return( 0 );
}
plen = mpi_size( &grp->P );
*olen = 2 * plen + 1;
if( buflen < *olen )
return( POLARSSL_ERR_ECP_GENERIC );
buf[0] = 0x04;
MPI_CHK( mpi_write_binary( &P->X, buf + 1, plen ) );
MPI_CHK( mpi_write_binary( &P->Y, buf + 1 + plen, plen ) );
cleanup:
return( ret );
}
/*
* Wrapper around fast quasi-modp functions, with fall-back to mpi_mod_mpi.
* See the documentation of struct ecp_group.