]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Delete function mpz_limbs_cmp.
authorNiels Möller <nisse@lysator.liu.se>
Fri, 19 Nov 2021 20:46:56 +0000 (21:46 +0100)
committerNiels Möller <nisse@lysator.liu.se>
Fri, 19 Nov 2021 20:46:56 +0000 (21:46 +0100)
ChangeLog
ecc-point.c
ecc-scalar.c
gmp-glue.c
gmp-glue.h
testsuite/ecdsa-sign-test.c
testsuite/gostdsa-sign-test.c
testsuite/testutils.c

index 1d00edf1cb51dd1ff7569d0f436cef5550ceef50..cac37f2ea60225032d75dcb4c3ce5f3015358dd2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-11-19  Niels Möller  <nisse@lysator.liu.se>
+
+       * gmp-glue.c (mpz_limbs_cmp): Deleted function. Usage replaced
+       with mpz_roinit_n and mpz_cmp.
+
 2021-11-15  Niels Möller  <nisse@lysator.liu.se>
 
        * testsuite/eddsa-compress-test.c (test_main): Use test_randomize.
index 4733b3447ce9cd793e88245c4c3a1fef8ccc1e50..f5aa9236e291fc5a683a1e6717e19e374523f8ea 100644 (file)
@@ -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);
index 2111ea298aaac409e269065231faa1f4f9965a04..eae90933f5dfa2141fc6498e69c7c1ac70f3b65c 100644 (file)
@@ -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);
index 2d8f3d506bc970f38b11f3ffb0be18793bf2236b..08f5b255d1562e9ada329815371ff7dca3a9cb80 100644 (file)
@@ -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. */
index ac2f9a3aaeeab8de5030fdb81aa4f8821498ed81..eaeed6c2e6bd51d9a3c68555673ed020553a6093 100644 (file)
@@ -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
index 08a10a1d22662f71d7b142c8af7b58bad8a1beb8..ba031fbf24cf4b318b717a230c1d4080e42b80b8 100644 (file)
@@ -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     = ");
index 0e2e0420a3133fe7440b18ff782ed974d1d3a338..dc1154b4194c356c40d163193def972b86a6372c 100644 (file)
@@ -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     = ");
index ef67c53ee905ea21596cd8404a0caa09cd0b09c7..9bb250b4e74debecc38fbeffd607ce85de1e4b88 100644 (file)
@@ -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;
 }