[Gmp-commit] /var/hg/gmp: Separate mpn_tabselect from mpn_powm_sec and prepar...

mercurial at gmplib.org mercurial at gmplib.org
Tue Nov 15 00:49:34 CET 2011


details:   /var/hg/gmp/rev/1df3d8fef666
changeset: 14440:1df3d8fef666
user:      Torbjorn Granlund <tege at gmplib.org>
date:      Tue Nov 15 00:49:29 2011 +0100
description:
Separate mpn_tabselect from mpn_powm_sec and prepare for asm support.

diffstat:

 ChangeLog               |  10 ++++++++++
 configure.in            |   5 ++++-
 mpn/asm-defs.m4         |   1 +
 mpn/generic/powm_sec.c  |  25 -------------------------
 mpn/generic/tabselect.c |  48 ++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 26 deletions(-)

diffs (151 lines):

diff -r c8ee6e9fb6f9 -r 1df3d8fef666 ChangeLog
--- a/ChangeLog	Sun Nov 13 21:33:48 2011 +0100
+++ b/ChangeLog	Tue Nov 15 00:49:29 2011 +0100
@@ -1,3 +1,13 @@
+2011-11-15  Torbjorn Granlund  <tege at gmplib.org>
+
+	* mpn/asm-defs.m4 (define_mpn): Add tabselect.
+
+	* configure.in (gmp_mpn_functions): Add tabselect.
+	(HAVE_NATIVE): Add entries for addncd_n, subcnd_n, tabselect.
+	
+	* mpn/generic/powm_sec.c: Remove mpn_tabselect implementation.
+	* mpn/generic/tabselect.c: New file with removed code.
+
 2011-11-13  Torbjorn Granlund  <tege at gmplib.org>
 
 	* tune/Makefile.am (TUNE_MPN_SRCS_BASIC): Add powm_sec.c.
diff -r c8ee6e9fb6f9 -r 1df3d8fef666 configure.in
--- a/configure.in	Sun Nov 13 21:33:48 2011 +0100
+++ b/configure.in	Tue Nov 15 00:49:29 2011 +0100
@@ -2640,7 +2640,7 @@
   divexact bdiv_dbm1c redc_1 redc_2 redc_n powm powlo powm_sec		   \
   trialdiv remove							   \
   and_n andn_n nand_n ior_n iorn_n nior_n xor_n xnor_n			   \
-  copyi copyd zero							   \
+  copyi copyd zero tabselect						   \
   $gmp_mpn_functions_optional"
 
 define(GMP_MULFUNC_CHOICES,
@@ -3103,6 +3103,7 @@
 #undef HAVE_NATIVE_mpn_add_n_sub_n
 #undef HAVE_NATIVE_mpn_add_nc
 #undef HAVE_NATIVE_mpn_addaddmul_1msb0
+#undef HAVE_NATIVE_mpn_addcnd_n
 #undef HAVE_NATIVE_mpn_addlsh1_n
 #undef HAVE_NATIVE_mpn_addlsh2_n
 #undef HAVE_NATIVE_mpn_addlsh_n
@@ -3191,6 +3192,7 @@
 #undef HAVE_NATIVE_mpn_sqr_diag_addlsh1
 #undef HAVE_NATIVE_mpn_sub_n
 #undef HAVE_NATIVE_mpn_sub_nc
+#undef HAVE_NATIVE_mpn_subcnd_n
 #undef HAVE_NATIVE_mpn_sublsh1_n
 #undef HAVE_NATIVE_mpn_sublsh2_n
 #undef HAVE_NATIVE_mpn_sublsh_n
@@ -3204,6 +3206,7 @@
 #undef HAVE_NATIVE_mpn_sublsh2_nc_ip1
 #undef HAVE_NATIVE_mpn_sublsh_nc_ip1
 #undef HAVE_NATIVE_mpn_submul_1c
+#undef HAVE_NATIVE_mpn_tabselect
 #undef HAVE_NATIVE_mpn_udiv_qrnnd
 #undef HAVE_NATIVE_mpn_udiv_qrnnd_r
 #undef HAVE_NATIVE_mpn_umul_ppmm
diff -r c8ee6e9fb6f9 -r 1df3d8fef666 mpn/asm-defs.m4
--- a/mpn/asm-defs.m4	Sun Nov 13 21:33:48 2011 +0100
+++ b/mpn/asm-defs.m4	Tue Nov 15 00:49:29 2011 +0100
@@ -1471,6 +1471,7 @@
 define_mpn(sub_nc)
 define_mpn(submul_1)
 define_mpn(submul_1c)
+define_mpn(tabselect)
 define_mpn(umul_ppmm)
 define_mpn(umul_ppmm_r)
 define_mpn(udiv_qrnnd)
diff -r c8ee6e9fb6f9 -r 1df3d8fef666 mpn/generic/powm_sec.c
--- a/mpn/generic/powm_sec.c	Sun Nov 13 21:33:48 2011 +0100
+++ b/mpn/generic/powm_sec.c	Tue Nov 15 00:49:29 2011 +0100
@@ -320,31 +320,6 @@
   TMP_FREE;
 }
 
-#if ! HAVE_NATIVE_mpn_tabselect
-/* Select entry `which' from table `tab', which has nents entries, each `n'
-   limbs.  Store the selected entry at rp.  Reads entire table to avoid
-   side-channel information leaks.  O(n*nents).
-   FIXME: Move to its own file.  */
-void
-mpn_tabselect (volatile mp_limb_t *rp, volatile mp_limb_t *tab, mp_size_t n,
-	       mp_size_t nents, mp_size_t which)
-{
-  mp_size_t k, i;
-  mp_limb_t mask;
-  volatile mp_limb_t *tp;
-
-  for (k = 0; k < nents; k++)
-    {
-      mask = -(mp_limb_t) (which == k);
-      tp = tab + n * k;
-      for (i = 0; i < n; i++)
-	{
-	  rp[i] = (rp[i] & ~mask) | (tp[i] & mask);
-	}
-    }
-}
-#endif
-
 mp_size_t
 mpn_powm_sec_itch (mp_size_t bn, mp_size_t en, mp_size_t n)
 {
diff -r c8ee6e9fb6f9 -r 1df3d8fef666 mpn/generic/tabselect.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpn/generic/tabselect.c	Tue Nov 15 00:49:29 2011 +0100
@@ -0,0 +1,48 @@
+/* mpn_tabselect.
+
+   THIS IS AN INTERNAL FUNCTION WITH A MUTABLE INTERFACE.  IT IS ONLY
+   SAFE TO REACH THIS FUNCTION THROUGH DOCUMENTED INTERFACES.
+
+Copyright 2007, 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"
+
+
+/* Select entry `which' from table `tab', which has nents entries, each `n'
+   limbs.  Store the selected entry at rp.  Reads entire table to avoid
+   side-channel information leaks.  O(n*nents).
+   FIXME: Move to its own file.  */
+void
+mpn_tabselect (volatile mp_limb_t *rp, volatile mp_limb_t *tab, mp_size_t n,
+	       mp_size_t nents, mp_size_t which)
+{
+  mp_size_t k, i;
+  mp_limb_t mask;
+  volatile mp_limb_t *tp;
+
+  for (k = 0; k < nents; k++)
+    {
+      mask = -(mp_limb_t) (which == k);
+      tp = tab + n * k;
+      for (i = 0; i < n; i++)
+	{
+	  rp[i] = (rp[i] & ~mask) | (tp[i] & mask);
+	}
+    }
+}


More information about the gmp-commit mailing list