used in mtree format.
It tested on FreeBSD, NetBSD and Ubuntu.
SVN-Revision: 509
CHECK_INCLUDE_FILE(sys/types.h HAVE_SYS_TYPES_H)
#
-# Find MD5 headers and library
+# Find MD5/SHA headers
#
+CHECK_HEADERS(openssl/md5.h openssl/sha.h)
SET(_files "")
IF(HAVE_SYS_TYPES_H)
SET(_files "sys/types.h")
ENDIF(HAVE_MD5GLOBAL_H)
SET(_files ${_files} "md5.h")
CHECK_INCLUDE_FILES("${_files}" HAVE_MD5_H)
-# libmd
-FIND_LIBRARY(MD_LIBRARY NAMES md)
-IF(MD_LIBRARY)
- SET(HAVE_LIBMD 1)
- LIST(APPEND ADDITIONAL_LIBS ${MD_LIBRARY})
-ENDIF(MD_LIBRARY)
-#
-# Find SHA headers
-#
CHECK_HEADERS(sha.h sha1.h sha2.h sha256.h)
+#
+# Find MD5/SHA library
+#
+FIND_LIBRARY(CRYPTO_LIBRARY NAMES crypto)
+IF(CRYPTO_LIBRARY)
+ LIST(APPEND ADDITIONAL_LIBS ${CRYPTO_LIBRARY})
+ELSE(CRYPTO_LIBRARY)
+ FIND_LIBRARY(SSL_LIBRARY NAMES ssl)
+ IF(SSL_LIBRARY)
+ LIST(APPEND ADDITIONAL_LIBS ${SSL_LIBRARY})
+ ELSE(SSL_LIBRARY)
+ FIND_LIBRARY(MD_LIBRARY NAMES md)
+ IF(MD_LIBRARY)
+ LIST(APPEND ADDITIONAL_LIBS ${MD_LIBRARY})
+ ENDIF(MD_LIBRARY)
+ ENDIF(SSL_LIBRARY)
+ENDIF(CRYPTO_LIBRARY)
+#
+# Check MD5/SHA functions
+#
+SET(CMAKE_REQUIRED_LIBRARIES ${ADDITIONAL_LIBS})
+CHECK_FUNCTION_EXISTS(MD5_Init HAVE_MD5_Init)
+IF(NOT HAVE_MD5_Init)
+ CHECK_FUNCTION_EXISTS(MD5Init HAVE_MD5Init)
+ IF(HAVE_MD5Init)
+ SET(MD5_Init, "MD5Init")
+ SET(MD5_Update, "MD5Update")
+ SET(MD5_Final, "MD5Final")
+ ENDIF(HAVE_MD5Init)
+ENDIF(NOT HAVE_MD5_Init)
+IF(HAVE_MD5_Init OR HAVE_MD5Init)
+ SET(HAVE_MD5 1)
+ENDIF(HAVE_MD5_Init OR HAVE_MD5Init)
+#
+CHECK_FUNCTION_EXISTS(SHA1_Init HAVE_SHA1_Init)
+IF(NOT HAVE_SHA1_Init)
+ CHECK_FUNCTION_EXISTS(SHA1Init HAVE_SHA1Init)
+ IF(HAVE_SHA1Init)
+ SET(SHA1_Init, "SHA1Init")
+ SET(SHA1_Update, "SHA1Update")
+ SET(SHA1_Final, "SHA1Final")
+ ENDIF(HAVE_SHA1Init)
+ENDIF(NOT HAVE_SHA1_Init)
+IF(HAVE_SHA1_Init OR HAVE_SHA1Init)
+ SET(HAVE_SHA1 1)
+ENDIF(HAVE_SHA1_Init OR HAVE_SHA1Init)
+#
+CHECK_FUNCTION_EXISTS(SHA256_Init HAVE_SHA256)
+CHECK_FUNCTION_EXISTS(SHA384_Init HAVE_SHA384)
+CHECK_FUNCTION_EXISTS(SHA512_Init HAVE_SHA512)
#
# Check functions
/* Define to 1 if you have the `lzmadec' library (-llzmadec). */
#cmakedefine HAVE_LIBLZMADEC 1
-/* Define to 1 if you have the `md' library (-lmd). */
-#cmakedefine HAVE_LIBMD 1
-
/* Define to 1 if you have the `z' library (-lz). */
#cmakedefine HAVE_LIBZ 1
/* Define to 1 if you have the <lzmadec.h> header file. */
#cmakedefine HAVE_LZMADEC_H 1
+/* Define to 1 if you have the `MD5' functions. */
+#cmakedefine HAVE_MD5 1
+
/* Define to 1 if you have the <md5global.h> header file. */
#cmakedefine HAVE_MD5GLOBAL_H 1
/* Define to 1 if you have the `nl_langinfo' function. */
#cmakedefine HAVE_NL_LANGINFO 1
+/* Define to 1 if you have the <openssl/md5.h> header file. */
+#cmakedefine HAVE_OPENSSL_MD5_H 1
+
+/* Define to 1 if you have the <openssl/sha.h> header file. */
+#cmakedefine HAVE_OPENSSL_SHA_H 1
+
/* Define to 1 if you have the <paths.h> header file. */
#cmakedefine HAVE_PATHS_H 1
/* Define to 1 if you have the `setlocale' function. */
#cmakedefine HAVE_SETLOCALE 1
+/* Define to 1 if you have the `SHA1' functions. */
+#cmakedefine HAVE_SHA1 1
+
/* Define to 1 if you have the <sha1.h> header file. */
#cmakedefine HAVE_SHA1_H 1
+/* Define to 1 if you have the `SHA256' functions. */
+#cmakedefine HAVE_SHA256 1
+
/* Define to 1 if you have the <sha256.h> header file. */
#cmakedefine HAVE_SHA256_H 1
/* Define to 1 if you have the <sha2.h> header file. */
#cmakedefine HAVE_SHA2_H 1
+/* Define to 1 if you have the `SHA384' functions. */
+#cmakedefine HAVE_SHA384 1
+
+/* Define to 1 if you have the `SHA512' functions. */
+#cmakedefine HAVE_SHA512 1
+
/* Define to 1 if you have the <sha.h> header file. */
#cmakedefine HAVE_SHA_H 1
<sysmacros.h>. */
#cmakedefine MAJOR_IN_SYSMACROS 1
+/* Define to the generates final MD5 hash function. */
+#cmakedefine MD5_Final ${MD5_Final}
+
+/* Define to the initializes MD5 context function. */
+#cmakedefine MD5_Init ${MD5_Init}
+
+/* Define to the updates MD5 context function. */
+#cmakedefine MD5_Update ${MD5_Update}
+
/* Define to 1 if your C compiler doesn't accept -c and -o together. */
#cmakedefine NO_MINUS_C_MINUS_O 1
+/* Define to the generates final SHA1 hash function. */
+#cmakedefine SHA1_Final ${SHA1_Final}
+
+/* Define to the initializes SHA1 context function. */
+#cmakedefine SHA1_Init ${SHA1_Init}
+
+/* Define to the updates SHA1 context function. */
+#cmakedefine SHA1_Update ${SHA1_Update}
+
/* Define to 1 if you have the ANSI C header files. */
#cmakedefine STDC_HEADERS 1
AC_CHECK_LIB(lzmadec,lzmadec_decode)
fi
+AC_CHECK_HEADERS([openssl/md5.h openssl/sha.h])
AC_CHECK_HEADERS([md5.h md5global.h])
-AC_CHECK_LIB(md,MD5Init)
AC_CHECK_HEADERS([sha.h sha1.h sha2.h sha256.h])
+AC_SEARCH_LIBS(SHA1_Init, crypto ssl md)
+AC_CHECK_FUNC(MD5_Init)
+if test "x$ac_cv_func_MD5_Init" != "xyes"; then
+ AC_CHECK_FUNC(MD5Init,
+ [AC_DEFINE(MD5_Init, MD5Init,
+ [Define to the initializes MD5 context function.])
+ AC_DEFINE(MD5_Update, MD5Update,
+ [Define to the updates MD5 context function.])
+ AC_DEFINE(MD5_Final, MD5Final,
+ [Define to the generates final MD5 hash function.])
+ ])
+fi
+if test "x$ac_cv_func_MD5_Init" = "xyes" -o "x$ac_cv_func_MD5Init" = "xyes" ; then
+ AC_DEFINE(HAVE_MD5, 1, [Define to 1 if you have the `MD5' functions.])
+fi
+AC_CHECK_FUNC(SHA1_Init)
+if test "x$ac_cv_func_SHA1_Init" != "xyes"; then
+ AC_CHECK_FUNC(SHA1Init,
+ [AC_DEFINE(SHA1_Init, SHA1Init,
+ [Define to the initializes SHA1 context function.])
+ AC_DEFINE(SHA1_Update, SHA1Update,
+ [Define to the updates SHA1 context function.])
+ AC_DEFINE(SHA1_Final, SHA1Final,
+ [Define to the generates final SHA1 hash function.])
+ ])
+fi
+if test "x$ac_cv_func_SHA1_Init" = "xyes" -o "x$ac_cv_func_SHA1Init" = "xyes" ; then
+ AC_DEFINE(HAVE_SHA1, 1, [Define to 1 if you have the `SHA1' functions.])
+fi
+AC_CHECK_FUNC(SHA256_Init)
+if test "x$ac_cv_func_SHA256_Init" = "xyes" ; then
+ AC_DEFINE(HAVE_SHA256, 1, [Define to 1 if you have the `SHA256' functions.])
+fi
+AC_CHECK_FUNC(SHA384_Init)
+if test "x$ac_cv_func_SHA384_Init" = "xyes" ; then
+ AC_DEFINE(HAVE_SHA384, 1, [Define to 1 if you have the `SHA384' functions.])
+fi
+AC_CHECK_FUNC(SHA512_Init)
+if test "x$ac_cv_func_SHA512_Init" = "xyes" ; then
+ AC_DEFINE(HAVE_SHA512, 1, [Define to 1 if you have the `SHA512' functions.])
+fi
# TODO: Give the user the option of using a pre-existing system
# libarchive. This will define HAVE_LIBARCHIVE which will cause
#include <errno.h>
#include <stdlib.h>
#include <string.h>
+#ifdef HAVE_OPENSSL_MD5_H
+#include <openssl/md5.h>
+#else /* HAVE_OPENSSL_MD5_H */
#ifdef HAVE_MD5GLOBAL_H
#include <md5global.h>
#endif
#ifdef HAVE_MD5_H
#include <md5.h>
#endif
+#endif /* HAVE_OPENSSL_MD5_H */
+#ifdef HAVE_OPENSSL_SHA_H
+#include <openssl/sha.h>
+#else /* HAVE_OPENSSL_SHA_H */
#ifdef HAVE_SHA_H
#include <sha.h>
#endif
#ifdef HAVE_SHA256_H
#include <sha256.h>
#endif
+#endif /* HAVE_OPENSSL_SHA_H */
#include "archive.h"
#include "archive_entry.h"
int compute_sum;
uint32_t crc;
uint64_t crc_len;
-#ifdef HAVE_MD5_H
+#ifdef HAVE_MD5
MD5_CTX md5ctx;
#endif
-#if defined(HAVE_SHA_H) || defined(HAVE_SHA1_H)
+#ifdef HAVE_SHA1
+#if defined(HAVE_OPENSSL_SHA_H) || defined(HAVE_SHA_H)
SHA_CTX sha1ctx;
+#else
+ SHA1_CTX sha1ctx;
+#endif
#endif
-#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+#ifdef HAVE_SHA256
SHA256_CTX sha256ctx;
#endif
-#ifdef HAVE_SHA2_H
+#ifdef HAVE_SHA384
+#if defined(HAVE_OPENSSL_SHA_H)
+ SHA512_CTX sha384ctx;
+#else
SHA384_CTX sha384ctx;
+#endif
+#endif
+#ifdef HAVE_SHA512
SHA512_CTX sha512ctx;
#endif
/* Keyword options */
mtree->crc_len = 0;
} else
mtree->compute_sum &= ~F_CKSUM;
-#ifdef HAVE_MD5_H
+#ifdef HAVE_MD5
if ((mtree->keys & F_MD5) != 0 &&
archive_entry_filetype(entry) == AE_IFREG) {
mtree->compute_sum |= F_MD5;
- MD5Init(&mtree->md5ctx);
+ MD5_Init(&mtree->md5ctx);
} else
mtree->compute_sum &= ~F_MD5;
#endif
-#if defined(HAVE_SHA_H) || defined(HAVE_SHA1_H)
+#ifdef HAVE_SHA1
if ((mtree->keys & F_SHA1) != 0 &&
archive_entry_filetype(entry) == AE_IFREG) {
mtree->compute_sum |= F_SHA1;
} else
mtree->compute_sum &= ~F_SHA1;
#endif
-#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+#ifdef HAVE_SHA256
if ((mtree->keys & F_SHA256) != 0 &&
archive_entry_filetype(entry) == AE_IFREG) {
mtree->compute_sum |= F_SHA256;
} else
mtree->compute_sum &= ~F_SHA256;
#endif
-#ifdef HAVE_SHA2_H
+#ifdef HAVE_SHA384
if ((mtree->keys & F_SHA384) != 0 &&
archive_entry_filetype(entry) == AE_IFREG) {
mtree->compute_sum |= F_SHA384;
SHA384_Init(&mtree->sha384ctx);
} else
mtree->compute_sum &= ~F_SHA384;
+#endif
+#ifdef HAVE_SHA512
if ((mtree->keys & F_SHA512) != 0 &&
archive_entry_filetype(entry) == AE_IFREG) {
mtree->compute_sum |= F_SHA512;
archive_string_sprintf(&mtree->buf, " cksum=%ju",
(uintmax_t)mtree->crc);
}
-#ifdef HAVE_MD5_H
+#ifdef HAVE_MD5
if (mtree->compute_sum & F_MD5) {
unsigned char buf[16];
- MD5Final(buf, &mtree->md5ctx);
+ MD5_Final(buf, &mtree->md5ctx);
archive_strcat(&mtree->buf, " md5digest=");
strappend_bin(&mtree->buf, buf, sizeof(buf));
}
#endif
-#if defined(HAVE_SHA_H) || defined(HAVE_SHA1_H)
+#ifdef HAVE_SHA1
if (mtree->compute_sum & F_SHA1) {
unsigned char buf[20];
strappend_bin(&mtree->buf, buf, sizeof(buf));
}
#endif
-#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+#ifdef HAVE_SHA256
if (mtree->compute_sum & F_SHA256) {
unsigned char buf[32];
strappend_bin(&mtree->buf, buf, sizeof(buf));
}
#endif
-#if defined(HAVE_SHA2_H)
+#ifdef HAVE_SHA384
if (mtree->compute_sum & F_SHA384) {
unsigned char buf[48];
archive_strcat(&mtree->buf, " sha384digest=");
strappend_bin(&mtree->buf, buf, sizeof(buf));
}
+#endif
+#ifdef HAVE_SHA512
if (mtree->compute_sum & F_SHA512) {
unsigned char buf[64];
COMPUTE_CRC(mtree->crc, *p);
mtree->crc_len += n;
}
-#ifdef HAVE_MD5_H
+#ifdef HAVE_MD5
if (mtree->compute_sum & F_MD5)
- MD5Update(&mtree->md5ctx, buff, n);
+ MD5_Update(&mtree->md5ctx, buff, n);
#endif
-#if defined(HAVE_SHA_H) || defined(HAVE_SHA1_H)
+#ifdef HAVE_SHA1
if (mtree->compute_sum & F_SHA1)
SHA1_Update(&mtree->sha1ctx, buff, n);
#endif
-#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+#ifdef HAVE_SHA256
if (mtree->compute_sum & F_SHA256)
SHA256_Update(&mtree->sha256ctx, buff, n);
#endif
-#ifdef HAVE_SHA2_H
+#ifdef HAVE_SHA384
if (mtree->compute_sum & F_SHA384)
SHA384_Update(&mtree->sha384ctx, buff, n);
+#endif
+#ifdef HAVE_SHA512
if (mtree->compute_sum & F_SHA512)
- SHA384_Update(&mtree->sha512ctx, buff, n);
+ SHA512_Update(&mtree->sha512ctx, buff, n);
#endif
return n;
}
keybit = F_SLINK;
break;
case 'm':
-#ifdef HAVE_MD5_H
+#ifdef HAVE_MD5
if (strcmp(key, "md5") == 0 ||
strcmp(key, "md5digest") == 0)
keybit = F_MD5;
keybit = F_NLINK;
break;
case 's':
-#if defined(HAVE_SHA_H) || defined(HAVE_SHA1_H)
+#ifdef HAVE_SHA1
if (strcmp(key, "sha1") == 0 ||
strcmp(key, "sha1digest") == 0)
keybit = F_SHA1;
#endif
-#if defined(HAVE_SHA2_H) || defined(HAVE_SHA256_H)
+#ifdef HAVE_SHA256
if (strcmp(key, "sha256") == 0 ||
strcmp(key, "sha256digest") == 0)
keybit = F_SHA256;
#endif
-#ifdef HAVE_SHA2_H
+#ifdef HAVE_SHA384
if (strcmp(key, "sha384") == 0 ||
strcmp(key, "sha384digest") == 0)
keybit = F_SHA384;
+#endif
+#ifdef HAVE_SHA384
if (strcmp(key, "sha512") == 0 ||
strcmp(key, "sha512digest") == 0)
keybit = F_SHA512;