summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2022-10-11 20:27:39 +0200
committerNiels Möller <nisse@lysator.liu.se>2022-10-11 20:27:39 +0200
commit6ff0510478d428f317dbb3cf62d2358be3321ffe (patch)
tree2ad5b92e692845edd3d7272d31cb8071601dd9a4
parent76bd07fb0b2f6cbd1c649b4dd8b449090a566cca (diff)
downloadnettle-6ff0510478d428f317dbb3cf62d2358be3321ffe.tar.gz
Delete sec_tabselect, use gmp's mpn_sec_tabselect instead.
-rw-r--r--ChangeLog6
-rw-r--r--Makefile.in2
-rw-r--r--ecc-internal.h6
-rw-r--r--ecc-mul-a-eh.c4
-rw-r--r--ecc-mul-a.c4
-rw-r--r--ecc-mul-g-eh.c8
-rw-r--r--ecc-mul-g.c8
-rw-r--r--sec-tabselect.c62
8 files changed, 19 insertions, 81 deletions
diff --git a/ChangeLog b/ChangeLog
index d23e23e5..98dc40a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2022-10-11 Niels Möller <nisse@lysator.liu.se>
+
+ * sec-tabselect.c (sec_tabselect): Delete file and function. All
+ callers updated to use gmp's mpn_sec_tabselect instead, which is
+ implemented in assembly on many platforms.
+
2022-10-02 Niels Möller <nisse@lysator.liu.se>
* examples/ecc-benchmark.c (bench_curve): Add benchmarking of
diff --git a/Makefile.in b/Makefile.in
index 73e25323..86b8a536 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -194,7 +194,7 @@ hogweed_SOURCES = sexp.c sexp-format.c \
dsa2sexp.c sexp2dsa.c \
pgp-encode.c rsa2openpgp.c \
der-iterator.c der2rsa.c der2dsa.c \
- sec-add-1.c sec-sub-1.c sec-tabselect.c \
+ sec-add-1.c sec-sub-1.c \
gmp-glue.c cnd-copy.c \
ecc-mod.c ecc-mod-inv.c \
ecc-mod-arith.c ecc-pp1-redc.c ecc-pm1-redc.c \
diff --git a/ecc-internal.h b/ecc-internal.h
index 6201bf05..be02de5f 100644
--- a/ecc-internal.h
+++ b/ecc-internal.h
@@ -81,7 +81,6 @@
#define cnd_copy _nettle_cnd_copy
#define sec_add_1 _nettle_sec_add_1
#define sec_sub_1 _nettle_sec_sub_1
-#define sec_tabselect _nettle_sec_tabselect
#define sec_modinv _nettle_sec_modinv
#define curve25519_eh_to_x _nettle_curve25519_eh_to_x
#define curve448_eh_to_x _nettle_curve448_eh_to_x
@@ -475,11 +474,6 @@ mp_limb_t
sec_sub_1 (mp_limb_t *rp, mp_limb_t *ap, mp_size_t n, mp_limb_t b);
void
-sec_tabselect (mp_limb_t *rp, mp_size_t rn,
- const mp_limb_t *table, unsigned tn,
- unsigned k);
-
-void
curve25519_eh_to_x (mp_limb_t *xp, const mp_limb_t *p,
mp_limb_t *scratch);
diff --git a/ecc-mul-a-eh.c b/ecc-mul-a-eh.c
index 1eb3efcc..980fec3f 100644
--- a/ecc-mul-a-eh.c
+++ b/ecc-mul-a-eh.c
@@ -140,7 +140,7 @@ ecc_mul_a_eh (const struct ecc_curve *ecc,
assert (bits < TABLE_SIZE);
- sec_tabselect (r, 3*ecc->p.size, table, TABLE_SIZE, bits);
+ mpn_sec_tabselect (r, table, 3*ecc->p.size, TABLE_SIZE, bits);
for (;;)
{
@@ -166,7 +166,7 @@ ecc_mul_a_eh (const struct ecc_curve *ecc,
ecc->dup (ecc, r, r, scratch_out);
bits &= TABLE_MASK;
- sec_tabselect (tp, 3*ecc->p.size, table, TABLE_SIZE, bits);
+ mpn_sec_tabselect (tp, table, 3*ecc->p.size, TABLE_SIZE, bits);
ecc->add_hhh (ecc, r, r, tp, scratch_out);
}
#undef table
diff --git a/ecc-mul-a.c b/ecc-mul-a.c
index cb9c7d41..8e1355eb 100644
--- a/ecc-mul-a.c
+++ b/ecc-mul-a.c
@@ -144,7 +144,7 @@ ecc_mul_a (const struct ecc_curve *ecc,
assert (bits < TABLE_SIZE);
- sec_tabselect (r, 3*ecc->p.size, table, TABLE_SIZE, bits);
+ mpn_sec_tabselect (r, table, 3*ecc->p.size, TABLE_SIZE, bits);
is_zero = (bits == 0);
for (;;)
@@ -171,7 +171,7 @@ ecc_mul_a (const struct ecc_curve *ecc,
ecc_dup_jj (ecc, r, r, scratch_out);
bits &= TABLE_MASK;
- sec_tabselect (tp, 3*ecc->p.size, table, TABLE_SIZE, bits);
+ mpn_sec_tabselect (tp, table, 3*ecc->p.size, TABLE_SIZE, bits);
cnd_copy (is_zero, r, tp, 3*ecc->p.size);
ecc_add_jjj (ecc, tp, tp, r, scratch_out);
diff --git a/ecc-mul-g-eh.c b/ecc-mul-g-eh.c
index 8b3ca8f8..57df1c6d 100644
--- a/ecc-mul-g-eh.c
+++ b/ecc-mul-g-eh.c
@@ -88,10 +88,10 @@ ecc_mul_g_eh (const struct ecc_curve *ecc, mp_limb_t *r,
shift = bit_index % GMP_NUMB_BITS;
bits = (bits << 1) | ((np[limb_index] >> shift) & 1);
}
- sec_tabselect (tp, 2*ecc->p.size,
- (ecc->pippenger_table
- + (2*ecc->p.size * (mp_size_t) j << c)),
- 1<<c, bits);
+ mpn_sec_tabselect (tp,
+ (ecc->pippenger_table
+ + (2*ecc->p.size * (mp_size_t) j << c)),
+ 2*ecc->p.size, 1<<c, bits);
ecc->add_hh (ecc, r, r, tp, scratch_out);
}
diff --git a/ecc-mul-g.c b/ecc-mul-g.c
index dcc7c3ea..677a37e7 100644
--- a/ecc-mul-g.c
+++ b/ecc-mul-g.c
@@ -88,10 +88,10 @@ ecc_mul_g (const struct ecc_curve *ecc, mp_limb_t *r,
shift = bit_index % GMP_NUMB_BITS;
bits = (bits << 1) | ((np[limb_index] >> shift) & 1);
}
- sec_tabselect (tp, 2*ecc->p.size,
- (ecc->pippenger_table
- + (2*ecc->p.size * (mp_size_t) j << c)),
- 1<<c, bits);
+ mpn_sec_tabselect (tp,
+ (ecc->pippenger_table
+ + (2*ecc->p.size * (mp_size_t) j << c)),
+ 2*ecc->p.size, 1<<c, bits);
cnd_copy (is_zero, r, tp, 2*ecc->p.size);
cnd_copy (is_zero, r + 2*ecc->p.size, ecc->unit, ecc->p.size);
diff --git a/sec-tabselect.c b/sec-tabselect.c
deleted file mode 100644
index e6bf2282..00000000
--- a/sec-tabselect.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/* sec-tabselect.c
-
- Copyright (C) 2013 Niels Möller
-
- This file is part of GNU Nettle.
-
- GNU Nettle is free software: you can redistribute it and/or
- modify it under the terms of either:
-
- * 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.
-
- or
-
- * the GNU General Public License as published by the Free
- Software Foundation; either version 2 of the License, or (at your
- option) any later version.
-
- or both in parallel, as here.
-
- GNU Nettle 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
- General Public License for more details.
-
- You should have received copies of the GNU General Public License and
- the GNU Lesser General Public License along with this program. If
- not, see http://www.gnu.org/licenses/.
-*/
-
-/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <assert.h>
-
-#include "ecc-internal.h"
-
-/* 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. */
-/* FIXME: Should we need to volatile declare anything? */
-void
-sec_tabselect (mp_limb_t *rp, mp_size_t rn,
- const mp_limb_t *table, unsigned tn,
- unsigned k)
-{
- const mp_limb_t *end = table + tn * rn;
- const mp_limb_t *p;
- mp_size_t i;
-
- assert (k < tn);
- mpn_zero (rp, rn);
- 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 & p[i];
- }
-}