]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Use CommonCrypto APIs on OS X only when available 612/head
authorBrad King <brad.king@kitware.com>
Wed, 21 Oct 2015 18:46:37 +0000 (14:46 -0400)
committerBrad King <brad.king@kitware.com>
Mon, 26 Oct 2015 14:20:51 +0000 (10:20 -0400)
Use each CommonCrypto API only when using an OS X SDK version new enough
to provide it.

libarchive/archive_cryptor.c
libarchive/archive_cryptor_private.h
libarchive/archive_hmac.c
libarchive/archive_hmac_private.h

index 9b01df8f1118761a1cb57dd37d4309513f299ac7..efd350d29ee4f78a3359444cb8b36aec7ff00020 100644 (file)
@@ -31,7 +31,7 @@
 #include "archive.h"
 #include "archive_cryptor_private.h"
 
-#ifdef __APPLE__
+#ifdef ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto
 
 static int
 pbkdf2_sha1(const char *pw, size_t pw_len, const uint8_t *salt,
@@ -114,7 +114,10 @@ pbkdf2_sha1(const char *pw, size_t pw_len, const uint8_t *salt,
 
 #endif
 
-#ifdef __APPLE__
+#ifdef ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto
+# if MAC_OS_X_VERSION_MAX_ALLOWED < 1090
+#  define kCCAlgorithmAES kCCAlgorithmAES128
+# endif
 
 static int
 aes_ctr_init(archive_crypto_ctx *ctx, const uint8_t *key, size_t key_len)
index b62ec0c666221581901d58f0784cf49753e3c0f5..9a96aeea6cc394090d87c48c93f4fbc01f1f27fc 100644 (file)
 #define ARCHIVE_CRYPTOR_PRIVATE_H_INCLUDED
 
 #ifdef __APPLE__
+# include <AvailabilityMacros.h>
+# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1080
+#  define ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto
+# endif
+#endif
+
+#ifdef ARCHIVE_CRYPTOR_USE_Apple_CommonCrypto
 #include <CommonCrypto/CommonCryptor.h>
 #include <CommonCrypto/CommonKeyDerivation.h>
 #define AES_BLOCK_SIZE 16
index 898853bd1e76c666980449a405e3a778e3de8d66..36e3e1c6fdf8faeb57c75eb0c2538752cb8a9d02 100644 (file)
@@ -31,7 +31,7 @@
 #include "archive.h"
 #include "archive_hmac_private.h"
 
-#ifdef __APPLE__
+#ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto
 
 static int
 __hmac_sha1_init(archive_hmac_sha1_ctx *ctx, const uint8_t *key, size_t key_len)
index 6a8bbf294767f8650a9753b3b196f6cf5fcc5e44..a9fb8eca5d0ffe7115c850e9e62724c6fa95c836 100644 (file)
 #define ARCHIVE_HMAC_PRIVATE_H_INCLUDED
 
 #ifdef __APPLE__
+# include <AvailabilityMacros.h>
+# if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
+#  define ARCHIVE_HMAC_USE_Apple_CommonCrypto
+# endif
+#endif
+
+#ifdef ARCHIVE_HMAC_USE_Apple_CommonCrypto
 #include <CommonCrypto/CommonHMAC.h>
 
 typedef        CCHmacContext archive_hmac_sha1_ctx;