summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjorn Granlund <tege@gmplib.org>2011-11-15 00:49:29 +0100
committerTorbjorn Granlund <tege@gmplib.org>2011-11-15 00:49:29 +0100
commite1d8e2b8173bbd8e9b034722206979eef782df2c (patch)
treea4bf95e0081f43df6a0c1b5770491d793fd25781
parent305da91c761535cf2b6fcdf4239aae04fa72e5da (diff)
downloadgmp-e1d8e2b8173bbd8e9b034722206979eef782df2c.tar.gz
Separate mpn_tabselect from mpn_powm_sec and prepare for asm support.
-rw-r--r--ChangeLog10
-rw-r--r--configure.in5
-rw-r--r--mpn/asm-defs.m41
-rw-r--r--mpn/generic/powm_sec.c25
-rw-r--r--mpn/generic/tabselect.c48
5 files changed, 63 insertions, 26 deletions
diff --git a/ChangeLog b/ChangeLog
index 262ff7215..0491b1574 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-11-15 Torbjorn Granlund <tege@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@gmplib.org>
* tune/Makefile.am (TUNE_MPN_SRCS_BASIC): Add powm_sec.c.
diff --git a/configure.in b/configure.in
index 6c9a313c3..eedab0eca 100644
--- a/configure.in
+++ b/configure.in
@@ -2640,7 +2640,7 @@ gmp_mpn_functions="$extra_functions \
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 @@ AH_VERBATIM([HAVE_NATIVE],
#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 @@ AH_VERBATIM([HAVE_NATIVE],
#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 @@ AH_VERBATIM([HAVE_NATIVE],
#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 --git a/mpn/asm-defs.m4 b/mpn/asm-defs.m4
index 4f049b21b..7a5639fbe 100644
--- a/mpn/asm-defs.m4
+++ b/mpn/asm-defs.m4
@@ -1471,6 +1471,7 @@ define_mpn(sub_n)
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 --git a/mpn/generic/powm_sec.c b/mpn/generic/powm_sec.c
index c6358947b..d7ed2b486 100644
--- a/mpn/generic/powm_sec.c
+++ b/mpn/generic/powm_sec.c
@@ -320,31 +320,6 @@ mpn_powm_sec (mp_ptr rp, mp_srcptr bp, mp_size_t bn,
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 --git a/mpn/generic/tabselect.c b/mpn/generic/tabselect.c
new file mode 100644
index 000000000..02e52fdc0
--- /dev/null
+++ b/mpn/generic/tabselect.c
@@ -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);
+ }
+ }
+}