[PATCH 2/2] Add support for GOST GC256C curve

2020-02-15 Thread dbaryshkov
From: Dmitry Baryshkov 

Add support for GC256C curve ("TLS Supported Groups" registry,
draft-smyshlyaev-tls12-gost-suites) also known as
GostR3410-2001-CryptoPro-B (RFC 4357).

Signed-off-by: Dmitry Baryshkov 
---
 .gitignore  |   1 +
 Makefile.in |  10 +-
 ecc-curve.h |   1 +
 ecc-gost-gc256c.c   | 174 
 ecc-internal.h  |   1 +
 eccdata.c   |  32 ++
 examples/ecc-benchmark.c|   1 +
 nettle.texinfo  |   8 ++
 testsuite/gostdsa-sign-test.c   |  11 ++
 testsuite/gostdsa-verify-test.c |  11 ++
 testsuite/testutils.c   |  14 ++-
 11 files changed, 260 insertions(+), 4 deletions(-)
 create mode 100644 ecc-gost-gc256c.c

diff --git a/.gitignore b/.gitignore
index 48e2b7f464da..a94d279e5d18 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,6 +46,7 @@ core
 /ecc-curve25519.h
 /ecc-curve448.h
 /ecc-gost-gc256b.h
+/ecc-gost-gc256c.h
 /ecc-gost-gc512a.h
 /ecc-secp192r1.h
 /ecc-secp224r1.h
diff --git a/Makefile.in b/Makefile.in
index d4fcb81302a2..7330ab893131 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -180,7 +180,8 @@ hogweed_SOURCES = sexp.c sexp-format.c \
  ecc-mod.c ecc-mod-inv.c \
  ecc-mod-arith.c ecc-pp1-redc.c ecc-pm1-redc.c \
  ecc-curve25519.c ecc-curve448.c \
- ecc-gost-gc256b.c ecc-gost-gc512a.c \
+ ecc-gost-gc256b.c ecc-gost-gc256c.c \
+ ecc-gost-gc512a.c \
  ecc-secp192r1.c ecc-secp224r1.c ecc-secp256r1.c \
  ecc-secp384r1.c ecc-secp521r1.c \
  ecc-size.c ecc-j-to-a.c ecc-a-to-j.c \
@@ -391,6 +392,9 @@ ecc-curve448.h: eccdata.stamp
 ecc-gost-gc256b.h: eccdata.stamp
./eccdata$(EXEEXT_FOR_BUILD) gost_gc256b 11 6 $(NUMB_BITS) > $@T && mv 
$@T $@
 
+ecc-gost-gc256c.h: eccdata.stamp
+   ./eccdata$(EXEEXT_FOR_BUILD) gost_gc256c 11 6 $(NUMB_BITS) > $@T && mv 
$@T $@
+
 # Some reasonable choices for 512:
 # k = 22, c =  6, S = 256, T = 110 ( 88 A + 22 D) 32 KB
 # k = 29, c =  6, S = 192, T = 116 ( 87 A + 29 D) 24 KB
@@ -407,6 +411,7 @@ eccdata.stamp: eccdata.c
 ecc-curve25519.$(OBJEXT): ecc-curve25519.h
 ecc-curve448.$(OBJEXT): ecc-curve448.h
 ecc-gost-gc256b.$(OBJEXT): ecc-gost-gc256b.h
+ecc-gost-gc256c.$(OBJEXT): ecc-gost-gc256c.h
 ecc-gost-gc512a.$(OBJEXT): ecc-gost-gc512a.h
 ecc-secp192r1.$(OBJEXT): ecc-secp192r1.h
 ecc-secp224r1.$(OBJEXT): ecc-secp224r1.h
@@ -661,7 +666,8 @@ distcheck: dist
 clean-here:
-rm -f $(TARGETS) *.$(OBJEXT) *.$(OBJEXT).d *.s *.so *.dll *.a \
ecc-curve25519.h ecc-curve448.h \
-   ecc-gost-gc256b.h ecc-gost-gc512a.h \
+   ecc-gost-gc256b.h ecc-gost-gc256c.h \
+   ecc-gost-gc512a.h \
ecc-secp192r1.h ecc-secp224r1.h ecc-secp256r1.h \
ecc-secp384r1.h ecc-secp521r1.h \
aesdata$(EXEEXT_FOR_BUILD) \
diff --git a/ecc-curve.h b/ecc-curve.h
index 8f050404a944..30a33d43782b 100644
--- a/ecc-curve.h
+++ b/ecc-curve.h
@@ -44,6 +44,7 @@ extern "C" {
 struct ecc_curve;
 
 const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc256b(void);
+const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc256c(void);
 const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc512a(void);
 const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_192r1(void);
 const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_224r1(void);
diff --git a/ecc-gost-gc256c.c b/ecc-gost-gc256c.c
new file mode 100644
index ..258cf75a26bc
--- /dev/null
+++ b/ecc-gost-gc256c.c
@@ -0,0 +1,174 @@
+/* ecc-gost-gc256c.c
+
+   Compile time constant (but machine dependent) tables.
+
+   Copyright (C) 2016, 2019 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 
+
+#include "ecc.h"
+#include "ecc-internal.h"
+
+#define USE_REDC 0
+
+#include

[PATCH 2/2] Add support for GOST GC256C curve

2020-01-27 Thread dbaryshkov
From: Dmitry Baryshkov 

Add support for GC256C curve ("TLS Supported Groups" registry,
draft-smyshlyaev-tls12-gost-suites) also known as
GostR3410-2001-CryptoPro-B (RFC 4357).

Signed-off-by: Dmitry Baryshkov 
---
 .gitignore  |   1 +
 Makefile.in |  10 +-
 ecc-curve.h |   1 +
 ecc-gost-gc256c.c   | 191 
 ecc-internal.h  |   1 +
 eccdata.c   |  32 ++
 examples/ecc-benchmark.c|   1 +
 nettle.texinfo  |   8 ++
 testsuite/gostdsa-sign-test.c   |  11 ++
 testsuite/gostdsa-verify-test.c |  11 ++
 testsuite/testutils.c   |  12 +-
 11 files changed, 275 insertions(+), 4 deletions(-)
 create mode 100644 ecc-gost-gc256c.c

diff --git a/.gitignore b/.gitignore
index 48e2b7f464da..a94d279e5d18 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,6 +46,7 @@ core
 /ecc-curve25519.h
 /ecc-curve448.h
 /ecc-gost-gc256b.h
+/ecc-gost-gc256c.h
 /ecc-gost-gc512a.h
 /ecc-secp192r1.h
 /ecc-secp224r1.h
diff --git a/Makefile.in b/Makefile.in
index f876e5e82197..9400a357fe81 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -176,7 +176,8 @@ hogweed_SOURCES = sexp.c sexp-format.c \
  ecc-mod.c ecc-mod-inv.c \
  ecc-mod-arith.c ecc-pp1-redc.c ecc-pm1-redc.c \
  ecc-curve25519.c ecc-curve448.c \
- ecc-gost-gc256b.c ecc-gost-gc512a.c \
+ ecc-gost-gc256b.c ecc-gost-gc256c.c \
+ ecc-gost-gc512a.c \
  ecc-secp192r1.c ecc-secp224r1.c ecc-secp256r1.c \
  ecc-secp384r1.c ecc-secp521r1.c \
  ecc-size.c ecc-j-to-a.c ecc-a-to-j.c \
@@ -387,6 +388,9 @@ ecc-curve448.h: eccdata.stamp
 ecc-gost-gc256b.h: eccdata.stamp
./eccdata$(EXEEXT_FOR_BUILD) gost_gc256b 11 6 $(NUMB_BITS) > $@T && mv 
$@T $@
 
+ecc-gost-gc256c.h: eccdata.stamp
+   ./eccdata$(EXEEXT_FOR_BUILD) gost_gc256c 11 6 $(NUMB_BITS) > $@T && mv 
$@T $@
+
 # Some reasonable choices for 512:
 # k = 22, c =  6, S = 256, T = 110 ( 88 A + 22 D) 32 KB
 # k = 29, c =  6, S = 192, T = 116 ( 87 A + 29 D) 24 KB
@@ -403,6 +407,7 @@ eccdata.stamp: eccdata.c
 ecc-curve25519.$(OBJEXT): ecc-curve25519.h
 ecc-curve448.$(OBJEXT): ecc-curve448.h
 ecc-gost-gc256b.$(OBJEXT): ecc-gost-gc256b.h
+ecc-gost-gc256c.$(OBJEXT): ecc-gost-gc256c.h
 ecc-gost-gc512a.$(OBJEXT): ecc-gost-gc512a.h
 ecc-secp192r1.$(OBJEXT): ecc-secp192r1.h
 ecc-secp224r1.$(OBJEXT): ecc-secp224r1.h
@@ -657,7 +662,8 @@ distcheck: dist
 clean-here:
-rm -f $(TARGETS) *.$(OBJEXT) *.$(OBJEXT).d *.s *.so *.dll *.a \
ecc-curve25519.h ecc-curve448.h \
-   ecc-gost-gc256b.h ecc-gost-gc512a.h \
+   ecc-gost-gc256b.h ecc-gost-gc256c.h \
+   ecc-gost-gc512a.h \
ecc-secp192r1.h ecc-secp224r1.h ecc-secp256r1.h \
ecc-secp384r1.h ecc-secp521r1.h \
aesdata$(EXEEXT_FOR_BUILD) \
diff --git a/ecc-curve.h b/ecc-curve.h
index 8f050404a944..30a33d43782b 100644
--- a/ecc-curve.h
+++ b/ecc-curve.h
@@ -44,6 +44,7 @@ extern "C" {
 struct ecc_curve;
 
 const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc256b(void);
+const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc256c(void);
 const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_gost_gc512a(void);
 const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_192r1(void);
 const struct ecc_curve * _NETTLE_ATTRIBUTE_PURE nettle_get_secp_224r1(void);
diff --git a/ecc-gost-gc256c.c b/ecc-gost-gc256c.c
new file mode 100644
index ..9725ff65e6e2
--- /dev/null
+++ b/ecc-gost-gc256c.c
@@ -0,0 +1,191 @@
+/* ecc-gost-gc256c.c
+
+   Compile time constant (but machine dependent) tables.
+
+   Copyright (C) 2016, 2019 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 
+
+#include "ecc.h"
+#include "ecc-internal.h"
+
+#define USE_REDC 0
+
+#include