From: Brad King Date: Mon, 30 Nov 2009 15:19:45 +0000 (-0500) Subject: Support openssl without SHA-2 hash functions X-Git-Tag: v2.8.0~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ee74d95f0f23822f52d563dd2407c3c96c4aa91;p=thirdparty%2Flibarchive.git Support openssl without SHA-2 hash functions Previously we assumed that provides all the SHA-2 hash functions if it exists. Some OpenSSL installations do not, so we need to test for them at configuration time. Currently we perform the tests only for CMake builds. We preserve the old behavior for the autotools build by hard-coding availability, and leave a TODO comment for someone to actually add the checks. SVN-Revision: 1691 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0356c9e17..944fca15f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -311,7 +311,11 @@ IF(HAVE_SHA2_H) CHECK_SYMBOL_EXISTS(SHA256_Init "sha2.h" HAVE_SHA256_INIT) CHECK_SYMBOL_EXISTS(SHA384_Init "sha2.h" HAVE_SHA384_INIT) CHECK_SYMBOL_EXISTS(SHA512_Init "sha2.h" HAVE_SHA512_INIT) -ENDIF(HAVE_SHA2_H) +ELSEIF(HAVE_OPENSSL_SHA_H) + CHECK_SYMBOL_EXISTS(SHA256_Init "openssl/sha.h" HAVE_OPENSSL_SHA256_INIT) + CHECK_SYMBOL_EXISTS(SHA384_Init "openssl/sha.h" HAVE_OPENSSL_SHA384_INIT) + CHECK_SYMBOL_EXISTS(SHA512_Init "openssl/sha.h" HAVE_OPENSSL_SHA512_INIT) +ENDIF() SET(CMAKE_REQUIRED_LIBRARIES "") # diff --git a/build/cmake/config.h.in b/build/cmake/config.h.in index 98cb37d0b..a285c73d4 100644 --- a/build/cmake/config.h.in +++ b/build/cmake/config.h.in @@ -314,6 +314,15 @@ /* Define to 1 if you have the header file. */ #cmakedefine HAVE_OPENSSL_SHA_H 1 +/* Define to 1 if your openssl has the `SHA256_Init' function. */ +#cmakedefine HAVE_OPENSSL_SHA256_INIT 1 + +/* Define to 1 if your openssl has the `SHA384_Init' function. */ +#cmakedefine HAVE_OPENSSL_SHA384_INIT 1 + +/* Define to 1 if your openssl has the `SHA512_Init' function. */ +#cmakedefine HAVE_OPENSSL_SHA512_INIT 1 + /* Define to 1 if you have the header file. */ #cmakedefine HAVE_PATHS_H 1 diff --git a/configure.ac b/configure.ac index fc80d6887..2a0361951 100644 --- a/configure.ac +++ b/configure.ac @@ -265,7 +265,19 @@ if test "x$with_openssl" != "xno"; then test "$ac_cv_func_SHA384_Init" != "yes" || test "$ac_cv_func_SHA512_Init" != "yes"; then AC_CHECK_HEADERS([openssl/sha.h]) + # TODO: Does AC_SEARCH_LIBS support more than one function at once? + # This appears to always fail. AC_SEARCH_LIBS([SHA256_Init SHA384_Init SHA512_Init], [crypto]) + + # TODO: Actually test for these. Previously our C code did not + # test for these at all and just assumed availability. Now that + # the C code tests these macros we preserve previous behavior + # for the autotools build by hard-coding availability. + if test "$ac_cv_header_openssl_sha_h" = "yes"; then + AC_DEFINE(HAVE_OPENSSL_SHA256_INIT, 1, [Define to 1 if your openssl has the `SHA256_Init' function.]) + AC_DEFINE(HAVE_OPENSSL_SHA384_INIT, 1, [Define to 1 if your openssl has the `SHA384_Init' function.]) + AC_DEFINE(HAVE_OPENSSL_SHA512_INIT, 1, [Define to 1 if your openssl has the `SHA512_Init' function.]) + fi fi fi fi diff --git a/libarchive/archive_hash.h b/libarchive/archive_hash.h index 6ba0da308..2c4275211 100644 --- a/libarchive/archive_hash.h +++ b/libarchive/archive_hash.h @@ -108,7 +108,7 @@ typedef SHA256_CTX archive_sha256_ctx; # define archive_sha256_init(ctx) SHA256Init(ctx) # define archive_sha256_final(ctx, buf) SHA256Final(buf, ctx) # define archive_sha256_update(ctx, buf, n) SHA256Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) +#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA256_INIT) # include # define ARCHIVE_HAS_SHA256 typedef SHA256_CTX archive_sha256_ctx; @@ -131,7 +131,7 @@ typedef SHA384_CTX archive_sha384_ctx; # define archive_sha384_init(ctx) SHA384Init(ctx) # define archive_sha384_final(ctx, buf) SHA384Final(buf, ctx) # define archive_sha384_update(ctx, buf, n) SHA384Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) +#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA384_INIT) # include # define ARCHIVE_HAS_SHA384 typedef SHA512_CTX archive_sha384_ctx; @@ -154,7 +154,7 @@ typedef SHA512_CTX archive_sha512_ctx; # define archive_sha512_init(ctx) SHA512Init(ctx) # define archive_sha512_final(ctx, buf) SHA512Final(buf, ctx) # define archive_sha512_update(ctx, buf, n) SHA512Update(ctx, buf, n) -#elif defined(HAVE_OPENSSL_SHA_H) +#elif defined(HAVE_OPENSSL_SHA_H) && defined(HAVE_OPENSSL_SHA512_INIT) # include # define ARCHIVE_HAS_SHA512 typedef SHA512_CTX archive_sha512_ctx;