diff --git a/include/libssh2.h b/include/libssh2.h index 14908976..f9e45e1f 100644 --- a/include/libssh2.h +++ b/include/libssh2.h @@ -1010,7 +1010,8 @@ typedef enum { libssh2_openssl, libssh2_gcrypt, libssh2_mbedtls, - libssh2_wincng + libssh2_wincng, + libssh2_os400qc3 } libssh2_crypto_engine_t; LIBSSH2_API diff --git a/src/bcrypt_pbkdf.c b/src/bcrypt_pbkdf.c index bfbc69e4..2b84c707 100644 --- a/src/bcrypt_pbkdf.c +++ b/src/bcrypt_pbkdf.c @@ -25,6 +25,7 @@ #include #endif +#define LIBSSH2_BCRYPT_PBKDF_C #include "blowfish.c" #define MINIMUM(a,b) (((a) < (b)) ? (a) : (b)) diff --git a/src/blowfish.c b/src/blowfish.c index 12eaed01..40134ef3 100644 --- a/src/blowfish.c +++ b/src/blowfish.c @@ -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) */ diff --git a/src/crypto.c b/src/crypto.c index 789fcc41..68db0f2a 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -1,3 +1,5 @@ +#define LIBSSH2_CRYPTO_C + #include "libssh2_priv.h" #if defined(LIBSSH2_OPENSSL) || defined(LIBSSH2_WOLFSSL) diff --git a/src/crypto.h b/src/crypto.h index b5d6e0e6..168a8d3f 100644 --- a/src/crypto.h +++ b/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 diff --git a/src/libgcrypt.c b/src/libgcrypt.c index 6d7092ee..699f05fd 100644 --- a/src/libgcrypt.c +++ b/src/libgcrypt.c @@ -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 @@ -741,4 +739,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, return NULL; } -#endif /* LIBSSH2_LIBGCRYPT */ +#endif /* LIBSSH2_CRYPTO_C */ diff --git a/src/libgcrypt.h b/src/libgcrypt.h index 54f01104..58a37557 100644 --- a/src/libgcrypt.h +++ b/src/libgcrypt.h @@ -39,6 +39,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_gcrypt + #include #define LIBSSH2_MD5 1 diff --git a/src/mbedtls.c b/src/mbedtls.c index 6c7f7f8c..366f7c22 100644 --- a/src/mbedtls.c +++ b/src/mbedtls.c @@ -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 */ diff --git a/src/mbedtls.h b/src/mbedtls.h index 4db9ee40..3fd7a8b1 100644 --- a/src/mbedtls.h +++ b/src/mbedtls.h @@ -37,6 +37,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_mbedtls + #include #include diff --git a/src/openssl.c b/src/openssl.c index 1dd6b17f..dd00b22a 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -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 @@ -3918,4 +3915,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, return NULL; } -#endif /* LIBSSH2_OPENSSL */ +#endif /* LIBSSH2_CRYPTO_C */ diff --git a/src/openssl.h b/src/openssl.h index c3d98f9d..2f347c36 100644 --- a/src/openssl.h +++ b/src/openssl.h @@ -39,6 +39,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_openssl + /* disable deprecated warnings in OpenSSL 3 */ #define OPENSSL_SUPPRESS_DEPRECATED diff --git a/src/os400qc3.c b/src/os400qc3.c index 420cfad2..b7fc7487 100644 --- a/src/os400qc3.c +++ b/src/os400qc3.c @@ -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 @@ -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: */ diff --git a/src/os400qc3.h b/src/os400qc3.h index 23148dbe..8d26dfbf 100644 --- a/src/os400qc3.h +++ b/src/os400qc3.h @@ -39,6 +39,8 @@ * OF SUCH DAMAGE. */ +#define LIBSSH2_CRYPTO_ENGINE libssh2_os400qc3 + #include #include diff --git a/src/version.c b/src/version.c index c54d57cd..2d5f46f9 100644 --- a/src/version.c +++ b/src/version.c @@ -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; } diff --git a/src/wincng.c b/src/wincng.c index 72f8bfed..eb5107f9 100644 --- a/src/wincng.c +++ b/src/wincng.c @@ -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 */ diff --git a/src/wincng.h b/src/wincng.h index 2b91afd1..32410d1e 100644 --- a/src/wincng.h +++ b/src/wincng.h @@ -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