summaryrefslogtreecommitdiff
path: root/ecc-gost-gc256b.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2020-01-28 16:26:06 +0100
committerNiels Möller <nisse@lysator.liu.se>2020-01-28 16:26:06 +0100
commitee28a24cd3cbd1796a62a9437089ed7b09f953ed (patch)
treed6e22e5722552c51f06f8eb61dd58a3c75982390 /ecc-gost-gc256b.c
parent6695f17fa9afb144fb2e2f0fb9cc8e4be91976a5 (diff)
parent1c2aba42ea6552bb84b7291015de4049604e29c3 (diff)
downloadnettle-ee28a24cd3cbd1796a62a9437089ed7b09f953ed.tar.gz
Merge branch 'ecc-gost'
Diffstat (limited to 'ecc-gost-gc256b.c')
-rw-r--r--ecc-gost-gc256b.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/ecc-gost-gc256b.c b/ecc-gost-gc256b.c
new file mode 100644
index 00000000..8adc8e17
--- /dev/null
+++ b/ecc-gost-gc256b.c
@@ -0,0 +1,128 @@
+/* ecc-gost-gc256b.c
+
+ Copyright (C) 2016-2020 Dmitry Eremin-Solenikov
+
+ 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/.
+*/
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <assert.h>
+
+#include "ecc.h"
+#include "ecc-internal.h"
+
+#define USE_REDC 0
+
+#include "ecc-gost-gc256b.h"
+
+static void
+ecc_gost_gc256b_modp (const struct ecc_modulo *m, mp_limb_t *rp)
+{
+ mp_size_t mn = m->size;
+ mp_limb_t hi;
+
+ hi = mpn_addmul_1(rp, rp + mn, mn, 0x269);
+ hi = sec_add_1 (rp, rp, mn, hi * 0x269);
+ hi = sec_add_1 (rp, rp, mn, hi * 0x269);
+ assert(hi == 0);
+}
+
+#define ecc_gost_gc256b_modp ecc_gost_gc256b_modp
+#define ecc_gost_gc256b_modq ecc_mod
+
+const struct ecc_curve _nettle_gost_gc256b =
+{
+ {
+ 256,
+ ECC_LIMB_SIZE,
+ ECC_BMODP_SIZE,
+ ECC_REDC_SIZE,
+ ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
+ 0,
+
+ ecc_p,
+ ecc_Bmodp,
+ ecc_Bmodp_shifted,
+ ecc_redc_ppm1,
+
+ ecc_pp1h,
+ ecc_gost_gc256b_modp,
+ ecc_gost_gc256b_modp,
+ ecc_mod_inv,
+ NULL,
+ },
+ {
+ 256,
+ ECC_LIMB_SIZE,
+ ECC_BMODQ_SIZE,
+ 0,
+ ECC_MOD_INV_ITCH (ECC_LIMB_SIZE),
+ 0,
+
+ ecc_q,
+ ecc_Bmodq,
+ ecc_Bmodq_shifted,
+ NULL,
+ ecc_qp1h,
+
+ ecc_gost_gc256b_modq,
+ ecc_gost_gc256b_modq,
+ ecc_mod_inv,
+ NULL,
+ },
+
+ USE_REDC,
+ ECC_PIPPENGER_K,
+ ECC_PIPPENGER_C,
+
+ ECC_ADD_JJA_ITCH (ECC_LIMB_SIZE),
+ ECC_ADD_JJJ_ITCH (ECC_LIMB_SIZE),
+ ECC_DUP_JJ_ITCH (ECC_LIMB_SIZE),
+ ECC_MUL_A_ITCH (ECC_LIMB_SIZE),
+ ECC_MUL_G_ITCH (ECC_LIMB_SIZE),
+ ECC_J_TO_A_ITCH (ECC_LIMB_SIZE),
+
+ ecc_add_jja,
+ ecc_add_jjj,
+ ecc_dup_jj,
+ ecc_mul_a,
+ ecc_mul_g,
+ ecc_j_to_a,
+
+ ecc_b,
+ ecc_g,
+ ecc_unit,
+ ecc_table
+};
+
+const struct ecc_curve *nettle_get_gost_gc256b(void)
+{
+ return &_nettle_gost_gc256b;
+}