]> git.ipfire.org Git - thirdparty/nettle.git/commitdiff
Add back implementation of mpn_sec_tabselect, for mini-gmp builds.
authorNiels Möller <nisse@lysator.liu.se>
Thu, 13 Oct 2022 17:16:36 +0000 (19:16 +0200)
committerNiels Möller <nisse@lysator.liu.se>
Thu, 13 Oct 2022 17:16:36 +0000 (19:16 +0200)
ChangeLog
gmp-glue.c
gmp-glue.h

index 98dc40a44d7bc2625f1431b19ab0ce719866cf96..3dc357f6afa32443278ff0ec369f7744eadd81c9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2022-10-13  Niels Möller  <nisse@lysator.liu.se>
+
+       * gmp-glue.c (mpn_sec_tabselect) [NETTLE_USE_MINI_GMP]: Add back
+       here, to support mini-gmp builds. Updated signature to be
+       compatible with the gmp version.
+       * gmp-glue.h: Add declaration.
+
 2022-10-11  Niels Möller  <nisse@lysator.liu.se>
 
        * sec-tabselect.c (sec_tabselect): Delete file and function. All
index e75d678b4a4c1ea4348caabc93f90964005d52e6..ffce6c306bee08d245f9918c9a0786b9bffa9075 100644 (file)
@@ -99,6 +99,26 @@ mpn_cnd_swap (mp_limb_t cnd, volatile mp_limb_t *ap, volatile mp_limb_t *bp, mp_
     }
 }
 
+/* Copy the k'th element of the table out tn elements, each of size
+   rn. Always read complete table. Similar to gmp's mpn_tabselect. */
+void
+mpn_sec_tabselect (volatile mp_limb_t *rp, volatile const mp_limb_t *table,
+                  mp_size_t rn, unsigned tn, unsigned k)
+{
+  volatile const mp_limb_t *end = table + tn * rn;
+  volatile const mp_limb_t *p;
+  mp_size_t i;
+
+  assert (k < tn);
+  for (p = table; p < end; p += rn, k--)
+    {
+      mp_limb_t mask = - (mp_limb_t) (k == 0);
+      for (i = 0; i < rn; i++)
+       rp[i] = (~mask & rp[i]) | (mask & p[i]);
+    }
+}
+
+
 #endif /* NETTLE_USE_MINI_GMP */
 
 int
index bc6dbf16ae17ee2759c0f892323e6418b1a5158b..dc0ede2abd8cdb3f520c7a798e83a34148484c2b 100644 (file)
@@ -66,6 +66,10 @@ mpn_cnd_sub_n (mp_limb_t cnd, mp_limb_t *rp,
 
 void
 mpn_cnd_swap (mp_limb_t cnd, volatile mp_limb_t *ap, volatile mp_limb_t *bp, mp_size_t n);
+
+void
+mpn_sec_tabselect (volatile mp_limb_t *rp, volatile const mp_limb_t *table,
+                  mp_size_t rn, unsigned tn, unsigned k);
 #endif
 
 /* Side-channel silent variant of mpn_zero_p. */