From ffe0f5871fcac544e5daf8e139b294811e3faef0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Niels=20M=C3=B6ller?= Date: Thu, 11 Nov 2021 21:43:13 +0100 Subject: [PATCH] eccdata: Output ecc_sqrt_z and ECC_SQRT_E only when computed. --- ChangeLog | 3 +++ eccdata.c | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7091ce53..b461a5a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2021-11-11 Niels Möller + * 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. diff --git a/eccdata.c b/eccdata.c index b20fef2c..a7e7e18a 100644 --- 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)); -- 2.47.2