From bfa1972b4fa47c9c6ce0230829109b42c4bc2ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 23 Aug 2017 17:39:18 +0200 Subject: [PATCH] Remove redundant checks, save a few muls ecp_mul() already checks for this, and this check is not going away, so no need to do it twice (didn't even result in better error reporting) --- library/ecdh.c | 5 ----- library/ecdsa.c | 9 ++------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/library/ecdh.c b/library/ecdh.c index b8a7dbf0a..25a788b93 100644 --- a/library/ecdh.c +++ b/library/ecdh.c @@ -87,11 +87,6 @@ static int ecdh_compute_shared_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point_init( &P ); - /* - * Make sure Q is a valid pubkey before using it - */ - MBEDTLS_MPI_CHK( mbedtls_ecp_check_pubkey( grp, Q ) ); - MBEDTLS_MPI_CHK( mbedtls_ecp_mul_restartable( grp, &P, d, Q, f_rng, p_rng, rs_ctx ) ); diff --git a/library/ecdsa.c b/library/ecdsa.c index 835d3de88..3fddc4e4d 100644 --- a/library/ecdsa.c +++ b/library/ecdsa.c @@ -498,13 +498,6 @@ static int ecdsa_verify_restartable( mbedtls_ecp_group *grp, goto cleanup; } - /* - * Additional precaution: make sure Q is valid - * For ops count, group that together with step 4 - */ - ECDSA_BUDGET( MBEDTLS_ECP_OPS_CHK + MBEDTLS_ECP_OPS_INV + 2 ); - MBEDTLS_MPI_CHK( mbedtls_ecp_check_pubkey( grp, Q ) ); - /* * Step 3: derive MPI from hashed message */ @@ -513,6 +506,8 @@ static int ecdsa_verify_restartable( mbedtls_ecp_group *grp, /* * Step 4: u1 = e / s mod n, u2 = r / s mod n */ + ECDSA_BUDGET( MBEDTLS_ECP_OPS_CHK + MBEDTLS_ECP_OPS_INV + 2 ); + MBEDTLS_MPI_CHK( mbedtls_mpi_inv_mod( &s_inv, s, &grp->N ) ); MBEDTLS_MPI_CHK( mbedtls_mpi_mul_mpi( pu1, &e, &s_inv ) );