From bcd3ee7ab858d62beb36af9f5986544b68a3dd35 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 28 Apr 2021 16:36:56 -0500 Subject: Clean up more 32-bit assumptions. --- src/dutil/cryputil.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/dutil/cryputil.cpp') diff --git a/src/dutil/cryputil.cpp b/src/dutil/cryputil.cpp index c5c1b221..24bb83f1 100644 --- a/src/dutil/cryputil.cpp +++ b/src/dutil/cryputil.cpp @@ -291,6 +291,9 @@ HRESULT DAPI CrypHashBuffer( HRESULT hr = S_OK; HCRYPTPROV hProv = NULL; HCRYPTHASH hHash = NULL; + DWORD cbDataHashed = 0; + SIZE_T cbTotal = 0; + SIZE_T cbRemaining = 0; // get handle to the crypto provider if (!::CryptAcquireContextW(&hProv, NULL, NULL, dwProvType, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) @@ -304,10 +307,17 @@ HRESULT DAPI CrypHashBuffer( CrypExitWithLastError(hr, "Failed to initiate hash."); } - if (!::CryptHashData(hHash, pbBuffer, static_cast(cbBuffer), 0)) + do { - CrypExitWithLastError(hr, "Failed to hash data."); - } + cbRemaining = cbBuffer - cbTotal; + cbDataHashed = (DWORD)min(DWORD_MAX, cbRemaining); + if (!::CryptHashData(hHash, pbBuffer + cbTotal, cbDataHashed, 0)) + { + CrypExitWithLastError(hr, "Failed to hash data."); + } + + cbTotal += cbDataHashed; + } while (cbTotal < cbBuffer); // get hash value if (!::CryptGetHashParam(hHash, HP_HASHVAL, pbHash, &cbHash, 0)) -- cgit v1.2.3-55-g6feb