From 68c3214b7c36ddf666c2ea3999698a44e2a7a6ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Mon, 21 Oct 2024 13:13:50 +0200 Subject: [PATCH 1/2] fix: avoid private api on Mac App Store --- mz_crypt_apple.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mz_crypt_apple.c b/mz_crypt_apple.c index 72a44c2d..998617f1 100644 --- a/mz_crypt_apple.c +++ b/mz_crypt_apple.c @@ -21,7 +21,7 @@ /***************************************************************************/ /* Avoid use of private API for iOS, Apple does not allow it on App Store. Zip format doesn't need GCM. */ -#if !TARGET_OS_IPHONE +#if !defined(__APPLE__) enum { kCCModeGCM = 11, }; @@ -227,7 +227,7 @@ int32_t mz_crypt_aes_encrypt(void *handle, const void *aad, int32_t aad_size, ui return MZ_PARAM_ERROR; if (aes->mode == MZ_AES_MODE_GCM) { -#if TARGET_OS_IPHONE +#if defined(__APPLE__) return MZ_SUPPORT_ERROR; #else if (aad && aad_size > 0) { @@ -251,14 +251,14 @@ int32_t mz_crypt_aes_encrypt(void *handle, const void *aad, int32_t aad_size, ui int32_t mz_crypt_aes_encrypt_final(void *handle, uint8_t *buf, int32_t size, uint8_t *tag, int32_t tag_size) { mz_crypt_aes *aes = (mz_crypt_aes *)handle; -#if !TARGET_OS_IPHONE +#if !defined(__APPLE__) size_t tag_outsize = tag_size; #endif if (!aes || !tag || !tag_size || !aes->crypt || aes->mode != MZ_AES_MODE_GCM) return MZ_PARAM_ERROR; -#if TARGET_OS_IPHONE +#if defined(__APPLE__) return MZ_SUPPORT_ERROR; #else aes->error = CCCryptorGCMEncrypt(aes->crypt, buf, size, buf); @@ -282,7 +282,7 @@ int32_t mz_crypt_aes_decrypt(void *handle, const void *aad, int32_t aad_size, ui return MZ_PARAM_ERROR; if (aes->mode == MZ_AES_MODE_GCM) { -#if TARGET_OS_IPHONE +#if defined(__APPLE__) return MZ_SUPPORT_ERROR; #else if (aad && aad_size > 0) { @@ -306,7 +306,7 @@ int32_t mz_crypt_aes_decrypt(void *handle, const void *aad, int32_t aad_size, ui int32_t mz_crypt_aes_decrypt_final(void *handle, uint8_t *buf, int32_t size, const uint8_t *tag, int32_t tag_length) { mz_crypt_aes *aes = (mz_crypt_aes *)handle; -#if !TARGET_OS_IPHONE +#if !defined(__APPLE__) uint8_t tag_actual_buf[MZ_AES_BLOCK_SIZE]; size_t tag_actual_len = sizeof(tag_actual_buf); uint8_t *tag_actual = tag_actual_buf; @@ -317,7 +317,7 @@ int32_t mz_crypt_aes_decrypt_final(void *handle, uint8_t *buf, int32_t size, con if (!aes || !tag || !tag_length || !aes->crypt || aes->mode != MZ_AES_MODE_GCM) return MZ_PARAM_ERROR; -#if TARGET_OS_IPHONE +#if defined(__APPLE__) return MZ_SUPPORT_ERROR; #else aes->error = CCCryptorGCMDecrypt(aes->crypt, buf, size, buf); @@ -353,7 +353,7 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l else if (aes->mode == MZ_AES_MODE_ECB) mode = kCCModeECB; else if (aes->mode == MZ_AES_MODE_GCM) -#if !TARGET_OS_IPHONE +#if !defined(__APPLE__) mode = kCCModeGCM; #else return MZ_SUPPORT_ERROR; @@ -369,7 +369,7 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l if (aes->error != kCCSuccess) return MZ_HASH_ERROR; -#if !TARGET_OS_IPHONE +#if !defined(__APPLE__) if (aes->mode == MZ_AES_MODE_GCM) { aes->error = CCCryptorGCMAddIV(aes->crypt, iv, iv_length); From 6d6491514365e8586d87bbf04ab50ecfa6978c1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C5=93ur?= Date: Tue, 22 Oct 2024 02:46:23 +0200 Subject: [PATCH 2/2] code review: MZ_TARGET_APPSTORE --- mz_crypt_apple.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/mz_crypt_apple.c b/mz_crypt_apple.c index 998617f1..e9419432 100644 --- a/mz_crypt_apple.c +++ b/mz_crypt_apple.c @@ -20,8 +20,12 @@ /***************************************************************************/ -/* Avoid use of private API for iOS, Apple does not allow it on App Store. Zip format doesn't need GCM. */ -#if !defined(__APPLE__) +#ifndef MZ_TARGET_APPSTORE +#define MZ_TARGET_APPSTORE 0 +#endif + +/* Avoid use of private API for App Store as Apple does not allow it. Zip format doesn't need GCM. */ +#if !MZ_TARGET_APPSTORE enum { kCCModeGCM = 11, }; @@ -227,7 +231,7 @@ int32_t mz_crypt_aes_encrypt(void *handle, const void *aad, int32_t aad_size, ui return MZ_PARAM_ERROR; if (aes->mode == MZ_AES_MODE_GCM) { -#if defined(__APPLE__) +#if MZ_TARGET_APPSTORE return MZ_SUPPORT_ERROR; #else if (aad && aad_size > 0) { @@ -251,14 +255,14 @@ int32_t mz_crypt_aes_encrypt(void *handle, const void *aad, int32_t aad_size, ui int32_t mz_crypt_aes_encrypt_final(void *handle, uint8_t *buf, int32_t size, uint8_t *tag, int32_t tag_size) { mz_crypt_aes *aes = (mz_crypt_aes *)handle; -#if !defined(__APPLE__) +#if !MZ_TARGET_APPSTORE size_t tag_outsize = tag_size; #endif if (!aes || !tag || !tag_size || !aes->crypt || aes->mode != MZ_AES_MODE_GCM) return MZ_PARAM_ERROR; -#if defined(__APPLE__) +#if MZ_TARGET_APPSTORE return MZ_SUPPORT_ERROR; #else aes->error = CCCryptorGCMEncrypt(aes->crypt, buf, size, buf); @@ -282,7 +286,7 @@ int32_t mz_crypt_aes_decrypt(void *handle, const void *aad, int32_t aad_size, ui return MZ_PARAM_ERROR; if (aes->mode == MZ_AES_MODE_GCM) { -#if defined(__APPLE__) +#if MZ_TARGET_APPSTORE return MZ_SUPPORT_ERROR; #else if (aad && aad_size > 0) { @@ -306,7 +310,7 @@ int32_t mz_crypt_aes_decrypt(void *handle, const void *aad, int32_t aad_size, ui int32_t mz_crypt_aes_decrypt_final(void *handle, uint8_t *buf, int32_t size, const uint8_t *tag, int32_t tag_length) { mz_crypt_aes *aes = (mz_crypt_aes *)handle; -#if !defined(__APPLE__) +#if !MZ_TARGET_APPSTORE uint8_t tag_actual_buf[MZ_AES_BLOCK_SIZE]; size_t tag_actual_len = sizeof(tag_actual_buf); uint8_t *tag_actual = tag_actual_buf; @@ -317,7 +321,7 @@ int32_t mz_crypt_aes_decrypt_final(void *handle, uint8_t *buf, int32_t size, con if (!aes || !tag || !tag_length || !aes->crypt || aes->mode != MZ_AES_MODE_GCM) return MZ_PARAM_ERROR; -#if defined(__APPLE__) +#if MZ_TARGET_APPSTORE return MZ_SUPPORT_ERROR; #else aes->error = CCCryptorGCMDecrypt(aes->crypt, buf, size, buf); @@ -353,7 +357,7 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l else if (aes->mode == MZ_AES_MODE_ECB) mode = kCCModeECB; else if (aes->mode == MZ_AES_MODE_GCM) -#if !defined(__APPLE__) +#if !MZ_TARGET_APPSTORE mode = kCCModeGCM; #else return MZ_SUPPORT_ERROR; @@ -369,7 +373,7 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l if (aes->error != kCCSuccess) return MZ_HASH_ERROR; -#if !defined(__APPLE__) +#if !MZ_TARGET_APPSTORE if (aes->mode == MZ_AES_MODE_GCM) { aes->error = CCCryptorGCMAddIV(aes->crypt, iv, iv_length);