diff options
author | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2025-02-08 01:17:55 +0100 |
---|---|---|
committer | Mounir IDRASSI <mounir.idrassi@idrix.fr> | 2025-02-08 01:17:55 +0100 |
commit | a2f11e11024a104dabf6921cd276baa4255473e0 (patch) | |
tree | 1c2b2271306449823e2c8865c48a610f9780e1c6 /src/Common | |
parent | effabb4c53adfb43d0c371f46e608e7deec2f828 (diff) | |
download | VeraCrypt-a2f11e11024a104dabf6921cd276baa4255473e0.tar.gz VeraCrypt-a2f11e11024a104dabf6921cd276baa4255473e0.zip |
Windows: Fix link error in 32-bit build by removing crypto.lib reference and implementing sha512 using BCrypt API.
Diffstat (limited to 'src/Common')
-rw-r--r-- | src/Common/Dlgcode.c | 69 |
1 files changed, 69 insertions, 0 deletions
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) { |