Start introducing mbedtls_ecjpake_context
This commit is contained in:
parent
3aed1851b3
commit
7af8bc1007
@ -30,6 +30,52 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const mbedtls_md_info_t *md_info; /**< Hash to use */
|
||||
mbedtls_ecp_group grp; /**< Elliptic curve */
|
||||
|
||||
mbedtls_ecp_point X1; /**< Public key one */
|
||||
mbedtls_ecp_point X2; /**< Public key two */
|
||||
mbedtls_ecp_point X3; /**< Public key three */
|
||||
mbedtls_ecp_point X4; /**< Public key four */
|
||||
|
||||
mbedtls_mpi xa; /**< Our first secret (x1 or x3) */
|
||||
mbedtls_mpi xb; /**< Our second secret (x2 or x4) */
|
||||
} mbedtls_ecjpake_context;
|
||||
|
||||
/*
|
||||
* \brief Initialize a context
|
||||
* (just makes it ready for setup() or free()).
|
||||
*
|
||||
* \param ctx context to initialize
|
||||
*/
|
||||
void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx );
|
||||
|
||||
/*
|
||||
* \brief Free a context's content
|
||||
*
|
||||
* \param ctx context to free
|
||||
*/
|
||||
void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx );
|
||||
|
||||
/*
|
||||
* \brief Set up a context for use
|
||||
*
|
||||
* \note Currently the only values for hash/curve allowed by the
|
||||
* standard are MBEDTLS_MD_SHA256/MBEDTLS_ECP_DP_SECP256R1.
|
||||
*
|
||||
* \param ctx context to set up
|
||||
* \param hash hash function to use (MBEDTLS_MD_XXX)
|
||||
* \param curve elliptic curve identifier (MBEDTLS_ECP_DP_XXX)
|
||||
*
|
||||
* \return 0 if successfull,
|
||||
* a negative error code otherwise
|
||||
*/
|
||||
int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
|
||||
mbedtls_md_type_t hash,
|
||||
mbedtls_ecp_group_id curve );
|
||||
|
||||
#if defined(MBEDTLS_SELF_TEST)
|
||||
/**
|
||||
* \brief Checkup routine
|
||||
|
@ -36,6 +36,64 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Initialize context
|
||||
*/
|
||||
void mbedtls_ecjpake_init( mbedtls_ecjpake_context *ctx )
|
||||
{
|
||||
if( ctx == NULL )
|
||||
return;
|
||||
|
||||
ctx->md_info = NULL;
|
||||
mbedtls_ecp_group_init( &ctx->grp );
|
||||
|
||||
mbedtls_ecp_point_init( &ctx->X1 );
|
||||
mbedtls_ecp_point_init( &ctx->X2 );
|
||||
mbedtls_ecp_point_init( &ctx->X3 );
|
||||
mbedtls_ecp_point_init( &ctx->X4 );
|
||||
|
||||
mbedtls_mpi_init( &ctx->xa );
|
||||
mbedtls_mpi_init( &ctx->xb );
|
||||
}
|
||||
|
||||
/*
|
||||
* Free context
|
||||
*/
|
||||
void mbedtls_ecjpake_free( mbedtls_ecjpake_context *ctx )
|
||||
{
|
||||
if( ctx == NULL )
|
||||
return;
|
||||
|
||||
ctx->md_info = NULL;
|
||||
mbedtls_ecp_group_free( &ctx->grp );
|
||||
|
||||
mbedtls_ecp_point_free( &ctx->X1 );
|
||||
mbedtls_ecp_point_free( &ctx->X2 );
|
||||
mbedtls_ecp_point_free( &ctx->X3 );
|
||||
mbedtls_ecp_point_free( &ctx->X4 );
|
||||
|
||||
mbedtls_mpi_free( &ctx->xa );
|
||||
mbedtls_mpi_free( &ctx->xb );
|
||||
}
|
||||
|
||||
/*
|
||||
* Setup context
|
||||
*/
|
||||
int mbedtls_ecjpake_setup( mbedtls_ecjpake_context *ctx,
|
||||
mbedtls_md_type_t hash,
|
||||
mbedtls_ecp_group_id curve )
|
||||
{
|
||||
int ret;
|
||||
|
||||
if( ( ctx->md_info = mbedtls_md_info_from_type( hash ) ) == NULL )
|
||||
return( MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE );
|
||||
|
||||
if( ( ret = mbedtls_ecp_group_load( &ctx->grp, curve ) ) != 0 )
|
||||
return( ret );
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a point plus its length to a buffer
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user