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.
{
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;
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);
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));
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));