]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Support openssl without SHA-2 hash functions
authorBrad King <brad.king@kitware.com>
Mon, 30 Nov 2009 15:19:45 +0000 (10:19 -0500)
committerBrad King <brad.king@kitware.com>
Mon, 30 Nov 2009 15:19:45 +0000 (10:19 -0500)
Previously we assumed that <openssl/sha.h> 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

CMakeLists.txt
build/cmake/config.h.in
configure.ac
libarchive/archive_hash.h

index 0356c9e17f216972f83d901f96749e1d522b822e..944fca15fffa96bb1bc6cd68b3ec1cce44a8555b 100644 (file)
@@ -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 "")
 
 #
index 98cb37d0b677294eec5c67a73fe7910bfe1f8c95..a285c73d409d0575d93d6cf3395582ee1ddb932a 100644 (file)
 /* Define to 1 if you have the <openssl/sha.h> 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 <paths.h> header file. */
 #cmakedefine HAVE_PATHS_H 1
 
index fc80d6887a43a1aec91f7cf414112264a8946b08..2a03619515df2d851e18df868f7d03002af8a28e 100644 (file)
@@ -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
index 6ba0da3088fadafb598874d3065fe2feeda8c24c..2c427521124337d4f45bfb5fdc1c6418f747131e 100644 (file)
@@ -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 <openssl/sha.h>
 #  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 <openssl/sha.h>
 #  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 <openssl/sha.h>
 #  define ARCHIVE_HAS_SHA512
 typedef SHA512_CTX archive_sha512_ctx;