From 57a5c8bff768f2ceb9ca1f289de5597cd317a744 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Sat, 25 Apr 2020 20:27:57 +0200
Subject: [PATCH] Delete compatibility definitions of mpz_limbs_read and
 friends.

---
 ChangeLog  |  6 +++++
 bignum.h   |  2 --
 gmp-glue.c | 77 ------------------------------------------------------
 gmp-glue.h | 48 ----------------------------------
 4 files changed, 6 insertions(+), 127 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f2f46ed6..f92c0268 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-04-25  Niels Möller  <nisse@lysator.liu.se>
 
+	* gmp-glue.c (mpz_limbs_read, mpz_limbs_write, mpz_limbs_modify)
+	(mpz_limbs_finish, mpz_roinit_n): Delete compatibility
+	definitions. These functions available in GMP since version 6.0.0.
+	* gmp-glue.h: Delete corresponding declarations, and preprocessor
+	conditions.
+
 	* configure.ac: Update required version of GMP to 6.1.0, needed
 	for mpn_zero_p.
 	* ecc-ecdsa-verify.c (zero_p): Deleted static function, usage
diff --git a/bignum.h b/bignum.h
index 6daeeb5f..94ca436d 100644
--- a/bignum.h
+++ b/bignum.h
@@ -44,8 +44,6 @@
 
 # define GMP_NUMB_MASK (~(mp_limb_t) 0)
 
-/* Function missing in older gmp versions, and checked for with ifdef */
-# define mpz_limbs_read mpz_limbs_read
 /* Side-channel silent powm not available in mini-gmp. */
 # define mpz_powm_sec mpz_powm
 #else
diff --git a/gmp-glue.c b/gmp-glue.c
index 805b50c4..8819601f 100644
--- a/gmp-glue.c
+++ b/gmp-glue.c
@@ -39,83 +39,6 @@
 
 #include "gmp-glue.h"
 
-#if !GMP_HAVE_mpz_limbs_read
-
-/* This implementation tries to make a minimal use of GMP internals.
-   We access and _mp_size and _mp_d, but not _mp_alloc. */
-
-/* Use macros compatible with gmp-impl.h. */
-#define ABS(x) ((x) >= 0 ? (x) : -(x))
-#define PTR(x) ((x)->_mp_d)
-#define SIZ(x) ((x)->_mp_size)
-#define ABSIZ(x) ABS (SIZ (x))
-
-#define MPN_NORMALIZE(xp, xn) do {		\
-    while ( (xn) > 0 && (xp)[xn-1] == 0)	\
-      (xn)--;					\
-  }  while (0)
-
-/* NOTE: Makes an unnecessary realloc if allocation is already large
-   enough, but looking at _mp_alloc may break in future GMP
-   versions. */
-#define MPZ_REALLOC(x, n) \
-  (ABSIZ(x) >= (n) ? PTR(x) : (_mpz_realloc ((x),(n)), PTR (x)))
-
-#define MPZ_NEWALLOC MPZ_REALLOC
-
-/* Read access to mpz numbers. */
-
-/* Return limb pointer, for read-only operations. Use mpz_size to get
-   the number of limbs. */
-const mp_limb_t *
-mpz_limbs_read (mpz_srcptr x)
-{
-  return PTR (x);
-}
-
-/* Write access to mpz numbers. */
-
-/* Get a limb pointer for writing, previous contents may be
-   destroyed. */
-mp_limb_t *
-mpz_limbs_write (mpz_ptr x, mp_size_t n)
-{
-  assert (n > 0);
-  return MPZ_NEWALLOC (x, n);
-}
-
-/* Get a limb pointer for writing, previous contents is intact. */
-mp_limb_t *
-mpz_limbs_modify (mpz_ptr x, mp_size_t n)
-{
-  assert (n > 0);
-  return MPZ_REALLOC (x, n);
-}
-
-void
-mpz_limbs_finish (mpz_ptr x, mp_size_t n)
-{
-  assert (n >= 0);
-  MPN_NORMALIZE (PTR(x), n);
-
-  SIZ (x) = n;
-}
-
-/* Needs some ugly casts. */
-mpz_srcptr
-mpz_roinit_n (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs)
-{
-  mp_size_t xn = ABS (xs);
-  
-  MPN_NORMALIZE (xp, xn);
-
-  x->_mp_size = xs < 0 ? -xn : xn;
-  x->_mp_alloc = 0;
-  x->_mp_d = (mp_limb_t *) xp;
-  return x;
-}
-#endif /* !GMP_HAVE_mpz_limbs_read */
-
 void
 cnd_swap (mp_limb_t cnd, mp_limb_t *ap, mp_limb_t *bp, mp_size_t n)
 {
diff --git a/gmp-glue.h b/gmp-glue.h
index 7f42cc2b..4dfcb384 100644
--- a/gmp-glue.h
+++ b/gmp-glue.h
@@ -35,21 +35,6 @@
 
 #include "bignum.h"
 
-#ifdef mpz_limbs_read
-#define GMP_HAVE_mpz_limbs_read 1
-#else
-#define GMP_HAVE_mpz_limbs_read 0
-#endif
-
-/* Name mangling. */
-#if !GMP_HAVE_mpz_limbs_read
-#define mpz_limbs_read _nettle_mpz_limbs_read
-#define mpz_limbs_write _nettle_mpz_limbs_write
-#define mpz_limbs_modify _nettle_mpz_limbs_modify
-#define mpz_limbs_finish _nettle_mpz_limbs_finish
-#define mpz_roinit_n _nettle_mpz_roinit_n
-#endif
-
 #define cnd_swap _nettle_cnd_swap
 #define mpz_limbs_cmp _nettle_mpz_limbs_cmp
 #define mpz_limbs_read_n _nettle_mpz_limbs_read_n
@@ -85,39 +70,6 @@
 #define NETTLE_OCTET_SIZE_TO_LIMB_SIZE(n) \
   (((n) * 8 + GMP_NUMB_BITS - 1) / GMP_NUMB_BITS)
 
-/* Some functions for interfacing between mpz and mpn code. Signs of
-   the mpz numbers are generally ignored. */
-
-#if !GMP_HAVE_mpz_limbs_read
-/* Read access to mpz numbers. */
-
-/* Return limb pointer, for read-only operations. Use mpz_size to get
-   the number of limbs. */
-const mp_limb_t *
-mpz_limbs_read (const mpz_srcptr x);
-
-/* Write access to mpz numbers. */
-
-/* Get a limb pointer for writing, previous contents may be
-   destroyed. */
-mp_limb_t *
-mpz_limbs_write (mpz_ptr x, mp_size_t n);
-
-/* Get a limb pointer for writing, previous contents is intact. */
-mp_limb_t *
-mpz_limbs_modify (mpz_ptr x, mp_size_t n);
-
-/* Update size. */
-void
-mpz_limbs_finish (mpz_ptr x, mp_size_t n);
-
-/* Using an mpn number as an mpz. Can be used for read-only access
-   only. x must not be cleared or reallocated. */
-mpz_srcptr
-mpz_roinit_n (mpz_ptr x, const mp_limb_t *xp, mp_size_t xs);
-
-#endif /* !GMP_HAVE_mpz_limbs_read */
-
 void
 cnd_swap (mp_limb_t cnd, mp_limb_t *ap, mp_limb_t *bp, mp_size_t n);
 
-- 
GitLab