From d512b25f69a1b6778881f6b4b5ff9cfc6023be42 Mon Sep 17 00:00:00 2001 From: Peter Stuge Date: Sun, 18 Mar 2012 06:40:58 +0100 Subject: [PATCH] Clean up crypto library abstraction in build system and source code libssh2 used to explicitly check for libgcrypt and default to OpenSSL. Now all possible crypto libraries are checked for explicitly, making the addition of further crypto libraries both simpler and cleaner. --- Makefile.inc | 19 +++++++++++++++---- configure.ac | 7 ++++++- src/crypto.h | 6 ++++-- src/openssl.c | 4 ---- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Makefile.inc b/Makefile.inc index 12a89e53..b2e0f78d 100644 --- a/Makefile.inc +++ b/Makefile.inc @@ -1,7 +1,18 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ packet.c publickey.c scp.c session.c sftp.c userauth.c transport.c \ - version.c knownhost.c agent.c openssl.c libgcrypt.c pem.c keepalive.c \ - global.c + version.c knownhost.c agent.c pem.c keepalive.c global.c +if OPENSSL +CSOURCES += openssl.c +endif +if LIBGCRYPT +CSOURCES += libgcrypt.c +endif -HHEADERS = libssh2_priv.h openssl.h libgcrypt.h transport.h channel.h \ - comp.h mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h +HHEADERS = libssh2_priv.h transport.h channel.h comp.h mac.h misc.h \ + packet.h userauth.h session.h sftp.h crypto.h +if OPENSSL +HHEADERS += openssl.h +endif +if LIBGCRYPT +HHEADERS += libgcrypt.h +endif diff --git a/configure.ac b/configure.ac index 4d3c80b3..0b4e06e7 100644 --- a/configure.ac +++ b/configure.ac @@ -93,7 +93,7 @@ AC_ARG_WITH(libz, AC_HELP_STRING([--with-libz],[Use Libz for compression]), use_libz=$withval,use_libz=auto) -# Look for OpenSSL (default) +# Look for OpenSSL if test "$use_openssl" != "no" && test "$use_libgcrypt" != "yes"; then AC_LIB_HAVE_LINKFLAGS([ssl], [crypto], [#include ]) LIBSREQUIRED=libssl,libcrypto @@ -110,6 +110,11 @@ if test "$ac_cv_libssl" != "yes" && test "$ac_cv_libgcrypt" != "yes"; then try --with-libssl-prefix=PATH or --with-libgcrypt-prefix=PATH]) fi +if test "$ac_cv_libssl" = "yes"; then + AC_DEFINE(LIBSSH2_OPENSSL, 1, [Use OpenSSL]) +fi +AM_CONDITIONAL(OPENSSL, test "$ac_cv_libssl" = "yes") + if test "$ac_cv_libgcrypt" = "yes"; then AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use libgcrypt]) fi diff --git a/src/crypto.h b/src/crypto.h index fb576b6c..9a052e3a 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -38,10 +38,12 @@ #ifndef LIBSSH2_CRYPTO_H #define LIBSSH2_CRYPTO_H +#ifdef LIBSSH2_OPENSSL +#include "openssl.h" +#endif + #ifdef LIBSSH2_LIBGCRYPT #include "libgcrypt.h" -#else -#include "openssl.h" #endif int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, diff --git a/src/openssl.c b/src/openssl.c index 29c8f47b..e810ad03 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -40,8 +40,6 @@ #include "libssh2_priv.h" -#ifndef LIBSSH2_LIBGCRYPT /* compile only if we build with OpenSSL */ - #include #ifndef EVP_MAX_BLOCK_LENGTH @@ -800,5 +798,3 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, EVP_PKEY_free(pk); return st; } - -#endif /* !LIBSSH2_LIBGCRYPT */