Add new function mbedtls_dhm_set_group to DHM Group
This commit is contained in:
parent
00d0a6834a
commit
8880e75dcb
2 changed files with 41 additions and 2 deletions
|
@ -127,8 +127,9 @@ int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx,
|
|||
* the byte-size of an MPI.
|
||||
*
|
||||
* \note This function assumes that ctx->P and ctx->G
|
||||
* have already been properly set (for example
|
||||
* using mbedtls_mpi_read_string or mbedtls_mpi_read_binary).
|
||||
* have already been properly set. For that, use
|
||||
* \c mbedtls_dhm_set_group below in conjunction with
|
||||
* \c mbedtls_mpi_read_binary and \c mbedtls_mpi_read_string.
|
||||
*
|
||||
* \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code
|
||||
*/
|
||||
|
@ -137,6 +138,22 @@ int mbedtls_dhm_make_params( mbedtls_dhm_context *ctx, int x_size,
|
|||
int (*f_rng)(void *, unsigned char *, size_t),
|
||||
void *p_rng );
|
||||
|
||||
/**
|
||||
* \brief Set prime modulus and generator
|
||||
*
|
||||
* \param ctx DHM context
|
||||
* \param P MPI holding DHM prime modulus
|
||||
* \param G MPI holding DHM generator
|
||||
*
|
||||
* \note This function can be used to set P, G
|
||||
* in preparation for \c mbedtls_dhm_make_params.
|
||||
*
|
||||
* \return 0 if successful, or an MBEDTLS_ERR_DHM_XXX error code
|
||||
*/
|
||||
int mbedtls_dhm_set_group( mbedtls_dhm_context *ctx,
|
||||
const mbedtls_mpi *P,
|
||||
const mbedtls_mpi *G );
|
||||
|
||||
/**
|
||||
* \brief Import the peer's public value G^Y
|
||||
*
|
||||
|
|
|
@ -218,6 +218,28 @@ cleanup:
|
|||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Set prime modulus and generator
|
||||
*/
|
||||
int mbedtls_dhm_set_group( mbedtls_dhm_context *ctx,
|
||||
const mbedtls_mpi *P,
|
||||
const mbedtls_mpi *G )
|
||||
{
|
||||
int ret;
|
||||
|
||||
if( ctx == NULL || P == NULL || G == NULL )
|
||||
return( MBEDTLS_ERR_DHM_BAD_INPUT_DATA );
|
||||
|
||||
if( ( ret = mbedtls_mpi_copy( &ctx->P, P ) ) != 0 ||
|
||||
( ret = mbedtls_mpi_copy( &ctx->G, G ) ) != 0 )
|
||||
{
|
||||
return( MBEDTLS_ERR_DHM_SET_GROUP_FAILED + ret );
|
||||
}
|
||||
|
||||
ctx->len = mbedtls_mpi_size( &ctx->P );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Import the peer's public value G^Y
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue