[Gmp-commit] /var/hg/gmp: 7 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Mon Mar 21 12:34:53 CET 2011


details:   /var/hg/gmp/rev/7a626952c625
changeset: 14078:7a626952c625
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Mar 21 11:09:06 2011 +0100
description:
Prepend _ to local variables, protect parameters within () where necessary.

details:   /var/hg/gmp/rev/3938c382d22b
changeset: 14079:3938c382d22b
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Mar 21 11:23:43 2011 +0100
description:
(define_mpn): Add addcnd_n and subcnd_n.

details:   /var/hg/gmp/rev/6e24be9781ea
changeset: 14080:6e24be9781ea
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Mar 21 11:24:25 2011 +0100
description:
New file.

details:   /var/hg/gmp/rev/2a29e2280b77
changeset: 14081:2a29e2280b77
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Mar 21 11:24:36 2011 +0100
description:
Combine nails and non-nails functions.

details:   /var/hg/gmp/rev/0f21f249cf02
changeset: 14082:0f21f249cf02
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Mar 21 11:24:55 2011 +0100
description:
(gmp_mpn_functions): Add addcnd_n.

details:   /var/hg/gmp/rev/5f886fb5e4ce
changeset: 14083:5f886fb5e4ce
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Mar 21 12:34:14 2011 +0100
description:
(mpn_addcnd_n): Declare.

details:   /var/hg/gmp/rev/9891afa665ea
changeset: 14084:9891afa665ea
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Mon Mar 21 12:34:47 2011 +0100
description:
*** empty log message ***

diffstat:

 ChangeLog              |  10 +++++++
 configure.in           |   7 +++--
 gmp-impl.h             |  63 ++++++++++++++++++++++++++-----------------------
 mpn/asm-defs.m4        |   2 +
 mpn/generic/addcnd_n.c |  62 +++++++++++++++++++++++++++++++++++++++++++++++++
 mpn/generic/subcnd_n.c |  45 ++++++++--------------------------
 6 files changed, 122 insertions(+), 67 deletions(-)

diffs (296 lines):

diff -r 45291e14fc9e -r 9891afa665ea ChangeLog
--- a/ChangeLog	Mon Mar 21 10:21:12 2011 +0100
+++ b/ChangeLog	Mon Mar 21 12:34:47 2011 +0100
@@ -1,5 +1,15 @@
 2011-03-21  Torbjorn Granlund  <tege at gmplib.org>
 
+	* mpn/generic/addcnd_n.c: New file.
+	* mpn/asm-defs.m4 (define_mpn): Add addcnd_n and subcnd_n.
+	* configure.in (gmp_mpn_functions): Add addcnd_n.
+	* gmp-impl.h (mpn_addcnd_n): Declare.
+
+	* mpn/generic/subcnd_n.c: Combine nails and non-nails functions.
+
+	* gmp-impl.h (invert_pi1): Prepend _ to local variables, protect
+	parameters within () where necessary.
+
 	* mpn/asm-defs.m4 (define_mpn): Add div_qr_2.
 	* configure.in (gmp_mpn_functions): Reinsert mercurial-bug-removed
 	line.
diff -r 45291e14fc9e -r 9891afa665ea configure.in
--- a/configure.in	Mon Mar 21 10:21:12 2011 +0100
+++ b/configure.in	Mon Mar 21 12:34:47 2011 +0100
@@ -2512,8 +2512,9 @@
   add_n_sub_n addaddmul_1msb0"
 
 gmp_mpn_functions="$extra_functions					   \
-  add add_1 add_n sub sub_1 sub_n neg com mul_1 addmul_1		   \
-  submul_1 lshift rshift dive_1 diveby3 divis divrem divrem_1 divrem_2     \
+  add add_1 add_n sub sub_1 sub_n addcnd_n subcnd_n neg com		   \
+  mul_1 addmul_1 submul_1						   \
+  lshift rshift dive_1 diveby3 divis divrem divrem_1 divrem_2		   \
   fib2_ui mod_1 mod_34lsub1 mode1o pre_divrem_1 pre_mod_1 dump		   \
   mod_1_1 mod_1_2 mod_1_3 mod_1_4 lshiftc				   \
   mul mul_fft mul_n sqr mul_basecase sqr_basecase nussbaumer_mul	   \
@@ -2545,7 +2546,7 @@
   dcpi1_bdiv_q dcpi1_bdiv_qr						   \
   mu_bdiv_q mu_bdiv_qr							   \
   bdiv_q bdiv_qr							   \
-  divexact bdiv_dbm1c redc_1 redc_2 redc_n powm powlo powm_sec subcnd_n	   \
+  divexact bdiv_dbm1c redc_1 redc_2 redc_n powm powlo powm_sec		   \
   redc_1_sec trialdiv remove						   \
   and_n andn_n nand_n ior_n iorn_n nior_n xor_n xnor_n			   \
   copyi copyd zero							   \
diff -r 45291e14fc9e -r 9891afa665ea gmp-impl.h
--- a/gmp-impl.h	Mon Mar 21 10:21:12 2011 +0100
+++ b/gmp-impl.h	Mon Mar 21 12:34:47 2011 +0100
@@ -1427,13 +1427,16 @@
 __GMP_DECLSPEC void      mpn_powm_sec __GMP_PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr));
 #define   mpn_powm_sec_itch __MPN(powm_sec_itch)
 __GMP_DECLSPEC mp_size_t mpn_powm_sec_itch __GMP_PROTO ((mp_size_t, mp_size_t, mp_size_t));
-#define   mpn_subcnd_n __MPN(subcnd_n)
-__GMP_DECLSPEC mp_limb_t mpn_subcnd_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_limb_t));
 #define   mpn_tabselect __MPN(tabselect)
 __GMP_DECLSPEC void      mpn_tabselect __GMP_PROTO ((volatile mp_limb_t *, volatile mp_limb_t *, mp_size_t, mp_size_t, mp_size_t));
 #define mpn_redc_1_sec __MPN(redc_1_sec)
 __GMP_DECLSPEC void mpn_redc_1_sec __GMP_PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
 
+#define   mpn_addcnd_n __MPN(addcnd_n)
+__GMP_DECLSPEC mp_limb_t mpn_addcnd_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_limb_t));
+#define   mpn_subcnd_n __MPN(subcnd_n)
+__GMP_DECLSPEC mp_limb_t mpn_subcnd_n __GMP_PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t, mp_limb_t));
+
 #ifndef DIVEXACT_BY3_METHOD
 #if GMP_NUMB_BITS % 2 == 0 && ! defined (HAVE_NATIVE_mpn_divexact_by3c)
 #define DIVEXACT_BY3_METHOD 0	/* default to using mpn_bdiv_dbm1c */
@@ -2731,38 +2734,38 @@
 #ifndef invert_limb
 #define invert_limb(invxl,xl)                   \
   do {                                          \
-    mp_limb_t dummy;                            \
+    mp_limb_t _dummy;                            \
     ASSERT ((xl) != 0);                         \
-    udiv_qrnnd (invxl, dummy, ~(xl), ~CNST_LIMB(0), xl);  \
+    udiv_qrnnd (invxl, _dummy, ~(xl), ~CNST_LIMB(0), xl);  \
   } while (0)
 #endif
 
