From efdf4d7baa25762e7564738333492ad8876278b9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Wintersteiger" Date: Fri, 15 Feb 2019 17:21:04 +0000 Subject: [PATCH] ECDH: Fix Everest x25519 make_public --- 3rdparty/everest/library/x25519.c | 14 +++++++------- programs/test/benchmark.c | 9 +-------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/3rdparty/everest/library/x25519.c b/3rdparty/everest/library/x25519.c index e5ec2e832..edaf5da1d 100644 --- a/3rdparty/everest/library/x25519.c +++ b/3rdparty/everest/library/x25519.c @@ -152,14 +152,14 @@ int mbedtls_x25519_make_public( mbedtls_x25519_context *ctx, size_t *olen, int( *f_rng )(void *, unsigned char *, size_t), void *p_rng ) { + int ret = 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 ) - 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; 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 ) return MBEDTLS_ERR_ECP_RANDOM_FAILED; - return(0); + return( ret ); } 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) ) return(MBEDTLS_ERR_ECP_BAD_INPUT_DATA); memcpy( ctx->peer_point, buf, MBEDTLS_X25519_KEY_SIZE_BYTES ); - return(0); + return( 0 ); } diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c index 7cdff10b1..244174ddf 100644 --- a/programs/test/benchmark.c +++ b/programs/test/benchmark.c @@ -1028,16 +1028,9 @@ int main( int argc, char *argv[] ) #if defined(MBEDTLS_ECDH_LEGACY_CONTEXT) 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 - 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_ecdh_gen_public( &ecdh_srv.ctx.mbed_ecdh.grp, - &ecdh_srv.ctx.mbed_ecdh.d, - &ecdh_srv.ctx.mbed_ecdh.Q, myrand, NULL )); - } #endif mbedtls_snprintf( title, sizeof( title ), "ECDHE-%s", curve_info->name );