From 38d80fdfddd027fe87bf5508e453d3e2cdbaa337 Mon Sep 17 00:00:00 2001 From: Jussi Kivilinna Date: Wed, 16 Jun 2021 20:27:15 +0300 Subject: mpi_ec_get_affine: fast path for Z==1 case * mpi/ec.c (_gcry_mpi_ec_get_affine): Return X and Y as is if Z is 1 (for Weierstrass and Edwards curves). -- Signed-off-by: Jussi Kivilinna --- mpi/ec.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'mpi') diff --git a/mpi/ec.c b/mpi/ec.c index 29b2ce30..e25d9d8a 100644 --- a/mpi/ec.c +++ b/mpi/ec.c @@ -1117,6 +1117,15 @@ _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t point, { gcry_mpi_t z1, z2, z3; + if (!mpi_cmp_ui (point->z, 1)) + { + if (x) + mpi_set (x, point->x); + if (y) + mpi_set (y, point->y); + return 0; + } + z1 = mpi_new (0); z2 = mpi_new (0); ec_invm (z1, point->z, ctx); /* z1 = z^(-1) mod p */ @@ -1156,6 +1165,15 @@ _gcry_mpi_ec_get_affine (gcry_mpi_t x, gcry_mpi_t y, mpi_point_t point, { gcry_mpi_t z; + if (!mpi_cmp_ui (point->z, 1)) + { + if (x) + mpi_set (x, point->x); + if (y) + mpi_set (y, point->y); + return 0; + } + z = mpi_new (0); ec_invm (z, point->z, ctx); -- cgit v1.2.1