summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--ecc-internal.h7
-rw-r--r--ecc-mod-arith.c10
-rw-r--r--testsuite/ecc-modinv-test.c14
4 files changed, 24 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 4cc12d7a..6c59e38d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -39,6 +39,12 @@
(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.
diff --git a/ecc-internal.h b/ecc-internal.h
index 277f5a02..2ea553b5 100644
--- a/ecc-internal.h
+++ b/ecc-internal.h
@@ -43,6 +43,7 @@
#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
@@ -248,6 +249,12 @@ ecc_mod_inv_func ecc_mod_inv;
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);
diff --git a/ecc-mod-arith.c b/ecc-mod-arith.c
index 0b0631af..310cbb1d 100644
--- a/ecc-mod-arith.c
+++ b/ecc-mod-arith.c
@@ -58,6 +58,16 @@ ecc_mod_zero_p (const struct ecc_modulo *m, const mp_limb_t *xp_in)
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)
diff --git a/testsuite/ecc-modinv-test.c b/testsuite/ecc-modinv-test.c
index b9993e02..a30f182e 100644
--- a/testsuite/ecc-modinv-test.c
+++ b/testsuite/ecc-modinv-test.c
@@ -38,18 +38,6 @@ ref_modinv (mp_limb_t *rp, const mp_limb_t *ap,
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
@@ -120,7 +108,7 @@ test_modulo (gmp_randstate_t rands, const char *name,
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);