1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-05 20:55:47 +03:00

build: be friendly with 3rd-party build tools

After recent build changes, 3rd party build that took the list of
C source to compile them as-is, stopped working as expected, due to
`blowfish.c` and crypto-backend C sources no longer expected to compile
separately but via `bcrypt_pbkdf.c` and `crypto.c`, respectively.

This patch ensures that compiling these files directly result in an
empty object instead of redundant code and duplicated symbols.

Also:
- add a compile-time error if none of the supported crypto backends
  are enabled.
- fix `libssh2_crypto_engine()` for wolfSSL and os400qc3.
  Rearrange code to avoid a hard-to-find copy of crypto-backend
  selection guards.

Follow-up to 4f0f4bff5a
Follow-up to ff3c774e03

Closes #951
This commit is contained in:
Viktor Szakats
2023-04-12 09:17:10 +00:00
parent fe02bd2b2d
commit 73d95a055c
16 changed files with 38 additions and 47 deletions

View File

@@ -1010,7 +1010,8 @@ typedef enum {
libssh2_openssl, libssh2_openssl,
libssh2_gcrypt, libssh2_gcrypt,
libssh2_mbedtls, libssh2_mbedtls,
libssh2_wincng libssh2_wincng,
libssh2_os400qc3
} libssh2_crypto_engine_t; } libssh2_crypto_engine_t;
LIBSSH2_API LIBSSH2_API

View File

@@ -25,6 +25,7 @@
#include <sys/param.h> #include <sys/param.h>
#endif #endif
#define LIBSSH2_BCRYPT_PBKDF_C
#include "blowfish.c" #include "blowfish.c"
#define MINIMUM(a,b) (((a) < (b)) ? (a) : (b)) #define MINIMUM(a,b) (((a) < (b)) ? (a) : (b))

View File

@@ -37,6 +37,8 @@
* Bruce Schneier. * Bruce Schneier.
*/ */
#if defined(LIBSSH2_BCRYPT_PBKDF_C) || defined(_DEBUG_BLOWFISH)
#if !defined(HAVE_BCRYPT_PBKDF) && (!defined(HAVE_BLOWFISH_INITSTATE) || \ #if !defined(HAVE_BCRYPT_PBKDF) && (!defined(HAVE_BLOWFISH_INITSTATE) || \
!defined(HAVE_BLOWFISH_EXPAND0STATE) || \ !defined(HAVE_BLOWFISH_EXPAND0STATE) || \
!defined(HAVE_BLF_ENC)) !defined(HAVE_BLF_ENC))
@@ -743,3 +745,5 @@ main(void)
(!defined(HAVE_BLOWFISH_INITSTATE) || \ (!defined(HAVE_BLOWFISH_INITSTATE) || \
!defined(HAVE_BLOWFISH_EXPAND0STATE) || \ !defined(HAVE_BLOWFISH_EXPAND0STATE) || \
'!defined(HAVE_BLF_ENC)) */ '!defined(HAVE_BLF_ENC)) */
#endif /* defined(LIBSSH2_BCRYPT_PBKDF_C) || defined(_DEBUG_BLOWFISH) */

View File

@@ -1,3 +1,5 @@
#define LIBSSH2_CRYPTO_C
#include "libssh2_priv.h" #include "libssh2_priv.h"
#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) #if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)

View File

@@ -40,22 +40,16 @@
#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) #if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)
#include "openssl.h" #include "openssl.h"
#endif #elif defined(LIBSSH2_LIBGCRYPT)
#ifdef LIBSSH2_LIBGCRYPT
#include "libgcrypt.h" #include "libgcrypt.h"
#endif #elif defined(LIBSSH2_MBEDTLS)
#ifdef LIBSSH2_WINCNG
#include "wincng.h"
#endif
#ifdef LIBSSH2_OS400QC3
#include "os400qc3.h"
#endif
#ifdef LIBSSH2_MBEDTLS
#include "mbedtls.h" #include "mbedtls.h"
#elif defined(LIBSSH2_OS400QC3)
#include "os400qc3.h"
#elif defined(LIBSSH2_WINCNG)
#include "wincng.h"
#else
#error "no cryptography backend selected"
#endif #endif
#ifdef LIBSSH2_NO_MD5 #ifdef LIBSSH2_NO_MD5

View File

@@ -36,9 +36,7 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#include "libssh2_priv.h" #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
#ifdef LIBSSH2_LIBGCRYPT /* compile only if we build with libgcrypt */
#include <string.h> #include <string.h>
@@ -741,4 +739,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
return NULL; return NULL;
} }
#endif /* LIBSSH2_LIBGCRYPT */ #endif /* LIBSSH2_CRYPTO_C */

