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

mercurial at gmplib.org mercurial at gmplib.org
Sat Jan 18 08:32:40 UTC 2014


details:   /var/hg/gmp/rev/d5ce22392270
changeset: 16191:d5ce22392270
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Thu Jan 16 22:20:47 2014 +0100
description:
NEWS entry for mpn_sec_minvert.

details:   /var/hg/gmp/rev/9649b744a5a8
changeset: 16192:9649b744a5a8
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Sat Jan 18 09:32:07 2014 +0100
description:
Make mpn_sec_add_1 public. Implement mpn_sec_sub_1.

diffstat:

 ChangeLog                 |  12 +++++++++++
 NEWS                      |   3 ++
 configure.ac              |   3 +-
 gmp-h.in                  |  10 +++++++++
 mpn/generic/sec_aors_1.c  |  50 +++++++++++++++++++++++++++++++++++++++++++++++
 mpn/generic/sec_minvert.c |  20 ++---------------
 6 files changed, 80 insertions(+), 18 deletions(-)

diffs (164 lines):

diff -r 6c9dba3c6d0d -r 9649b744a5a8 ChangeLog
--- a/ChangeLog	Thu Jan 16 21:30:22 2014 +0100
+++ b/ChangeLog	Sat Jan 18 09:32:07 2014 +0100
@@ -1,3 +1,15 @@
+2014-01-18  Niels Möller  <nisse at lysator.liu.se>
+
+	* mpn/generic/sec_aors_1.c (mpn_sec_add_1, mpn_sec_sub_1): New
+	file.
+
+	* mpn/generic/sec_minvert.c (mpn_sec_add_1_itch, mpn_sec_add_1):
+	Deleted static definitions.
+	(mpn_cnd_swap): Use volatile.
+
+	* configure.ac (gmp_mpn_functions): sec_add_1 and sec_sub_1.
+	(GMP_MULFUNC_CHOICES): Set up for sec_aors_1.
+
 2014-01-16  Niels Möller  <nisse at lysator.liu.se>
 
 	* tune/common.c (speed_mpn_sec_minvert): New function.
diff -r 6c9dba3c6d0d -r 9649b744a5a8 NEWS
--- a/NEWS	Thu Jan 16 21:30:22 2014 +0100
+++ b/NEWS	Sat Jan 18 09:32:07 2014 +0100
@@ -42,6 +42,9 @@
 
   * New function mpn_sec_powm, implementing side-channel silent modexp.
 
+  * New function mpn_sec_minvert, implementing side-channel silent
+    modular inversion.
+
   * New functions mpn_sec_mul and mpn_sec_sqr, implementing side-channel silent
     multiplication and squaring.
 
diff -r 6c9dba3c6d0d -r 9649b744a5a8 configure.ac
--- a/configure.ac	Thu Jan 16 21:30:22 2014 +0100
+++ b/configure.ac	Sat Jan 18 09:32:07 2014 +0100
@@ -2835,7 +2835,7 @@
   bdiv_q bdiv_qr broot brootinv bsqrt bsqrtinv				   \
   divexact bdiv_dbm1c redc_1 redc_2 redc_n powm powlo sec_powm		   \
   sec_mul sec_sqr sec_div_qr sec_div_r sec_pi1_div_qr sec_pi1_div_r	   \
-  sec_minvert								   \
+  sec_add_1 sec_sub_1 sec_minvert					   \
   trialdiv remove							   \
   and_n andn_n nand_n ior_n iorn_n nior_n xor_n xnor_n			   \
   copyi copyd zero sec_tabselect					   \
@@ -2854,6 +2854,7 @@
   add_err3_n|sub_err3_n)
 		     tmp_mulfunc="aors_err3_n" ;;
   cnd_add_n|cnd_sub_n) tmp_mulfunc="cnd_aors_n"   ;;
+  sec_add_1|sec_sub_1) tmp_mulfunc="sec_aors_1"   ;;
   addmul_1|submul_1) tmp_mulfunc="aorsmul_1" ;;
   mul_2|addmul_2)    tmp_mulfunc="aormul_2" ;;
   mul_3|addmul_3)    tmp_mulfunc="aormul_3" ;;
diff -r 6c9dba3c6d0d -r 9649b744a5a8 gmp-h.in
--- a/gmp-h.in	Thu Jan 16 21:30:22 2014 +0100
+++ b/gmp-h.in	Sat Jan 18 09:32:07 2014 +0100
@@ -1629,6 +1629,16 @@
 #define mpn_cnd_sub_n __MPN(cnd_sub_n)
 __GMP_DECLSPEC mp_limb_t mpn_cnd_sub_n (mp_limb_t, mp_ptr, mp_srcptr, mp_srcptr, mp_size_t);
 
