From: Niels Möller Date: Fri, 19 Nov 2021 20:46:56 +0000 (+0100) Subject: Delete function mpz_limbs_cmp. X-Git-Tag: nettle_3.8_release_20220602~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd5662399b985f6f0b127840b2173c73c2855e15;p=thirdparty%2Fnettle.git Delete function mpz_limbs_cmp. --- diff --git a/ChangeLog b/ChangeLog index 1d00edf1..cac37f2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2021-11-19 Niels Möller + + * gmp-glue.c (mpz_limbs_cmp): Deleted function. Usage replaced + with mpz_roinit_n and mpz_cmp. + 2021-11-15 Niels Möller * testsuite/eddsa-compress-test.c (test_main): Use test_randomize. diff --git a/ecc-point.c b/ecc-point.c index 4733b344..f5aa9236 100644 --- a/ecc-point.c +++ b/ecc-point.c @@ -55,14 +55,15 @@ int ecc_point_set (struct ecc_point *p, const mpz_t x, const mpz_t y) { mp_size_t size; - mpz_t lhs, rhs; + mpz_t m, lhs, rhs; mpz_t t; int res; size = p->ecc->p.size; + mpz_roinit_n (m, p->ecc->p.m, size); - if (mpz_sgn (x) < 0 || mpz_limbs_cmp (x, p->ecc->p.m, size) >= 0 - || mpz_sgn (y) < 0 || mpz_limbs_cmp (y, p->ecc->p.m, size) >= 0) + if (mpz_sgn (x) < 0 || mpz_cmp (x, m) >= 0 + || mpz_sgn (y) < 0 || mpz_cmp (y, m) >= 0) return 0; mpz_init (lhs); diff --git a/ecc-scalar.c b/ecc-scalar.c index 2111ea29..eae90933 100644 --- a/ecc-scalar.c +++ b/ecc-scalar.c @@ -55,8 +55,8 @@ int ecc_scalar_set (struct ecc_scalar *s, const mpz_t z) { mp_size_t size = s->ecc->p.size; - - if (mpz_sgn (z) <= 0 || mpz_limbs_cmp (z, s->ecc->q.m, size) >= 0) + mpz_t t; + if (mpz_sgn (z) <= 0 || mpz_cmp (z, mpz_roinit_n(t, s->ecc->q.m, size)) >= 0) return 0; mpz_limbs_copy (s->p, z, size); diff --git a/gmp-glue.c b/gmp-glue.c index 2d8f3d50..08f5b255 100644 --- a/gmp-glue.c +++ b/gmp-glue.c @@ -115,23 +115,6 @@ sec_zero_p (const mp_limb_t *ap, mp_size_t n) /* Additional convenience functions. */ -int -mpz_limbs_cmp (mpz_srcptr a, const mp_limb_t *bp, mp_size_t bn) -{ - mp_size_t an = mpz_size (a); - assert (mpz_sgn (a) >= 0); - assert (bn >= 0); - - if (an < bn) - return -1; - if (an > bn) - return 1; - if (an == 0) - return 0; - - return mpn_cmp (mpz_limbs_read(a), bp, an); -} - /* Get a pointer to an n limb area, for read-only operation. n must be greater or equal to the current size, and the mpz is zero-padded if needed. */ diff --git a/gmp-glue.h b/gmp-glue.h index ac2f9a3a..eaeed6c2 100644 --- a/gmp-glue.h +++ b/gmp-glue.h @@ -35,7 +35,6 @@ #include "bignum.h" -#define mpz_limbs_cmp _nettle_mpz_limbs_cmp #define mpz_limbs_read_n _nettle_mpz_limbs_read_n #define mpz_limbs_copy _nettle_mpz_limbs_copy #define mpz_set_n _nettle_mpz_set_n @@ -78,8 +77,6 @@ sec_zero_p (const mp_limb_t *ap, mp_size_t n); (((n) * 8 + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS) /* Convenience functions */ -int -mpz_limbs_cmp (mpz_srcptr a, const mp_limb_t *bp, mp_size_t bn); /* Get a pointer to an n limb area, for read-only operation. n must be greater or equal to the current size, and the mpz is zero-padded if diff --git a/testsuite/ecdsa-sign-test.c b/testsuite/ecdsa-sign-test.c index 08a10a1d..ba031fbf 100644 --- a/testsuite/ecdsa-sign-test.c +++ b/testsuite/ecdsa-sign-test.c @@ -12,6 +12,7 @@ test_ecdsa (const struct ecc_curve *ecc, const char *r, const char *s) { struct dsa_signature ref; + mpz_t t; mpz_t z; mpz_t k; mp_limb_t *rp = xalloc_limbs (ecc->p.size); @@ -30,8 +31,8 @@ test_ecdsa (const struct ecc_curve *ecc, mpz_set_str (ref.r, r, 16); mpz_set_str (ref.s, s, 16); - if (mpz_limbs_cmp (ref.r, rp, ecc->p.size) != 0 - || mpz_limbs_cmp (ref.s, sp, ecc->p.size) != 0) + if (mpz_cmp (ref.r, mpz_roinit_n (t, rp, ecc->p.size)) != 0 + || mpz_cmp (ref.s, mpz_roinit_n (t, sp, ecc->p.size)) != 0) { fprintf (stderr, "_ecdsa_sign failed, bit_size = %u\n", ecc->p.bit_size); fprintf (stderr, "r = "); diff --git a/testsuite/gostdsa-sign-test.c b/testsuite/gostdsa-sign-test.c index 0e2e0420..dc1154b4 100644 --- a/testsuite/gostdsa-sign-test.c +++ b/testsuite/gostdsa-sign-test.c @@ -13,6 +13,7 @@ test_gostdsa (const struct ecc_curve *ecc, const char *r, const char *s) { struct dsa_signature ref; + mpz_t t; mpz_t z; mpz_t k; mp_limb_t *rp = xalloc_limbs (ecc->p.size); @@ -31,8 +32,8 @@ test_gostdsa (const struct ecc_curve *ecc, mpz_set_str (ref.r, r, 16); mpz_set_str (ref.s, s, 16); - if (mpz_limbs_cmp (ref.r, rp, ecc->p.size) != 0 - || mpz_limbs_cmp (ref.s, sp, ecc->p.size) != 0) + if (mpz_cmp (ref.r, mpz_roinit_n (t, rp, ecc->p.size)) != 0 + || mpz_cmp (ref.s, mpz_roinit_n (t, sp, ecc->p.size)) != 0) { fprintf (stderr, "_gostdsa_sign failed, bit_size = %u\n", ecc->p.bit_size); fprintf (stderr, "r = "); diff --git a/testsuite/testutils.c b/testsuite/testutils.c index ef67c53e..9bb250b4 100644 --- a/testsuite/testutils.c +++ b/testsuite/testutils.c @@ -1748,14 +1748,12 @@ const struct ecc_curve * const ecc_curves[] = { static int test_mpn (const char *ref, const mp_limb_t *xp, mp_size_t n) { - mpz_t r; + mpz_t r, x; int res; mpz_init_set_str (r, ref, 16); - while (n > 0 && xp[n-1] == 0) - n--; - res = (mpz_limbs_cmp (r, xp, n) == 0); + res = (mpz_cmp (r, mpz_roinit_n (x, xp, n)) == 0); mpz_clear (r); return res; }