summaryrefslogtreecommitdiffstats
path: root/lib/libarchive/archive_hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libarchive/archive_hash.h')
-rw-r--r--lib/libarchive/archive_hash.h171
1 files changed, 128 insertions, 43 deletions
diff --git a/lib/libarchive/archive_hash.h b/lib/libarchive/archive_hash.h
index 3e10e8d..dc63d94 100644
--- a/lib/libarchive/archive_hash.h
+++ b/lib/libarchive/archive_hash.h
@@ -29,6 +29,10 @@
#error This header is only to be used internally to libarchive.
#endif
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+
/*
* Hash function support in various Operating Systems:
*
@@ -41,43 +45,71 @@
* - OpenBSD 4.4 and earlier have SHA2 in libc with _ after algorithm name
*
* DragonFly and FreeBSD (XXX not used yet):
- * - MD5 in libmd: without _ after algorithm name
- * - SHA{1,256,512} in libmd: with _ after algorithm name (conflicts w/OpenSSL!)
+ * - MD5 and SHA1 in libmd: without _ after algorithm name
+ * - SHA256: with _ after algorithm name
+ *
+ * Mac OS X (10.4 and later):
+ * - MD5, SHA1 and SHA2 in libSystem: with CC_ prefix and _ after algorithm name
*
* OpenSSL:
- * - MD5, SHA1, SHA2, SHA{256,384,512} in libcrypto: with _ after algorithm name
+ * - MD5, SHA1 and SHA2 in libcrypto: with _ after algorithm name
+ *
+ * Windows:
+ * - MD5, SHA1 and SHA2 in archive_windows.c: without algorithm name
+ * and with __la_ prefix.
*/
+#if defined(ARCHIVE_HASH_MD5_WIN) ||\
+ defined(ARCHIVE_HASH_SHA1_WIN) || defined(ARCHIVE_HASH_SHA256_WIN) ||\
+ defined(ARCHIVE_HASH_SHA384_WIN) || defined(ARCHIVE_HASH_SHA512_WIN)
+#include <wincrypt.h>
+typedef struct {
+ int valid;
+ HCRYPTPROV cryptProv;
+ HCRYPTHASH hash;
+} Digest_CTX;
+extern void __la_hash_Init(Digest_CTX *, ALG_ID);
+extern void __la_hash_Final(unsigned char *, size_t, Digest_CTX *);
+extern void __la_hash_Update(Digest_CTX *, const unsigned char *, size_t);
+#endif
-#if defined(HAVE_MD5_H) && defined(HAVE_MD5INIT)
+#if defined(ARCHIVE_HASH_MD5_LIBC)
# include <md5.h>
# define ARCHIVE_HAS_MD5
typedef MD5_CTX archive_md5_ctx;
# define archive_md5_init(ctx) MD5Init(ctx)
# define archive_md5_final(ctx, buf) MD5Final(buf, ctx)
# define archive_md5_update(ctx, buf, n) MD5Update(ctx, buf, n)
-#elif defined(HAVE_OPENSSL_MD5_H)
+#elif defined(ARCHIVE_HASH_MD5_LIBSYSTEM)
+# include <CommonCrypto/CommonDigest.h>
+# define ARCHIVE_HAS_MD5
+typedef CC_MD5_CTX archive_md5_ctx;
+# define archive_md5_init(ctx) CC_MD5_Init(ctx)
+# define archive_md5_final(ctx, buf) CC_MD5_Final(buf, ctx)
+# define archive_md5_update(ctx, buf, n) CC_MD5_Update(ctx, buf, n)
+#elif defined(ARCHIVE_HASH_MD5_OPENSSL)
# include <openssl/md5.h>
# define ARCHIVE_HAS_MD5
typedef MD5_CTX archive_md5_ctx;
# define archive_md5_init(ctx) MD5_Init(ctx)
# define archive_md5_final(ctx, buf) MD5_Final(buf, ctx)
# define archive_md5_update(ctx, buf, n) MD5_Update(ctx, buf, n)
-#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_MD5)
+#elif defined(ARCHIVE_HASH_MD5_WIN)
# define ARCHIVE_HAS_MD5
-typedef MD5_CTX archive_md5_ctx;
-# define archive_md5_init(ctx) MD5_Init(ctx)
-# define archive_md5_final(ctx, buf) MD5_Final(buf, ctx)
-# define archive_md5_update(ctx, buf, n) MD5_Update(ctx, buf, n)
+# define MD5_DIGEST_LENGTH 16
+typedef Digest_CTX archive_md5_ctx;
+# define archive_md5_init(ctx) __la_hash_Init(ctx, CALG_MD5)
+# define archive_md5_final(ctx, buf) __la_hash_Final(buf, MD5_DIGEST_LENGTH, ctx)
+# define archive_md5_update(ctx, buf, n) __la_hash_Update(ctx, buf, n)
#endif
-#if defined(HAVE_RMD160_H) && defined(HAVE_RMD160INIT)
+#if defined(ARCHIVE_HASH_RMD160_LIBC)
# include <rmd160.h>
# define ARCHIVE_HAS_RMD160
typedef RMD160_CTX archive_rmd160_ctx;
# define archive_rmd160_init(ctx) RMD160Init(ctx)
# define archive_rmd160_final(ctx, buf) RMD160Final(buf, ctx)
# define archive_rmd160_update(ctx, buf, n) RMD160Update(ctx, buf, n)
-#elif defined(HAVE_OPENSSL_RIPEMD_H)
+#elif defined(ARCHIVE_HASH_RMD160_OPENSSL)
# include <openssl/ripemd.h>
# define ARCHIVE_HAS_RMD160
typedef RIPEMD160_CTX archive_rmd160_ctx;
@@ -86,111 +118,164 @@ typedef RIPEMD160_CTX archive_rmd160_ctx;
# define archive_rmd160_update(ctx, buf, n) RIPEMD160_Update(ctx, buf, n)
#endif
-#if defined(HAVE_SHA1_H) && defined(HAVE_SHA1INIT)
+#if defined(ARCHIVE_HASH_SHA1_LIBC)
# include <sha1.h>
# define ARCHIVE_HAS_SHA1
typedef SHA1_CTX archive_sha1_ctx;
# define archive_sha1_init(ctx) SHA1Init(ctx)
# define archive_sha1_final(ctx, buf) SHA1Final(buf, ctx)
# define archive_sha1_update(ctx, buf, n) SHA1Update(ctx, buf, n)
-#elif defined(HAVE_OPENSSL_SHA_H)
+#elif defined(ARCHIVE_HASH_SHA1_LIBSYSTEM)
+# include <CommonCrypto/CommonDigest.h>
+# define ARCHIVE_HAS_SHA1
+typedef CC_SHA1_CTX archive_sha1_ctx;
+# define archive_sha1_init(ctx) CC_SHA1_Init(ctx)
+# define archive_sha1_final(ctx, buf) CC_SHA1_Final(buf, ctx)
+# define archive_sha1_update(ctx, buf, n) CC_SHA1_Update(ctx, buf, n)
+#elif defined(ARCHIVE_HASH_SHA1_OPENSSL)
# include <openssl/sha.h>
# define ARCHIVE_HAS_SHA1
typedef SHA_CTX archive_sha1_ctx;
# define archive_sha1_init(ctx) SHA1_Init(ctx)
# define archive_sha1_final(ctx, buf) SHA1_Final(buf, ctx)
# define archive_sha1_update(ctx, buf, n) SHA1_Update(ctx, buf, n)
-#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA1)
+#elif defined(ARCHIVE_HASH_SHA1_WIN)
# define ARCHIVE_HAS_SHA1
-typedef SHA1_CTX archive_sha1_ctx;
-# define archive_sha1_init(ctx) SHA1_Init(ctx)
-# define archive_sha1_final(ctx, buf) SHA1_Final(buf, ctx)
-# define archive_sha1_update(ctx, buf, n) SHA1_Update(ctx, buf, n)
+# define SHA1_DIGEST_LENGTH 20
+typedef Digest_CTX archive_sha1_ctx;
+# define archive_sha1_init(ctx) __la_hash_Init(ctx, CALG_SHA1)
+# define archive_sha1_final(ctx, buf) __la_hash_Final(buf, SHA1_DIGEST_LENGTH, ctx)
+# define archive_sha1_update(ctx, buf, n) __la_hash_Update(ctx, buf, n)
#endif
-#if defined(HAVE_SHA2_H) && defined(HAVE_SHA256_INIT)
+#if defined(ARCHIVE_HASH_SHA256_LIBC)
# include <sha2.h>
# define ARCHIVE_HAS_SHA256
typedef SHA256_CTX archive_sha256_ctx;
# define archive_sha256_init(ctx) SHA256_Init(ctx)
# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx)
# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n)
-#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA256INIT)
+#elif defined(ARCHIVE_HASH_SHA256_LIBC2)
# include <sha2.h>
# define ARCHIVE_HAS_SHA256
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) && defined(HAVE_OPENSSL_SHA256_INIT)
+#elif defined(ARCHIVE_HASH_SHA256_LIBC3)
+# include <sha2.h>
+# define ARCHIVE_HAS_SHA256
+typedef SHA2_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(ARCHIVE_HASH_SHA256_LIBSYSTEM)
+# include <CommonCrypto/CommonDigest.h>
+# define ARCHIVE_HAS_SHA256
+typedef CC_SHA256_CTX archive_shs256_ctx;
+# define archive_shs256_init(ctx) CC_SHA256_Init(ctx)
+# define archive_shs256_final(ctx, buf) CC_SHA256_Final(buf, ctx)
+# define archive_shs256_update(ctx, buf, n) CC_SHA256_Update(ctx, buf, n)
+#elif defined(ARCHIVE_HASH_SHA256_OPENSSL)
# include <openssl/sha.h>
# define ARCHIVE_HAS_SHA256
typedef SHA256_CTX archive_sha256_ctx;
# define archive_sha256_init(ctx) SHA256_Init(ctx)
# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx)
# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n)
-#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_256)
+#elif defined(ARCHIVE_HASH_SHA256_WIN)
# define ARCHIVE_HAS_SHA256
-typedef SHA256_CTX archive_sha256_ctx;
-# define archive_sha256_init(ctx) SHA256_Init(ctx)
-# define archive_sha256_final(ctx, buf) SHA256_Final(buf, ctx)
-# define archive_sha256_update(ctx, buf, n) SHA256_Update(ctx, buf, n)
+# define SHA256_DIGEST_LENGTH 32
+typedef Digest_CTX archive_sha256_ctx;
+# define archive_sha256_init(ctx) __la_hash_Init(ctx, CALG_SHA_256)
+# define archive_sha256_final(ctx, buf) __la_hash_Final(buf, SHA256_DIGEST_LENGTH, ctx)
+# define archive_sha256_update(ctx, buf, n) __la_hash_Update(ctx, buf, n)
#endif
-#if defined(HAVE_SHA2_H) && defined(HAVE_SHA384_INIT)
+#if defined(ARCHIVE_HASH_SHA384_LIBC)
# include <sha2.h>
# define ARCHIVE_HAS_SHA384
typedef SHA384_CTX archive_sha384_ctx;
# define archive_sha384_init(ctx) SHA384_Init(ctx)
# define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx)
# define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n)
-#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA384INIT)
+#elif defined(ARCHIVE_HASH_SHA384_LIBC2)
# include <sha2.h>
# define ARCHIVE_HAS_SHA384
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) && defined(HAVE_OPENSSL_SHA384_INIT)
+#elif defined(ARCHIVE_HASH_SHA384_LIBC3)
+# include <sha2.h>
+# define ARCHIVE_HAS_SHA384
+typedef SHA2_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(ARCHIVE_HASH_SHA384_LIBSYSTEM)
+# include <CommonCrypto/CommonDigest.h>
+# define ARCHIVE_HAS_SHA384
+typedef CC_SHA512_CTX archive_shs384_ctx;
+# define archive_shs384_init(ctx) CC_SHA384_Init(ctx)
+# define archive_shs384_final(ctx, buf) CC_SHA384_Final(buf, ctx)
+# define archive_shs384_update(ctx, buf, n) CC_SHA384_Update(ctx, buf, n)
+#elif defined(ARCHIVE_HASH_SHA384_OPENSSL)
# include <openssl/sha.h>
# define ARCHIVE_HAS_SHA384
typedef SHA512_CTX archive_sha384_ctx;
# define archive_sha384_init(ctx) SHA384_Init(ctx)
# define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx)
# define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n)
-#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_384)
+#elif defined(ARCHIVE_HASH_SHA384_WIN)
# define ARCHIVE_HAS_SHA384
-typedef SHA512_CTX archive_sha384_ctx;
-# define archive_sha384_init(ctx) SHA384_Init(ctx)
-# define archive_sha384_final(ctx, buf) SHA384_Final(buf, ctx)
-# define archive_sha384_update(ctx, buf, n) SHA384_Update(ctx, buf, n)
+# define SHA384_DIGEST_LENGTH 48
+typedef Digest_CTX archive_sha384_ctx;
+# define archive_sha384_init(ctx) __la_hash_Init(ctx, CALG_SHA_384)
+# define archive_sha384_final(ctx, buf) __la_hash_Final(buf, SHA384_DIGEST_LENGTH, ctx)
+# define archive_sha384_update(ctx, buf, n) __la_hash_Update(ctx, buf, n)
#endif
-#if defined(HAVE_SHA2_H) && defined(HAVE_SHA512_INIT)
+#if defined(ARCHIVE_HASH_SHA512_LIBC)
# include <sha2.h>
# define ARCHIVE_HAS_SHA512
typedef SHA512_CTX archive_sha512_ctx;
# define archive_sha512_init(ctx) SHA512_Init(ctx)
# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx)
# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n)
-#elif defined(HAVE_SHA2_H) && defined(HAVE_SHA512INIT)
+#elif defined(ARCHIVE_HASH_SHA512_LIBC2)
# include <sha2.h>
# define ARCHIVE_HAS_SHA512
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) && defined(HAVE_OPENSSL_SHA512_INIT)
+#elif defined(ARCHIVE_HASH_SHA512_LIBC3)
+# include <sha2.h>
+# define ARCHIVE_HAS_SHA512
+typedef SHA2_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(ARCHIVE_HASH_SHA512_LIBSYSTEM)
+# include <CommonCrypto/CommonDigest.h>
+# define ARCHIVE_HAS_SHA512
+typedef CC_SHA512_CTX archive_shs512_ctx;
+# define archive_shs512_init(ctx) CC_SHA512_Init(ctx)
+# define archive_shs512_final(ctx, buf) CC_SHA512_Final(buf, ctx)
+# define archive_shs512_update(ctx, buf, n) CC_SHA512_Update(ctx, buf, n)
+#elif defined(ARCHIVE_HASH_SHA512_OPENSSL)
# include <openssl/sha.h>
# define ARCHIVE_HAS_SHA512
typedef SHA512_CTX archive_sha512_ctx;
# define archive_sha512_init(ctx) SHA512_Init(ctx)
# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx)
# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n)
-#elif defined(_WIN32) && !defined(__CYGWIN__) && defined(CALG_SHA_512)
+#elif defined(ARCHIVE_HASH_SHA512_WIN)
# define ARCHIVE_HAS_SHA512
-typedef SHA512_CTX archive_sha512_ctx;
-# define archive_sha512_init(ctx) SHA512_Init(ctx)
-# define archive_sha512_final(ctx, buf) SHA512_Final(buf, ctx)
-# define archive_sha512_update(ctx, buf, n) SHA512_Update(ctx, buf, n)
+# define SHA512_DIGEST_LENGTH 64
+typedef Digest_CTX archive_sha512_ctx;
+# define archive_sha512_init(ctx) __la_hash_Init(ctx, CALG_SHA_512)
+# define archive_sha512_final(ctx, buf) __la_hash_Final(buf, SHA512_DIGEST_LENGTH, ctx)
+# define archive_sha512_update(ctx, buf, n) __la_hash_Update(ctx, buf, n)
#endif
OpenPOWER on IntegriCloud