]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
nettle/gost: support use GOST DSA support from master branch
authorDmitry Baryshkov <dbaryshkov@gmail.com>
Wed, 29 Jan 2020 17:00:53 +0000 (20:00 +0300)
committerDmitry Baryshkov <dbaryshkov@gmail.com>
Thu, 30 Jan 2020 13:50:00 +0000 (16:50 +0300)
Use GOST DSA and GOST curves provided by Nettle's master branch.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
configure.ac
lib/nettle/Makefile.am
lib/nettle/gost/ecc-gost-curve.h
lib/nettle/gost/ecc-gost256cpa.c
lib/nettle/gost/ecc-gost512a.c
lib/nettle/gost/gostdsa-mask.c
lib/nettle/gost/gostdsa-vko.c
lib/nettle/gost/gostdsa.h
lib/nettle/gost/gostdsa2.h [new file with mode: 0644]
lib/nettle/pk.c

index 2e73a904d6842e3129476cb067fed187b2567219..09acf8b22f77c59701d03ed9b11e278b57f8f1e1 100644 (file)
@@ -660,6 +660,15 @@ AC_CHECK_FUNCS([nettle_curve448_mul nettle_ed448_shake256_sign],
 LIBS=$save_LIBS
 AM_CONDITIONAL(NEED_CURVE448, test "$have_curve448" != "yes")
 
+have_gostdsa=yes
+save_LIBS=$LIBS
+LIBS="$LIBS $HOGWEED_LIBS $NETTLE_LIBS"
+AC_CHECK_FUNCS([nettle_get_gost_gc256b nettle_get_gost_gc512a nettle_gostdsa_sign], [],
+              have_gostdsa=no)
+LIBS=$save_LIBS
+AS_IF([test "$have_gostdsa" != "yes"], AC_DEFINE([NEED_GOSTDSA], 1, [Use backported GOST R 34.10 DSA support]))
+AM_CONDITIONAL(NEED_GOSTDSA, [test "$have_gostdsa" != "yes"])
+
 AC_MSG_CHECKING([whether to build libdane])
 AC_ARG_ENABLE(libdane,
     AS_HELP_STRING([--disable-libdane],
index 8c1a2d17ee6a171728bffeaef8513c7966fcb301..e4d9ad64efc324e90b77fef8174aee2443042f1a 100644 (file)
@@ -86,14 +86,19 @@ libcrypto_la_SOURCES += \
        gost/pbkdf2-hmac-gosthash94.c gost/pbkdf2-hmac-streebog.c \
        gost/pbkdf2-gost.h
 
+if NEED_GOSTDSA
 libcrypto_la_SOURCES += \
        gost/nettle-internal.h \
        gost/ecc-gost256cpa.c gost/ecc-gost256cpa-32.h  gost/ecc-gost256cpa-64.h\
        gost/ecc-gost512a.c gost/ecc-gost512a-32.h gost/ecc-gost512a-64.h \
        gost/ecc-internal.h gost/gmp-glue.h \
        gost/ecc-gostdsa-sign.c gost/ecc-gostdsa-verify.c \
-       gost/gostdsa-mask.c gost/gostdsa-sign.c gost/gostdsa-verify.c gost/gostdsa-vko.c \
+       gost/gostdsa-sign.c gost/gostdsa-verify.c \
        gost/gostdsa.h gost/ecc-gost-curve.h gost/ecc-gost-hash.c
+endif
+
+libcrypto_la_SOURCES += \
+       gost/gostdsa-mask.c gost/gostdsa-vko.c gost/gostdsa2.h
 
 libcrypto_la_SOURCES += gost_keywrap.c
 endif
index 9e972c76890dd3b03a1485fb836cc105f2cd03e5..a7979275d07caa78e6c5ddd9ff2cb2d1b1ee83b6 100644 (file)
@@ -49,10 +49,10 @@ struct ecc_curve;
 #endif
 #endif
 
-#define nettle_get_gost_256cpa _gnutls_get_gost_256cpa
-#define nettle_get_gost_512a _gnutls_get_gost_512a
-const struct ecc_curve * NETTLE_PURE nettle_get_gost_256cpa(void);
-const struct ecc_curve * NETTLE_PURE nettle_get_gost_512a(void);
+#define nettle_get_gost_gc256b _gnutls_get_gost_gc256b
+#define nettle_get_gost_gc512a _gnutls_get_gost_gc512a
+const struct ecc_curve * NETTLE_PURE nettle_get_gost_gc256b(void);
+const struct ecc_curve * NETTLE_PURE nettle_get_gost_gc512a(void);
 
 #ifdef __cplusplus
 }
index 6d7fa51b3e677e24f815b9a5701a91f2c9305efe..74ea4d2685f175a337b95e94447d6c914ab3d2e4 100644 (file)
@@ -64,7 +64,7 @@
 #define ecc_256_modp ecc_mod
 #define ecc_256_modq ecc_mod
 
-static const struct ecc_curve _gnutls_gost_256cpa =
+static const struct ecc_curve _gnutls_gost_gc256b =
 {
   {
     256,
@@ -140,7 +140,7 @@ static const struct ecc_curve _gnutls_gost_256cpa =
   ecc_table
 };
 
-const struct ecc_curve *nettle_get_gost_256cpa(void)
+const struct ecc_curve *nettle_get_gost_gc256b(void)
 {
-  return &_gnutls_gost_256cpa;
+  return &_gnutls_gost_gc256b;
 }
index 1bd4d1b7afaac8ec59b6cb33b53cc5b517ce71db..d77a41f4c08844f718343820f19be3771492f8d0 100644 (file)
@@ -64,7 +64,7 @@
 #define ecc_512_modp ecc_mod
 #define ecc_512_modq ecc_mod
 
-static const struct ecc_curve _gnutls_gost_512a =
+static const struct ecc_curve _gnutls_gost_gc512a =
 {
   {
     512,
@@ -140,7 +140,7 @@ static const struct ecc_curve _gnutls_gost_512a =
   ecc_table
 };
 
-const struct ecc_curve *nettle_get_gost_512a(void)
+const struct ecc_curve *nettle_get_gost_gc512a(void)
 {
-  return &_gnutls_gost_512a;
+  return &_gnutls_gost_gc512a;
 }
index 49dc2f4569dfb58733d28c5bb759f2ee42765004..6654d386b21f7af56840d8bbf5509f93c73ab1a6 100644 (file)
@@ -37,7 +37,7 @@
 
 #include <stdlib.h>
 
-#include "gostdsa.h"
+#include "gostdsa2.h"
 #include "ecc-internal.h"
 
 #include "gmp-glue.h"
index 89dff1cc452d5678321a563c759c77d934bc0063..4251930a8003b42a661a261e98fe746719a0a604 100644 (file)
@@ -38,7 +38,7 @@
 #include <stdlib.h>
 
 #include "ecc-internal.h"
-#include "gostdsa.h"
+#include "gostdsa2.h"
 
 int
 gostdsa_vko(const struct ecc_scalar *key,
index 9e0375f2ce365d8372234d0e7714eb1073b54d88..d9b79ff3ce97f30f17fb9073f57b079d6b51dc91 100644 (file)
@@ -46,8 +46,6 @@ extern "C" {
 /* Name mangling */
 #define gostdsa_sign _gnutls_gostdsa_sign
 #define gostdsa_verify _gnutls_gostdsa_verify
-#define gostdsa_unmask_key _gnutls_gostdsa_unmask_key
-#define gostdsa_vko _gnutls_gostdsa_vko
 #define ecc_gostdsa_sign _gnutls_ecc_gostdsa_sign
 #define ecc_gostdsa_sign_itch _gnutls_ecc_gostdsa_sign_itch
 #define ecc_gostdsa_verify _gnutls_ecc_gostdsa_verify
@@ -72,16 +70,6 @@ gostdsa_verify (const struct ecc_point *pub,
                size_t length, const uint8_t *digest,
                const struct dsa_signature *signature);
 
-int
-gostdsa_unmask_key (const struct ecc_curve *ecc,
-                   mpz_t key);
-
-int
-gostdsa_vko(const struct ecc_scalar *key,
-           const struct ecc_point *pub,
-           size_t ukm_length, const uint8_t *ukm,
-           size_t out_length, uint8_t *out);
-
 /* Low-level GOSTDSA functions. */
 mp_size_t
 ecc_gostdsa_sign_itch (const struct ecc_curve *ecc);
diff --git a/lib/nettle/gost/gostdsa2.h b/lib/nettle/gost/gostdsa2.h
new file mode 100644 (file)
index 0000000..a4b26ab
--- /dev/null
@@ -0,0 +1,62 @@
+/* gostdsa.h
+
+   Copyright (C) 2015 Dmity Eremin-Solenikov
+   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 https://www.gnu.org/licenses/.
+*/
+
+/* Development of Nettle's ECC support was funded by the .SE Internet Fund. */
+
+#ifndef GNUTLS_LIB_NETTLE_GOST_GOSTDSA2_H
+#define GNUTLS_LIB_NETTLE_GOST_GOSTDSA2_H
+
+#include <nettle/ecc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Name mangling */
+#define gostdsa_unmask_key _gnutls_gostdsa_unmask_key
+#define gostdsa_vko _gnutls_gostdsa_vko
+
+int
+gostdsa_unmask_key (const struct ecc_curve *ecc,
+                   mpz_t key);
+
+int
+gostdsa_vko(const struct ecc_scalar *key,
+           const struct ecc_point *pub,
+           size_t ukm_length, const uint8_t *ukm,
+           size_t out_length, uint8_t *out);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GNUTLS_LIB_NETTLE_GOST_GOSTDSA2_H */
index 4be8dc7edaeb8def7eb787b3746bad61b36eafbf..f236cef3db66a96a7c1ac334b03330acb1313d98 100644 (file)
 #include <nettle/eddsa.h>
 #include <nettle/version.h>
 #if ENABLE_GOST
+#if NEED_GOSTDSA
 #include "gost/gostdsa.h"
 #include "gost/ecc-gost-curve.h"
+#else
+#include <nettle/gostdsa.h>
+#endif
+#include "gost/gostdsa2.h"
 #endif
 #include "int/ecdsa-compute-k.h"
 #include "int/dsa-compute-k.h"
@@ -1499,13 +1504,11 @@ static inline const struct ecc_curve *get_supported_gost_curve(int curve)
        switch (curve) {
 #if ENABLE_GOST
        case GNUTLS_ECC_CURVE_GOST256CPA:
-               return nettle_get_gost_256cpa();
        case GNUTLS_ECC_CURVE_GOST256CPXA:
-               return nettle_get_gost_256cpa();
-       case GNUTLS_ECC_CURVE_GOST512A:
-               return nettle_get_gost_512a();
        case GNUTLS_ECC_CURVE_GOST256B:
-               return nettle_get_gost_256cpa();
+               return nettle_get_gost_gc256b();
+       case GNUTLS_ECC_CURVE_GOST512A:
+               return nettle_get_gost_gc512a();
 #endif
        default:
                return NULL;