mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 02:05:39 +01:00
Add Curve25519 to known groups
This commit is contained in:
parent
3afa07f05b
commit
661536677b
@ -248,6 +248,10 @@
|
|||||||
#define POLARSSL_ECP_DP_BP256R1_ENABLED
|
#define POLARSSL_ECP_DP_BP256R1_ENABLED
|
||||||
#define POLARSSL_ECP_DP_BP384R1_ENABLED
|
#define POLARSSL_ECP_DP_BP384R1_ENABLED
|
||||||
#define POLARSSL_ECP_DP_BP512R1_ENABLED
|
#define POLARSSL_ECP_DP_BP512R1_ENABLED
|
||||||
|
//#define POLARSSL_ECP_DP_M221_ENABLED // Not implemented yet!
|
||||||
|
#define POLARSSL_ECP_DP_M255_ENABLED
|
||||||
|
//#define POLARSSL_ECP_DP_M383_ENABLED // Not implemented yet!
|
||||||
|
//#define POLARSSL_ECP_DP_M511_ENABLED // Not implemented yet!
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \def POLARSSL_ECP_NIST_OPTIM
|
* \def POLARSSL_ECP_NIST_OPTIM
|
||||||
|
@ -64,10 +64,16 @@ typedef enum
|
|||||||
POLARSSL_ECP_DP_BP256R1, /*!< 256-bits Brainpool curve */
|
POLARSSL_ECP_DP_BP256R1, /*!< 256-bits Brainpool curve */
|
||||||
POLARSSL_ECP_DP_BP384R1, /*!< 384-bits Brainpool curve */
|
POLARSSL_ECP_DP_BP384R1, /*!< 384-bits Brainpool curve */
|
||||||
POLARSSL_ECP_DP_BP512R1, /*!< 512-bits Brainpool curve */
|
POLARSSL_ECP_DP_BP512R1, /*!< 512-bits Brainpool curve */
|
||||||
|
POLARSSL_ECP_DP_M221, /*!< (not implemented yet) */
|
||||||
|
POLARSSL_ECP_DP_M255, /*!< Curve25519 */
|
||||||
|
POLARSSL_ECP_DP_M383, /*!< (not implemented yet) */
|
||||||
|
POLARSSL_ECP_DP_M511, /*!< (not implemented yet) */
|
||||||
} ecp_group_id;
|
} ecp_group_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of supported curves (plus one for NONE)
|
* Number of supported curves (plus one for NONE).
|
||||||
|
*
|
||||||
|
* (Montgomery curves excluded for now.)
|
||||||
*/
|
*/
|
||||||
#define POLARSSL_ECP_DP_MAX 9
|
#define POLARSSL_ECP_DP_MAX 9
|
||||||
|
|
||||||
|
@ -341,11 +341,39 @@ static int ecp_mod_p521( mpi * );
|
|||||||
G ## _gy, sizeof( G ## _gy ), \
|
G ## _gy, sizeof( G ## _gy ), \
|
||||||
G ## _n, sizeof( G ## _n ) )
|
G ## _n, sizeof( G ## _n ) )
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Specialized function for creating the Curve25519 group
|
||||||
|
*/
|
||||||
|
static int ecp_use_curve25519( ecp_group *grp )
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Actually ( A + 2 ) / 4 */
|
||||||
|
MPI_CHK( mpi_read_string( &grp->A, 16, "01DB42" ) );
|
||||||
|
|
||||||
|
/* P = 2^255 - 19 */
|
||||||
|
MPI_CHK( mpi_lset( &grp->P, 1 ) );
|
||||||
|
MPI_CHK( mpi_shift_l( &grp->P, 255 ) );
|
||||||
|
MPI_CHK( mpi_sub_int( &grp->P, &grp->P, 19 ) );
|
||||||
|
grp->pbits = mpi_msb( &grp->P );
|
||||||
|
|
||||||
|
/* Actually, the required msb for private keys */
|
||||||
|
grp->nbits = 254;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if( ret != 0 )
|
||||||
|
ecp_group_free( grp );
|
||||||
|
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set a group using well-known domain parameters
|
* Set a group using well-known domain parameters
|
||||||
*/
|
*/
|
||||||
int ecp_use_known_dp( ecp_group *grp, ecp_group_id id )
|
int ecp_use_known_dp( ecp_group *grp, ecp_group_id id )
|
||||||
{
|
{
|
||||||
|
ecp_group_free( grp );
|
||||||
|
|
||||||
grp->id = id;
|
grp->id = id;
|
||||||
|
|
||||||
switch( id )
|
switch( id )
|
||||||
@ -395,6 +423,11 @@ int ecp_use_known_dp( ecp_group *grp, ecp_group_id id )
|
|||||||
return( LOAD_GROUP( brainpoolP512r1 ) );
|
return( LOAD_GROUP( brainpoolP512r1 ) );
|
||||||
#endif /* POLARSSL_ECP_DP_BP512R1_ENABLED */
|
#endif /* POLARSSL_ECP_DP_BP512R1_ENABLED */
|
||||||
|
|
||||||
|
#if defined(POLARSSL_ECP_DP_M255_ENABLED)
|
||||||
|
case POLARSSL_ECP_DP_M255:
|
||||||
|
return( ecp_use_curve25519( grp ) );
|
||||||
|
#endif /* POLARSSL_ECP_DP_M255_ENABLED */
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ecp_group_free( grp );
|
ecp_group_free( grp );
|
||||||
return( POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE );
|
return( POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE );
|
||||||
|
Loading…
Reference in New Issue
Block a user