View File

@@ -39,6 +39,8 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#define LIBSSH2_CRYPTO_ENGINE libssh2_gcrypt
#include <gcrypt.h> #include <gcrypt.h>
#define LIBSSH2_MD5 1 #define LIBSSH2_MD5 1

View File

@@ -35,9 +35,7 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#include "libssh2_priv.h" #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
#ifdef LIBSSH2_MBEDTLS /* compile only if we build with mbedtls */
#if MBEDTLS_VERSION_NUMBER < 0x03000000 #if MBEDTLS_VERSION_NUMBER < 0x03000000
#define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen) #define mbedtls_cipher_info_get_key_bitlen(c) (c->key_bitlen)
@@ -1456,4 +1454,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
} }
#endif /* LIBSSH2_ECDSA */ #endif /* LIBSSH2_ECDSA */
#endif /* LIBSSH2_MBEDTLS */ #endif /* LIBSSH2_CRYPTO_C */

View File

@@ -37,6 +37,8 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#define LIBSSH2_CRYPTO_ENGINE libssh2_mbedtls
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@@ -38,10 +38,7 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#include "libssh2_priv.h" #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
/* compile only if we build with openssl or wolfSSL */
#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)
#include <string.h> #include <string.h>
@@ -3918,4 +3915,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
return NULL; return NULL;
} }
#endif /* LIBSSH2_OPENSSL */ #endif /* LIBSSH2_CRYPTO_C */

View File

@@ -39,6 +39,8 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#define LIBSSH2_CRYPTO_ENGINE libssh2_openssl
/* disable deprecated warnings in OpenSSL 3 */ /* disable deprecated warnings in OpenSSL 3 */
#define OPENSSL_SUPPRESS_DEPRECATED #define OPENSSL_SUPPRESS_DEPRECATED

View File

@@ -37,9 +37,7 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#include "libssh2_priv.h" #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
#ifdef LIBSSH2_OS400QC3 /* compile only if we build with OS/400 QC3 library */
#include <stdlib.h> #include <stdlib.h>
@@ -2442,6 +2440,6 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
return NULL; return NULL;
} }
#endif /* LIBSSH2_OS400QC3 */ #endif /* LIBSSH2_CRYPTO_C */
/* vim: set expandtab ts=4 sw=4: */ /* vim: set expandtab ts=4 sw=4: */

View File

@@ -39,6 +39,8 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#define LIBSSH2_CRYPTO_ENGINE libssh2_os400qc3
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>

View File

@@ -56,15 +56,5 @@ const char *libssh2_version(int req_version_num)
LIBSSH2_API LIBSSH2_API
libssh2_crypto_engine_t libssh2_crypto_engine(void) libssh2_crypto_engine_t libssh2_crypto_engine(void)
{ {
#if defined LIBSSH2_OPENSSL return LIBSSH2_CRYPTO_ENGINE;
return libssh2_openssl;
#elif defined LIBSSH2_LIBGCRYPT
return libssh2_gcrypt;
#elif defined LIBSSH2_MBEDTLS
return libssh2_mbedtls;
#elif defined LIBSSH2_WINCNG
return libssh2_wincng;
#else
return libssh2_no_crypto;
#endif
} }

View File

@@ -36,9 +36,7 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#include "libssh2_priv.h" #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
#ifdef LIBSSH2_WINCNG /* compile only if we build with wincng */
/* required for cross-compilation against the w64 mingw-runtime package */ /* required for cross-compilation against the w64 mingw-runtime package */
#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) #if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
@@ -2730,4 +2728,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
return NULL; return NULL;
} }
#endif /* LIBSSH2_WINCNG */ #endif /* LIBSSH2_CRYPTO_C */

View File

@@ -38,6 +38,8 @@
* OF SUCH DAMAGE. * OF SUCH DAMAGE.
*/ */
#define LIBSSH2_CRYPTO_ENGINE libssh2_wincng
/* required for cross-compilation against the w64 mingw-runtime package */ /* required for cross-compilation against the w64 mingw-runtime package */
#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600) #if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
#undef _WIN32_WINNT #undef _WIN32_WINNT