]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
eccdata: Output ecc_sqrt_z and ECC_SQRT_E only when computed.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 11 Nov 2021 20:43:13 +0000 (21:43 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Thu, 11 Nov 2021 20:43:13 +0000 (21:43 +0100)
ChangeLog
eccdata.c

index 7091ce53bfcb49043e7868a4e9fe7a1086fb57e1..b461a5a30eb942038df76874e83753c724240b22 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2021-11-11  Niels Möller  <nisse@lysator.liu.se>
 
+       * eccdata.c (output_curve): Output ecc_sqrt_z and ECC_SQRT_E only
+       when computed. Fixes uninitialized value bug from previous change.
+
        * ecc-secp384r1.c (ecc_mod_pow_288m32m1): New function.
        (ecc_secp384r1_inv): Use ecc_mod_pow_288m32m1.
        (ecc_secp384r1_sqrt): Likewise.
index b20fef2c2e836957db0c4ad0fed405b48b32c55b..a7e7e18a94f490aea3ae7af40f3808487762b180 100644 (file)
--- a/eccdata.c
+++ b/eccdata.c
@@ -1175,7 +1175,7 @@ output_curve (const struct ecc_curve *ecc, unsigned bits_per_limb)
 {
   unsigned limb_size = (ecc->bit_size + bits_per_limb - 1)/bits_per_limb;
   unsigned i;
-  unsigned bits, e;
+  unsigned bits;
   int redc_limbs;
   mpz_t t;
   mpz_t z;
@@ -1313,7 +1313,7 @@ output_curve (const struct ecc_curve *ecc, unsigned bits_per_limb)
   else
     {
       /* p-1 = 2^e s, s odd, t = (s-1)/2*/
-      unsigned g, i;
+      unsigned g, i, e;
       mpz_t s;
 
       mpz_init (s);
@@ -1347,12 +1347,12 @@ output_curve (const struct ecc_curve *ecc, unsigned bits_per_limb)
       mpz_fdiv_q_2exp (t, s, 1);
 
       mpz_clear (s);
+      printf ("#define ECC_SQRT_E %u\n", e);
     }
-  printf ("#define ECC_SQRT_E %u\n", e);
-
   printf ("#if USE_REDC\n");
   printf ("#define ecc_unit ecc_Bmodp\n");
-  output_bignum_redc ("ecc_sqrt_z", z, ecc->p, limb_size, bits_per_limb);
+  if (mpz_sgn(z) > 0)
+    output_bignum_redc ("ecc_sqrt_z", z, ecc->p, limb_size, bits_per_limb);
 
   printf ("static const mp_limb_t ecc_table[%lu] = {",
         (unsigned long) (2*ecc->table_size * limb_size));
@@ -1365,7 +1365,8 @@ output_curve (const struct ecc_curve *ecc, unsigned bits_per_limb)
 
   mpz_set_ui (t, 1);
   output_bignum ("ecc_unit", t, limb_size, bits_per_limb);
-  output_bignum ("ecc_sqrt_z", z, limb_size, bits_per_limb);
+  if (mpz_sgn(z) > 0)
+    output_bignum ("ecc_sqrt_z", z, limb_size, bits_per_limb);
   
   printf ("static const mp_limb_t ecc_table[%lu] = {",
         (unsigned long) (2*ecc->table_size * limb_size));