diff --git a/CMakeLists.txt b/CMakeLists.txt index 97a9819..ef2f4b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ include(CheckLibraryExists) include(CheckSymbolExists) include(CheckFunctionExists) include(CheckIncludeFile) +include(CheckIncludeFiles) include(CheckTypeSize) include(GNUInstallDirs) include(FeatureSummary) @@ -434,7 +435,18 @@ if(WIN32) if(MZ_OPENSSL) list(APPEND MINIZIP_DEP_PKG OpenSSL) else() - list(APPEND MINIZIP_SRC mz_crypt_winvista.c mz_crypt_winxp.c) + check_include_files("windows.h;bcrypt.h" BCRYPT_FOUND) + if (BCRYPT_FOUND) + message(STATUS "Using BCrypt") + + list(APPEND MINIZIP_SRC mz_crypt_winvista.c) + list(APPEND MINIZIP_LIB bcrypt.lib ncrypt.lib) + else() + message(STATUS "Using CryptoAPI") + + list(APPEND MINIZIP_SRC mz_crypt_winxp.c) + endif() + list(APPEND MINIZIP_LIB crypt32.lib) endif() else() list(APPEND MINIZIP_DEF -DMZ_ZIP_NO_CRYPTO) diff --git a/mz_crypt_winvista.c b/mz_crypt_winvista.c index daf41e5..4d7c182 100644 --- a/mz_crypt_winvista.c +++ b/mz_crypt_winvista.c @@ -19,10 +19,6 @@ #endif #if _WIN32_WINNT >= _WIN32_WINNT_VISTA -#pragma comment(lib, "bcrypt.lib") -#pragma comment(lib, "crypt32.lib") -#pragma comment(lib, "ncrypt.lib") - #include /***************************************************************************/ @@ -230,7 +226,7 @@ int32_t mz_crypt_aes_encrypt(void *handle, uint8_t *buf, int32_t size) { if (!aes || !buf || size % MZ_AES_BLOCK_SIZE != 0) return MZ_PARAM_ERROR; - status = BCryptEncrypt(aes->key, buf, size, NULL, aes->iv, sizeof(aes->iv), buf, size, + status = BCryptEncrypt(aes->key, buf, size, NULL, aes->iv, sizeof(aes->iv), buf, size, &output_size, 0); if (!NT_SUCCESS(status)) { @@ -248,7 +244,7 @@ int32_t mz_crypt_aes_decrypt(void *handle, uint8_t *buf, int32_t size) { if (!aes || !buf || size % MZ_AES_BLOCK_SIZE != 0) return MZ_PARAM_ERROR; - status = BCryptDecrypt(aes->key, buf, size, NULL, aes->iv, sizeof(aes->iv), buf, size, + status = BCryptDecrypt(aes->key, buf, size, NULL, aes->iv, sizeof(aes->iv), buf, size, &output_size, 0); if (!NT_SUCCESS(status)) { diff --git a/mz_crypt_winxp.c b/mz_crypt_winxp.c index 7f9d515..e7b33ad 100644 --- a/mz_crypt_winxp.c +++ b/mz_crypt_winxp.c @@ -15,8 +15,6 @@ #include #if _WIN32_WINNT <= _WIN32_WINNT_WINXP -#pragma comment(lib, "crypt32.lib") - #include /***************************************************************************/ @@ -423,7 +421,7 @@ int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) { #else return MZ_SUPPORT_ERROR; #endif - + hmac->info.HashAlgid = alg_id; result = CryptAcquireContext(&hmac->provider, NULL, MS_ENHANCED_PROV, PROV_RSA_FULL,