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.
This commit is contained in:
Peter Stuge 2012-03-18 06:40:58 +01:00
parent b4f71fd25a
commit d512b25f69
4 changed files with 25 additions and 11 deletions

View File

@ -1,7 +1,18 @@
CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \ 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 \ 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 \ version.c knownhost.c agent.c pem.c keepalive.c global.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 \ HHEADERS = libssh2_priv.h transport.h channel.h comp.h mac.h misc.h \
comp.h mac.h misc.h packet.h userauth.h session.h sftp.h crypto.h packet.h userauth.h session.h sftp.h crypto.h
if OPENSSL
HHEADERS += openssl.h
endif
if LIBGCRYPT
HHEADERS += libgcrypt.h
endif

View File

@ -93,7 +93,7 @@ AC_ARG_WITH(libz,
AC_HELP_STRING([--with-libz],[Use Libz for compression]), AC_HELP_STRING([--with-libz],[Use Libz for compression]),
use_libz=$withval,use_libz=auto) use_libz=$withval,use_libz=auto)
# Look for OpenSSL (default) # Look for OpenSSL
if test "$use_openssl" != "no" && test "$use_libgcrypt" != "yes"; then if test "$use_openssl" != "no" && test "$use_libgcrypt" != "yes"; then
AC_LIB_HAVE_LINKFLAGS([ssl], [crypto], [#include <openssl/ssl.h>]) AC_LIB_HAVE_LINKFLAGS([ssl], [crypto], [#include <openssl/ssl.h>])
LIBSREQUIRED=libssl,libcrypto 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]) try --with-libssl-prefix=PATH or --with-libgcrypt-prefix=PATH])
fi 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 if test "$ac_cv_libgcrypt" = "yes"; then
AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use libgcrypt]) AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use libgcrypt])
fi fi

View File

@ -38,10 +38,12 @@
#ifndef LIBSSH2_CRYPTO_H #ifndef LIBSSH2_CRYPTO_H
#define LIBSSH2_CRYPTO_H #define LIBSSH2_CRYPTO_H
#ifdef LIBSSH2_OPENSSL
#include "openssl.h"
#endif
#ifdef LIBSSH2_LIBGCRYPT #ifdef LIBSSH2_LIBGCRYPT
#include "libgcrypt.h" #include "libgcrypt.h"
#else
#include "openssl.h"
#endif #endif
int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa,

View File

@ -40,8 +40,6 @@
#include "libssh2_priv.h" #include "libssh2_priv.h"
#ifndef LIBSSH2_LIBGCRYPT /* compile only if we build with OpenSSL */
#include <string.h> #include <string.h>
#ifndef EVP_MAX_BLOCK_LENGTH #ifndef EVP_MAX_BLOCK_LENGTH
@ -800,5 +798,3 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session,
EVP_PKEY_free(pk); EVP_PKEY_free(pk);
return st; return st;
} }
#endif /* !LIBSSH2_LIBGCRYPT */