[PATCH 1/4] mpi_ec_get_affine: fast path for Z==1 case

Jussi Kivilinna jussi.kivilinna at iki.fi
Sun Jun 20 11:52:11 CEST 2021


* 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 <jussi.kivilinna at iki.fi>
---
 mpi/ec.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

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);
 
-- 
2.30.2




More information about the Gcrypt-devel mailing list