From ca09d73cb2de70c509f283c66d88a7e8369abc5f Mon Sep 17 00:00:00 2001
From: Andreas Enge <andreas.enge@inria.fr>
Date: Mon, 7 Aug 2023 10:16:45 +0200
Subject: [PATCH] Remove an unused variable.

Reported by Paul Underwood.

* lib/curve.c (elliptic_curve_random): Remove variable. Clarify test.
---
 lib/curve.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/curve.c b/lib/curve.c
index d1c8ab0..47fc6e6 100644
--- a/lib/curve.c
+++ b/lib/curve.c
@@ -474,11 +474,9 @@ static void elliptic_curve_random (mpz_ptr P_x, mpz_ptr P_y,
       The point is not really random, since successive X-coordinates from
       1 on are tested. */
 {
-   mpz_t  tmp;
    long unsigned int P_x_long = 0;
    bool P_infty = true;
 
-   mpz_init (tmp);
    while (P_infty) {
       P_x_long++;
       /* P_y = P_x^3 + a P_x + b */
@@ -487,7 +485,7 @@ static void elliptic_curve_random (mpz_ptr P_x, mpz_ptr P_y,
       mpz_add_ui (P_y, P_y, P_x_long * P_x_long * P_x_long);
       mpz_mod (P_y, P_y, p);
       /* try to compute the square root of P_y */
-      if (mpz_jacobi (P_y, p) != -1) {
+      if (mpz_jacobi (P_y, p) == 1) {
          mpz_set_ui (P_x, P_x_long);
          cm_nt_mpz_tonelli (P_y, P_y, p);
          /* get rid of the cofactor */
@@ -495,7 +493,6 @@ static void elliptic_curve_random (mpz_ptr P_x, mpz_ptr P_y,
          elliptic_curve_multiply (P_x, P_y, &P_infty, cofactor, a, p);
       }
    }
-   mpz_clear (tmp);
 }
 
 /*****************************************************************************/
-- 
GitLab