mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 12:48:32 +00:00
Add ecdh_{make,read}_public()
This commit is contained in:
parent
854fbd7ba2
commit
5cceb41d2c
3 changed files with 59 additions and 0 deletions
|
@ -122,6 +122,33 @@ int ecdh_make_params( ecdh_context *ctx, size_t *olen,
|
||||||
int ecdh_read_params( ecdh_context *ctx,
|
int ecdh_read_params( ecdh_context *ctx,
|
||||||
const unsigned char **buf, const unsigned char *end );
|
const unsigned char **buf, const unsigned char *end );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Setup and export the client's public value
|
||||||
|
*
|
||||||
|
* \param ctx ECDH context
|
||||||
|
* \param olen number of bytes actually written
|
||||||
|
* \param buf destination buffer
|
||||||
|
* \param blen size of destination buffer
|
||||||
|
*
|
||||||
|
* \return 0 if successful, or an POLARSSL_ERR_ECP_XXX error code
|
||||||
|
*/
|
||||||
|
int ecdh_make_public( ecdh_context *ctx, size_t *olen,
|
||||||
|
unsigned char *buf, size_t blen,
|
||||||
|
int (*f_rng)(void *, unsigned char *, size_t),
|
||||||
|
void *p_rng );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Parse and import the client's public value
|
||||||
|
*
|
||||||
|
* \param ctx ECDH context
|
||||||
|
* \param buf start of input buffer
|
||||||
|
* \param blen length of input buffer
|
||||||
|
*
|
||||||
|
* \return 0 if successful, or an POLARSSL_ERR_ECP_XXX error code
|
||||||
|
*/
|
||||||
|
int ecdh_read_public( ecdh_context *ctx,
|
||||||
|
const unsigned char *buf, size_t blen );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Checkup routine
|
* \brief Checkup routine
|
||||||
*
|
*
|
||||||
|
|
|
@ -159,6 +159,33 @@ int ecdh_read_params( ecdh_context *ctx,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Setup and export the client public value
|
||||||
|
*/
|
||||||
|
int ecdh_make_public( ecdh_context *ctx, size_t *olen,
|
||||||
|
unsigned char *buf, size_t blen,
|
||||||
|
int (*f_rng)(void *, unsigned char *, size_t),
|
||||||
|
void *p_rng )
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if( ( ret = ecdh_gen_public( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng ) )
|
||||||
|
!= 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
|
return ecp_tls_write_point( &ctx->grp, &ctx->Q, ctx->point_format,
|
||||||
|
olen, buf, blen );
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse and import the client's public value
|
||||||
|
*/
|
||||||
|
int ecdh_read_public( ecdh_context *ctx,
|
||||||
|
const unsigned char *buf, size_t blen )
|
||||||
|
{
|
||||||
|
return ecp_tls_read_point( &ctx->grp, &ctx->Qp, &buf, blen );
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(POLARSSL_SELF_TEST)
|
#if defined(POLARSSL_SELF_TEST)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -99,6 +99,11 @@ ecdh_exchange:id
|
||||||
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||||
TEST_ASSERT( ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
|
TEST_ASSERT( ecdh_read_params( &cli, &vbuf, buf + len ) == 0 );
|
||||||
|
|
||||||
|
memset( buf, 0x00, sizeof( buf ) ); vbuf = buf;
|
||||||
|
TEST_ASSERT( ecdh_make_public( &cli, &len, buf, 1000,
|
||||||
|
&rnd_pseudo_rand, &rnd_info ) == 0 );
|
||||||
|
TEST_ASSERT( ecdh_read_public( &srv, buf, len ) == 0 );
|
||||||
|
|
||||||
ecdh_free( &srv );
|
ecdh_free( &srv );
|
||||||
ecdh_free( &cli );
|
ecdh_free( &cli );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue