]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
nettle/gost: support building with GOST-enabled Nettle
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Thu, 11 Jul 2019 18:37:08 +0000 (21:37 +0300)
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Sun, 14 Jul 2019 09:16:49 +0000 (12:16 +0300)
Nettle library starts to gain support for GOST algorithms. Support
building GnuTLS with GOST-enabled nettle library.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
17 files changed:
configure.ac
lib/nettle/cipher.c
lib/nettle/gost/gost28147.c
lib/nettle/gost/gost28147.h
lib/nettle/gost/gosthash94-meta.c
lib/nettle/gost/gosthash94.c
lib/nettle/gost/gosthash94.h
lib/nettle/gost/hmac-gost.h
lib/nettle/gost/hmac-gosthash94.c
lib/nettle/gost/hmac-streebog.c
lib/nettle/gost/pbkdf2-gost.h
lib/nettle/gost/pbkdf2-hmac-gosthash94.c
lib/nettle/gost/pbkdf2-hmac-streebog.c
lib/nettle/gost/streebog-meta.c
lib/nettle/gost/streebog.c
lib/nettle/gost/streebog.h
lib/nettle/mac.c

index e246fdcb73a845affd8ea9334d4c80ae259b8e62..9728f316ed6ec3fb3d67c3c40d34feeef6de1629 100644 (file)
@@ -576,6 +576,23 @@ LIBS="$LIBS $NETTLE_LIBS"
 AC_CHECK_FUNCS(xts_encrypt_message)
 LIBS=$save_LIBS
 
+# Check for Gosthash94 with CryptoPro S-box support
+save_LIBS=$LIBS
+LIBS="$LIBS $NETTLE_LIBS"
+AC_CHECK_FUNCS(nettle_gosthash94cp_update)
+LIBS=$save_LIBS
+
+# Check for GOST28147
+save_LIBS=$LIBS
+LIBS="$LIBS $NETTLE_LIBS"
+AC_CHECK_FUNCS(nettle_gost28147_set_key)
+LIBS=$save_LIBS
+
+# Check for Streebog support
+save_LIBS=$LIBS
+LIBS="$LIBS $NETTLE_LIBS"
+AC_CHECK_FUNCS(nettle_streebog512_update)
+LIBS=$save_LIBS
 
 AC_MSG_CHECKING([whether to build libdane])
 AC_ARG_ENABLE(libdane,
index 632528140af08052a5dffc43e14f948939df451f..09032f353d6ddad16856463f537e8ab53f71f0fd 100644 (file)
 #include <nettle/des.h>
 #include <nettle/version.h>
 #if ENABLE_GOST
+#ifndef HAVE_NETTLE_GOST28147_SET_KEY
 #include "gost/gost28147.h"
+#else
+#include <nettle/gost28147.h>
+#endif
 #endif
 #include <nettle/nettle-meta.h>
 #include <nettle/cbc.h>
index 0b70d39ca66aa50cd5df619a6d1888863fa47b9f..0b047242f2de15ba35d9f2cb0b7dc933775fa4f8 100644 (file)
@@ -32,6 +32,8 @@
 #include "config.h"
 #endif
 
+#ifndef HAVE_NETTLE_GOST28147_SET_KEY
+
 #include <gnutls_int.h>
 
 #include <string.h>
@@ -2365,3 +2367,4 @@ gost28147_encrypt_for_cfb(struct gost28147_ctx *ctx,
       ctx->key_count += GOST28147_BLOCK_SIZE;
     }
 }
+#endif
index ca45517f415fb6d5d9b4b973457adb6182ce096a..7329d2ed8bf3e403c8e738c44b1f753070b758d3 100644 (file)
 #ifndef GNUTLS_LIB_NETTLE_GOST_GOST28147_H
 #define GNUTLS_LIB_NETTLE_GOST_GOST28147_H
 
+#include "config.h"
+
+#ifndef HAVE_NETTLE_GOST28147_SET_KEY
+
 #include <nettle/nettle-types.h>
 
 #ifdef __cplusplus
@@ -115,4 +119,6 @@ gost28147_encrypt_for_cfb(struct gost28147_ctx *ctx,
 }
 #endif
 
+#endif
+
 #endif /* GNUTLS_LIB_NETTLE_GOST_GOST28147_H */
index 3af3c8fa4c5972af103f1c72fad65daa24ed2191..9cdbe8d566a5ebebcc279652e3259e1bb2b3e3c6 100644 (file)
@@ -33,6 +33,8 @@
 # include "config.h"
 #endif
 
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
+
 #include <gnutls_int.h>
 
 #include <nettle/nettle-meta.h>
@@ -41,3 +43,5 @@
 
 const struct nettle_hash nettle_gosthash94cp
 = _NETTLE_HASH(gosthash94cp, GOSTHASH94CP);
+
+#endif
index ec90ec80c0ca8caac5654e43b13ce5284dd0721d..ae96cd6a8066d49ae4f7a455e3f9e8004be46d04 100644 (file)
@@ -34,6 +34,7 @@
 #include "config.h"
 #endif
 
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
 #include <gnutls_int.h>
 
 #include <string.h>
@@ -372,3 +373,4 @@ gosthash94cp_digest (struct gosthash94_ctx *ctx,
   gosthash94_write_digest (ctx, length, result,
                           gost28147_param_CryptoPro_3411.sbox);
 }
+#endif
index 091d0256eea97ddb430c24a9bb4ffb75fff0b6cb..c37701d62090bc3e018cf20fe1eefa0fd92a3f52 100644 (file)
 #ifndef GNUTLS_LIB_NETTLE_GOST_GOSTHASH94_H
 #define GNUTLS_LIB_NETTLE_GOST_GOSTHASH94_H
 
+#include "config.h"
+
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
+
 #include <nettle/nettle-types.h>
 
 #ifdef __cplusplus
@@ -92,4 +96,6 @@ extern const struct nettle_hash _gnutls_gosthash94cp;
 }
 #endif
 
+#endif
+
 #endif /* GNUTLS_LIB_NETTLE_GOST_GOSTHASH94_H */
index e847cda4f0ad1060b8a6af5aaedf98759ff7846c..7b697183ecab1e66a1c87e7127ce96e948db7e7a 100644 (file)
 #ifndef GNUTLS_LIB_NETTLE_GOST_HMAC_GOST_H
 #define GNUTLS_LIB_NETTLE_GOST_HMAC_GOST_H
 
+#include "config.h"
+
 #include <nettle/hmac.h>
 
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
 #include "gosthash94.h"
+#endif
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 #include "streebog.h"
+#endif
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* Namespace mangling */
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
 #define hmac_gosthash94cp_set_key _gnutls_hmac_gosthash94cp_set_key
 #define hmac_gosthash94cp_update _gnutls_hmac_gosthash94cp_update
 #define hmac_gosthash94cp_digest _gnutls_hmac_gosthash94cp_digest
+#endif
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 #define hmac_streebog256_set_key _gnutls_hmac_streebog256_set_key
 #define hmac_streebog256_digest _gnutls_hmac_streebog256_digest
 #define hmac_streebog512_set_key _gnutls_hmac_streebog512_set_key
 #define hmac_streebog512_update _gnutls_hmac_streebog512_update
 #define hmac_streebog512_digest _gnutls_hmac_streebog512_digest
+#endif
 
 /* hmac-gosthash94 */
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
 struct hmac_gosthash94cp_ctx HMAC_CTX(struct gosthash94cp_ctx);
 
 void
@@ -67,9 +78,11 @@ hmac_gosthash94cp_update(struct hmac_gosthash94cp_ctx *ctx,
 void
 hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
                         size_t length, uint8_t *digest);
+#endif
 
 
 /* hmac-streebog */
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 struct hmac_streebog512_ctx HMAC_CTX(struct streebog512_ctx);
 
 void
@@ -95,6 +108,7 @@ hmac_streebog256_set_key(struct hmac_streebog256_ctx *ctx,
 void
 hmac_streebog256_digest(struct hmac_streebog256_ctx *ctx,
                   size_t length, uint8_t *digest);
+#endif
 
 #ifdef __cplusplus
 }
index 06c41cb871dfa9140da27192281ef6bf5cef92c7..1fca292ba754c454bd166038b3a1bcd5c609b7ab 100644 (file)
@@ -35,6 +35,8 @@
 # include <config.h>
 #endif
 
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
+
 #include <gnutls_int.h>
 
 #include <nettle/hmac.h>
@@ -60,3 +62,4 @@ hmac_gosthash94cp_digest(struct hmac_gosthash94cp_ctx *ctx,
 {
   HMAC_DIGEST(ctx, &nettle_gosthash94cp, length, digest);
 }
+#endif
index 18ed916694c79b9bc99c2b1021cc64797e819d45..00fcdb9132bc4ac1e93099a33488b01ee1fbfc8b 100644 (file)
@@ -35,6 +35,7 @@
 # include <config.h>
 #endif
 
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 #include <gnutls_int.h>
 
 #include <nettle/hmac.h>
@@ -74,3 +75,4 @@ hmac_streebog256_digest(struct hmac_streebog256_ctx *ctx,
 {
   HMAC_DIGEST(ctx, &nettle_streebog256, length, digest);
 }
+#endif
index bde2014704e0b762ffa5e9809e512191bed9a3fe..fc4181ae19f6fd0d925ab9f355143dad68e523dd 100644 (file)
@@ -34,6 +34,8 @@
 #ifndef GNUTLS_LIB_NETTLE_GOST_PBKDF2_GOST_H
 #define GNUTLS_LIB_NETTLE_GOST_PBKDF2_GOST_H
 
+#include "config.h"
+
 #include <nettle/nettle-meta.h>
 #include <nettle/pbkdf2.h>
 
@@ -43,16 +45,23 @@ extern "C"
 #endif
 
 /* Namespace mangling */
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
 #define pbkdf2_hmac_gosthash94cp _gnutls_pbkdf2_hmac_gosthash94cp
+#endif
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 #define pbkdf2_hmac_streebog256 _gnutls_pbkdf2_hmac_streebog256
 #define pbkdf2_hmac_streebog512 _gnutls_pbkdf2_hmac_streebog512
+#endif
 
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
 void
 pbkdf2_hmac_gosthash94cp (size_t key_length, const uint8_t *key,
                          unsigned iterations,
                          size_t salt_length, const uint8_t *salt,
                          size_t length, uint8_t *dst);
+#endif
 
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 void
 pbkdf2_hmac_streebog256 (size_t key_length, const uint8_t *key,
                         unsigned iterations,
@@ -64,6 +73,7 @@ pbkdf2_hmac_streebog512 (size_t key_length, const uint8_t *key,
                         unsigned iterations,
                         size_t salt_length, const uint8_t *salt,
                         size_t length, uint8_t *dst);
+#endif
 
 #ifdef __cplusplus
 }
index f44b0ea8d55178c625a3d853a8254c99232efff2..c9bf80aa9adca9ccb5ef1692142d664ac5a1592e 100644 (file)
@@ -36,6 +36,8 @@
 # include "config.h"
 #endif
 
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
+
 #include <gnutls_int.h>
 
 #include "pbkdf2-gost.h"
@@ -54,3 +56,4 @@ pbkdf2_hmac_gosthash94cp (size_t key_length, const uint8_t *key,
   PBKDF2 (&gosthash94cpctx, hmac_gosthash94cp_update, hmac_gosthash94cp_digest,
          GOSTHASH94CP_DIGEST_SIZE, iterations, salt_length, salt, length, dst);
 }
+#endif
index 315cc9d106bdd8ccdac0bea81faf6d3816fc4e44..6ee32766a803249209036b239549e00ff09ca5ab 100644 (file)
@@ -36,6 +36,7 @@
 # include "config.h"
 #endif
 
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 #include <gnutls_int.h>
 
 #include "pbkdf2-gost.h"
@@ -67,3 +68,4 @@ pbkdf2_hmac_streebog512 (size_t key_length, const uint8_t *key,
   PBKDF2 (&streebog512ctx, hmac_streebog512_update, hmac_streebog512_digest,
          STREEBOG512_DIGEST_SIZE, iterations, salt_length, salt, length, dst);
 }
+#endif
index f13772d349f02b7f1b94588f43eca02868d096ee..c64fa001c91a8f4ac3eb039b62921a6c53e21d92 100644 (file)
@@ -33,6 +33,7 @@
 # include "config.h"
 #endif
 
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 #include <gnutls_int.h>
 
 #include <nettle/nettle-meta.h>
@@ -44,3 +45,4 @@ const struct nettle_hash nettle_streebog512
 
 const struct nettle_hash nettle_streebog256
 = _NETTLE_HASH(streebog256, STREEBOG256);
+#endif
index 4d7c131da25a97732e704b2a2e4d3d5bb127b2c3..2799e9ea4a618eb2f1abfddb639192891e9be2e1 100644 (file)
@@ -35,6 +35,7 @@
 # include "config.h"
 #endif
 
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 #include <gnutls_int.h>
 
 #include <stdlib.h>
@@ -1333,3 +1334,4 @@ streebog256_digest(struct streebog256_ctx *ctx,
       digest);
   streebog256_init(ctx);
 }
+#endif
index 3df9b3ab671301b8f09b687b0d812ff9bdc6104e..e2348bbb41b8237d8ffc2dee426e1f40764e39d3 100644 (file)
@@ -34,6 +34,8 @@
 #ifndef GNUTLS_LIB_NETTLE_GOST_STREEBOG_H
 #define GNUTLS_LIB_NETTLE_GOST_STREEBOG_H
 
+#include "config.h"
+
 #include <nettle/nettle-types.h>
 #include <nettle/nettle-meta.h>
 
@@ -41,6 +43,7 @@
 extern "C" {
 #endif
 
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 /* Name mangling */
 #define streebog256_init _gnutls_streebog256_init
 #define streebog256_digest _gnutls_streebog256_digest
@@ -97,6 +100,7 @@ streebog256_digest(struct streebog256_ctx *ctx,
 #define nettle_streebog512 _gnutls_streebog512
 extern const struct nettle_hash _gnutls_streebog256;
 extern const struct nettle_hash _gnutls_streebog512;
+#endif
 
 #ifdef __cplusplus
 }
index 5e8bcec0a7fbb8575626fa3019cdb7711739e087..b6c0bce85d53be28b3aed1eb76eed504b3b9d649 100644 (file)
 #include <nettle/umac.h>
 #if ENABLE_GOST
 #include "gost/hmac-gost.h"
+#ifndef HAVE_NETTLE_GOSTHASH94CP_UPDATE
 #include "gost/gosthash94.h"
+#endif
+#ifndef HAVE_NETTLE_STREEBOG512_UPDATE
 #include "gost/streebog.h"
 #endif
+#endif
 #ifdef HAVE_NETTLE_CMAC128_UPDATE
 #include <nettle/cmac.h>
 #else