From a2f11e11024a104dabf6921cd276baa4255473e0 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Sat, 8 Feb 2025 01:17:55 +0100 Subject: [PATCH] Windows: Fix link error in 32-bit build by removing crypto.lib reference and implementing sha512 using BCrypt API. --- src/COMReg/COMReg.vcxproj | 5 ++- src/Common/Dlgcode.c | 69 +++++++++++++++++++++++++++++++++++ src/Setup/Portable.vcxproj | 8 ++-- src/Setup/Setup.vcxproj | 8 ++-- src/SetupDLL/SetupDLL.vcxproj | 6 +-- 5 files changed, 83 insertions(+), 13 deletions(-) diff --git a/src/COMReg/COMReg.vcxproj b/src/COMReg/COMReg.vcxproj index 4c5987a3..8af84056 100644 --- a/src/COMReg/COMReg.vcxproj +++ b/src/COMReg/COMReg.vcxproj @@ -65,7 +65,7 @@ Windows true - ..\Common\Debug\Zip.lib;..\Crypto\Debug\crypto.lib;..\Common\Debug\lzma.lib;%(AdditionalDependencies) + ..\Common\Debug\Zip.lib;..\Common\Debug\lzma.lib;%(AdditionalDependencies) copy Debug\VeraCryptCOMRegBase.exe "..\Debug\Setup Files\VeraCryptCOMRegBase.exe" @@ -88,8 +88,9 @@ true true true - ..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + ..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) true + bcrypt.dll copy Release\VeraCryptCOMRegBase.exe "..\Release\Setup Files\VeraCryptCOMRegBase.exe" diff --git a/src/Common/Dlgcode.c b/src/Common/Dlgcode.c index 6a068529..6c98b4d7 100644 --- a/src/Common/Dlgcode.c +++ b/src/Common/Dlgcode.c @@ -868,6 +868,75 @@ BOOL TCCopyFile (wchar_t *sourceFileName, wchar_t *destinationFile) return TCCopyFileBase (src, dst); } +#if !defined(_WIN64) && defined(NDEBUG) && !defined (VC_SKIP_OS_DRIVER_REQ_CHECK) +// in 32-bit build, Crypto project is not compiled so we need to provide this function here + +#pragma comment(lib, "bcrypt.lib") + +void sha512(unsigned char* result, const unsigned char* source, uint64_t sourceLen) +{ + BCRYPT_ALG_HANDLE hAlg = NULL; + BCRYPT_HASH_HANDLE hHash = NULL; + NTSTATUS status = 0; + + // Open an algorithm provider for SHA512. + status = BCryptOpenAlgorithmProvider( + &hAlg, + BCRYPT_SHA512_ALGORITHM, + NULL, + 0); + if (!BCRYPT_SUCCESS(status)) + { + goto cleanup; + } + + // Create a hash handle. + status = BCryptCreateHash( + hAlg, + &hHash, + NULL, + 0, + NULL, // Optional secret, not needed for SHA512 + 0, + 0); + if (!BCRYPT_SUCCESS(status)) + { + goto cleanup; + } + + // Hash the data. Note: BCryptHashData takes an ULONG for the length. + status = BCryptHashData( + hHash, + (PUCHAR)source, + (ULONG)sourceLen, + 0); + if (!BCRYPT_SUCCESS(status)) + { + goto cleanup; + } + + // Finalize the hash computation and write the result. + status = BCryptFinishHash( + hHash, + result, + SHA512_DIGESTSIZE, + 0); + if (!BCRYPT_SUCCESS(status)) + { + goto cleanup; + } + +cleanup: + if (hHash) + { + BCryptDestroyHash(hHash); + } + if (hAlg) + { + BCryptCloseAlgorithmProvider(hAlg, 0); + } +} +#endif BOOL VerifyModuleSignature (const wchar_t* path) { diff --git a/src/Setup/Portable.vcxproj b/src/Setup/Portable.vcxproj index a493c304..d60f68cc 100644 --- a/src/Setup/Portable.vcxproj +++ b/src/Setup/Portable.vcxproj @@ -107,7 +107,7 @@ /NODEFAULTLIB:LIBCMTD %(AdditionalOptions) - libcmtd.lib;atls.lib;mpr.lib;..\Common\Debug\Zip.lib;..\Crypto\Debug\crypto.lib;..\Common\Debug\lzma.lib;%(AdditionalDependencies) + libcmtd.lib;atls.lib;mpr.lib;..\Common\Debug\Zip.lib;..\Common\Debug\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptPortable.exe AsInvoker mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) @@ -147,7 +147,7 @@ copy PortableDebug\VeraCryptPortable.exe "..\Debug\Setup Files\VeraCrypt Portabl /IGNORE:4089 %(AdditionalOptions) - atls.lib;mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + atls.lib;mpr.lib;..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptPortable.exe AsInvoker mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) @@ -185,7 +185,7 @@ copy PortableDebug\VeraCryptPortable.exe "..\Debug\Setup Files\VeraCrypt Portabl /IGNORE:4089 %(AdditionalOptions) - mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + mpr.lib;..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptPortable.exe AsInvoker mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) @@ -223,7 +223,7 @@ copy PortableDebug\VeraCryptPortable.exe "..\Debug\Setup Files\VeraCrypt Portabl /IGNORE:4089 %(AdditionalOptions) - mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + mpr.lib;..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptPortable.exe AsInvoker mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) diff --git a/src/Setup/Setup.vcxproj b/src/Setup/Setup.vcxproj index a82b967d..2d10ba22 100644 --- a/src/Setup/Setup.vcxproj +++ b/src/Setup/Setup.vcxproj @@ -107,7 +107,7 @@ /NODEFAULTLIB:LIBCMTD %(AdditionalOptions) - libcmtd.lib;atls.lib;mpr.lib;..\Common\Debug\Zip.lib;..\Crypto\Debug\crypto.lib;..\Common\Debug\lzma.lib;%(AdditionalDependencies) + libcmtd.lib;atls.lib;mpr.lib;..\Common\Debug\Zip.lib;..\Common\Debug\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.exe RequireAdministrator mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) @@ -148,7 +148,7 @@ copy Debug\VeraCryptSetup.exe "..\Debug\Setup Files\VeraCrypt Setup.exe" >NUL /IGNORE:4089 %(AdditionalOptions) - atls.lib;mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + atls.lib;mpr.lib;..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.exe RequireAdministrator mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) @@ -186,7 +186,7 @@ copy Debug\VeraCryptSetup.exe "..\Debug\Setup Files\VeraCrypt Setup.exe" >NUL /IGNORE:4089 %(AdditionalOptions) - mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + mpr.lib;..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.exe RequireAdministrator mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) @@ -224,7 +224,7 @@ copy Debug\VeraCryptSetup.exe "..\Debug\Setup Files\VeraCrypt Setup.exe" >NUL /IGNORE:4089 %(AdditionalOptions) - mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + mpr.lib;..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.exe RequireAdministrator mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) diff --git a/src/SetupDLL/SetupDLL.vcxproj b/src/SetupDLL/SetupDLL.vcxproj index 71a61ba5..af0d6fb8 100644 --- a/src/SetupDLL/SetupDLL.vcxproj +++ b/src/SetupDLL/SetupDLL.vcxproj @@ -89,7 +89,7 @@ /NODEFAULTLIB:LIBCMTD %(AdditionalOptions) - version.lib;msi.lib;libcmtd.lib;atls.lib;mpr.lib;..\Common\Debug\Zip.lib;..\Crypto\Debug\crypto.lib;..\Common\Debug\lzma.lib;%(AdditionalDependencies) + version.lib;msi.lib;libcmtd.lib;atls.lib;mpr.lib;..\Common\Debug\Zip.lib;..\Common\Debug\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.dll RequireAdministrator mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) @@ -130,7 +130,7 @@ copy Debug\VeraCryptSetup.dll "..\Debug\Setup Files\VeraCryptSetup.dll" >NUL: /IGNORE:4089 %(AdditionalOptions) - version.lib;atls.lib;msi.lib;mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + version.lib;atls.lib;msi.lib;mpr.lib;..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.dll RequireAdministrator mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs) @@ -169,7 +169,7 @@ copy Debug\VeraCryptSetup.dll "..\Debug\Setup Files\VeraCryptSetup.dll" >NUL: /IGNORE:4089 %(AdditionalOptions) - version.lib;msi.lib;mpr.lib;..\Common\Release\Zip.lib;..\Crypto\Release\crypto.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) + version.lib;msi.lib;mpr.lib;..\Common\Release\Zip.lib;..\Common\Release\lzma.lib;%(AdditionalDependencies) $(OutDir)VeraCryptSetup.exe RequireAdministrator mpr.dll;bcrypt.dll;user32.dll;gdi32.dll;advapi32.dll;shell32.dll;ole32.dll;oleaut32.dll;shlwapi.dll;setupapi.dll;wintrust.dll;comctl32.dll;%(DelayLoadDLLs)