-#define invert_pi1(dinv, d1, d0)				\
-  do {								\
-    mp_limb_t v, p, t1, t0, mask;				\
-    invert_limb (v, d1);					\
-    p = d1 * v;							\
-    p += d0;							\
-    if (p < d0)							\
-      {								\
-	v--;							\
-	mask = -(mp_limb_t) (p >= d1);				\
-	p -= d1;						\
-	v += mask;						\
-	p -= mask & d1;						\
-      }								\
-    umul_ppmm (t1, t0, d0, v);					\
-    p += t1;							\
-    if (p < t1)							\
-      {								\
-        v--;							\
-	if (UNLIKELY (p >= d1))					\
-	  {							\
-	    if (p > d1 || t0 >= d0)				\
-	      v--;						\
-	  }							\
-      }								\
-    (dinv).inv32 = v;						\
+#define invert_pi1(dinv, d1, d0)					\
+  do {									\
+    mp_limb_t _v, _p, _t1, _t0, _mask;					\
+    invert_limb (_v, d1);						\
+    _p = (d1) * _v;							\
+    _p += (d0);								\
+    if (_p < (d0))							\
+      {									\
+	_v--;								\
+	_mask = -(mp_limb_t) (_p >= (d1));				\
+	_p -= (d1);							\
+	_v += _mask;							\
+	_p -= _mask & (d1);						\
+      }									\
+    umul_ppmm (_t1, _t0, d0, _v);					\
+    _p += _t1;								\
+    if (_p < _t1)							\
+      {									\
+        _v--;								\
+	if (UNLIKELY (_p >= (d1)))					\
+	  {								\
+	    if (_p > (d1) || _t0 >= (d0))				\
+	      _v--;							\
+	  }								\
+      }									\
+    (dinv).inv32 = _v;							\
   } while (0)
 
 
diff -r 45291e14fc9e -r 9891afa665ea mpn/asm-defs.m4
--- a/mpn/asm-defs.m4	Mon Mar 21 10:21:12 2011 +0100
+++ b/mpn/asm-defs.m4	Mon Mar 21 12:34:47 2011 +0100
@@ -1308,6 +1308,7 @@
 define_mpn(add_1)
 define_mpn(add_n)
 define_mpn(add_nc)
+define_mpn(addcnd_n)
 define_mpn(addlsh1_n)
 define_mpn(addlsh1_nc)
 define_mpn(addlsh2_n)
@@ -1426,6 +1427,7 @@
 define_mpn(sqr_diagonal)
 define_mpn(sqr_diag_addlsh1)
 define_mpn(sub_n)
+define_mpn(subcnd_n)
 define_mpn(sublsh1_n)
 define_mpn(sublsh1_nc)
 define_mpn(sublsh1_n_ip1)
diff -r 45291e14fc9e -r 9891afa665ea mpn/generic/addcnd_n.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpn/generic/addcnd_n.c	Mon Mar 21 12:34:47 2011 +0100
@@ -0,0 +1,62 @@
+/* mpn_addcnd_n -- Compute R = U + V if CND != 0 or R = U if CND == 0.
+   Both cases should take the same time and perform the exact same memory
+   accesses, since this function is intended to be used where side-chanell
+   attack resilience is relevant.
+
+   THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE.  IT IS ONLY
+   SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES.
+
+Copyright 1992, 1993, 1994, 1996, 2000, 2002, 2008, 2009, 2011 Free Software
+Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
+
+#include "gmp.h"
+#include "gmp-impl.h"
+
+mp_limb_t
+mpn_addcnd_n (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n, mp_limb_t cnd)
+{
+  mp_limb_t ul, vl, sl, rl, cy, cy1, cy2, mask;
+
+  ASSERT (n >= 1);
+  ASSERT (MPN_SAME_OR_SEPARATE_P (rp, up, n));
+  ASSERT (MPN_SAME_OR_SEPARATE_P (rp, vp, n));
+
+  mask = -(mp_limb_t) (cnd != 0);
+  cy = 0;
+  do
+    {
+      ul = *up++;
+      vl = *vp++ & mask;
+#if GMP_NAIL_BITS == 0
+      sl = ul + vl;
+      cy1 = sl < ul;
+      rl = sl + cy;
+      cy2 = rl < sl;
+      cy = cy1 | cy2;
+      *rp++ = rl;
+#else
+      rl = ul + vl;
+      rl += cy;
+      cy = rl >> GMP_NUMB_BITS;
+      *rp++ = rl & GMP_NUMB_MASK;
+#endif
+    }
+  while (--n != 0);
+
+  return cy;
+}
diff -r 45291e14fc9e -r 9891afa665ea mpn/generic/subcnd_n.c
--- a/mpn/generic/subcnd_n.c	Mon Mar 21 10:21:12 2011 +0100
+++ b/mpn/generic/subcnd_n.c	Mon Mar 21 12:34:47 2011 +0100
@@ -1,9 +1,12 @@
 /* mpn_subcnd_n -- Compute R = U - V if CND != 0 or R = U if CND == 0.
+   Both cases should take the same time and perform the exact same memory
+   accesses, since this function is intended to be used where side-chanell
+   attack resilience is relevant.
 
    THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE.  IT IS ONLY
    SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES.
 
-Copyright 1992, 1993, 1994, 1996, 2000, 2002, 2008, 2009 Free Software
+Copyright 1992, 1993, 1994, 1996, 2000, 2002, 2008, 2009, 2011 Free Software
 Foundation, Inc.
 
 This file is part of the GNU MP Library.
@@ -24,9 +27,6 @@
 #include "gmp.h"
 #include "gmp-impl.h"
 
-
-#if GMP_NAIL_BITS == 0
-
 mp_limb_t
 mpn_subcnd_n (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n, mp_limb_t cnd)
 {
@@ -42,44 +42,21 @@
     {
       ul = *up++;
       vl = *vp++ & mask;
+#if GMP_NAIL_BITS == 0
       sl = ul - vl;
       cy1 = sl > ul;
       rl = sl - cy;
       cy2 = rl > sl;
       cy = cy1 | cy2;
       *rp++ = rl;
+#else
+      rl = ul - vl;
+      rl -= cy;
+      cy = rl >> (GMP_LIMB_BITS - 1);
+      *rp++ = rl & GMP_NUMB_MASK;
+#endif
     }
   while (--n != 0);
 
   return cy;
 }
-
-#endif
-
-#if GMP_NAIL_BITS >= 1
-
-mp_limb_t
-mpn_subcnd_n (mp_ptr rp, mp_srcptr up, mp_srcptr vp, mp_size_t n, mp_limb_t cnd)
-{
-  mp_limb_t ul, vl, rl, cy, mask;
-
-  ASSERT (n >= 1);
-  ASSERT (MPN_SAME_OR_SEPARATE_P (rp, up, n));
-  ASSERT (MPN_SAME_OR_SEPARATE_P (rp, vp, n));
-
-  mask = -(mp_limb_t) (cnd != 0);
-  cy = 0;
-  do
-    {
-      ul = *up++;
-      vl = *vp++ & mask;
-      rl = ul - vl - cy;
-      cy = rl >> (GMP_LIMB_BITS - 1);
-      *rp++ = rl & GMP_NUMB_MASK;
-    }
-  while (--n != 0);
-
-  return cy;
-}
-
-#endif


More information about the gmp-commit mailing list