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 to4f0f4bff5a
Follow-up toff3c774e03
Closes #951
This commit is contained in:
@@ -1010,7 +1010,8 @@ typedef enum {
|
||||
libssh2_openssl,
|
||||
libssh2_gcrypt,
|
||||
libssh2_mbedtls,
|
||||
libssh2_wincng
|
||||
libssh2_wincng,
|
||||
libssh2_os400qc3
|
||||
} libssh2_crypto_engine_t;
|
||||
|
||||
LIBSSH2_API
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
|
||||
#define LIBSSH2_BCRYPT_PBKDF_C
|
||||
#include "blowfish.c"
|
||||
|
||||
#define MINIMUM(a,b) (((a) < (b)) ? (a) : (b))
|
||||
|
@@ -37,6 +37,8 @@
|
||||
* Bruce Schneier.
|
||||
*/
|
||||
|
||||
#if defined(LIBSSH2_BCRYPT_PBKDF_C) || defined(_DEBUG_BLOWFISH)
|
||||
|
||||
#if !defined(HAVE_BCRYPT_PBKDF) && (!defined(HAVE_BLOWFISH_INITSTATE) || \
|
||||
!defined(HAVE_BLOWFISH_EXPAND0STATE) || \
|
||||
!defined(HAVE_BLF_ENC))
|
||||
@@ -743,3 +745,5 @@ main(void)
|
||||
(!defined(HAVE_BLOWFISH_INITSTATE) || \
|
||||
!defined(HAVE_BLOWFISH_EXPAND0STATE) || \
|
||||
'!defined(HAVE_BLF_ENC)) */
|
||||
|
||||
#endif /* defined(LIBSSH2_BCRYPT_PBKDF_C) || defined(_DEBUG_BLOWFISH) */
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#define LIBSSH2_CRYPTO_C
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
|
||||
#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)
|
||||
|
22
src/crypto.h
22
src/crypto.h
@@ -40,22 +40,16 @@
|
||||
|
||||
#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)
|
||||
#include "openssl.h"
|
||||
#endif
|
||||
|
||||
#ifdef LIBSSH2_LIBGCRYPT
|
||||
#elif defined(LIBSSH2_LIBGCRYPT)
|
||||
#include "libgcrypt.h"
|
||||
#endif
|
||||
|
||||
#ifdef LIBSSH2_WINCNG
|
||||
#include "wincng.h"
|
||||
#endif
|
||||
|
||||
#ifdef LIBSSH2_OS400QC3
|
||||
#include "os400qc3.h"
|
||||
#endif
|
||||
|
||||
#ifdef LIBSSH2_MBEDTLS
|
||||
#elif defined(LIBSSH2_MBEDTLS)
|
||||
#include "mbedtls.h"
|
||||
#elif defined(LIBSSH2_OS400QC3)
|
||||
#include "os400qc3.h"
|
||||
#elif defined(LIBSSH2_WINCNG)
|
||||
#include "wincng.h"
|
||||
#else
|
||||
#error "no cryptography backend selected"
|
||||
#endif
|
||||
|
||||
#ifdef LIBSSH2_NO_MD5
|
||||
|
@@ -36,9 +36,7 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
|
||||
#ifdef LIBSSH2_LIBGCRYPT /* compile only if we build with libgcrypt */
|
||||
#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -741,4 +739,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* LIBSSH2_LIBGCRYPT */
|
||||
#endif /* LIBSSH2_CRYPTO_C */
|
||||
|
@@ -39,6 +39,8 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_gcrypt
|
||||
|
||||
#include <gcrypt.h>
|
||||
|
||||
#define LIBSSH2_MD5 1
|
||||
|
@@ -35,9 +35,7 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
|
||||
#ifdef LIBSSH2_MBEDTLS /* compile only if we build with mbedtls */
|
||||
#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
|
||||
|
||||
#if MBEDTLS_VERSION_NUMBER < 0x03000000
|
||||
#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_MBEDTLS */
|
||||
#endif /* LIBSSH2_CRYPTO_C */
|
||||
|
@@ -37,6 +37,8 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_mbedtls
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@@ -38,10 +38,7 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
|
||||
/* compile only if we build with openssl or wolfSSL */
|
||||
#if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL)
|
||||
#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -3918,4 +3915,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* LIBSSH2_OPENSSL */
|
||||
#endif /* LIBSSH2_CRYPTO_C */
|
||||
|
@@ -39,6 +39,8 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_openssl
|
||||
|
||||
/* disable deprecated warnings in OpenSSL 3 */
|
||||
#define OPENSSL_SUPPRESS_DEPRECATED
|
||||
|
||||
|
@@ -37,9 +37,7 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
|
||||
#ifdef LIBSSH2_OS400QC3 /* compile only if we build with OS/400 QC3 library */
|
||||
#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -2442,6 +2440,6 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* LIBSSH2_OS400QC3 */
|
||||
#endif /* LIBSSH2_CRYPTO_C */
|
||||
|
||||
/* vim: set expandtab ts=4 sw=4: */
|
||||
|
@@ -39,6 +39,8 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_os400qc3
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@@ -56,15 +56,5 @@ const char *libssh2_version(int req_version_num)
|
||||
LIBSSH2_API
|
||||
libssh2_crypto_engine_t libssh2_crypto_engine(void)
|
||||
{
|
||||
#if defined LIBSSH2_OPENSSL
|
||||
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
|
||||
return LIBSSH2_CRYPTO_ENGINE;
|
||||
}
|
||||
|
@@ -36,9 +36,7 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "libssh2_priv.h"
|
||||
|
||||
#ifdef LIBSSH2_WINCNG /* compile only if we build with wincng */
|
||||
#ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */
|
||||
|
||||
/* required for cross-compilation against the w64 mingw-runtime package */
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
|
||||
@@ -2730,4 +2728,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* LIBSSH2_WINCNG */
|
||||
#endif /* LIBSSH2_CRYPTO_C */
|
||||
|
@@ -38,6 +38,8 @@
|
||||
* OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define LIBSSH2_CRYPTO_ENGINE libssh2_wincng
|
||||
|
||||
/* required for cross-compilation against the w64 mingw-runtime package */
|
||||
#if defined(_WIN32_WINNT) && (_WIN32_WINNT < 0x0600)
|
||||
#undef _WIN32_WINNT
|
||||
|
Reference in New Issue
Block a user