Add ecp_genkey(), prettier wrapper

This commit is contained in:
Manuel Pégourié-Gonnard 2013-11-30 14:13:16 +01:00
parent 76f03118c4
commit 104ee1d1f6
4 changed files with 50 additions and 0 deletions

View File

@ -535,6 +535,20 @@ int ecp_gen_keypair( ecp_group *grp, mpi *d, ecp_point *Q,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
/**
* \brief Generate a keypair
*
* \param grp_id ECP group identifier
* \param key Destination keypair
* \param f_rng RNG function
* \param p_rng RNG parameter
*
* \return 0 if successful,
* or a POLARSSL_ERR_ECP_XXX or POLARSSL_MPI_XXX error code
*/
int ecp_gen_key( ecp_group_id grp_id, ecp_keypair *key,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
/**
* \brief Checkup routine
*

View File

@ -1669,6 +1669,20 @@ int ecp_gen_keypair( ecp_group *grp, mpi *d, ecp_point *Q,
return( ecp_mul( grp, Q, d, &grp->G, f_rng, p_rng ) );
}
/*
* Generate a keypair, prettier wrapper
*/
int ecp_gen_key( ecp_group_id grp_id, ecp_keypair *key,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
{
int ret;
if( ( ret = ecp_use_known_dp( &key->grp, grp_id ) ) != 0 )
return( ret );
return( ecp_gen_keypair( &key->grp, &key->d, &key->Q, f_rng, p_rng ) );
}
#if defined(POLARSSL_ECP_NIST_OPTIM)
/*
* Fast reduction modulo the primes used by the NIST curves.

View File

@ -247,6 +247,10 @@ ECP gen keypair
depends_on:POLARSSL_ECP_DP_SECP192R1_ENABLED
ecp_gen_keypair:POLARSSL_ECP_DP_SECP192R1
ECP gen keypair wrapper
depends_on:POLARSSL_ECP_DP_SECP192R1_ENABLED
ecp_gen_key:POLARSSL_ECP_DP_SECP192R1
ECP mod p192 small (more than 192 bits, less limbs than 2 * 192 bits)
depends_on:POLARSSL_ECP_DP_SECP192R1_ENABLED
ecp_fast_mod:POLARSSL_ECP_DP_SECP192R1:"0100000000000103010000000000010201000000000001010100000000000100"

View File

@ -522,6 +522,24 @@ void ecp_gen_keypair( int id )
}
/* END_CASE */
/* BEGIN_CASE */
void ecp_gen_key( int id )
{
ecp_keypair key;
rnd_pseudo_info rnd_info;
ecp_keypair_init( &key );
memset( &rnd_info, 0x00, sizeof( rnd_pseudo_info ) );
TEST_ASSERT( ecp_gen_key( id, &key, &rnd_pseudo_rand, &rnd_info ) == 0 );
TEST_ASSERT( ecp_check_pubkey( &key.grp, &key.Q ) == 0 );
TEST_ASSERT( ecp_check_privkey( &key.grp, &key.d ) == 0 );
ecp_keypair_free( &key );
}
/* END_CASE */
/* BEGIN_CASE depends_on:POLARSSL_SELF_TEST */
void ecp_selftest()
{