mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-29 16:04:23 +01:00
ECDH: Fix Everest x25519 make_public
This commit is contained in:
parent
537f41ebbf
commit
efdf4d7baa
14
3rdparty/everest/library/x25519.c
vendored
14
3rdparty/everest/library/x25519.c
vendored
@ -152,14 +152,14 @@ int mbedtls_x25519_make_public( mbedtls_x25519_context *ctx, size_t *olen,
|
|||||||
int( *f_rng )(void *, unsigned char *, size_t),
|
int( *f_rng )(void *, unsigned char *, size_t),
|
||||||
void *p_rng )
|
void *p_rng )
|
||||||
{
|
{
|
||||||
|
int ret = 0;
|
||||||
unsigned char base[MBEDTLS_X25519_KEY_SIZE_BYTES] = { 0 };
|
unsigned char base[MBEDTLS_X25519_KEY_SIZE_BYTES] = { 0 };
|
||||||
|
|
||||||
/* CMW: Is it okay that f_rng, p_rng are not used? */
|
|
||||||
(( void )f_rng);
|
|
||||||
(( void )p_rng);
|
|
||||||
|
|
||||||
if( ctx == NULL )
|
if( ctx == NULL )
|
||||||
return(MBEDTLS_ERR_ECP_BAD_INPUT_DATA);
|
return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
|
||||||
|
|
||||||
|
if( ( ret = f_rng( p_rng, ctx->our_secret, MBEDTLS_X25519_KEY_SIZE_BYTES ) ) != 0 )
|
||||||
|
return ret;
|
||||||
|
|
||||||
*olen = 33;
|
*olen = 33;
|
||||||
if( blen < *olen )
|
if( blen < *olen )
|
||||||
@ -173,7 +173,7 @@ int mbedtls_x25519_make_public( mbedtls_x25519_context *ctx, size_t *olen,
|
|||||||
if( memcmp( buf, base, MBEDTLS_X25519_KEY_SIZE_BYTES ) == 0 )
|
if( memcmp( buf, base, MBEDTLS_X25519_KEY_SIZE_BYTES ) == 0 )
|
||||||
return MBEDTLS_ERR_ECP_RANDOM_FAILED;
|
return MBEDTLS_ERR_ECP_RANDOM_FAILED;
|
||||||
|
|
||||||
return(0);
|
return( ret );
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_x25519_read_public( mbedtls_x25519_context *ctx,
|
int mbedtls_x25519_read_public( mbedtls_x25519_context *ctx,
|
||||||
@ -184,7 +184,7 @@ int mbedtls_x25519_read_public( mbedtls_x25519_context *ctx,
|
|||||||
if( (*buf++ != MBEDTLS_X25519_KEY_SIZE_BYTES) )
|
if( (*buf++ != MBEDTLS_X25519_KEY_SIZE_BYTES) )
|
||||||
return(MBEDTLS_ERR_ECP_BAD_INPUT_DATA);
|
return(MBEDTLS_ERR_ECP_BAD_INPUT_DATA);
|
||||||
memcpy( ctx->peer_point, buf, MBEDTLS_X25519_KEY_SIZE_BYTES );
|
memcpy( ctx->peer_point, buf, MBEDTLS_X25519_KEY_SIZE_BYTES );
|
||||||
return(0);
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1028,16 +1028,9 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
|
#if defined(MBEDTLS_ECDH_LEGACY_CONTEXT)
|
||||||
CHECK_AND_CONTINUE( mbedtls_ecp_group_load(&ecdh_srv.grp, curve_info->grp_id));
|
CHECK_AND_CONTINUE( mbedtls_ecp_group_load(&ecdh_srv.grp, curve_info->grp_id));
|
||||||
CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public(&ecdh_srv.grp,
|
|
||||||
&ecdh_srv.d,
|
|
||||||
&ecdh_srv.Q, myrand, NULL));
|
|
||||||
#else
|
#else
|
||||||
if( ecdh_srv.var == MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0 ) {
|
if( ecdh_srv.var == MBEDTLS_ECDH_VARIANT_MBEDTLS_2_0 )
|
||||||
CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh_srv.ctx.mbed_ecdh.grp, curve_info->grp_id ));
|
CHECK_AND_CONTINUE( mbedtls_ecp_group_load( &ecdh_srv.ctx.mbed_ecdh.grp, curve_info->grp_id ));
|
||||||
CHECK_AND_CONTINUE( mbedtls_ecdh_gen_public( &ecdh_srv.ctx.mbed_ecdh.grp,
|
|
||||||
&ecdh_srv.ctx.mbed_ecdh.d,
|
|
||||||
&ecdh_srv.ctx.mbed_ecdh.Q, myrand, NULL ));
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", curve_info->name );
|
mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", curve_info->name );
|
||||||
|
Loading…
Reference in New Issue
Block a user