(struct ecc_modulo): Renamed corresponding function pointer to
sqrt_ratio. Updated all uses.
+2021-10-28 Niels Möller <nisse@lysator.liu.se>
+
+ * ecc-mod-arith.c (ecc_mod_equal_p): New function, moved from
+ ecc-modinv-test.c. Based on patch by Wim Lewis.
+ * testsuite/ecc-modinv-test.c (mod_eq_p): Deleted, replaced with ecc_mod_equal_p.
+
2021-10-26 Niels Möller <nisse@lysator.liu.se>
* ecc-mod-arith.c (ecc_mod_zero_p): New function.
#define ecc_pp1_redc _nettle_ecc_pp1_redc
#define ecc_pm1_redc _nettle_ecc_pm1_redc
#define ecc_mod_zero_p _nettle_ecc_mod_zero_p
+#define ecc_mod_equal_p _nettle_ecc_mod_equal_p
#define ecc_mod_add _nettle_ecc_mod_add
#define ecc_mod_sub _nettle_ecc_mod_sub
#define ecc_mod_mul_1 _nettle_ecc_mod_mul_1
int
ecc_mod_zero_p (const struct ecc_modulo *m, const mp_limb_t *xp);
+/* Requires that a < 2m, and ref < m, needs m->size limbs of scratch
+ space. Overlap, a == scratch or ref == scratch, is allowed. */
+int
+ecc_mod_equal_p (const struct ecc_modulo *m, const mp_limb_t *a,
+ const mp_limb_t *ref, mp_limb_t *scratch);
+
void
ecc_mod_add (const struct ecc_modulo *m, mp_limb_t *rp,
const mp_limb_t *ap, const mp_limb_t *bp);
return (is_non_zero == 0) | (is_not_p == 0);
}
+int
+ecc_mod_equal_p (const struct ecc_modulo *m, const mp_limb_t *a,
+ const mp_limb_t *ref, mp_limb_t *scratch)
+{
+ mp_limb_t cy;
+ cy = mpn_sub_n (scratch, a, ref, m->size);
+ /* If cy > 0, i.e., a < ref, then they can't be equal mod m. */
+ return (cy == 0) & ecc_mod_zero_p (m, scratch);
+}
+
void
ecc_mod_add (const struct ecc_modulo *m, mp_limb_t *rp,
const mp_limb_t *ap, const mp_limb_t *bp)
return res;
}
-/* Requires that a < 2m, and ref < m. */
-static int
-mod_eq_p (const struct ecc_modulo *m, const mp_limb_t *a, const mp_limb_t *ref,
- mp_limb_t *scratch) {
- mp_limb_t cy;
- assert (mpn_cmp (ref, m->m, m->size) < 0);
- cy = mpn_sub_n (scratch, a, ref, m->size);
- /* If cy > 0, i.e., a < ref, then they can't be equal mod m. */
- return (cy == 0) & ecc_mod_zero_p (m, scratch);
-
-}
-
#define MAX_ECC_SIZE (1 + 521 / GMP_NUMB_BITS)
#define COUNT 500
continue;
}
m->invert (m, ai, a, scratch);
- if (!mod_eq_p (m, ai, ref, scratch))
+ if (!ecc_mod_equal_p (m, ai, ref, scratch))
{
fprintf (stderr, "%s->invert failed (test %u, bit size %u):\n",
name, j, m->bit_size);