+2021-11-10 Niels Möller <nisse@lysator.liu.se>
+
+ * eccdata.c (output_bignum_redc): New function.
+ (output_curve): Generate both redc and non-redc versions of
+ ecc_sqrt_z. Fixes secp224r1 sqrt, in configs using redc.
+
2021-11-08 Niels Möller <nisse@lysator.liu.se>
Square root functions, based on patch by Wim Lewis.
printf("\n};\n");
}
+static void
+output_bignum_redc (const char *name, const mpz_t x, const mpz_t p,
+ unsigned size, unsigned bits_per_limb)
+{
+ mpz_t t;
+ mpz_init (t);
+ mpz_mul_2exp (t, x, size * bits_per_limb);
+ mpz_mod (t, t, p);
+ output_bignum (name, t, size, bits_per_limb);
+}
+
static void
output_point (const struct ecc_curve *ecc,
const struct ecc_point *p, int use_redc,
unsigned bits, e;
int redc_limbs;
mpz_t t;
+ mpz_t z;
mpz_init (t);
+ mpz_init (z);
printf ("/* For NULL. */\n#include <stddef.h>\n");
/* p-1 = 2^e s, s odd, t = (s-1)/2*/
unsigned g, i;
mpz_t s;
- mpz_t z;
mpz_init (s);
- mpz_init (z);
mpz_sub_ui (s, ecc->p, 1);
e = mpz_scan1 (s, 0);
}
mpz_add_ui (t, t, 1);
assert (mpz_cmp (t, ecc->p) == 0);
- output_bignum ("ecc_sqrt_z", z, limb_size, bits_per_limb);
mpz_fdiv_q_2exp (t, s, 1);
mpz_clear (s);
- mpz_clear (z);
}
printf ("#define ECC_SQRT_E %u\n", e);
printf ("#define ECC_SQRT_T_BITS %u\n",
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);
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);
printf ("static const mp_limb_t ecc_table[%lu] = {",
(unsigned long) (2*ecc->table_size * limb_size));
printf ("#endif\n");
mpz_clear (t);
+ mpz_clear (z);
}
int