mirror of
https://github.com/yuzu-emu/mbedtls
synced 2024-11-24 10:48:46 +00:00
Add ecdh_make_server_params (untested yet)
This commit is contained in:
parent
63533e44c2
commit
13724765b2
2 changed files with 60 additions and 6 deletions
|
@ -34,11 +34,12 @@
|
|||
*/
|
||||
typedef struct
|
||||
{
|
||||
ecp_group grp; /*!< ellipitic curve used */
|
||||
mpi d; /*!< our secret value */
|
||||
ecp_point Q; /*!< our public value */
|
||||
ecp_point Qp; /*!< peer's public value */
|
||||
mpi z; /*!< shared secret */
|
||||
ecp_group grp; /*!< ellipitic curve used */
|
||||
mpi d; /*!< our secret value */
|
||||
ecp_point Q; /*!< our public value */
|
||||
ecp_point Qp; /*!< peer's public value */
|
||||
mpi z; /*!< shared secret */
|
||||
int point_format; /*!< format for point export */
|
||||
}
|
||||
ecdh_context;
|
||||
|
||||
|
@ -90,6 +91,25 @@ void ecdh_init( ecdh_context *ctx );
|
|||
*/
|
||||
void ecdh_free( ecdh_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Setup and write the ServerKeyExhange parameters
|
||||
*
|
||||
* \param ctx ECDH context
|
||||
* \param buf destination buffer
|
||||
* \param olen number of chars written
|
||||
* \param f_rng RNG function
|
||||
* \param p_rng RNG parameter
|
||||
*
|
||||
* \note This function assumes that ctx->grp has already been
|
||||
* properly set (for example using ecp_use_known_dp).
|
||||
*
|
||||
* \return 0 if successful, or an POLARSSL_ERR_ECP_XXX error code
|
||||
*/
|
||||
int ecdh_make_server_params( ecdh_context *ctx, size_t *olen,
|
||||
unsigned char *buf, size_t blen,
|
||||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
*
|
||||
|
|
|
@ -85,9 +85,9 @@ void ecdh_init( ecdh_context *ctx )
|
|||
ecp_point_init( &ctx->Q );
|
||||
ecp_point_init( &ctx->Qp );
|
||||
mpi_init ( &ctx->z );
|
||||
ctx->point_format = POLARSSL_ECP_PF_UNCOMPRESSED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Free context
|
||||
*/
|
||||
|
@ -103,6 +103,40 @@ void ecdh_free( ecdh_context *ctx )
|
|||
mpi_free ( &ctx->z );
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup and write the ServerKeyExhange parameters
|
||||
* struct {
|
||||
* ECParameters curve_params;
|
||||
* ECPoint public;
|
||||
* } ServerECDHParams;
|
||||
*/
|
||||
int ecdh_make_server_params( 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;
|
||||
size_t grp_len, pt_len;
|
||||
|
||||
if( ( ret = ecdh_gen_public( &ctx->grp, &ctx->d, &ctx->Q, f_rng, p_rng ) )
|
||||
!= 0 )
|
||||
return( ret );
|
||||
|
||||
if( ( ret = ecp_tls_write_group( &ctx->grp, &grp_len, buf, blen ) )
|
||||
!= 0 )
|
||||
return( ret );
|
||||
|
||||
buf += grp_len;
|
||||
blen -= grp_len;
|
||||
|
||||
if( ( ret = ecp_tls_write_point( &ctx->grp, &ctx->Q, ctx->point_format,
|
||||
&pt_len, buf, blen ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
*olen = grp_len + pt_len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#if defined(POLARSSL_SELF_TEST)
|
||||
|
||||
|
|
Loading…
Reference in a new issue