Add new function mbedtls_dhm_set_group to DHM Group

This commit is contained in:
Hanno Becker 2017-10-04 13:15:08 +01:00
parent 00d0a6834a
commit 8880e75dcb
2 changed files with 41 additions and 2 deletions

View File

@ -127,8 +127,9 @@ int mbedtls_dhm_read_params( mbedtls_dhm_context *ctx,
* the byte-size of an MPI. * the byte-size of an MPI.
* *
* \note This function assumes that ctx->P and ctx->G * \note This function assumes that ctx->P and ctx->G
* have already been properly set (for example * have already been properly set. For that, use
* using mbedtls_mpi_read_string or mbedtls_mpi_read_binary). * \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 * \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), int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng ); 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 * \brief Import the peer's public value G^Y
* *

View File

@ -218,6 +218,28 @@ cleanup:
return( 0 ); 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 * Import the peer's public value G^Y
*/ */