+#define mpn_sec_add_1 __MPN(sec_add_1)
+__GMP_DECLSPEC mp_limb_t mpn_sec_add_1 (mp_limb_t *, mp_limb_t *, mp_size_t, mp_limb_t, mp_ptr);
+#define mpn_sec_add_1_itch __MPN(sec_add_1_itch)
+__GMP_DECLSPEC mp_size_t mpn_sec_add_1_itch (mp_size_t) __GMP_ATTRIBUTE_PURE;
+
+#define mpn_sec_sub_1 __MPN(sec_sub_1)
+__GMP_DECLSPEC mp_limb_t mpn_sec_sub_1 (mp_limb_t *, mp_limb_t *, mp_size_t, mp_limb_t, mp_ptr);
+#define mpn_sec_sub_1_itch __MPN(sec_sub_1_itch)
+__GMP_DECLSPEC mp_size_t mpn_sec_sub_1_itch (mp_size_t) __GMP_ATTRIBUTE_PURE;
+
 #define mpn_sec_mul __MPN(sec_mul)
 __GMP_DECLSPEC void mpn_sec_mul (mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t, mp_ptr);
 #define mpn_sec_mul_itch __MPN(sec_mul_itch)
diff -r 6c9dba3c6d0d -r 9649b744a5a8 mpn/generic/sec_aors_1.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mpn/generic/sec_aors_1.c	Sat Jan 18 09:32:07 2014 +0100
@@ -0,0 +1,50 @@
+/* mpn_sec_add_1, mpn_sec_sub_1
+
+   Contributed to the GNU project by Niels Möller
+
+Copyright 2013, 2014 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 https://www.gnu.org/licenses/.  */
+
+#include "gmp.h"
+#include "gmp-impl.h"
+
+#if OPERATION_sec_add_1
+#define FNAME mpn_sec_add_1
+#define FNAME_itch mpn_sec_add_1_itch
+#define OP_N mpn_add_n
+#endif
+#if OPERATION_sec_sub_1
+#define FNAME mpn_sec_sub_1
+#define FNAME_itch mpn_sec_sub_1_itch
+#define OP_N mpn_sub_n
+#endif
+
+/* It's annoying to that we need scratch space */
+mp_size_t
+FNAME_itch (mp_size_t n)
+{
+  return n;
+}
+
+mp_limb_t
+FNAME (mp_limb_t *rp, mp_limb_t *ap, mp_size_t n, mp_limb_t b,
+       mp_ptr scratch)
+{
+  scratch[0] = b;
+  MPN_ZERO (scratch + 1, n-1);
+  return OP_N (rp, ap, scratch, n);
+}
diff -r 6c9dba3c6d0d -r 9649b744a5a8 mpn/generic/sec_minvert.c
--- a/mpn/generic/sec_minvert.c	Thu Jan 16 21:30:22 2014 +0100
+++ b/mpn/generic/sec_minvert.c	Sat Jan 18 09:32:07 2014 +0100
@@ -23,21 +23,6 @@
 #include "gmp-impl.h"
 
 static mp_size_t
-mpn_sec_add_1_itch (mp_size_t n)
-{
-  return n;
-}
-
-static mp_limb_t
-mpn_sec_add_1 (mp_limb_t *rp, mp_limb_t *ap, mp_size_t n, mp_limb_t b,
-	       mp_ptr scratch)
-{
-  scratch[0] = b;
-  MPN_ZERO (scratch + 1, n-1);
-  return mpn_add_n (rp, ap, scratch, n);
-}
-
-static mp_size_t
 mpn_cnd_neg_itch (mp_size_t n)
 {
   return n;
@@ -53,9 +38,10 @@
 }
 
 static void
-mpn_cnd_swap (int cnd, mp_limb_t *ap, mp_limb_t *bp, mp_size_t n)
+mpn_cnd_swap (int cnd, volatile mp_limb_t *ap, volatile mp_limb_t *bp,
+	      mp_size_t n)
 {
-  mp_limb_t mask = - (mp_limb_t) (cnd != 0);
+  volatile mp_limb_t mask = - (mp_limb_t) (cnd != 0);
   mp_size_t i;
   for (i = 0; i < n; i++)
     {


More information about the gmp-commit mailing list